I would also like to hear recommended books.
What about forums? Are there any "online multiplayer game programming" specific forums out there? So far I've seen network programming sections in some forums - it would be great to find a forum dedicated to network programming...
Anyway, as I'm developing the game further, reading these articles I have developed a high level model for the server-client. I believe this reminds Quake 3 model + best practises of RakNet.
EDIT: This code is to handle gameplay, it won't deal with checking connections, game times or other similar stuff
So basically the server would keep pushing object states to clients until each client informs "state received". As there won't be many changes in states (I believe there's only roughly 20-30 objects moving on screen, most of them being enemy units which will have waypoints/targets that are not updated much) I think this model could work very well.
Receive object state
Inform server "object state received"
update object state
send request to server asking to change object state
if (change is okay)
change object state
flag object NOT SENT TO CLIENTS // clear for all clients
if (object flag is NOT SENT TO CLIENT) // test each client
send state to client
flag object to SENT TO CLIENT // specific client
I would also bear in mind that:
- no useless data would be sent (when object state changes I would only send what's really been changed (like position, target, health, action - sometimes it might be only action, sometimes only position+target)
- only newest state would be sent (if there's quick changes in the action of the object, like "receive healing" and then another change "get hit by character", then only the last change would be handled). This could mean that if fighting gets really intense, it might be possible that with poor connections some client might not show all the animations (like "receive healing" animation / effects could be missed, as the "get hit by character" state would replace the old state. This would be only visual loss - clients would receive the latest health point / position changes from servers nevertheless. I might add some animation buffer in the future if it looks like too many animations/effects are missed - but so far I suppose this is a quite decent solution.
- the biggest benefit from this approach would naturally be that it would be extremely easy to add new updates/effects to the character without need to touch much network code: if I need to have a new animation or effect, I can simply add constant RECEIVE_HEALING and let the server change user status to RECEIVE_HEALING, in the client's end client could see RECEIVE_HEALING and do appropriate animations/effects right away. I wouldn't need to have separate client code for "askHostForHealing", "receiveHealing" etc...
- Bit flagging. I'm going to use some number bytes to tell about the object state changes. For example: 1000 would mean that only object position is changed. 1011 could mean that object position (X/Y/Z), health and weapon values needs to be updated. 2 bytes gives me 16 different change values - and 4 bytes would let me use 32 which should be more than enough.
Little addition: by state I mean all the attributes and values of object. For example, player character has several attributes like "positionX, positionY, positionZ, health, action, actionModifier, weapon" and so on.