From deb6842a4db07c65a090df0e1ad822048f53439c Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 12 Jul 2022 22:22:58 +0200 Subject: [PATCH] Record all players as leaving on server exit In the case of shutdown the Factorio server will not notify the currently online players as leaving the game. Notify the master server that all remaining online players quit the game in this case. --- packages/lib/plugin.js | 6 ++++-- packages/slave/src/Instance.js | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index 23499e4b..162794d4 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -210,7 +210,8 @@ class BaseInstancePlugin { * @param {string} event.name - Name of the player that joined/left. * @param {string=} event.reason - * Only present for type "leave". Reason for player leaving the - * game, one of the possible reasons in defines.disconnect_reason. + * game, one of the possible reasons in defines.disconnect_reason + * or "server_quit" if the server exits while the player is online. */ async onPlayerEvent(event) { } @@ -505,7 +506,8 @@ class BaseMasterPlugin { * @param {string} event.name - Name of the player that joined/left. * @param {string=} event.reason - * Only present for type "leave". Reason for player leaving the - * game, one of the possible reasons in defines.disconnect_reason. + * game, one of the possible reasons in defines.disconnect_reason + * or "server_quit" if the server exits while the player is online. */ async onPlayerEvent(instance, event) { } diff --git a/packages/slave/src/Instance.js b/packages/slave/src/Instance.js index 1fa1543c..58f15554 100644 --- a/packages/slave/src/Instance.js +++ b/packages/slave/src/Instance.js @@ -483,6 +483,9 @@ class Instance extends libLink.Link { pluginInstance.onExit(); } + for (let player of left) { + this._recordPlayerLeave(player, "server_quit"); + } this._saveStats().catch(err => this.logger.error(`Error saving stats:\n${err.stack}`)); }