2

I'm creating a 2d minecraft style game, where the map is stored in an 2 dimensional int array. You can place and destroy blocks and ai-controlled characters will walk around the map. The game's made using xna/c#. The problem is that i don't have much experience coding networked games.

Which protocol should i use? UDP, TCP? Or perhaps the lidgren library? (which uses UDP + reliability)

Should i let the following things be done on the client, server or on both?

  1. ai/pathfinding
  2. collision detection

Also, is it good practice to send destroy and place-block messages to the server? I guess that when the client starts, it first needs tot download the map. And then changes to the map will be made in paralell to the maps on the clients and the one on the server....

Finally, should i broadcast the positions of the characters only when they change (tends towards TCP) or should i continually send them (tends towards UDP)?

Any help is usefull :)

Thanks in advance.

PS: sorry about the bad quality of my english (i'm dutch)

4

2 回答 2

2

我觉得好像下面的线程有一些对你有用的好信息。就像 AmitApollo 所说,简而言之,UDP 速度更快,但可靠性较低。如果您通过该网络发送的所有信息都非常重要,那么 TCP 可能是最好的实现方式。您可以随时尝试两者,看看您有什么样的性能/延迟命中。一般来说,我读过的大多数快节奏/实时游戏都使用了 UDP。

安卓游戏UDP/TCP?

于 2013-06-24T19:38:50.133 回答
1

一切都应由服务器验证,以使游戏不可破解或修改;通过修改内存地址或其他一些漏洞。

AI/寻路和冲突都应该由服务器验证,但是由于握手和窗口开销,两者都使用 TCP 会导致拥塞。今天的 MMO 使用带有自定义拥塞控制和握手的 UDP 数据包。作为第一个版本,您应该简单地使用 UDP 数据包 - 当数据包在传输过程中丢失或丢失时,游戏将简单地lag冻结,直到 UDP 数据包通过。您的游戏的后续版本可以使用 UDP 实现自定义确认设置,以便角色在验证之前暂停。

Client --    Movement request UDP    --> Server
Client: Character is frozen              Server: Validate coordinates on map
Client: <-- YES or NO to move request -- Server
Client: Move character based on response

这确保了角色的每一个动作都是有效的。您还需要安全密钥或协议安全性,这样不仅任何人都可以发送坐标进行验证。

您可能认为这种设计会落后于您的游戏,但如果设计得当,它将是安全的,并且不会受到客户端黑客的影响。请记住将您的 UDP 数据包设计得尽可能小(按大小计算)。

于 2014-01-15T15:26:53.643 回答