Browse Source

feat #1866: Moved save to after delete and ensured that deleted objects aren't processed (or crashing) objects update

tags/v0.10.6^2
Shaun 2 years ago
parent
commit
5dde12f198
4 changed files with 24 additions and 9 deletions
  1. +1
    -1
      src/client/js/objects/objBase.js
  2. +9
    -7
      src/server/components/portal/sendObjToZone.js
  3. +8
    -0
      src/server/objects/objects.js
  4. +6
    -1
      src/server/world/syncer.js

+ 1
- 1
src/client/js/objects/objBase.js View File

@@ -174,7 +174,7 @@ define([

offEvents: function () {
if (this.pather)
this.pather.clearPath();
this.pather.resetPath();

for (let e in this.eventCallbacks)
this.eventCallbacks[e].forEach(c => events.off(e, c));


+ 9
- 7
src/server/components/portal/sendObjToZone.js View File

@@ -36,17 +36,19 @@ const sendObjToZone = async ({ obj, invokingObj, zoneName, toPos, toRelativePos
obj.y = invokingObj.obj.y + toRelativePos.y;
}

await obj.auth.doSave();

//Destroy, flush events and notify other objects
globalSyncer.processDestroyedObject(obj);
await obj.auth.doSave();

//Test code, remove later
const queued = Object.values(globalSyncer.buffer).filter(b => b.to.includes(serverId));
if (queued.length) {
/* eslint-disable-next-line */
console.log('Found', queued.length, 'events for rezoning object');
}
Object.entries(globalSyncer.buffer).forEach(([k, v]) => {
v.forEach(e => {
if (e.to.includes(serverId)) {
/* eslint-disable-next-line */
console.log('Found event', k, 'for rezoning object');
}
});
});

const simpleObj = obj.getSimple(true, false, true);



+ 8
- 0
src/server/objects/objects.js View File

@@ -340,6 +340,14 @@ module.exports = {
if ((o.update) && (!o.destroyed))
o.update();

//When objects are sent to other zones, we destroy them immediately (thhrough sendObjToZone)
// In these cases, we DO need to remove it
if (o.forceDestroy) {
i--;
len--;
continue;
}

if (o.ttl) {
o.ttl--;
if (!o.ttl)


+ 6
- 1
src/server/world/syncer.js View File

@@ -185,7 +185,10 @@ module.exports = {
const { id, serverId } = obj;

obj.destroyed = true;
this.flushForTarget(serverId);

//We mark forceDestroy to tell objects that we're destroying an object outside of the
// syncer's update method
obj.forceDestroy = true;

const msg = {
id: id,
@@ -194,6 +197,8 @@ module.exports = {

objects.removeObject(obj);

this.flushForTarget(serverId);

const fnQueueMsg = queue.bind(this, 'onGetObject');

//Find any players that have seen this obj


Loading…
Cancel
Save