Multiplayer network theory?
Hey fellas I've done plenty of single player game programming in the past, and now I'm feeling comfortable enough (and excited) to start implementing multiplayer in the game. Just to give you some background, it's a fairly simple top down 2D space shooter. Players have a ship and fly around shooting at other ships until either they get bored or they have to go to class. I've done multiplayer for this with two players sitting at one keyboard, that was easy. But actual network programming? I haven't tried this before. It's simple enough to read some tutorials and implement a command line chat program, but a graphical network game (realtime, yo) gets quite a bit more complex I imagine. I have the go ahead from some people at my University to host the server on their big fat Linux box once I'm done, and it's hosted on the University's internet connection so that's nice... only problem will be getting a port openned up but I'm not too concerned about that (they were willing to open a port to let them host a CS:S server). Now for some basics about the game and what I'm thinking of doing: I've got Raknet (free version) and plan to use that, so I'll be able to handle up to 32 connections or something (correct me if I'm wrong, I can't remember where I read that part). Anyways, here's how I was thinking it would work: -Client connects to server -Server tells client to load whatever models -Server tells client about what objects they should create (duplicates of the server data, pretty much) -main loop - clients get keyboard input - clients process input and send server info regarding what actions should be performed - server processes this information and does things like collision checks - server sends client information like updated positions of objects that will now be in their field of view and tells the client to render them Now, I'm sure that alot of that is probably wrong. Here was my original (naive?) reasoning: Process everything on the server so people don't just modify things like their own ship's HP on their computer and send that to the server. Also, with everything happening on the server, things should be synchronized. Problems with this: -I guess it could be slow (I'm new to this, don't kill me) -If indeed it is slow, there will be choppy gameplay . -How often should I be updating information from/to the server? Once per loop wouldn't be good (because of varying framerates), but that means I should do it with respect to time. So again, how often? Every 0.1s? Thanks for taking the time to read through my confused ramblings. If you could help me out by pointing me in the right direction, I'd appreciate it.
Ok.
Typcially:
1) Server tells client what "map" or "area of the world" client is in.
2) Client starts loading this map and the models of that area of the world.
3) Server starts telling client about the objects around the client in the world (including the client itself :-) Information typically includes the object template, and variable object data (such as position, veliocity and hit points).
4) For each object the client discovers, it loads the template for that object, and instantiates the graphics and behavior indicated by the template.
5) As objects receive input that changes state on the server, the input or the state of the changed objects is forwarded to clients that can see those objects, and the clients apply the same changes in state.
The exact specifics of how often you send/receive input; how you apply the input to your objects, etc, vary based on your game type. Sending data ten times a second is likely quite sufficient for a space game, even if it's fairly action oriented.
1) Server tells client what "map" or "area of the world" client is in.
2) Client starts loading this map and the models of that area of the world.
3) Server starts telling client about the objects around the client in the world (including the client itself :-) Information typically includes the object template, and variable object data (such as position, veliocity and hit points).
4) For each object the client discovers, it loads the template for that object, and instantiates the graphics and behavior indicated by the template.
5) As objects receive input that changes state on the server, the input or the state of the changed objects is forwarded to clients that can see those objects, and the clients apply the same changes in state.
The exact specifics of how often you send/receive input; how you apply the input to your objects, etc, vary based on your game type. Sending data ten times a second is likely quite sufficient for a space game, even if it's fairly action oriented.
enum Bool { True, False, FileNotFound };
Thanks for the feedback!
So, you think it's alright to do pretty much everything server-side? Then all the client gets is the position of ships (that need to be rendered) along with their velocities (so the client can guesses as to where the ship should be until the server notifies it of changes) and other particles like lasers and explosions (the server just tells the client to make an explosion, since it's all visual the client takes over from there)
So, you think it's alright to do pretty much everything server-side? Then all the client gets is the position of ships (that need to be rendered) along with their velocities (so the client can guesses as to where the ship should be until the server notifies it of changes) and other particles like lasers and explosions (the server just tells the client to make an explosion, since it's all visual the client takes over from there)
Ok.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement