How do I make a multiplayer game with code join in godot? - multiplayer

I want to have a lobby type thing. One player would press host and would get a game key. And the other player would type that code in and join the game. Something like in Jackbox party pack.

The godot docs have a example for lobby code in their documentation here: https://docs.godotengine.org/de/stable/tutorials/networking/high_level_multiplayer.html
There is also a part for running godot as a dedicated server : https://docs.godotengine.org/de/stable/getting_started/workflow/export/exporting_for_dedicated_servers.html#doc-exporting-for-dedicated-servers
There are also enough tutorials out there on youtube like: https://www.youtube.com/watch?v=TGIWD24QIvY&list=PLKCbXu2bxxqa2PtT2rYNb4t5QUsotrTlP
The first link shows you a way to create simple server lobby in godot. To do the password way you have to create some kind of server application which does the routing for you.
For example:
Host creates new Game by calling a server
Server creates an Instance (dedicated Server with ip and port) and a unique Passcode.
Clients connect to the server by entering the passcode.
The server searches with the passcode for the right ip and port the Clients have to connect to.

Related

Client based Winsock application C++

I want to make a game server/room. I tried to search it up, but it always needs a physical server room to run. Is there a way and how to make a game room by hosting it on the client's device and people can join and play?
--My own theory--
When the player presses "Host", create a server on their device.
People can enter the game code (an encoded device's public IP address) to join the room
Shut down server & disconnect all client when the host exit the game.
Player can press "Join" and enter a game code (mentioned above) to join a server.
--Problems--
The internet says that IP address is not the only thing needed. What more do I need?
When I try to connect with the public IP address, it blocks the connection (tested with a chat application I created, it can only connect with local IP such as 192.168.0.1 and not public IP like 222.133.114.88). How to make them allow my connections?
Thank you!

Scalable login/lobby servers for a multiplayer game

I am developing a multiplayer game (client-server model) and I am stuck when it comes to scaling its servers.
I understand that most games never even reach 10 000+ players, and I don't think mine will either.
Though if I would be very lucky to get that I want to develop the servers so they cannot become a huge obsticle later.
I have searched a lot for a solution to my problem on the internet, checking GDC talks about it and checking other posts on this website, but none of them seems to solve my specific problem.
My current setup is below and all servers are written in C++ using ENet as my network library.
Game server
This server handles the actual gameplay of the game and requires quite a lot of CPU and packages being sent between the server and its connected clients.
But this dedicated server is hosted by the players themselves, so I don't have to think about scaling it at all.
Lobby server
This server handles the server list, containing all servers currently up.
All game servers are sending a UDP package to this server every 5 seconds to say they are still alive.
This is so the lobby server can keep an updated list of all servers currently online.
All clients are sending a UDP package to this server when they want to fetch all servers (which is only in the server
list screen), and the lobby server sends back a list of all servers.
This does not happen that often and the lobby server is limited to send 4 servers per second to a client (and not a huge package containing all servers).
Login server
This server handles creating accounts, lost password, logins, friends and their current game status,
private messages to other logged in players and player profiles that specifies what in-game items they have.
All clients are sending a UDP package to this server every 5 seconds to say they are still alive, while also
sending what game they are currently in. The server then sends back their friend lists online/offline/in-game statuses.
This is so their friends can keep an updated list of which friend is online/offline/in-game.
It sends messages only with player actions otherwise, like creating an account, logging in, changing/resetting password,
adding/removing/ignoring a friend, private messages to friends, etc.
My questions
What I am worried about is that my lobby and login server might not be scalable and that they would have too much traffic on them.
1. Could they in theory be hosted on just a single computer? Or would it be too much traffic for 10 000+ players?
2. If they can be hosted on a single computer, will the servers still not have issues for people that live far away?
Would it be better to have the lobby and login servers per region of the world in that case?
The bad thing about that is that the players would not be able to see servers in the US if they live in Europe, and that their account and items would not exist on the other servers.
3. Might be far-fetched, but if I would rewrite both servers to instead be on a website with a database and make the client/game server do
web requests instead (such as HTTPS or calling a php with specific headers),
would it help in solving my problems somehow?
All your problems and questions are solved by serverless cloud based solution AWS Lambda e.g. or similar. In this case the scalability is not your problem. Just develop the logic. This will save you much time.
If you would like to make servers as single app hosted by your own server. Consider using something like e.g. Go instead of C++. It's designed exactly for these purposes. I mean highly loaded web/network services.
Well, this is c++ and i code in java, but maybe the logic is useful for you any way so i will tell you how i end up implementing something similar but in a casino.
In my case I have 2 diferrent sockets in the same server program, one of the sockets is TCP and it handles all logins, registers and payments, while the second socket is UDP and it handle the actual game multiple payers are playing, then you could group internally all those UDP connection in groups (probably arrays of sockets) to generate those lobbies. Doing that all your server is just one class that could run in a single pc using 2 ports (one for each socket) However this do not solve the problem of the ping for people who live far away.
If ping is a problem (not my case in a casino) you could probably host your server region base but removing the login, registration and paymets of your server and replace it for a connection to a central server (this central server should be TCP and you could also implement a https socket to also allow your webpage to connect to this server and create accounts or pay you directly from the browser)
sorry to mess your life even more, but i hope it helps

Qt matchmaking Server

I want to build a matchmaking globe server,so that players on the internet can connect to and find an opponent, every player is represented by a QTcpSocket on the server.
My question is how to make the two socket talk to each other without using the glob server as a middle man? Is that even possible?
Do I need to create a server on one of them and give the other one its address?
If yes, what about NAT can I use the host number in the TCP protocol - I don't wanna use port forwarding.
Or is there any other approach in matchmaking that I don't know about.

Connect to DBus service via TCP

I'm new in work with interprocess communication. I need you help and clear explanation. I have 2 applications. One of them is a service and one is a client. I've used QT/C++ to write them. When they are working on the one local PC - all is good. But I need to separate them.
So, I have a service on the PC with IP 192.30.82.101.
I connect it to bus using next code:
QDBusConnection connection = QDBusConnection::sessionBus();
connection.registerObject("/my/service/MyService", mySvc);
connection.registerService("my.service.MyService");
Also I have a client on the another PC with IP 192.30.82.40.
I connect my client using the next code:
QDBusServiceWatcher serviceWatcher = new QDBusServiceWatcher();
serviceWatcher->setConnection(QDBusConnection::sessionBus());
serviceWatcher->addWatchedService("my.service.MyService");
.....
myServiceProxy = new local::MyService("my.service.MyService",
"/my/service/MyService", QDBusConnection::sessionBus(), this);
I need to connect my client on the PC with IP 192.30.82.40 to the service on the PC 192.30.82.101. I don't know how to do this. I've found a few topics on the forum but I still don't understand what to do.
So, what I have found:
On the PC where is my service I have to add additional lines to /etc/dbus-1/session.conf:
<listen>tcp:host=<host>,port=<port></listen>
<listen>unix:tmpdir=/tmp</listen>
<auth>ANONYMOUS</auth>
<allow_anonymous/>
Here I have a question: Which IP address I have to use here (server or client)? Which port is used for DBUS (is it default port or how I can check it)? I have tried to set an IP address of my client PC, my service PC and different ports, and port 0, but I've got an error: Failed to bind socket "172.30.82.40:0": Cannot assign requested address.
On the client side I have to set DBUS_SESSION_BUS_ADDRESS with the same address: export DBUS_SESSION_BUS_ADDRESS=tcp:host=<host>,port=<port>.
I've tried to do this with different ports, with 0 port, because this means - use any free port. But I cannot start bus daemon with any port+IP configuration.
Also I've tried to connect client QDBusServiceWatcher to bus using the next code:
serviceWatcher->setConnection(QDBusConnection::connectToBus("tcp:host=<host>,port=<port>", "session"));
It was not successful.
I have no idea how to connect them to each other.
Can anybody, please, explain me how it should be, how does it work?
I want to clearly understanding how does it work?
I will be very grateful for any help. I hope for your kindness.
UPDATE
I have found how to connect my client to DBus bus via TCP:
On the PC where is my service I have to add additional lines to /etc/dbus-1/session.conf:
<listen>tcp:host=localhost,bind=*,port=6667,family=ipv4</listen>
<listen>unix:tmpdir=/tmp</listen>
<auth>ANONYMOUS</auth>
<allow_anonymous/>
Here we should add PORT. We can find it in dbus config file.
On the client side I have to set DBUS_SESSION_BUS_ADDRESS with corresponding address (IP of PC where is service):
export DBUS_SESSION_BUS_ADDRESS=tcp:host=192.50.88.10,port=6667,family=ipv4.
Thats all. We can check it just started dbus-monitor.
But now I have another issue: how to connect my client to my service?
I need to do something more to connect to my service.
I guess that this is something like:
QDBusConnection::connectToBus("tcp:host=<host>,port=<port>","connectionName");
I've tried to connect with any random name, but this is not correct.
So, my question is - where I can get correct connection name?
Correct answer to my question is:
On the PC where is one application add additional lines to
/etc/dbus-1/session.conf:
<listen>tcp:host=localhost,bind=*,port=6667,family=ipv4</listen>
<listen>unix:tmpdir=/tmp</listen>
<auth>ANONYMOUS</auth>
<allow_anonymous/>
Correct port you can find in dbus config file.
On the client side It's needed to set DBUS_SESSION_BUS_ADDRESS with
corresponding address (IP of PC where is service):
export DBUS_SESSION_BUS_ADDRESS=tcp:host=192.50.88.10,port=6667,family=ipv4.
To connect to session where is alive your remote app use the next
connection string:
DBusConnection::connectToBus("tcp:host=192.50.88.10,port=6667", "qt_default_session_bus"));
How to know session name? I've added log in my service:
qDebug() << "Connection name: " << connection.name();
Then started app, copy printed name and set it in my client.
Now it works!

How can a server application safely connect to a user-supplied IP address?

I'm making a public web service with an "announce" endpoint, that allows users to supply a host+port on which they are hosting a multiplayer game (Minecraft). My service then connects to their game to get some info about it. The game protocol requires my service to send the initial handshake, and then wait for a proper reply.
Ideally, the game could be listening on any port above 1024, and on a host that is not necessarily the source of the announcement. If that cannot be done safely, I could potentially restrict to the game's standard port and/or the remote host of the announce request.
How can I do this in a safe way? What restrictions do I need to put on the host/port? Is there something special I should do when connecting to the game?