1

I'm currently trying to write (as a part of "simple multiplayer game as an example of real time client-server application" assignment) multiplayer game server for simple fast-paced game for few players (less than 20 i think). I'm using TCP sockets for packets that require guaranteed delivery (ie.: chat messages, login and logout requests, ping packets, etc) and UDP for everything that does not necessarily need to be delivered since only the last packet that got through is important (ie.: user input, game world and objects updates, etc).

I should mention here, how my game world looks like. Every object server side has its id, role and owner members. Id is basically identifier for clients so, once I send them object updates they know which object to update on their side. Owner is information about object owner, ie.: player which controls the actor. I use it to remove orphaned objects once player loses connection / logs out. Most objects however has this value set to Server. And finally role determines whether object is important to clients. This can be set to ServerSide (for objects that do not need to be replicated to clients as they are only used in server side game state calculation), RelevantToOwner (this objects get replicated only to their owner, ie.: player private inventory does not need to be replicated to everyone), RelevantToList (object gets replicated to all players from list, ie.: i have list of players to whom the object is visible and i replicate only to them) and RelevantToAll (replicate to everyone).

When user sends login packet I check whether I have free slot and if yes, then I replicate world to him (send current world state - every object that does not have role set as ServerSide or RelevantToList - unless of course the client is on the list for that object).

Then after each iteration of server game state update loop I send exactly same thing - whole world state.

When users send logout packet I remove him from logged in clients, free slot, and remove all orphaned objects from game world (objects that had this user as owner).

Here are my questions:

  • Is this model suitable for real-time multiplayer game or am I doing it horribly wrong?
  • Is there a way to reduce amount of packets sent after the initial world replication (ie.: updating only objects which state has changed since last iteration. I've given it a thought and so far I've encountered one huge problem with this approach - if UDP packet from previous iteration is lost and state of the object haven't changed in subsequent iterations, the object will not be updated on the player side.)
  • How can i pack multiple object updates into one packet (I'm currently sending one object / packet which is inefficient and also probably horribly wrong.
  • Could someone point me to some working example (source would be nice) of simple Client/Server game so I can see how professionals do it? C++ or C would be nice but Java / C# / Python are fine too.
1
  • btw if this is an assignment, really you should add the homework tag Commented Aug 24, 2012 at 8:59

1 Answer 1

2

This depends a lot so much on what type of game you're talking about - example: Im doing roughly the same thing in a text based muck game.. My updates are simple, on arrival, send room details. On change, send messages to say people/object came/went. Done.

UDP is how most online games work just because they need to deal ith 100k+ connectios. UDP loss is often why players "warp" in game. If you're doing 20 people and you can guarentee that, then sticking with tcp will help.

do you need to send them the whole world? Is your world not made of zones/rooms. Normally you send the smaller area. It also depends on how much data on the objects within that you should send, for example. If a player has an inventory, no point sending that to all the other players unless they specifically ask for it - items worn (if a visual game then yes you need to or it draws them wrong)

Just because we have much faster connections these days doesnt mean we shouldnt take into consideration some people dont. You should try and send updates only and have the client maintain its own state, and then, when you change zones, and reload the area, you ensure sync.

To pack object changes in a packet, most likely Im guessing its location changes, eg co-ordinates, and availability, eg, person picks up item. Have an upate structure, item_id, update_type, update_values[], then you can send a chunk of updates.

Are you after text based or more mmorg type? text based I can say google tinymuck, or tinymush, tinymud, there are plenty, graphics ones? thats harder, you could lookup some of the old EQ code and WoW emulators maybe..

Sign up to request clarification or add additional context in comments.

6 Comments

This depends a lot so much on what type of game you're talking about It will be probably simple tile-based MUD. Not sure yet... Is your world not made of zones/rooms. actually, it's one giant zone atm. Normally you send the smaller area. That's why i added the role member - now i send only objects relevant to given cliuent.
And all the other questions I asked?
Have an upate structure, item_id, update_type, update_values[], then you can send a chunk of updates. and by chunk you mean packet consisting of several such structures, right? Also, If you're doing 20 people and you can guarentee that, then sticking with tcp will help. Unfortunately I cannot choose the protocol, it's part of the assignment.
Fine, but you us as a community asked a bunch of vague questions, didnt answer a number of specific questions. You can still do the same theory with udp, of course you jsut dont guarentee receipt, but thats fine. You havent really answered about the sending of the world data... If you insist on a giant zone, then only thing you can do is only send data from areas visible.
I do not insist on anything. It's just ho it is done now, and I'm not saying i will not change it in the future. Also, as I stated before, I AM currently sending only objects relevant to given client. But I guess world divided into zone would have it pros. I'm assuming I would be able to update zone states independently and then send to player only relevant objects from zone the player is in. Also, I'm looking at the sources of TinyMUX atm, guess I'll have something to read for a while.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.