游戏中的网络问题
我正在寻找特定于游戏的网络设计和技巧。我知道一些问题,并且对其中一些问题有一些部分解决方案,但可能还有一些我还看不到的问题。我认为这个问题没有明确的答案,但我会接受我真正喜欢的答案。我可以想到 4 类问题。
网络不好
客户端发送的消息需要一些时间才能到达服务器。服务器不能只处理 FCFS,因为这对延迟较高的玩家不公平。对此的部分解决方案是消息上的时间戳,但为此您需要两件事:
- 能够信任客户端时钟。 (我认为这是不可能的。)
- 您可以测量恒定的延迟。对于可变延迟你能做什么?
许多游戏使用 UDP,这意味着消息可能会丢失。在这种情况下,他们会尝试根据已有的信息来估计游戏状态。连接再次工作后,如何知道估计的状态是否正确?
在 MMO 游戏中,服务器处理大量客户端。分配负载的最佳方法是什么?基于游戏中的位置?将一组客户端绑定到服务器?您可以避免通过服务器发送所有内容吗?
玩家离开
当这种情况发生时,我看到了两种不同的行为。在大多数FPS游戏中,如果主持游戏的玩家(我猜他是服务器)离开,其他人就无法玩。在大多数 RTS 游戏中,如果任何玩家离开,其他玩家可以在没有他的情况下继续玩游戏。没有专用服务器怎么可能?大家都知道完整的状态吗?他们是否以某种方式转移了服务器的角色?
信息获取
下一个问题可以通过专用服务器来解决,但我很好奇是否可以在没有专用服务器的情况下完成。在很多游戏中,玩家不应该知道游戏的完整状态。 RTS 中的战争迷雾和 FPS 中的墙壁就是很好的例子。但是,他们需要知道某个操作是否有效。 (例如,你能从那里向我射击吗?还是你在地图的另一边。)在这种情况下,客户端需要验证对未知状态的更改。这听起来像是可以通过巧妙使用加密原语来解决的问题。有什么想法吗?
作弊
上述一些问题在受信任的客户端环境中很容易出现,但不能假设。例如,是否有适用于 80% 正常用户 - 20% 作弊者环境的解决方案?你真的可以制作一个有效的反作弊软件(并且不需要像内核模块这样荒谬的东西)吗?
我确实阅读了这个问题和一些答案 https://stackoverflow.com/ questions/901592/best-game-network-programming-articles-and-books,但其他答案链接到不可用/受限内容。这是一个独立于平台/操作系统的问题,但也欢迎针对特定平台/操作系统的解决方案。
I am looking for networking designs and tricks specific to games. I know about a few problems and I have some partial solutions to some of them but there can be problems I can't see yet. I think there is no definite answer to this but I will accept an answer I really like. I can think of 4 categories of problems.
Bad network
The messages sent by the clients take some time to reach the server. The server can't just process them FCFS because that is unfair against players with higher latency. A partial solution for this would be timestamps on the messages but you need 2 things for that:
- Be able to trust the clients clock. (I think this is impossible.)
- Constant latencies you can measure. What can you do about variable latency?
A lot of games use UDP which means messages can be lost. In that case they try to estimate the game state based on the information they already have. How do you know if the estimated state is correct or not after the connection is working again?
In MMO games the server handles a large amount of clients. What is the best way for distributing the load? Based on location in game? Bind a groups of clients to servers? Can you avoid sending everything through the server?
Players leaving
I have seen 2 different behaviours when this happens. In most FPS games if the player who hosted the game (I guess he is the server) leaves the others can't play. In most RTS games if any player leaves the others can continue playing without him. How is it possible without dedicated server? Does everyone know the full state? Are they transfering the role of the server somehow?
Access to information
The next problem can be solved by a dedicated server but I am curious if it can be done without one. In a lot of games the players should not know the full state of the game. Fog-of-war in RTS and walls in FPS are good examples. However, they need to know if an action is valid or not. (Eg. can you shoot me from there or are you on the other side of the map.) In this case clients need to validate changes to an unknown state. This sounds like something that can be solved with clever use of cryptographic primitives. Any ideas?
Cheating
Some of the above problems are easy in a trusted client environment but that can not be assumed. Are there solutions which work for example in a 80% normal user - 20% cheater environment? Can you really make an anti-cheat software that works (and does not require ridiculous things like kernel modules)?
I did read this questions and some of the answers https://stackoverflow.com/questions/901592/best-game-network-programming-articles-and-books but other answers link to unavailable/restricted content. This is a platform/OS independent question but solutions for specific platforms/OSs are welcome as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
认为密码学可以解决此类问题是一个非常常见且非常严重的错误:客户端本身当然必须能够解密它,所以这是完全没有意义的。您并没有增加安全性,您只是增加了模糊性(并且将被破解)。
作弊过于特定于游戏。有些游戏无法完全消除这种情况(FPS 中的瞄准机器人),而有些游戏如果你没有搞砸,则根本不可能消除这种情况(基于服务器的回合制游戏)。
一般来说,此类网络问题与预测密切相关,这是一个非常复杂的主题,充其量,并且在 关于它的著名 Valve 文章。
Thinking cryptography will solve this kind of problem is a very common and very bad mistake: the client itself of course have to be able to decrypt it, so it is completely pointless. You are not adding security, you're just adding obscurity (and that will be cracked).
Cheating is too game specific. There are some kind of games where it can't be totally eliminated (aimbots in FPS), and some where if you didn't screw up will not be possible at all (server-based turn games).
In general network problems like those are deeply related to prediction which is a very complicated subject at best and is very well explained in the famous Valve article about it.
是的,可以。由于延迟时间各不相同,试图准确猜测某人的延迟时间并不公平。
服务器根本不需要猜测——它知道状态。客户端只需在连接断开时进行猜测 - 当连接恢复时,将向其发送新状态。
没有“最好的方法”。然而,地理分区的效果相当好。
仅适用于不受信任的通信,这些通信通常带宽很低,没有任何意义。
许多 RTS 游戏在所有机器上同时保持完整状态。
大多数向公众开放的游戏都需要假设一个 100% 作弊的环境。
Yes it can. Trying to guess exactly how much latency someone has is no more fair as latency varies.
The server doesn't have to guess at all - it knows the state. The client only has to guess while the connection is down - when it's back up, it will be sent the new state.
There's no "best way". Geographical partitioning works fairly well, however.
Only for untrusted communications, which generally are so low on bandwidth that there's no point.
Many RTS games maintain the full state simultaneously across all machines.
Most games open to the public need to assume a 100% cheater environment.
网络不好
延迟较高的玩家应该购买新的调制解调器。我认为增加更多延迟并不是一个好主意,因为游戏中的一个人的连接状况不佳。或者,如果您指的是微小的延迟差异,谁在乎呢?如果你拒绝 FCFS,只会让事情变得更慢、更复杂。
作弊:瞄准机器人和类似
你真的能制作出有效的反作弊软件吗?不,你不能。您无法知道他们是否正在运行您的程序或其他与您的程序类似的程序。
作弊:获取信息
如果您与可以信任的专用服务器建立了安全连接,那么作弊(例如查看超出允许范围的状态)应该是不可能的。
在一些游戏中,加密技术可以防止作弊。像扑克这样的纸牌游戏,每个玩家都有机会“洗牌”。维基百科上的详细信息:心理扑克。
理论上,使用 RTS 或 FPS,您可以加密您的游戏状态部分。然后将其发送给每个人,并且仅发送允许他们查看的部分或允许他们查看的时间的解密密钥。然而,我怀疑 2010 年我们能否实时做到这一点。
例如,如果我想验证你确实可能在位置B。那么我需要知道你来自哪里以及你何时到达那里。但如果你之前告诉过我,我就知道了一些我不被允许知道的事情。如果你事后告诉我,你可以告诉我任何你想让我相信的事情。你可以事先告诉我,加密,并在我需要验证时给我解密密钥。这意味着,您必须使用不同的加密密钥来加密您所做的每一步。哎哟。
如果您没有实施扑克网站,作弊无论如何都不会是您最大的问题。
Bad network
Players with high latency should buy a new modem. I don't think its a good idea to add even more latency because one person in the game got a bad connection. Or if you mean minor latency differences, who cares? You will only make things slower and complicated if you refuse to FCFS.
Cheating: aimbots and similar
Can you really make an anti-cheat software that works? No, you can not. You can't know if they are running your program or another program that acts like yours.
Cheating: access to information
If you have a secure connection with a dedicated server you can trust, then cheating, like seeing more state than allowed, should be impossible.
There are a few games where cryptography can prevent cheating. Card games like poker, where every player gets a chance to 'shuffle the deck'. Details on wikipedia : Mental Poker.
With a RTS or FPS you could, in theory, encrypt your part of the game state. Then send it to everyone and only send decryption keys for the parts they are allowed to see or when they are allowed to see it. However, I doubt that in 2010 we can do this in real time.
For example, if I want to verify, that you could indeed be at location B. Then I need to know where you came from and when you were there. But if you've told me that before, I knew something I was not allowed to know. If you tell me afterwards, you can tell me anything you want me to believe. You could have told me before, encrypted, and give me the decryption key when I need to verify it. That would mean, you'll have to encrypt every move you make with a different encryption key. Ouch.
If your not implementing a poker site, cheating won't be your biggest problem anyway.
由于很多人在移动设备上访问游戏,当玩家位于信号接收不良的区域或连接到速度较慢的 Wi-Fi 连接时,可能会出现“网络状况不佳”的情况。因此,这不仅仅是人口稀少地区的人们连接问题。对于移动客户端,“不良网络”可能经常发生,而且通常很难诊断。
UDP 会导致数据包丢失,但即使使用基于 TCP 和 HTTP 的游戏也会遇到客户端和客户端无法正常工作的问题。当验证数据包已发送时,服务器通信速度会变得缓慢。对于通信 UDP 数据包丢失的补偿通常取决于数据包包含的内容。如果您谈论的是运动数据,通常如果未收到数据包,服务器会插入先前的轨迹并进行位置更改。通常,游戏的处理方式是自定义的,这就是为什么人们经常避免使用 UDP,除非他们的游戏类型需要它。通常,为了处理高网络延迟,有问题的游戏会自动降低用户可用的功能数量,以便他们仍然可以与游戏交互,而不会导致用户被踢或体验太多损坏的功能。
最好您希望有一个像 Loggly 这样的日志记录工具,可以帮助您找到与不良连接和延迟相关的错误,并向您显示通过这种可见性,您可以诊断用户遇到的常见问题并制定解决这些问题的策略。
球员离开
如今大多数游戏都有专用服务器,因此这个问题基本上没有实际意义。但是,有时可以将服务器更改为另一个客户端。
作弊
很难预测玩家将如何作弊并创建一个无人能破解的防作弊系统。如今,许多作弊检测策略都是基于对日志记录和行为分析信息数据的启发式分析,以在异常发生时发现异常并将其标记以供审查。您绝对应该尽可能合理地尝试防作弊,但您也确实需要一个早期检测系统,可以发现人们正在利用的新缺陷。
With a lot of people accessing games on mobile devices, a "bad network" can occur when a player is in an area of poor reception or they're connected to a slow-wifi connection. So it's not just a problem of people connecting in sparsely populated areas. With mobile clients "bad networks" can occur very very often and it's usually EXTREMELY hard to diagnose.
UDP results in packet loss, but even games that use TCP and HTTP based can experience problems where the client & server communication slows to a crawl while packets are verified to have been sent. With communication UDP compensation for packet loss USUALLY depends on what the packets contain. If you're talking about motion data, usually if packets aren't received, the server interpolates the previous trajectory and makes a position change. Usually it's custom to the game how this is handled, which is why people often avoid UDP unless their game type requires it. Often to handle high network latency, problems games will automatically degrade the amount of features available to the users so that they can still interact with the game without causing the user to get kicked or experience too many broken features.
Optimally you want to have a logging tool like Loggly available that can help you find errors related to bad connection and latency and show you the conditions on the clients and server at the time they happened, this visibility lets you diagnose common problems users experience and develop strategies to address them.
Players leaving
Most games these days have dedicated servers, so this issue is mostly moot. However, sometimes yes, the server can be changed to another client.
Cheating
It's extremely hard to anticipate how players will cheat and create a cheat-proof system no one can hack. These days, a lot of cheat detection strategies are based on heuristic analysis of logging and behavioral analytics information data to spot abnormalities when they happen and flag it for review. You definitely should try to cheat-proof as much as is reasonable, but you also really need an early detection system that can spot new flaws people are exploiting.