Archived

This topic is now archived and is closed to further replies.

LonelyStar

how to handle network in fast action games

Recommended Posts

Hi everybody, I am writing an Multiplayer-Action Game. I have some little Problems handling the Network Messages: The Game is Client-Server based! Whenever a client is doing something (when a key is pressed on the clients keyboard), like accelerating, breaking, shooting e.t.c. a messageis send to the Server (TCP). The Server then Broadcast the Message to all clients and in the moment the acting Client recieves the answer, he "fullfills" the action (so a client waits befor the Message is send to the Server and back befor he does anything). At the same time the Clients send a "Update State" Message (UDP) to the Server a few times per second. That is absolutly neccessary because the mouse is an important input device and I can not send message everytime the mouse changes. The Server is also Broadcasting "update State" messages to all clients. My Question: First of all, is this a good way of doing it? Or is there some better concept I should have a look at? My Problem is, that when it takes like 200ms to send to the Server and back, actions are taken out a little slow, or not? But I can not do an action befor all clients now about it! It would also be very cool if someone of you knows some public-source Internet-Multiplayer action game which is small enough that I could see how Network is handled. Well, thanks a lot! Nathan

Share this post


Link to post
Share on other sites
I didn''t look at it thoroughly, bot 3D Realms recently released the source code for Rise ot the Triad which had network multiplayer. You might be able to salvage something from that. You can get the source here (direct link here). The game is quite old but the concepts should hold true.

Share this post


Link to post
Share on other sites
[qoute]Oh but you can![/qoute]
How? I mean, the other Clients can predict what is happening when their is User-Input they don''t know about, can they? I mean, if the action is done befor the other players can see it, Players with a huge can do things the others won''t see to soon ?!?

Share this post


Link to post
Share on other sites
This is indeed a complicated topic...

Here is a link to the Quake 2 Sourcecode, which as far as I know uses UDP (TCP is too inefficient) for network communication. However, I am not sure whether it uses client/server or peer to peer network model....

ftp://ftp.idsoftware.com/idstuff/source/quake2.zip

Share this post


Link to post
Share on other sites
quote:
Original post by LonelyStar
[quote]Oh but you can![/qoute]
How? I mean, the other Clients can predict what is happening when their is User-Input they don''t know about, can they? I mean, if the action is done befor the other players can see it, Players with a huge can do things the others won''t see to soon ?!?


Your client should predict what the server will send it (ie, your physics and other game logic should be accessible to the client) and update the display based on what it expects the server to send back. When the server actually responds, the client then compensates for any differences between what was predicted and what actually happened.

Share this post


Link to post
Share on other sites
if you take the delta of mouse moves, you only need to send 2 bytes per mouse move.

so even if the user moved the mouse 32 times a second... that would only be 64bytes/sec... and you have at least 1500bytes/sec to play with (and thats only if you want to accomidate 28.8k users)

Share this post


Link to post
Share on other sites
quote:
Original post by Smurfwow
if you take the delta of mouse moves, you only need to send 2 bytes per mouse move.

so even if the user moved the mouse 32 times a second... that would only be 64bytes/sec... and you have at least 1500bytes/sec to play with (and thats only if you want to accomidate 28.8k users)


First, a UDP packet has a 28-byte header. Second, you don''t want to send 30 packets a second just cuz the user is wiggling the mouse back and forth. In fact, if you are sending more than 10 packets/second to the server, you are sending too many (no matter how small).

Share this post


Link to post
Share on other sites
ok.. so my theory sux

so, i guess to make it(the big header) worthwhile youd want to send a fair bit of data per packet...

how many packets does quake(or any fps) send for mouse position updates?

Share this post


Link to post
Share on other sites