Tutorial: Online Multiplayer with PodSixNet

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Carousel Animation, make carousel of you image gallery or anything
  • n the subject of object picking, isn't it best if the server dishes out a unique ID to each player that is permanent while they are online, then when you send a movement packet to the server, it affixes your ID to the packet, then sends it to all clients near you (in my game, it would be all clients in your sector). When they recieve the packet, they use events to pick the correct Player instance (Player.Value('ID') = IDinPacket]) or something? (we could pass the contents of the packet to construct using a function with parameters. Or can we do all this in python now without having to pass anything to construct's events?)

    On object picking...I've been getting hung up on using Sprite[instance] access which with the new version of Construct perhaps this is not the best way to go. You will notice in the tuts that that method is used ALL over the place to move objects. It is nice because it has good performance.. I'm not sure what the performance would be to pick an object based on ID (of course you could improve it by only picking objects in your sector/screen which should be sufficient).

    So you could probably do something like this:

    1. New player connects

    2. Server issues unique ID to the client with command to spawn a new "myplayer" instance. You are planning to use instances of the same player sprite, correct? When the new sprite is spawned, the 'ID' of the sprite is set in Python using:

    System.Create('Sprite',1,0,0)
    objRef=SOL.Sprite  #this gets the reference of the new Sprite.
    objRef.Value('ID') = uniqueID [/code:1927f3g8]
    
    3. This same info is sent to all other players in the same sector so they too can spawn the new instance.
    4. Each tick, player movement, etc is sent to the server along with the uniqueID.
    5. The server forwards the movement info to all clients in same sector
    6. Each client then picks by value as you mentioned to update the correct myplayer instance.  This can all be done in Python now.
    
    So instead of:
    [code:1927f3g8]# function to manage player movement
       def Network_move(self, data):      
          myplayer[data['player']-1].SetPosition(data['playerx'],data['playery'])    
          [/code:1927f3g8]
    
    You would have:
    [code:1927f3g8] def Network_move(self, data):
         if myplayer.Value('ID') == data['uniqueID']:
              myplayer.SetPosition(data['playerx'],data['playery'])
    
    [/code:1927f3g8]
    
    I haven't tested the above out, but believe it will work.  You would of course need to limit your search through myplayerto only those objects in sector for performance reasons.
    
    See this thread, which you probably have already read.
    
    So with this new approach you lose the coolness of being able to act on your sprite instances directly, you get around all the problems of accessing instances by index when a sprite is destroyed.. which screws up the numbering system.
  • So you're saying its up to the player to change his own health in this time. What if the DoT kills the player? That means that its up to the client to decide when the dot has killed him (of course insecure). The only secure way is if the server checks ever DoT tick if the player has been killed.

    I'm pretty sure they stream data and thus the damage tick comes in at regular intervals. It's speculation, but indeed, more secure.

    My only point was demonstrating how events may work

    I do not sniff packets or view incoming traffic while playing games... I tend to just play the games =)

  • For those interested in Networking and Online there is a new library out that is a high level wrapper around PodSixNet. It is beta, but is supposed to support: object synchronization, dead reckoning, client side interpolation, etc.. Pretty much all the cool stuff you need to do to make your game smoother and easier over the internet. It is called "Astral Networking".

    http://code.google.com/p/astralnetworking/

    I haven't tried it out yet.. hope to sometime soon. But you can download the sourcecode to the beta and supposedly it is working. Might be worth a look if you are experimenting with PodSixNet.

  • At the end of the tutorial, you say that this information is all you need to create a multiplayer game unless it's a fast paced action game or a FPS. Does that mean that I can't create a 12 player platformer shooter game with PodSixNet and Construct?

  • Hi!

    Does that mean that I can't create a 12 player platformer shooter game with PodSixNet and Construct?

    You could create a 12 player platformer shooter, but it would be much harder than what I showed in the tutorials. You would need to create a way to deal with all the bullet collisions and people jumping around fast. Would have to deal with lag issues and prediction.

    It is possible but would take a lot of work. I've been really busy with work, but when July roles around I was planning on creating a simple space shooter with Podsixnet and Construct to test out faster action games and see how feasible it is in practice.

  • Thanks for the info scidave. I think that, with my time limit in mind, it would be the best option for me to go for a single player game then. When I have more time for a project, I'll definitely try it out though.

  • Does this tutorial work under the latest construct? It seems the pythonLib event sheet is empty in all of the caps I open.

    EDIT: Ah my bad, I had another cap open and it was opening the wrong event sheet even though I was in the layout of the tutorial caps. But now I see it's there

  • I'm working on this rpg that in later updates, I want to be a social game (the game is similar to those facebook rpgs) as in you give credits, and resources to other players, join their fleet, and fight them. The game is text based and I was wondering how hard would it be to make it have online.

  • Very easy. Adding text based online using PodSixNet would be as simple as taking the chat example and expanding it a little bit.

    The only part that isn't easy is initiating connections with your opponents. Right now you need a internet facing server (or you have to manually configure port forwarding on your computer).. it's not hard, but the module doesn't do it for you.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here is my post to thank Scidave for the tutorial of this awesome subject. Have not tried the tutorial yet. Hoping it is "foolproof".

  • Here is my post to thank Scidave for the tutorial of this awesome subject. Have not tried the tutorial yet. Hoping it is "foolproof".

  • Here is my post to thank Scidave for the tutorial of this awesome subject. Have not tried the tutorial yet. Hoping it is "foolproof".

    Here is my post to thank Scidave for the tutorial of this awesome subject. Have not tried the tutorial yet. Hoping it is "foolproof".

    If it's worth saying, it's worth saying twice!

    Krush.

  • So I've been messing with this and have been able to get it working and to pass the data I want back and forth Thanks for the awesome tutorial.

    One thing I don't get is, how can I limit the number of connections? I don't actually know how this works, just how to manipulate it to change it to pass the data I want around, so I'm not sure how to turn off the listening for new connections without disconnecting everything.

    Right now the way it works is that the client and server are teh same cap, and a player chooses to either Host or Join (it's p2p). When one player joins, I want to stop listening for other players.

    Edit: I seem to be having another issue as well. When the server and client change layouts (since its p2p both of them do this at the same time) sometimes the connection drops. I can't tell when or how to reliably reproduce it but it seems to happen often enough and not sure what causes it. Any ideas on whta I could try?

  • Hi!

    When one player joins, I want to stop listening for other players.

       # function called on every connection
       def Connected(self, player, addr):
          statusText.AppendText("New Player" + str(player.addr) + "\n")
    [/code:10y9ykaa]
    
    In the above function in the Server code you want a line like this:
    
    if len(self.players) == 2:
       "Send a message to new client that game is full"  and don't add the client to list.
    else
       add player to list and send him his number...
    
    For the connection problem:
    
    You could try this:
    
    For the client:
    
    [code:10y9ykaa]
    try:
       myclient.Pump()
    except:
       pass   
    
    [/code:10y9ykaa]
    
    For the server:
    
    [code:10y9ykaa]
    try:
       myserver.Pump()
    except:
       pass   
    [/code:10y9ykaa]
    
    What may happen is packets are still being sent from client to server or server to client, but there isn't anybody there yet to handle it so you get an exception??  If so, then the above should solve it.  If not, I'd need more details.  
    
    Glad the tutorial is helpful!
  • I did try a bunch of

    try:

    except:

    combinations with server and client. The issue is the myserver.Pump() command in the new layout to which I'm switching for sure. If I put that in a try/except block, the popup error goes away, though I still cannot communicate between server and client any more.

    The error message in particular is:

    Traceback (most recent call last):

    File "<string", line 1 in <module>

    File "PodSixNet\Server.pyc", line 39, in Pump

    File "asyncore.pyc", line 143, in poll

    File "asyncore.pyc", line 80, in read

    File "PodSixNet\Channel.pyc", line 52 in handle_error

    File "asyncore.pyc", line 470, in handle_error

    File "PodSixNet\Channel.pyc", line 59, in handle_close

    File "<string", line 28, in Close

    File "<string>", line 6769, in_getattr_

    File "<string>", line 6782, in _getitem_

    IndexError

    The function Network_disconnected under the client also runs when this happens, so I guess somehow the connection is being lost or cut.

    Also, is there no way to not even acknowledge incoming connections after I've gotten one player connected? I'm not sure it's ideal to have the server bother processing new incoming connections and sending error messages back. It'll work if that's the only way but I'd rather not even acknowledge any more connection attempts after a player has connected.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)