(cherry picked from commit 740a214362
)
tags/v0.13.0.2^0
@@ -43,7 +43,7 @@ define([ | |||||
el.css('margin-top', e.top); | el.css('margin-top', e.top); | ||||
this.message = { | this.message = { | ||||
ttl: this.maxTtl, | |||||
ttl: e.ttl ?? this.maxTtl, | |||||
el: el | el: el | ||||
}; | }; | ||||
}, | }, | ||||
@@ -107,10 +107,6 @@ module.exports = { | |||||
atlas.addObject(this.obj, true); | atlas.addObject(this.obj, true); | ||||
eventEmitter.emit('playerObjAdded', { | |||||
obj | |||||
}); | |||||
cb(); | cb(); | ||||
}, | }, | ||||
@@ -159,7 +159,8 @@ const config = { | |||||
] | ] | ||||
}, | }, | ||||
uiLoginList: [ | uiLoginList: [ | ||||
'login' | |||||
'login', | |||||
'announcements' | |||||
], | ], | ||||
uiList: [ | uiList: [ | ||||
'inventory', | 'inventory', | ||||
@@ -179,7 +180,6 @@ const config = { | |||||
'tooltips', | 'tooltips', | ||||
'tooltipInfo', | 'tooltipInfo', | ||||
'tooltipItem', | 'tooltipItem', | ||||
'announcements', | |||||
'quests', | 'quests', | ||||
'events', | 'events', | ||||
'progressBar', | 'progressBar', | ||||
@@ -2,7 +2,8 @@ | |||||
const objects = require('../objects/objects'); | const objects = require('../objects/objects'); | ||||
const events = require('../misc/events'); | const events = require('../misc/events'); | ||||
const { | const { | ||||
getThread, killThread, sendMessageToThread, getThreadFromId, returnWhenThreadsIdle, gePlayerCountInThread | |||||
getThread, killThread, sendMessageToThread, getThreadFromId, doesThreadExist, | |||||
returnWhenThreadsIdle, getPlayerCountInThread, killThreadIfEmpty | |||||
} = require('./threadManager'); | } = require('./threadManager'); | ||||
const { registerCallback, removeCallback } = require('./atlas/registerCallback'); | const { registerCallback, removeCallback } = require('./atlas/registerCallback'); | ||||
@@ -40,10 +41,29 @@ module.exports = { | |||||
zoneId = partyLeader.zoneId; | zoneId = partyLeader.zoneId; | ||||
} | } | ||||
const { thread, resetObjPosition } = await getThread({ | |||||
const eGetThread = { | |||||
zoneName, | zoneName, | ||||
zoneId | 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) { | if (resetObjPosition) { | ||||
delete obj.x; | delete obj.x; | ||||
@@ -108,7 +128,7 @@ module.exports = { | |||||
return; | return; | ||||
} | } | ||||
if (thread.instanced && (await gePlayerCountInThread(thread)) === 1) { | |||||
if (thread.instanced && (await getPlayerCountInThread(thread)) === 1) { | |||||
this.removeObjectFromInstancedZone(thread, playerId, callback); | this.removeObjectFromInstancedZone(thread, playerId, callback); | ||||
return; | return; | ||||
@@ -20,7 +20,7 @@ const getThreadFromId = threadId => { | |||||
return threads.find(t => t.id === threadId); | return threads.find(t => t.id === threadId); | ||||
}; | }; | ||||
const gePlayerCountInThread = async thread => { | |||||
const getPlayerCountInThread = async thread => { | |||||
const { playerCount } = await new Promise(res => { | const { playerCount } = await new Promise(res => { | ||||
const cb = registerCallback(res); | const cb = registerCallback(res); | ||||
@@ -94,7 +94,7 @@ const messageHandlers = { | |||||
rezone: async function (thread, message) { | rezone: async function (thread, message) { | ||||
const { args: { obj, newZone, keepPos = true } } = 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(); | thread.worker.kill(); | ||||
threads.spliceWhere(t => t === thread); | threads.spliceWhere(t => t === thread); | ||||
} | } | ||||
@@ -173,6 +173,12 @@ const spawnThread = async ({ name, path, instanced }) => { | |||||
return promise; | 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 getThread = async ({ zoneName, zoneId }) => { | ||||
const result = { | const result = { | ||||
resetObjPosition: false, | resetObjPosition: false, | ||||
@@ -208,6 +214,13 @@ const killThread = thread => { | |||||
threads.spliceWhere(t => t === thread); | threads.spliceWhere(t => t === thread); | ||||
}; | }; | ||||
const killThreadIfEmpty = async thread => { | |||||
const playerCount = await getPlayerCountInThread(thread); | |||||
if (playerCount === 0) | |||||
killThread(thread); | |||||
}; | |||||
const spawnMapThreads = async () => { | const spawnMapThreads = async () => { | ||||
const promises = mapList | const promises = mapList | ||||
.filter(m => !m.disabled && !m.instanced) | .filter(m => !m.disabled && !m.instanced) | ||||
@@ -255,9 +268,11 @@ module.exports = { | |||||
getThread, | getThread, | ||||
killThread, | killThread, | ||||
getThreadFromId, | getThreadFromId, | ||||
doesThreadExist, | |||||
spawnMapThreads, | spawnMapThreads, | ||||
messageAllThreads, | messageAllThreads, | ||||
killThreadIfEmpty, | |||||
sendMessageToThread, | sendMessageToThread, | ||||
returnWhenThreadsIdle, | returnWhenThreadsIdle, | ||||
gePlayerCountInThread | |||||
getPlayerCountInThread | |||||
}; | }; |