PDA

View Full Version : Network Code Design


Bachus
2004.09.14, 12:40 PM
So I'm working on the networking code for my uDG entry. While the networking specifics (opening sockets, transmitting data, etc) are no problem, I'm running into problems on the general design of the program.

The popular thing to do seems to be separate the game code into a client and server that runs separately, even in single-player mode. I shim a network layer between the two that handles communications. However, that seems woefully inefficient. If the server is also playing (or in single-player mode) then there would either need to be two copies of the game state in memory, or there would be a mess of spaghetti code to work around it.

So basically I'm looking for some insight into network code structure (specifically related to video games preferably). Tutorials, sample code, articles, snippets of wisdom, anything. Such knowledge seems to be lacking on the grand intraweb of ours.

nabobnick
2004.09.14, 01:14 PM
You could check out the Quake 2 source code, specifically the one at Fruitz of Dojo. From what it looks like the client and server are implemented in one binary, with also the option to run the game in a console as server only.

Bachus
2004.09.14, 04:38 PM
I have been looking at the Fruitz of Dojo source, and it's been a big help. Of course, we're talking production code on a finished game here, so the codebase is immense and hard to follow.

I guess I'm looking for an article or something that explains why the client-server structure is the best way to go even for single-player mode. It seems to be very popular yet very inefficient. I guess I'm missing that "Aha! It all makes sense!" moment. For some reason my brain just isn't grasping "it", whatever "it" is.

Please pardon my lack of sleep for my rambling idiocy. :wacko:

anonuser
2004.09.15, 11:17 AM
I believe Q3 did it this, don't quote me on this, you basically start the server and loopback for a connect for single player and multiplayer as well. unless running a dedicated server which is strictly a server.

I'm not sure if Q3's network code was ever released.

szymczyk
2004.09.16, 10:52 PM
I guess I'm looking for an article or something that explains why the client-server structure is the best way to go even for single-player mode.

Client-server has several advantages:

1. It's easy to add and remove players from the game. To add a player, you create a connection between the player and the server. To remove the player, you remove the connection. Without client/server when you add a player to the game, you must create a connection between the new player and every other player in the game.

2. Client/server can handle more players at one time.

3. Client/server makes it harder for players to cheat. Without a server, all you can do is trust that the other players aren't cheating.

arcnon
2004.09.26, 09:54 PM
this might help a bit. http://65.68.188.177/Networking.pdf