策略游戏服务器概念

发布于 2024-12-01 06:41:37 字数 325 浏览 2 评论 0原文

我计划创建一款基于 WebGL 的实时策略游戏,玩家可以一起玩。我将使用 Node.js 创建游戏服务器和用于实时连接的 Websocket。

我已经完全不知道什么是同步客户端的最佳概念。

一种可能性是仅将用户的订单(移动单位、建筑等)发送到服务器,服务器将它们发送到所有其他客户端。但在这里,我遇到了延迟的问题。我认为游戏会以这种方式异步。

另一种可能性是在服务器上计算游戏。客户端仍然向服务器发送指令,但是服务器现在以高间隔向客户端发送所有单元和建筑物的所有改变的状态。问题在于数据量很大以及速度有多快......

您还有其他想法或改进建议吗?

谢谢!

I´m planning to create a WebGL-based, realtime strategy game, where players are able to play together. I´ll use Node.js to create the game server, and websockets for realtime connections.

I´ve broken my mind about what would be the best concept to synchronize the clients.

One possibility would be to send only the orders of the users (moving units, building buildings etc.) to the server, which sends them to all other clients. But here, I have the problem of the delay. I think that the games would get async this way.

Another possibility would be to calulate the game on the server. The clients still send the instructions to the server, but the server sends now all changed states of all units&buildings to the clients in a high interval. The problem is here the high amount of data and how fast this can be...

Do you have some other ideas or improvement proposals?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

烂柯人 2024-12-08 06:41:37

基本上,您必须在速度安全性之间做出选择。

让客户端完成工作和计算速度更快,但数据存在风险,因为客户端可以操纵数据。

另一方面,让服务器完成所有工作速度较慢,但​​数据更安全。

您可以选择双重方法,决定让客户端仅计算一些数据,同步并检查其有效性,然后让其余部分在服务器上执行。

它还取决于游戏运行的速度、要计算的数据量、服务器和带宽/连接的速度等......

您应该对这两种方法进行原型设计并尝试一些测试来模拟客户端和服务器负载。

如果游戏很小,我会选择更多的服务器端工作。另一方面,对于一个非常复杂的游戏来说,向客户端分享更多的工作可能是最好的。无论如何,我认为总是需要进行权衡。

以下是一些您可能会发现有用的链接

多人游戏编程简介

<一个href="http://zoo.cs.yale.edu/classes/cs538/readings/papers/terrano_1500arch.pdf#search=%22Real%20time%20strategy%20networking%20lockstep%22" rel="nofollow noreferrer">真实时间策略网络

多人游戏编程线程(旧的但仍然有许多有用的链接)

延迟补偿

防止多人游戏作弊

第一个链接在过去对我帮助很大,恕我直言,它仍然是该主题上可用的最佳资源之一。

书籍

多人游戏编程

Basically you have to decide between speed vs security.

Letting the client do the job and the calculations is faster but the data is at risk because the client can manipulate the data.

On the other side, having the server do all the job is slower but the data is more secure.

You could opt for a dual approach, decide to let the client calculate only some data, synchronize and then check for its validity, and let the rest being executed on the server.

It also depends on how fast the game runs, the amount of data to calculate, the speed of the server and band/connections, etc...

You should prototype both methods and try some tests to emulate the client and servers load.

If the game is small I would opt for a more server-side work. On the other hand, for a much complex game probably sharing more work to the client is best. Anyway I think a tradeoff is always needed.

Here are a few links you may find useful

Multiplayer Game Programming Introduction

Real time strategy networking

Multiplayer Programming thread (old but still with many useful links)

Lag Compensation

Prevent Multiplayer Cheating

The first link has helped me a lot back in the days and imho is still one of the best resources avaiable on the subject.

Books

Multiplayer Game Programming

眼角的笑意。 2024-12-08 06:41:37

不幸的是我没有基于WebGL的网络游戏的经验,但通常让游戏逻辑在客户端执行并同步结果是一个很好的方法。

在这种方法中,跟踪哪个游戏对象由哪个客户端“拥有”非常重要。客户端仅发送自己对象的更新(创建、更新、删除),并从其他客户端接收其他游戏对象的更新。

此外,您可以设置一个消息传递框架来传递其他消息,例如“玩家已进入/离开”或类似的消息。

事实证明,这个概念对我创建的游戏很有用,我希望它对您也同样有用。

Unfortunately I have no experiences in WebGL based online games, but usually it is a good approach to let the game logic be executed on the client side, and synchronize the results.

In this approach it is important to keep track of what game object is "owned" by what client. Clients only send updates (creation, update, deleteion) from their own objects and receive the updates of the other game objects from the other clients.

Additionally you can set up a messaging framework to deliver additional messages like "Player has entered/left" or something like that.

This concept has proven useful for a game I created, and I hope it is as useful to you.

非要怀念 2024-12-08 06:41:37

您应该在服务器上拥有游戏状态和逻辑,否则您的游戏很容易作弊。服务器是游戏国家的最终权威。

You should have the game state and logic on the server, otherwise your game is wide open to cheating. The server is the ultimate authority the game state.

神回复 2024-12-08 06:41:37

不确定 WebGL,但据我了解,以下方法会很好。

  1. 初始化服务器上​​的所有对象(在玩家之间通用)并运行它们
  2. 在客户端启动时,它将请求所有渲染器(与特定客户端相关)在服务器上运行的对象。
  3. 客户端将为所有收到的渲染器渲染 UI 上的对象。
  4. 当客户端对 UI 进行任何更新时,更改将通知到服务器,服务器将相应地更新对象。
  5. 当玩家之间公共的对象被一个玩家修改时,每个玩家(客户端)将收到通知进行 UI 更改。

此方法将特定于常见对象,而不是 UI/客户端特定对象。

Not sure about WebGL, but to my understanding following approach will be good.

  1. Initialize all objects (which are common across players) on server and run them
  2. On client start, it will request all renderer (related to specific client) for the objects running on server.
  3. client will render the objects on UI for all recieved renderer.
  4. When client make any update on UI, changes will be notified to server, and server will update the object accordingly
  5. When objects common between players are modified by one player, each player (client) will be notified to make UI changes.

This approach will be specific to common objects not UI / client specific objects.

久伴你 2024-12-08 06:41:37

出于安全原因,所有逻辑都应该在服务器端,所有数据更新都在服务器上。

但客户端能够先预测一些逻辑并播放动画,这称为客户端预测。

服务器端负责验证客户端逻辑,如果没有作弊,则全部完成。
如果有人作弊,服务器可以告诉客户端返回到正确的状态。

如果您使用 Node.js 作为服务器,有一个开源框架 pomelo
还有一个完整的源代码演示和在线演示:lordofpomelo

For security reasons, all the logic should be on servers side, and all the data update is on server.

But the client is able to predict some logic and play animation first, which is called client prediction.

The server side is in charge of verify the client logic, if there is no cheating, all done.
If there is someone cheating, the server can tell the client to go back to right state.

If you are using node.js for server, there is an open source framework , pomelo .
And there is also a full source code demo and online demo for it: lordofpomelo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文