Multiplayer server update problem

Here is a nut to crack:

I’m creating a multiplayer game with both server and client being instances of Defold engine.

Now I want to the server to have a tickrate of 0.1 seconds (10 updates/second) and was therefor suggested to use the socket.sleep() function. Question is where I should do it.

Server is headless and authoritative and all messages coming in there first needs to be processed, all gameobjects in server needs to be updated. The full gamestate will then be packaged and sent as package to the clients. THEN the server can allow itself to sleep.

To complicate things this also includes physics handling like collision responses and raycast responses.
Just putting a socket.sleep() in the end of the server.script update loop just wont do it as I have no control of when the different scripts are being updated and when messages are done being sent.

Having the headless instance respecting the framerate would help some of course and is requested since earlier BUT I still dont know if all messages/physics etc has been sent so I can package the gamestate and send it to the clients before update is done.

Any suggestions?
I remember something about proxycollections having their own update loop? Maybe that could solve something.

2 Likes

Hmm, ok, so what if the script that is responsible for packaging up the game state and sending it to the clients would in it’s update() function post a message to itself and in the on_message() function of same script receive the message. At that point you’re guaranteed that the update function of all scripts have run, but as you said, you’re not guaranteed that no other script has also posted in it’s update() loop and that message might have been handled already.

I understand the need for things to be processed in a very predictable order, but I wonder if you won’t run into problems regardless if you need to have the exact same simulation on clients and server, down to the order of messages being processed.

Is it a real time multiplayer game? You mentioned 10 updates per second on the server, but I guess the clients will do 60 updates per second? By this alone it becomes obvious that the clients and server will behave differently and you need to find a way for the clients to retroactively correct their state based on what the authoritative server says. And how would you deal with lag? Would the clients do a best guess based on previous state (velocities, directions etc) and then correct when they get an update? Could you tell us a little bit more about the game itself?

2 Likes

The game is real time multiplayer with strict server auth where clients are just sending inputs and interpolating the values coming from server (position etc). It also hides a lot of action you would like to have immediate feedback with animations etc. Most actions could be described more of MOBA/MMO actions (eg buttons that show direct trigger response but actual result is presented when server has sent back the result).
Sometimes we predict on clientside and need to correct afterwards but those times are not many (as we know now, very early in stage).
Its no question of determinism and we are aware that we will have to fight every single lagged feature in different ways.
This in mind makes it even more important that when an input from client comes in (eg firing a gun) it must be handled in that tick and also being sent in the same tick. Having to wait for the next tick would be a minor disaster lag-wise.
As the game is actually running in it’s full, serverside, there are lots of gameobjects sending messages back and forth, both within themselves and to each other. Eg. ray cast that will wait for physics update to send a response back.
The order where it all happens is not that important to control. It’s just that I would love to find a solution that could at least tell me that it has now all been handled.
Where trying to think of all gameobjects to report when they are done updated but still couldn’t figure out a nice way to handle this.

2 Likes