MMORPG 客户端/服务器编码
MMORPG 客户端/服务器通信中如何使用 UDP 和 TCP 协议?
例如:
客户端是否通过 UDP 向服务器广播(玩家位置等)? 或相反亦然?
或者它更像是使用 TCP,其中客户端请求服务器移动玩家。 服务器收到请求,移动玩家并向客户端发送玩家现在位于位置 xyz?
聊天频道必须使用TCP 来实现吗?
有这方面的好的文章/书籍吗? 我已经找到了一些零碎的东西,但似乎真正的肉和土豆是从经验中获得的。
How are the UDP and TCP protocols used in MMORPG client/server communication?
For example:
Does the client broadcast (player position, etc) via UDP to the server? or vice versa?
Or is it more like using TCP where the Client requests that the server move the player. The server receives the request, moves the player and sends back to the client that the player is now at position xyz?
The chat channels must be implemented using TCP?
Are there any good articles/books on this? I've found bits and pieces but it seems the real meat and potatoes are won from experience.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
许多游戏使用 UDP 进行与运动相关的活动 - 因此,例如,当您走路时,很可能会发送一堆 UDP 请求。 服务器仍然最终控制这是否有效,但您不一定关心是否每个数据包都到达服务器。 这就是为什么很多游戏客户端也使用某种预测机制。
关于你第二次提到的,是的,所有控制都由服务器管理是很常见的。 您不希望客户端向服务器广播任何内容; 您应该在服务器端进行错误和输入处理,以防止人们进行黑客攻击。 您还可以限制每秒的输入。
不管怎样,UDP 和 TCP 的组合是合适的——你只需要问自己,“我想要可靠性还是速度?”
A lot of games use UDP for movement related activities--so, like, when you are walking, chances are, a bunch of UDP requests are being sent. The server still ultimately controls whether that's valid, but you don't necessarily care whether every single packet gets to the server. This is why a lot of game clients also use some kind of prediction mechanism.
In terms of your second mention, yes, it's very common for all control to be managed by the server. You don't want clients to be broadcasting anything to the server; you should do error and input handling server side to prevent people from hacking. You might also limit input per second.
Anyway, a combination of UDP and TCP would be appropriate--you just need to ask yourself, "Do I want reliability or speed?"
有许多不同的可能实现,但大多数情况下,它们看起来像这样。 游戏世界中的几乎所有动作都会重复这种模式。
There are many different possible implementations, but for the most part, they'll look like this. This pattern is repeated with almost any action in the game world.
您不能依赖客户传递真实信息。 有人会破解协议并进行欺骗。 加密数据并不能阻止这种情况——只是让它变得更难一些。
客户端应该只发送移动请求等,服务器需要对请求进行健全性检查,以确保它们不违反游戏规则。 服务器应该只发送回客户端绝对需要的数据 - 你不能依赖客户端获取大量世界数据并过滤掉玩家当前无法观察到的所有内容。 有人会掌握额外的信息并利用它。
如果游戏需要“实时”,那么客户端需要假设服务器将允许移动请求并相应地更新显示 - 如果服务器稍后纠正它,则回滚移动。 在大多数情况下,客户端和服务器会达成一致,一切都会顺利进行。 当客户试图作弊时(无论如何,这都是他们的错),或者客户由于连接不良而严重滞后(对此你无能为力),他们不会同意。
You can't rely on the client to pass in truthful information. Someone will hack the protocol and cheat. Encrypting the data won't stop this - just make it a little harder to do.
The client should only send in requests for movements etc and the server needs to sanity check the requests to make sure that they don't violate the game rules. The server should only send data back that the client absolutely needs - you can't rely on the client to get a chunk of world data and just filter out everything that the player can't currently observe. Someone will get hold of the extra information and exploit it.
If the game needs to be 'real-time' then the client needs to assume that the server will allow the movement requests and update the display accordingly - and roll-back the movement if the server corrects it later. Under most conditions the client and server will agree and everything will flow smoothly. They won't agree when the client is attempting to cheat (which is their fault anyway) - or the client is lagging badly due to a poor connection (not much you can do about that).
您的问题的一半(使用的传输层协议)可以通过安装wireshark并查看流量来回答。
Half of your question (transport layer protocols used) could be answered by installing wireshark and looking at the traffic.
您可能对暗星计划感兴趣。 它是一个开源 MMO 框架。
You may be interested in Project Darkstar. It's an open source MMO framework.
我认为您可以通过阅读其他人如何实现这些类型的系统来学到很多。 在此,我可以向您介绍一下Tim Sweeney 和The Croquet Consortium 的工作
Tim Sweeney 的论文改变了我对编程的思考方式。 我极力推荐他们。
I think you can learn a lot from reading how others have implemented these types of systems. In that vain, may I point you to the work of Tim Sweeney and The Croquet Consortium
Tim Sweeney's papers transformed the way I thought about programming. I can't recommend them enough.
除了作为玩家的观察之外,我不知道任何细节,但大多数游戏绝对不会等待服务器回复来移动角色,这会破坏用户体验,除非它是回合制的。 看起来发生的情况是移动在客户端完成并发送到服务器,然后服务器将这些消息发送给其他玩家。 至少在《魔兽世界》中,如果玩家落后,你可能会看到他们仍在前进,然后神奇地出现在另一个位置,这对我来说,客户端收到的不仅仅是位置数据,还有他们正在移动以及移动的方向然后在没有进一步数据的情况下推断运动。
I don't know any details other than observations as a player, but most game most definitely do not wait for a server reply to move a character, that would kill the user experience unless it was turn-based. What looks like happens is the movement is done client-side and sent to the server which then sends those messages to other players. At least in WoW, if a player is lagging you may see them still moving forward then magically appear at another location later, which says to me that the client receives more than location data, but also that they are moving and the direction they were moving and then extrapolates the movement in absence of further data.
您最好的选择可能是查看 Planeshift 的网络代码,它是一款开源 MMO。 我相信这是现场最发达的(我上次检查过)。
Your best bet is probably to take a look at Planeshift's networking code, it's an open source MMO. I believe it's the most developed on the scene(last I checked).
我认为这个问题没有一个简短的单一答案,它的范围相当广泛。 不过,有几点需要注意:
Gamasutra 中有关于网络的文章,但我现在没有任何可用的链接。 抱歉,不确定它们是否仍然公开可用。
I don't think there's a brief single answer to this question, it's quite wide in its scope. Still, a few points:
There have been articles about networking in Gamasutra, but I don't have any links handy right now. Not ever sure if they're still openly available, sorry.