-
Notifications
You must be signed in to change notification settings - Fork 18
Disconnections and Reconnections v7
- status: complete
- version: 7.x
- follows from: Automated Players
Handling disconnections (i.e., dropouts) correctly is key. nodeGame offers a standard solution and many customization options.
The first thing is to decide whether reconnections are enabled in the channel.
Reconnections are enabled/disabled in file channel/channel.settings.js
:
-
enableReconnections: If TRUE, reconnections are enabled (default TRUE).
-
sameStepReconnectionOnly: If TRUE, reconnections are enabled only within the same game step (default: FALSE).
-
disposeFailedReconnections: If TRUE, clients that tried to reconnect but failed are disposed. If FALSE, failed reconnections are treated as new connections (default FALSE). A reconnection can fail for any reason, but in particular, if:
- parameter
enabledReconnections
is FALSE, - parameter
sameStepReconnectionOnly
is TRUE and the client's stage and the logic's stage are different. - the room in which the client was before the disconnection is no longer existing.
- parameter
If reconnections are enabled, the following methods are available:
- Size handlers: pauses the game and take custom actions when the number of connected players changes,
- Push Manager: force clients to go the next step, else disconnects them.
- Reconnect Callback: initialize reconnecting clients.
Each method is described in details in the next pages.
Below is an overview of how they interact when a client attempts to reconnect.
When a client reconnects after a disconnection the following steps are taken:
-
The game room in which the player was at the moment of disconnection is looked up. If no longer existing, the client is either disposed or treated as a new connection, depending on the channel settings described above.
-
The stage in which the player disconnected and the current logic's stage are compared. If
sameStepReconnectionOnly
is enabled in the channel settings (default FALSE), then the client is disposed if the stages are different. -
The client is setup again (the
node.game
object is recreated). Language settings are also sent, if different from English. -
The client is initialized, but the game is not started yet.
-
If a reconnect step property is set in the logic, it is executed. If it returns FALSE, the client is disposed.
-
The reconnection options, as prepared by the reconnect callback are sent to the client, including the current value of the step timer, any modification to the plot object.
-
The client is advanced to the proper reconnecting step: either the step of in which the disconnection had happened, or the current logic's step, whichever is more ahead in the game sequence.
-
If any size-handler is defined, it is evaluated. If the number of players is still not correct, the reconnecting client is immediately paused.
To test the if your reconnections are working correctly, you can simulate disconnections and reconnections inserting the following code in any step of player.js
.
node.socket.disconnect();
node.game.stop();
node.timer.random(2000, 4000).exec(function() {
node.socket.reconnect();
});
To conditionally execute disconnections, see how to create probabilistic events with the Timer API.
To replace a disconnected player with a bot refer to the Server API.
The widget DisconnectBox can handle disconnections and reconnections directly on the browser.
Go back to the wiki Home.
Copyright (C) 2021 Stefano Balietti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.