Browse Source

Merge branch 'master' into 'release'

bug: Fixed an issue causing threads to stay alive when dc'ing

See merge request Isleward/isleward!618
tags/v0.12.0.4
Big Bad Waffle 1 year ago
parent
commit
7ea6f6290f
2 changed files with 6 additions and 6 deletions
  1. +2
    -2
      src/server/world/atlas.js
  2. +4
    -4
      src/server/world/threadManager.js

+ 2
- 2
src/server/world/atlas.js View File

@@ -2,7 +2,7 @@
const objects = require('../objects/objects');
const events = require('../misc/events');
const {
getThread, killThread, sendMessageToThread, getThreadFromId, returnWhenThreadsIdle, canThreadBeClosed
getThread, killThread, sendMessageToThread, getThreadFromId, returnWhenThreadsIdle, gePlayerCountInThread
} = require('./threadManager');
const { registerCallback, removeCallback } = require('./atlas/registerCallback');

@@ -87,7 +87,7 @@ module.exports = {
if (!thread)
return;

if (thread.instanced && await canThreadBeClosed(thread, this.registerCallback.bind(this))) {
if (thread.instanced && (await gePlayerCountInThread(thread)) === 1) {
this.removeObjectFromInstancedZone(thread, obj, callback);

return;


+ 4
- 4
src/server/world/threadManager.js View File

@@ -20,7 +20,7 @@ const getThreadFromId = threadId => {
return threads.find(t => t.id === threadId);
};

const canThreadBeClosed = async thread => {
const gePlayerCountInThread = async thread => {
const { playerCount } = await new Promise(res => {
const cb = registerCallback(res);

@@ -32,7 +32,7 @@ const canThreadBeClosed = async thread => {
});
});

return playerCount === 0;
return playerCount;
};

const messageHandlers = {
@@ -94,7 +94,7 @@ const messageHandlers = {
rezone: async function (thread, message) {
const { args: { obj, newZone, keepPos = true } } = message;

if (thread.instanced && await canThreadBeClosed(thread)) {
if (thread.instanced && (await gePlayerCountInThread(thread)) === 0) {
thread.worker.kill();
threads.spliceWhere(t => t === thread);
}
@@ -259,5 +259,5 @@ module.exports = {
messageAllThreads,
sendMessageToThread,
returnWhenThreadsIdle,
canThreadBeClosed
gePlayerCountInThread
};

Loading…
Cancel
Save