Question about multiplayer event handling

Hi,

I’ve managed to use PlayFab lua sdk to login PlayFab and get a session token.
I know how to run a linux or windows headless game and pass config info to it (sys.get_config(“some_param”)) (in case I need to pass in server ip etc).

However I don’t know how or where I can write code for the game to receive events from external sources (as in player 1 just told me they fired a gun at xyz position).

My initial plan is to have one of the players be the host.

Actually this question isn’t even about PlayFab or whether one of the players is the host or not, this question is whether I am wrong in assuming that in theory I could just run a headless on my windows 10 pro machine and then run an instance on my android phone pointing to the computer/server and pass events back and forth.

Is there a mechanism for that or I’m I missing something?
I don’t want any logic to run on a server (unless it’s the hedless game itself running in a vm in the server like PlayFab can do).

Any pointers would be great, thank you.

Online multiplayer game development is hard and there are many things that can go wrong!

You can have a headless Defold instance running somewhere as your authoritative server. It runs your game simulation, received the actions of the game clients, updates/validates game state and serves out deltas or full updates to the clients. Clients usually connect using socket connections. Clients usually get the server IP from some kind of lobby service specific to your game (perhaps from Playfab, Nakama or Colyseus).

There are many articles on the subject online. You should be able to apply the learnings to Defold.

The other approach is similar to the one above, but instead of an authoritative server you have one client acting as host.

1 Like

Thanks, I think I found something: https://github.com/defold/extension-websocket I’ll check it out when I get home. Cheers.

1 Like

Note that this extension (currently) only supports client mode. This means that you need a proper websocket server in one of the instances.

1 Like

I found the Colyseus authoritative server quite good and easy to setup.

1 Like

I see, I suppose I could use something like this for allowing clients to keep their IP address private. Mind you as far as server technology I’ve only used IIS and Playfab is new to me, but I’ll give it a go

The reason I haven’t tried Colyseus yet is because I am trying to limit the amount of time I spend setting up and maintaining the server infrastructure. My server-side experience is limited to IIS and Kestrel for .Net web apps, not with server-side node.js.

I also saw Nakama but I don’t think they support hosting a game instance in a VM and their starting price is 600 dollars per month.

I was merely commenting on your suggested use of that particular websocket extension to pass events back and forth directly between the two defold engine instances. For websockets to work, there has to exist a websocket server, and that extension currently doesn’t support that (it could if anyone wishes to update it).

2 Likes

Yes you are right, thanks for letting me know, I’ll see what server component I can find (if I need one). I’ll try to make it so the headless game can be containerised in a vm so that I can move it around or scale it horizontally in the future if necessary.

1 Like

Unfortunately headless games that can be put in a vm for the PlayFab infrastructure are games that are written in either C++, C# or Java. I’ll take a look at @SpencerWF’s suggestion on Colyseus