Devlog | M17

Character select and joining

The character select screen, with three sample characters over the town

Until now, the game server believed whatever a client told it. "Hi, I'm this character" was enough. That was fine with one player on one computer, and it stops being fine the moment strangers connect.

So the client doesn't get to say who it is any more. You pick a character on the new select screen, and the backend checks that it's yours. It hands you a token that works once, for 60 seconds, on one server. You show that to the game server while the connection is still waiting at the door, and the server asks the backend who you are. No valid token, no way in.

The tricky part is making sure a character only ever exists once. If you could log in twice, you could hand your items to a friend on one login and still have them on the other. So a character is claimed in the database by the server holding it, and a server without the claim can't even save it.

Logging in again takes over. The old connection gets dropped, and the new one waits until the old player has been saved. Put 7 scrap in your bag, log in a second time, and there are still 7.

If a server crashes, nothing lets go of its claims, so they run out by themselves. Servers report in every 20 seconds, and a claim that isn't renewed is gone after 90.

A new character is a small trick. The backend only reserves the name, because it knows nothing about classes or roads. The game server then shows the normal creation screen and checks your choices itself, the same as before.

All of this ran against the real setup on my PC, the Linux server in Docker and the backend behind Caddy, with clients joining, being refused and taking over from each other.

And it's now running on an actual server on the internet.