策略游戏服务器概念
我计划创建一款基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
基本上,您必须在速度与安全性之间做出选择。
让客户端完成工作和计算速度更快,但数据存在风险,因为客户端可以操纵数据。
另一方面,让服务器完成所有工作速度较慢,但数据更安全。
您可以选择双重方法,决定让客户端仅计算一些数据,同步并检查其有效性,然后让其余部分在服务器上执行。
它还取决于游戏运行的速度、要计算的数据量、服务器和带宽/连接的速度等......
您应该对这两种方法进行原型设计并尝试一些测试来模拟客户端和服务器负载。
如果游戏很小,我会选择更多的服务器端工作。另一方面,对于一个非常复杂的游戏来说,向客户端分享更多的工作可能是最好的。无论如何,我认为总是需要进行权衡。
以下是一些您可能会发现有用的链接
多人游戏编程简介
<一个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
我建议观看以下有关基于浏览器的游戏开发概念的资源:
I would suggest to watch these resources regarding browser based game development concepts:
不幸的是我没有基于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.
您应该在服务器上拥有游戏状态和逻辑,否则您的游戏很容易作弊。服务器是游戏国家的最终权威。
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.
不确定 WebGL,但据我了解,以下方法会很好。
此方法将特定于常见对象,而不是 UI/客户端特定对象。
Not sure about WebGL, but to my understanding following approach will be good.
This approach will be specific to common objects not UI / client specific objects.
出于安全原因,所有逻辑都应该在服务器端,所有数据更新都在服务器上。
但客户端能够先预测一些逻辑并播放动画,这称为客户端预测。
服务器端负责验证客户端逻辑,如果没有作弊,则全部完成。
如果有人作弊,服务器可以告诉客户端返回到正确的状态。
如果您使用 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