How to learn multiplayer inplementation?

Hello everyone,

I’m looking for ways to implement multiplayer in my game project. I don’t know anything about networking, servers, etc. but I’m willing to learn (after all, I learned a bunch about game development starting from coding equations in python for work and not knowing much about programming…) (I’m using godot 4).

The question is simple, what type of multiplayer architecture would you recommend for a single-player real-time strategy game project that is quite small 2 to 4 players max, few objects and quite slow (no or very few mobile units moving from tile to tile, it’s not Starcraft II, the game doesn’t need to be ultra responsive) ?

Ideally, I’d like a matchmaking system or less ideally, just a way for players to find other players fairly easily or even just a way to invite friends to play or let them play together.

  • What basic knowledge do you need?
  • What tools do you recommend?
  • How do you recommend learning these basics and tools?

PS: I’ve already read a bunch of posts saying “the technical part is less of a problem than keeping a player base active and operational … dead game … blah blah blah …” I’m not there, I just want to create the RTS game of my dreams and see if people like it and push the idea as far as it can go.

What basic knowledge do you need?

First of all, I’d recommend these two:

  1. https://www.gdcvault.com/play/1022195/Physics-for-Game-Programmers-Networking
  2. 1500 Archers on a 28.8: Network Programming in Age of Empires and Beyond

It gives you a good introduction on what kind of state synchronization strategies you can use. Mind you, these are not the only approaches, and it varies a lot from game to game, but it can give a good grasp on the mindset for building multiplayer games.

The other thing to consider is how much of the game logic you want to run on the server.

The more things you run on the server, the easier it is, since you just broadcast the results and be done with it. However, this means that players will have to wait for the server to respond, i.e. it won’t be responsive.

The more things you run at the player, the more difficult it is to code, since now you have to either make sure you get approximately the same result on each player’s machine, or have to somehow synchronize between multiple game instances and fix mismatches gracefully. However, things will respond instantly.

For an RTS with a small amount of units, I’d say the easiest would be to just run everything on the server, players submit their inputs and be done with it. It gives basically zero chance to cheat ( unless the server itself is compromised ), is easy to code, but on the flipside, reacts poorly to network latency. Also since you’re broadcasting every single unit’s state, it can take a lot of network traffic. To be a bit more specific, for state just add a MultiplayerSynchronizer node to your units, and send the client inputs via RPC calls.


What tools do you recommend?

I think Godot’s built-in multiplayer API should do fine.

Shameless plug: I’ve written netfox, a set of addons to help with building multiplayer games. For now its main feature is CSP which is not your best bet for RTS games, but you might be able to make use of its network tick loop, or the TickInterpolator to interpolate unit positions and such between two ticks. I’ll also start the next dev cycle on it in the coming weeks - the community has some good proposals which I plan to implement.
You absolutely can build your game without netfox, just wanted to give it a mention :slight_smile:


How do you recommend learning these basics and tools?

My take is to just start building things and ask along the way, but I hope others can give more specific advice :smiley:

For Godot’s API, reading through the High Level Networking page a few times got me started pretty easily.

2 Likes

Wow, that’s a very precise (and appreciated answer) ! There is a ton of information around about the subject but it’s a lot to take in if you really have no knowledge to begin with. You clear up a lot of it thanks!

So, to sum up: you recommend going for using a dedicated server to manage (almost) everything and to recieve players input. With the few things as possible managed on the player computer ? I could do that with the godot built in API with the

MultiplayerSynchronizer nodes and stuffs in the High Level Networking documentation?

Does it still mean I need to pay for dedicated servers, or one player could host the server on its computer? I’ve read somewhere that dedicated severs can be needlessly expensive and there is other alternatives such as “WebSocket”, “PlayFab”, “Peer2Peer” ? But I don’t really understand what those words really refers to and if they are exclusive options. Do you have an opinion on those, are they harder to handle, really cheaper, doesn’t fit my needs?

Thanks again for your first answer, I’ll check out your links! I hope this topic can help others. :smiling_face_with_three_hearts:

1 Like

Yeah, dedicated servers are one option, but there’s others.


WebSocket

WebSocket is really just a technology that lets regular HTTP servers do bi-directional communication with clients, instead of just sending the page and closing the connection. ( I’m simplifying an absurd amount here )

Anyway, you would still need a dedicated server, maybe it could be a bit cheaper if you use some really common stack supported by the provider. For example, there used to be cheap or even free PHP hosting services.

The downside is that you’d need to write the game logic twice, once in Godot, once for the server.


Peer2Peer

Peer-to-peer is a different network topology. Instead of having a central server that everybody connects to, every player connects to every other player. This is supported by Godot. Data is then broadcast to all the players necessary.

Even though this way you don’t technically need a server, you still need some way for players to connect to eachother. Even if players just e.g. DM their IP addresses to eachother on Discord, their routers will probably still decline the connection.


I’ve skipped PlayFab as I have no experience there :slight_smile:


Overall, you definitely can get by without a dedicated server, but it might not work for all your players, and you are putting more work on the players by making them figure out their network settings for themselves, if something doesn’t end up working.

However, running the full game on your own dedicated server is not the only option. You can also use a dedicated server to orchestrate connection between players. Think of master servers e.g. in old arena shooters like Quake III. The master server doesn’t run any game logic, it just serves a list of game servers. Then game servers can be hosted by players.

I’ve implemented something similar myself with noray, and its Godot integration, netfox.noray ( does not rely on the rest of netfox ). It basically controls the handshake between two players to make sure their routers doesn’t decline the connection. If it fails, noray can also simply relay messages between players. So, in theory, connection should be bulletproof.

You can also check out Nakama, that has a similar feature.

The win here is that you need significantly less processing power to simply relay messages instead of running a whole game, so you can get by with cheaper hosting.

I personally use Linode’s smallest plan, which is around ~5 USD/mo. Of course sometimes you don’t have the extra money to throw around, in these cases you can still fall back to player hosting and creating guides for players on how to set up their network, but be aware that this limits your audience.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.