How can I make a really simple LAN system ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ZacB

I need to add a trade system in my game so that two players can be in a room and trade their cards. But I’ve searched everywhere and I can’t find a simple way to do it, I’ve just seen a lot of 3D LAN tutorials…

What I would like :

  • both players have a button to join the trade room

  • server max peers = 2 so if a third player plays and two players are already in that trade room, he won’t see a “go to trade room” button

  • when a trade is done the server shuts down and everyone can see the “go to trade room” button again

Have u figured it out? I have a same problem.

Floxicek | 2020-10-06 19:35

:bust_in_silhouette: Reply From: Zylann

You can use the high-level multiplayer API of Godot, which is explained here: High level multiplayer — Godot Engine (3.0) documentation in English
I would suggest you get familiar with this first.

This will require one of your players to host the trade room, and the other to use the IP address to connect. But you can also make a separate trade server and have both players enter the IP of that server.

If you don’t want them to enter any IP address, then you will have to either hardcode it and make sure the server always run under the same IP, or have an intermediate server (using HTTP for example) which provides the list of available trade servers.

In the case of not entering any IP in a LAN context, you could use network discovery to search for trade servers in your local network (aka an instance of your game that opened a trade peer). I don’t know how that works in detail, but it was mentionned here: https://github.com/godotengine/godot/issues/13947

Thx for your answer. I need to use a LAN system and the first player pressing the connect button would create the trade room. But I’ve two problems :
How can I check if a server is already running so the second player can join it ?
And is there a way to close the server when a trade is done ?

ZacB | 2018-07-14 06:59

You know if a server runs if it responds to your connection/discovery broadcast. You can never assume a server is always running (even if it should ideally).

Closing a server when the trade is gone is relative. I’d say, your clients have to leave it first, because if the server closes first your clients won’t be gracefully kicked out (depends how you code this, though). Also, if you use a dedicated server or that, it could still be running all the time and handle trades by “sessions”. It’s up to you to decide which flow you want.

I’m new to networking in Godot as well, so I mostly know theory, sorry if I can’t share actual code^^

Zylann | 2018-07-14 13:31

So what are the codes to :

  • check if a server is running
  • leave the server

?

(sry I’m lost with network stuff :))

ZacB | 2018-07-14 13:34