5
\$\begingroup\$

I'm wondering why there aren't any tools to automate the generation of an authoritative game server? It appears to be a simple task. However I've only worked in simple 2d games so I'm not understanding the complexity of other games that would make this impossible.

For example, if one built a client game, it seems it would be quite simple to extract

  1. the physics world and related elements
  2. player inputs

And then simulate 1 with 2 on a server.

\$\endgroup\$
9
  • 10
    \$\begingroup\$ Server and Client are always out of sync. What the client "sees" is not what the server "sees". Imagine you need to wait 500ms before you can actually move since the latency is just that awful \$\endgroup\$ Commented May 12 at 10:58
  • 1
    \$\begingroup\$ @Raildex yes i know. not sure how that's relevant \$\endgroup\$ Commented May 12 at 15:46
  • 10
    \$\begingroup\$ your "trivial authorative server" forces you to have an awful game experience. at all times. \$\endgroup\$ Commented May 12 at 18:22
  • \$\begingroup\$ A 250 ms latency is at the upper limit of tolerable for most games. \$\endgroup\$ Commented May 12 at 23:47
  • 4
    \$\begingroup\$ BTW, I don't know your background, so forgive me if this is obvious, but most of the source code of a game engine doesn't come distributed with the game, aside from some scripts. The rest of it is compiled low level machine instructions. Computers are dumb, they have no idea what's going on - they are just blindly following an enormous list of extremely simple instructions (like add 10 to this box, copy the result to this other box, etc.). There's very little there to tell you what a specific stream of instructions is actually for in the big picture, what it's really doing game-wise. \$\endgroup\$ Commented May 13 at 15:58

4 Answers 4

44
\$\begingroup\$

Bjarne Stroustrup once said:

"If you think it's simple, then you have misunderstood the problem".

In the real world, creating an authoritative server is more complex than "just" moving all the logic to the server and all the input and rendering to the client.

  1. A completely authoritative server is usually not feasible. If you move everything to the server, then your server-costs will go through the roof and your will generate so much network traffic that players with bad internet connections will have an awful game experience.

    You have to decide what's really worth handling authoritively and what can stay on the client. For example, does it really matter if the smoke particles of a fire are controlled by the server? Isn't it just cosmetic? Or maybe it's not because players can use those smoke clouds to hide in? This is a decision you have to make consciously for every system in the game.

  2. It's usually not "quite simple to extract" the logic and the input handling. The decoupling between the systems you want to move to the server and the systems you want to keep on the client will not always be as clean as you would imagine it. In a real-world codebase, you will always have dependencies creeping in. So moving a system (or part of a system) from client to server will usually imply some serious refactoring.

  3. When a system moves to the server, then you now have a couple ms of latency. This is something you need to design for. Function calls that were simple getter-functions now suddenly require an asynchronous request with callback. You might need to build some prediction and/or interpolation to keep the illusion of a fluent game experience. Which will usually require custom algorithms depending on what data you are dealing with and how you expect the server to answer to requests.

  4. A client-server application requires a netcode protocol. What data needs to be synced each frame? What data needs to be synced only when it changes? What data should be synced through a request-response model? What data doesn't change, so it only needs to be synced on startup? What data is irrelevant so it doesn't need to be synced at all?

    Oh, and what happens when there is packet loss? Is the information so important that you need automatic confirmation and resending on fail? Or will the next update take care of this?

    These are usually not decisions you can make automatically. And the decisions you make here usually have wide-reaching consequences on the architecture of both the client and the server.

So bottom-line is: No, you can not solve this with a tool. You will have to do a lot of manual software engineering to turn a non-trivial single-player game into a game with an authoritative server.

\$\endgroup\$
1
  • \$\begingroup\$ Comments have been moved to chat; please do not continue the discussion here. Before posting a comment below this one, please review the purposes of comments. Comments that do not request clarification or suggest improvements usually belong as an answer, on Game Development Meta, or in Game Development Chat. Comments continuing discussion may be removed. \$\endgroup\$ Commented May 13 at 19:51
11
\$\begingroup\$

the physics world and related elements, player inputs

You forgot the third vitally important part of a game, taking the game state and presenting it to the user.

Looking something up in a local data structure takes microseconds at worst (and less if it's in CPU cache), looking something up over an internet connection likely takes milliseconds at best and more likely tens or hundreds of miliseconds, on a bad day I've seen latencys get up into the seconds. A frame is of the order of 20 milliseconds, so on a good day you might get tens to round trips per frame and on a bad day you might be waiting numerous frames for a round trip.

So you can't have a client render a frame by making a bunch of synchronous requests for information from the server. Even a single request may receive a response several frames after it was sent. So generally whatever you choose to send must be sent in a largely asynchronous manner.

At one extreme you could use a "remote play" approach, the client sends requests to the server and gets a video stream back. All the chatty code sits on the server. You could also do a variant of this where, instead of sending a video stream you sent a series of drawing commands.

This is very secure and potentially allows a lightweight client, but it needs both a powerful server and a fast, stable low-latency network. It's usually ruled impractical for these reasons.

At the other extreme is the fully synchronised game state approach. Player (and sometimes AI) inputs are distributed to all the clients, which then maintain their own copies of the complete game state. This keeps network traffic to a minimum and means the server can skip UI code and handle only game state. Sometimes you can do this without even having a "server" at all.

But it creates a few problems.

  1. The logic must operate exactly the same on all clients, this can be easier said than done, some code can behave differently on different systems. Floating point arithmetic was historically a problem, though afaict it's less of an issue nowadays, care must be taken to ensure that inputs are applied consistently on all clients and that random number generation is done in a synchronised manner. Synchronised games will often have two separate RNGs, one for use by the game state, and a separate one used in (non-synced) display code..
  2. It enables cheating, a modified game client can easily be made to reveal information that the player should not have.
  3. It can make bringing new clients into an existing game difficult. Games that use this technique (for example, openttd and factorio) often have significant pauses of the game when a new client connects.
  4. Because all systems must process inputs at the same time, a slow network can still be unacceptable latency between player input and response on screen.

So many games end up with a hybrid approach, the server has a complete copy of the game state, clients have partial copies, for which the server sends updates in an asynchronous manner. The client then uses this partial copy of the game state to render the game.

Most of the simulation happens on the server, but some parts may be pushed to the client. In particular in first/third person 3D games the player character's movement is often simulated on the client and only later sent to the server. The server must then try to reconcile what happened on the client with what is happening on the server. Doing this in a way that minimises the scope for cheating and minimises noticeable artificts, while also hiding as much of the latency as possible from users is probably one of the biggest challenges in competitive shooters.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ The "remote play" approach was very popular in the era of MUDs and other text-based multiplayer games. \$\endgroup\$ Commented May 12 at 23:33
  • \$\begingroup\$ @Mark Yes, because with an entirely text-based game, latency and bandwidth aren't that much of an issue. Nowadays we have things like Stadia (that went out of business) or GeForce NOW (which doesn't seem very popular to me, but I could be mistaken). But playing through screen-sharing on a machine owned by someone else (or "cloud gaming" how the marketing people call it) always suffers from the problem that it has to make do with no client-sided prediction at all. Which is a serious problem for anyone not living right next to the datacenter. \$\endgroup\$ Commented May 13 at 10:25
  • 2
    \$\begingroup\$ @Philipp There is also moonlight, steamplay, etc... Which allow streaming from one machine you own to another. It works great when you are the same local network as your source device... Doesn't work at all when you are on a different network. \$\endgroup\$ Commented May 13 at 22:04
7
\$\begingroup\$

It's easy if the game is designed in a way that makes it easy. In particular:

  1. Game code is clearly separated to rule and visual parts.
  2. All calculations affecting rule logic are repeatable, and do not depend on e.g. video frame timing.
  3. The resources needed by the rule logic are not excessive for a server handling multiple clients.

Latency is an issue, but it can be solved by having the client run its own copy of the rule logic. If the repeatability condition holds and the client is not cheating, the server will get the same result.

However, many games have rule logic that is heavily interconnected with the visual rendering. Usually the same game engine handles visual display and e.g. collision detection, and may not support separating them. Getting repeatable results while minimizing latency from control inputs to rendering has its own problems, but there are solutions for this such as running the physics simulation on its own thread with timestep independent of the frame interval.

If the need for an authoritative game server is taken into account early in the project, there is no particular need for a tool - rather, the need is for a game engine and libraries designed to be used in this way. And if the game has already been made, the task can be close to impossible without also refactoring the client game to well separated portions - a task that is currently beyond automatic tooling.

Like you allude to in the comments, a basic authoritative server does not really solve all cheating. As long as the rendering is done on the client side, it is possible to make walls transparent or highlight enemy players.

To take the concept to extreme, you can use technology similar to cloud gaming services, where the client just streams video and sends control inputs. These have unavoidable tradeoffs in bandwidth and server resources needed and the input latency. But as evidenced by the available services, it is straightforward to run existing games in the cloud and stream video to clients, and this would be the "ultimate" authoritative server.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ "Latency is an issue, but it can be solved by having the client run its own copy of the rule logic. If the repeatability condition holds and the client is not cheating, the server will get the same result." This does not hold if multiple clients are affecting the same game world, or if the server can initiate changes to the world without client input. \$\endgroup\$ Commented May 12 at 23:42
  • 1
    \$\begingroup\$ @RussellBorogove It does not solve all problems of latency in multiplayer games, but those problems exist even without an authorative server. Timestamping the rule-relevant data does allow server to verify the results afterwards. \$\endgroup\$ Commented May 13 at 5:37
0
\$\begingroup\$

It is indeed trivially easy*

As Valheim and Satisfactory prove, extracting an authoritative server from your game is indeed trivially easy,

IF you designed your architecture centered on this setup from the beginning

Then it's not that much more than creating a build without the graphical frontend, inputs or own player-related things and there you go, the server is done. [It is of course a bit more complicated in reality, but not immensely more so]

Where this conflicts with your approach though is that the extraction that you want a tool to magically do was done at the very start when the architecture, structure and so on was planned by experienced human software engineers.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Well, using those as examples are a bit silly... because their architecture means they already were authoritative server games. They just also happened to let the authoritative server run accept direct player inputs for a single actor. \$\endgroup\$ Commented May 14 at 18:55
  • 1
    \$\begingroup\$ @Delioth that's the point of this answer \$\endgroup\$ Commented May 15 at 8:34
  • \$\begingroup\$ @Delioth as Caleth perfectly noticed: that was the point. I showed how it can be trivially easy (if you design for it from the very start). The other answers already go into the technicalities, so there's no gain from including the same points in my answer again. \$\endgroup\$ Commented May 15 at 11:41
  • \$\begingroup\$ @QuestionablePresence Rather, answering "why is it hard to do [X]?" with "it isn't, provided you have already done [X]" is... just a goofy way to answer a question? I.e. it's not answering the question - it's a frame challenge at best (which is valid but last I checked, answers that challenge the frame are expected to say such explicitly) \$\endgroup\$ Commented May 15 at 16:21

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.