Browse Source

bug #2004: no longer emitting players before they are added to map threads

tags/v0.14.0^2
Shaun 6 months ago
parent
commit
740a214362
5 changed files with 45 additions and 14 deletions
  1. +1
    -1
      src/client/ui/templates/announcements/announcements.js
  2. +0
    -4
      src/server/components/player.js
  3. +2
    -2
      src/server/config/clientConfig.js
  4. +24
    -4
      src/server/world/atlas.js
  5. +18
    -3
      src/server/world/threadManager.js

+ 1
- 1
src/client/ui/templates/announcements/announcements.js View File

@@ -43,7 +43,7 @@ define([
el.css('margin-top', e.top);

this.message = {
ttl: this.maxTtl,
ttl: e.ttl ?? this.maxTtl,
el: el
};
},


+ 0
- 4
src/server/components/player.js View File

@@ -107,10 +107,6 @@ module.exports = {

atlas.addObject(this.obj, true);

eventEmitter.emit('playerObjAdded', {
obj
});

cb();
},



+ 2
- 2
src/server/config/clientConfig.js View File

@@ -159,7 +159,8 @@ const config = {
]
},
uiLoginList: [
'login'
'login',
'announcements'
],
uiList: [
'inventory',
@@ -179,7 +180,6 @@ const config = {
'tooltips',
'tooltipInfo',
'tooltipItem',
'announcements',
'quests',
'events',
'progressBar',


+ 24
- 4
src/server/world/atlas.js View File

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

@@ -40,10 +41,29 @@ module.exports = {
zoneId = partyLeader.zoneId;
}

const { thread, resetObjPosition } = await getThread({
const eGetThread = {
zoneName,
zoneId
});
};

if (!doesThreadExist(eGetThread)) {
serverObj.socket.emit('event', {
event: 'onGetAnnouncement',
data: {
msg: 'Generating a new map, please wait as this may take a few moments..',
ttl: 5000
}
});
}

const { thread, resetObjPosition } = await getThread(eGetThread);

//Perhaps the player disconnected while waiting for the thread to spawn
if (!obj.socket.connected) {
await killThreadIfEmpty(thread);

return;
}
if (resetObjPosition) {
delete obj.x;
@@ -108,7 +128,7 @@ module.exports = {
return;
}

if (thread.instanced && (await gePlayerCountInThread(thread)) === 1) {
if (thread.instanced && (await getPlayerCountInThread(thread)) === 1) {
this.removeObjectFromInstancedZone(thread, playerId, callback);

return;


+ 18
- 3
src/server/world/threadManager.js View File

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

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

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

if (thread.instanced && (await gePlayerCountInThread(thread)) === 0) {
if (thread.instanced && (await getPlayerCountInThread(thread)) === 0) {
thread.worker.kill();
threads.spliceWhere(t => t === thread);
}
@@ -173,6 +173,12 @@ const spawnThread = async ({ name, path, instanced }) => {
return promise;
};

const doesThreadExist = ({ zoneName, zoneId }) => {
const exists = threads.some(t => t.id === zoneId && t.name === zoneName);

return exists;
};

const getThread = async ({ zoneName, zoneId }) => {
const result = {
resetObjPosition: false,
@@ -208,6 +214,13 @@ const killThread = thread => {
threads.spliceWhere(t => t === thread);
};

const killThreadIfEmpty = async thread => {
const playerCount = await getPlayerCountInThread(thread);

if (playerCount === 0)
killThread(thread);
};

const spawnMapThreads = async () => {
const promises = mapList
.filter(m => !m.disabled && !m.instanced)
@@ -255,9 +268,11 @@ module.exports = {
getThread,
killThread,
getThreadFromId,
doesThreadExist,
spawnMapThreads,
messageAllThreads,
killThreadIfEmpty,
sendMessageToThread,
returnWhenThreadsIdle,
gePlayerCountInThread
getPlayerCountInThread
};

Loading…
Cancel
Save