Tutorial: Online Multiplayer with PodSixNet

Post your own tutorials, guides and demos.

Post » Sat Sep 04, 2010 11:38 am

[quote:2hc0w47c]Events can happen in both directions, obviously. In the case of a DoT the client will receive an event that they have a DOT which does X damage over Y interval (display the debuff icon, duration, graphic, etc). The client could then simulate that effect with just the one packet send from the server. It could be broken up based on the tick duration too (multiple packets), but somehow I'd think they would resolve the damage ahead of time and let the client simply display the results over the course of the spell however it sees fit, rather than waste packet overhead simply on that.[/quote:2hc0w47c]

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.

But anyhow, my game is far from pixel perfect, there are no collisions or physics. I'm gonna see if I can mock something up and show you what i mean later...

On 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?)
B
2
S
2
G
5
Posts: 448
Reputation: 2,546

Post » Sat Sep 04, 2010 12:21 pm

[quote="alee":1927f3g8]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?)[/quote:1927f3g8]

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:
[code:1927f3g8]
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.
viewtopic.php?f=2&t=7086&start=10

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.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sun Sep 05, 2010 4:35 am

[quote="alee":1x5qyzqe]

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.

[/quote:1x5qyzqe]

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 =)
B
3
G
2
Posts: 31
Reputation: 737

Post » Thu Sep 09, 2010 8:58 pm

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.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Fri Apr 01, 2011 10:09 am

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?
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Sat Apr 02, 2011 1:10 am

Hi!
[quote="Muurtegel":3bi028ef]Does that mean that I can't create a 12 player platformer shooter game with PodSixNet and Construct?[/quote:3bi028ef]

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.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sat Apr 02, 2011 9:39 am

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.
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Tue Jun 14, 2011 4:09 am

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 :)
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Wed Jun 15, 2011 9:16 am

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.
B
5
S
3
G
4
Posts: 189
Reputation: 2,910

Post » Wed Jun 15, 2011 12:02 pm

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.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

PreviousNext

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests