From 2e2749bdb76028370f921ecbba039d20bc7660ff Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 1 Jun 2023 12:43:43 +0200 Subject: [PATCH] bug #1995 --- src/server/world/instancer.js | 58 ++++++++++++++++------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/src/server/world/instancer.js b/src/server/world/instancer.js index cdd1d2a6..00f20b76 100644 --- a/src/server/world/instancer.js +++ b/src/server/world/instancer.js @@ -319,15 +319,7 @@ module.exports = { if (this.regenBusy) { this.unqueueMessage(msg); - if (msg.callbackId) { - process.send({ - module: 'atlas', - method: 'resolveCallback', - msg: { - id: msg.callbackId - } - }); - } + this.resolveCallback(msg); return; } @@ -339,7 +331,9 @@ module.exports = { let obj = msg.obj; obj = objects.find(o => o.serverId === obj.id); if (!obj) { - //We should probably never reach this + //We could reach this if a player dc's while zoning in + this.resolveCallback(msg); + return; } @@ -354,15 +348,7 @@ module.exports = { obj.destroyed = true; - if (msg.callbackId) { - process.send({ - module: 'atlas', - method: 'resolveCallback', - msg: { - id: msg.callbackId - } - }); - } + this.resolveCallback(msg); }, notifyOnceIdle: async function () { @@ -373,7 +359,8 @@ module.exports = { }); }, - forceSavePlayer: async function ({ playerId, callbackId }) { + forceSavePlayer: async function (msg) { + const { playerId } = msg; const player = objects.objects.find(o => o.serverId === playerId); if (!player?.auth) { @@ -388,25 +375,32 @@ module.exports = { await player.auth.doSave(); - process.send({ - module: 'atlas', - method: 'resolveCallback', - msg: { - id: callbackId + this.resolveCallback(msg); + }, + + getPlayerCount: function (msg) { + this.resolveCallback(msg, { + result: { + playerCount: objects.objects.filter(o => o.player !== undefined).length } }); }, - getPlayerCount: function ({ callbackId }) { - process.send({ + resolveCallback: function ({ callbackId }, data) { + if (!callbackId) + return; + + const payload = { module: 'atlas', method: 'resolveCallback', msg: { - id: callbackId, - result: { - playerCount: objects.objects.filter(o => o.player !== undefined).length - } + id: callbackId } - }); + }; + + if (data) + Object.assign(payload.msg, data); + + process.send(payload); } };