Good multiplayer game programming tutorials? (from beginner to advanced)

Discussion in 'Game Development (Technical)' started by Game Producer, Oct 12, 2006.

  1. Game Producer

    Moderator Original Member

    Joined:
    Jan 13, 2006
    Messages:
    1,418
    Likes Received:
    2
    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

    Code:
    ***Client: 
    updateNetwork() {
       Receive object state
       Inform server "object state received"
       update object state
    }
    updateInput() {
       if mouseclick/keyhit
          send request to server asking to change object state
    }
    ***Server:
    receiveClientAskingChange() {
       if (change is okay)
          change object state
          flag object NOT SENT TO CLIENTS // clear for all clients
    }
    
    updateNetwork() {
       loop objects
          if (object flag is NOT SENT TO CLIENT) // test each client
              send state to client
    }
    
    clientReceivedObjectState() {
       flag object to SENT TO CLIENT // specific client
    }
    
    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.

    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.
     
    #21 Game Producer, Oct 20, 2006
    Last edited: Oct 20, 2006
  2. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    Actually, there are some very useful general multiplayer programming articles in the "Massively multiplayer" books. Dont be scared by the name, plenty of good client-server oriented stuff in there too.

    In general, I think many of the "multiplayer game programming using X" kind of books arent really that useful.

    Your goal of not sending redundant data is a good one, but be aware that sometimes it is USEFUL to send data. Even if it is a simple ack/nack packet. This is because it helps keep firewalls and NAT's primed and maintains your "connection" in the list of connections.

    These days, programming multiplayer games is probably more about addressing NAT/Firewall issues than it is about game object state updates and latency etc.

    I'd definitely recommend using a low cost networking library and not rolling your own.
     
  3. Game Producer

    Moderator Original Member

    Joined:
    Jan 13, 2006
    Messages:
    1,418
    Likes Received:
    2
    I bought "3D Game Programming All In One" (to help learning Torque) and it's shame that it doesn't go that deep into "logic" of network programming. There's plenty of ok stuff in that book (about general 3D programming).

    Now - give some good tips about those MM books :)

    Naturally! My model was intended for game logic - it does not deal with connections, game time or things like that. I forgot to mention...

    I have purchased & been using one lib for a long time. It handles very well all the ugly low-level stuff for me. So far it handles NAT/Firewalls/Routers "well enough".

    Although NAT/firewalls can be tricky - and sometimes it's not in the hands of the network library to deal with them :( I remember some games by big corps "recommending switching off firewall when playing" ;) (Not sure, but I believe EA's LOTR: Battle for Middle Earth mentions something like this - I might be wrong though)
     
  4. Karja

    Original Member

    Joined:
    Dec 5, 2004
    Messages:
    232
    Likes Received:
    0
    I don't know what method your networking lib is using, but if I may be so bold as to suggest that you skim through the bottom of this blog post... I searched a bit for NAT traversal solutions, and this seemed to be the only way that would work in all(?) instances, and at the same time wouldn't require a complete proxy server.

    The basic idea is to use the stateless property of UDP in combination with a co-ordinating webserver which will ensure that both clients start the punch-through at almost the same time, and that they use matching ports etc. So, something external is needed; but nothing more than (for example) a PHP script.

    If I don't remember incorrectly, this would ensure better compatibility than STUN and simpler punch-through methods.

    [Edit: Right, sorry. There I was thinking in my DIY way again; forget this post - it's not applicable to indie developers who want to be productive.]
     
    #24 Karja, Oct 20, 2006
    Last edited: Oct 20, 2006
  5. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    One of the things that OpenTNL offers for instance, is exactly the NAT/Firewall stuff. I wouldnt dream of bothering myself with that kind of thing these days, as I prefer to be more productive.

    To be honest, the game state stuff really isnt THAT hard of a task, at least not as hard as it was in the days of 2400 baud modems etc.

    These days, your task is mainly latency hiding (prediction etc) and trying to maintain consistancy as best as possible, assuming you dont go for a truly deterministic lockstep model.

    A good example from one of the MMO books btw, talks about why you WOULDNT want to use bitmasks for designating states for update. But anyway, it does all tend to be fairly game specific. For instance an RTS game requires a fair bit of difference to a MMO to an FPS etc.

    I'd suggest getting "Massively Multiplayer Game Development" 1 & 2 (Thor Alexander as editor, charles river media publishers). There is also a multiplayer game roundtable thing usually at GDC, perhaps there are some notes from those meetings?

    In the end, this is another one of those things (like game architecture in general) where there is no *right* way to do it. Only ways that work and ways that dont.
     
  6. scriptedfun

    scriptedfun New Member

    Joined:
    Oct 18, 2006
    Messages:
    13
    Likes Received:
    0
    books

    The book Programming Linux Games by John Hall, which is also available as a PDF download, contains a chapter about adding networking to a game.

    You may also want to take a look at the book Core Techniques and Algorithms by Sanchez-Crespo Dalmau, available online via Safari, which also contains a section on multiplayer game programming. If you don't already have a subscription to Safari, you may want to avail of a free trial, which should allow you to access the book plus a few others for a few days.

    Another book which you may want to look at is Programming Role-Playing Games with DirectX. As pointed out in GameDev.net's For Beginners page, this book is a good general game programming resource despite its title. And, it contains sections on implementing networked games. It's also available online through Safari.

    All three books, being surveys of game programming in general, should contain material that is generally accessible to the average programmer.

    Another corner of GameDev.net which you may want to look at is their Networking Books category, which also contains reviews.

    A book which I saw in our university library which may also be of interest to you is NetWarriors in C++, which was reviewed in ACCU.

    As you have noted earlier, most of these books have been around for quite some time already, but the principles behind them should still be applicable today.
     
  7. impossible

    Original Member

    Joined:
    Aug 9, 2004
    Messages:
    443
    Likes Received:
    0
    I picked up a book in Japan called "MMORPG Game Server Game Programming" written by one of the lead coders of the Lineage games. It seems pretty good, and has a lot of info that I haven't seen in any books in released in the US. The problem is, its Japanese and I don't really know any Japanese :). As far as I know, there are only Korean and Japanese versions of this book. I would love to see someone localize it to English. If you want to check out the source code included with the book, you can download it here.
     
  8. Game Producer

    Moderator Original Member

    Joined:
    Jan 13, 2006
    Messages:
    1,418
    Likes Received:
    2
  9. Gaffer

    Gaffer New Member

    Joined:
    Oct 24, 2008
    Messages:
    1
    Likes Received:
    0

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer