views:

56

answers:

3

I am making a multiplayer game in c++ :

The clients simply take commands from the users, calculate their player's new position and communicate it to the server. The server accepts such position updates from all clients and broadcasts the same about each to every. In such a scenario, what parameters should determine the time gap between consecutive updates ( i dont want too many updates, hence choking the n/w). I was thinking, the max ping among the clients should be one of the contributing parameters.

Secondly, how do i determine this ping/latency of the clients ? Other threads on this forum suggest using "raw sockets" or using the system's ping command and collecting the output from a file .. do they mean using something like system('ping "client ip add" > file') or forking and exec'ing a ping command..

A: 

If you're going to end up doing raw-packet stuff, you might as well roll your own ICMP packet; the structure is trivial (http://en.wikipedia.org/wiki/Ping).

Oli Charlesworth
+2  A: 

This answer is going to depend on what kind of a multiplayer game you are talking about. It sounds like you are talking about an mmo-type game. If this is the case then it will make sense to use an 'ephemeral channel', which basically means the client can generate multiple movement packets per second, but only the most recent movement packets are sent to the server. If you use a technique like this then you should base your update rate on the rate in which players move in the game. By doing this you can ensure that players don't slip through walls or run past a trigger too quickly.

Your second question I would use boost::asio to set up a service that your clients can 'ping' by sending a simple packet, then the service would send a message back to the client and you could determine the time it took to get the packet returned.

Kyle C
the suggestion makes a lot of sense .. however in my scenario this wont really work .. In my game, the client sends the position of its player, the server, also does some calculations based on this position and the position of other players, and other objects in the scene. If the client sends only some of the position upadtes, then the server doesnt always know accurate positions of clients and hence may perform incorect calculations
AnkurVj
@AnkurVj: Why does the client send the position of the player? Is there some unusual requirement here? Typically, the client sends player commands, and the server determines things like positions. Otherwise, people are going to hack the client or connection to allow themselves to be wherever they like whenever they like.
David Thornley
@David Thornley: You are exactly right, the players can easily hack their clients or do things like speed hacks with the greatest of ease. @AnkurVj: you might rethink your design, the server really does need to be the ultimate authority on player position.
Kyle C
@Kyle, David, absolutely valid point, please see the comments to my question
AnkurVj
btw the asio thing would help me a lot with its "timer" feature , nice
AnkurVj
For movement, it's common to have a client send its claimed position and for the server to verify it. Sending 'commands' doesn't work well for fine-grained movement activities. This is doubly important when using UDP because you don't want to have to retransmit such data.
Kylotan
A: 

The enet library does a lot of the networking for you. It calculates latency as well.

Jay
i dont really wanna use a library for a single feature ..
AnkurVj