Godot Version
Godot Engine 4.3
Question
I am trying to create a lobby system for my android game on godot engine.
What I mean by lobby system is that…
there are plenty of mobile games for android that have multiplayer (and that are made on unity). Basically, let’s say you’re a player. You as a player from main menu press “create new lobby”, after that new lobby was created. You can play, walk around and do whatever you want. But, this lobby has appeared in the global lobby list.
Other players in the global internet can see your created lobby in the global lobby list and can join your lobby.
I have two questions: how to create it? and is my implementation idea would be technically good for that?
My implementation idea:
I have dedicated server on linux. I can export my godot engine project as both “Android” instance and as “Dedicated Server” instance. For “Dedicated Server” specific things I can always check OS.has_feature("dedicated_server").
Now the thing is that my actual linux dedicated server is django web application.
Basically, through gunicorn and nginx all requests to my domain are forwarded to my django web application.
So instead of having a headache in forwarding some requests to my dedicated server godot engine I decided to use my django web application. There will be certain API urls registered specifically for my game like so: domain.com/create_lobby, domain.com/join_lobby. (The only problem is that for POST requests django requires csrf-tokens in terms of security, so I would need to come up with some kind of API token system or move to the REST framework addon of django.)
The create lobby is the neat part.
As far as I am aware… Godot Engine 4 high-level multiplayer API primarily uses peer-to-peer connections. Because of that I decided to:
- HTTPRequest to “create_lobby” returns port for that new created lobby.
* What I mean by port? There will be specific range of ports (let’s say 7000-7100) specifically for lobbies. Everytime a new lobby is created then free port will be returned and dedicated for client players to connect to new created lobby on my server through peer-to-peer connection. - All lobbies are saved in django database… perhaps would be cool feature in the future to create not just simple lobbies but special “community” lobbies that have custom settings on them that are setup by player lobby owner.
Now you probably see what I mean. Because high-level multiplayer API primarily uses peer-to-peer connections, everyime new lobby is created → specific port is being dedicated for that lobby in order to establish peer-to-peer connection between client and server → new godot engine “dedicated server” subprocess is created that has this port used for basically server.
During creation of new lobby, there will be launched new “subprocess” of my godot engine “Dedicated Server” exported game with specific port being set as launch argument (OS.get_cmdline_args() like this for launch arguments).
In this dedicated server subprocess there will be all things that server does: such as synchronizing player movements, actions and etc.
The only thing that makes me worry about this implementation is the port dedication part. Do any of these types of games that has such system actually do that? Perhaps there is other way around? I haven’t checked unity templates for this if there is really are though… perhaps I should?
I am NOT gonna use external services such as W4.