From 2da0208563c356e23cd1cd36b04f77caf7bfa1f8 Mon Sep 17 00:00:00 2001 From: Shaun Date: Sun, 1 May 2022 09:10:36 +0200 Subject: [PATCH] bug #1934: Fixed saveAll command crashing --- src/server/components/auth.js | 14 +++++++++++ .../components/extensions/socialCommands.js | 10 ++++++-- src/server/security/connections.js | 24 +++++++++++++------ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/server/components/auth.js b/src/server/components/auth.js index 0dc556ff..700378d6 100644 --- a/src/server/components/auth.js +++ b/src/server/components/auth.js @@ -113,6 +113,20 @@ module.exports = { callback(); }, + //This function is called from the 'forceSave' command. Because of this, the first argument is the action data + // instead of (callback, saveStash) + doSaveManual: async function (msg) { + await this.doSave(null, true); + + process.send({ + module: 'atlas', + method: 'resolveCallback', + msg: { + id: msg.callbackId + } + }); + }, + doSaveStash: async function () { const { username, obj: { stash } } = this; diff --git a/src/server/components/extensions/socialCommands.js b/src/server/components/extensions/socialCommands.js index 8d3208f6..af6ceedc 100644 --- a/src/server/components/extensions/socialCommands.js +++ b/src/server/components/extensions/socialCommands.js @@ -600,8 +600,14 @@ module.exports = { }); }, - saveAll: function () { - connections.forceSaveAll(); + saveAll: async function () { + const { obj: { social } } = this; + + social.sendMessage('Initiating Save', 'color-blueA'); + + await connections.forceSaveAll(); + + social.sendMessage('Save Complete', 'color-blueA'); }, rezone: function (msg) { diff --git a/src/server/security/connections.js b/src/server/security/connections.js index 4304dd66..091b96b8 100644 --- a/src/server/security/connections.js +++ b/src/server/security/connections.js @@ -162,16 +162,26 @@ module.exports = { return result; }, - forceSaveAll: function () { - this.players + forceSaveAll: async function () { + const promises = this.players .filter(p => p.zoneName !== undefined) - .forEach(p => { - atlas.performAction(p, { - cpn: 'auth', - method: 'doSave', - data: {} + .map(p => { + const promise = new Promise(res => { + const msg = { + cpn: 'auth', + method: 'doSaveManual', + data: { + callbackId: atlas.registerCallback(res) + } + }; + + atlas.performAction(p, msg); }); + + return promise; }); + + await Promise.all(promises); }, modifyPlayerCount: function (delta) {