I
I
IonianWind2012-04-03 12:25:37
Node.js
IonianWind, 2012-04-03 12:25:37

How to organize the restoration of the state of the game after a disconnection?

The bottom line is this:
I'm writing an online game using node.js and WebSockets (socket.io).
With the opening of the game menu, the application session is initialized.
Next, the user can start a new game. A game room is created and waited until someone else wants to play, after which the game starts.

The question is how to organize the recovery of game data if the connection with the user is interrupted - either the user is disconnected, or the server is cut off, or something else.

In my opinion, the difficulty lies in the ability to launch multiple instances of windows with the game, and not all windows can lose their connection, plus at one time the user can only play in one game room, the creation of new ones should be stopped until the end of the current game.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitaly Zheltyakov, 2012-04-03
@VitaZheltyakov

In the vast majority of browser games, it is customary to save the player's state in the database. In your case, you will need two tables: player state and game room state.

I
Ivan Zhuravlev, 2012-04-04
@InteractiveTechnology

In socket.io, it creates a unique UID for each session (client-server connection). When creating a room, create a url so that this very UID is a parameter in it and assign this very UID when creating a new connection, so with the architecture of the game, if 2 players are still connected by these very UIDs in the database, then the desired game will be displayed to them , even after refreshing the page. This is if you do everything through socket.io with a hard binding.
And the second option is based on the same logic, but without binding to socket.io. Generate a unique hash for each game, when creating a player room, translate by url with the parameter of this unique hash (the hash is different for different players) and the same hash binds them in the game to a specific player.
I hope I explained it clearly, if you have any questions please ask :)

A
Anton fon Faust, 2014-01-29
@bubandos

Probably, it is no longer relevant, but still ...
Why not register this same room ID in the database for the user?
When the page is updated, a query is made to the database, from which the room in which the game takes place is obtained.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question