@@ -168,7 +168,9 @@ define([ | |||||
client.request({ | client.request({ | ||||
cpn: 'social', | cpn: 'social', | ||||
method: 'getInvite', | method: 'getInvite', | ||||
id: charId | |||||
data: { | |||||
targetId: charId | |||||
} | |||||
}); | }); | ||||
} | } | ||||
}; | }; | ||||
@@ -196,7 +196,9 @@ define([ | |||||
client.request({ | client.request({ | ||||
cpn: 'social', | cpn: 'social', | ||||
method: 'acceptInvite', | method: 'acceptInvite', | ||||
id: this.invite.fromId | |||||
data: { | |||||
targetId: this.invite.fromId | |||||
} | |||||
}); | }); | ||||
}, | }, | ||||
@@ -204,9 +206,8 @@ define([ | |||||
client.request({ | client.request({ | ||||
cpn: 'social', | cpn: 'social', | ||||
method: 'declineInvite', | method: 'declineInvite', | ||||
id: this.invite.fromId, | |||||
data: { | data: { | ||||
targetId: window.player.serverId | |||||
targetId: this.invite.fromId | |||||
} | } | ||||
}); | }); | ||||
}, | }, | ||||
@@ -208,8 +208,11 @@ module.exports = { | |||||
}, | }, | ||||
splitStack: function (msg) { | splitStack: function (msg) { | ||||
let { stackSize = 1 } = msg; | |||||
stackSize = ~~stackSize; | |||||
let item = this.findItem(msg.itemId); | let item = this.findItem(msg.itemId); | ||||
if (!item || !item.quantity || item.quantity <= msg.stackSize || msg.stackSize < 1 || item.quest) | |||||
if (!item || !item.quantity || item.quantity <= stackSize || stackSize < 1 || item.quest) | |||||
return; | return; | ||||
const hasSpace = this.hasSpace(item, true); | const hasSpace = this.hasSpace(item, true); | ||||
@@ -219,8 +222,8 @@ module.exports = { | |||||
} | } | ||||
let newItem = extend({}, item); | let newItem = extend({}, item); | ||||
item.quantity -= msg.stackSize; | |||||
newItem.quantity = msg.stackSize; | |||||
item.quantity -= stackSize; | |||||
newItem.quantity = stackSize; | |||||
this.getItem(newItem, true, true); | this.getItem(newItem, true, true); | ||||
@@ -36,6 +36,8 @@ const sendObjToZone = async ({ obj, invokingObj, zoneName, toPos, toRelativePos | |||||
return; | return; | ||||
} | } | ||||
obj.fireEvent('beforeRezone'); | |||||
//We set this before saving so that objects aren't saved ON portals | //We set this before saving so that objects aren't saved ON portals | ||||
obj.zoneName = zoneName; | obj.zoneName = zoneName; | ||||
fixPosition(obj, toPos, toRelativePos, invokingObj); | fixPosition(obj, toPos, toRelativePos, invokingObj); | ||||
@@ -1,5 +1,10 @@ | |||||
let objects = require('../objects/objects'); | |||||
//External Modules | |||||
const objects = require('../objects/objects'); | |||||
//Helpers | |||||
const { route, routeGlobal } = require('./connections/route'); | |||||
//Module | |||||
module.exports = { | module.exports = { | ||||
players: [], | players: [], | ||||
@@ -57,56 +62,11 @@ module.exports = { | |||||
}, | }, | ||||
route: function (socket, msg) { | route: function (socket, msg) { | ||||
let player = null; | |||||
if (msg.id) { | |||||
player = this.players.find(p => p.id === msg.id); | |||||
let source = this.players.find(p => p.socket.id === socket.id); | |||||
if (!source) | |||||
return; | |||||
if (!msg.data) | |||||
msg.data = {}; | |||||
msg.data.sourceId = source.id; | |||||
} else | |||||
player = this.players.find(p => p.socket.id === socket.id); | |||||
if ( | |||||
(!player) || | |||||
( | |||||
(player.permadead) && | |||||
(['getCharacterList', 'getCharacter', 'deleteCharacter'].indexOf(msg.method) === -1) | |||||
) || | |||||
( | |||||
player.dead && | |||||
!( | |||||
(msg.method === 'performAction' && ['respawn'].includes(msg.data.method)) || | |||||
(msg.method === 'clientAck') | |||||
) | |||||
) | |||||
) | |||||
return; | |||||
if (msg.threadModule) { | |||||
const source = this.players.find(p => p.socket.id === socket.id); | |||||
if (!source) | |||||
return; | |||||
if (msg.callback) | |||||
msg.data.callbackId = atlas.registerCallback(msg.callback); | |||||
msg.data.sourceId = source.id; | |||||
atlas.send(player.zone, msg); | |||||
return; | |||||
} | |||||
let cpn = player[msg.cpn]; | |||||
if (!cpn) | |||||
return; | |||||
route.call(this, socket, msg); | |||||
}, | |||||
let method = msg.method; | |||||
if (cpn[method]) | |||||
cpn[method](msg); | |||||
routeGlobal: function (msg) { | |||||
routeGlobal.call(this, msg); | |||||
}, | }, | ||||
routeGlobal: function (msg) { | routeGlobal: function (msg) { | ||||
@@ -0,0 +1,58 @@ | |||||
const route = function (socket, msg) { | |||||
const source = this.players.find(p => p.socket.id === socket.id); | |||||
if (!source) | |||||
return; | |||||
if (!msg.data) | |||||
msg.data = {}; | |||||
msg.data.sourceId = source.id; | |||||
if ( | |||||
( | |||||
(source.permadead) && | |||||
(['getCharacterList', 'getCharacter', 'deleteCharacter'].indexOf(msg.method) === -1) | |||||
) || | |||||
( | |||||
source.dead && | |||||
!( | |||||
(msg.method === 'performAction' && ['respawn'].includes(msg.data.method)) || | |||||
(msg.method === 'clientAck') | |||||
) | |||||
) | |||||
) | |||||
return; | |||||
if (msg.threadModule) { | |||||
if (msg.callback) | |||||
msg.data.callbackId = atlas.registerCallback(msg.callback); | |||||
atlas.send(source.zone, msg); | |||||
return; | |||||
} | |||||
let target = source; | |||||
if (msg.data.targetId !== undefined) { | |||||
target = this.players.find(p => p.id === msg.data.targetId); | |||||
if (!target) | |||||
return; | |||||
} | |||||
let cpn = target[msg.cpn]; | |||||
if (!cpn) | |||||
return; | |||||
let method = msg.method; | |||||
if (cpn[method]) | |||||
cpn[method](msg); | |||||
}; | |||||
const routeGlobal = function (msg) { | |||||
global[msg.module][msg.method](msg); | |||||
}; | |||||
module.exports = { | |||||
route, | |||||
routeGlobal | |||||
}; |
@@ -1,4 +1,4 @@ | |||||
const { routerConfig: { allowed, secondaryAllowed, globalAllowed, allowTargetId } } = require('./routerConfig'); | |||||
const { routerConfig: { allowed, allowTargetId, secondaryAllowed, globalAllowed, secondaryAllowTargetId } } = require('./routerConfig'); | |||||
module.exports = { | module.exports = { | ||||
allowedCpn: function (msg) { | allowedCpn: function (msg) { | ||||
@@ -8,15 +8,22 @@ module.exports = { | |||||
if (!valid) | if (!valid) | ||||
return false; | return false; | ||||
if (!secondaryCpn) | |||||
if (!secondaryCpn) { | |||||
if (targetId !== undefined) { | |||||
const canHaveTargetId = allowTargetId?.[cpn]?.includes(method); | |||||
if (!canHaveTargetId) | |||||
return false; | |||||
} | |||||
return true; | return true; | ||||
} | |||||
const secondaryValid = secondaryAllowed?.[secondaryCpn]?.includes(secondaryMethod); | const secondaryValid = secondaryAllowed?.[secondaryCpn]?.includes(secondaryMethod); | ||||
if (!secondaryValid) | if (!secondaryValid) | ||||
return false; | return false; | ||||
if (targetId !== undefined) { | if (targetId !== undefined) { | ||||
const canHaveTargetId = allowTargetId?.[secondaryCpn]?.includes(secondaryMethod); | |||||
const canHaveTargetId = secondaryAllowTargetId?.[secondaryCpn]?.includes(secondaryMethod); | |||||
if (!canHaveTargetId) | if (!canHaveTargetId) | ||||
return false; | return false; | ||||
} | } | ||||
@@ -1,11 +1,18 @@ | |||||
let events = require('../misc/events'); | let events = require('../misc/events'); | ||||
const routerConfig = { | const routerConfig = { | ||||
//Component methods that can be called on the main thread | |||||
allowed: { | allowed: { | ||||
player: ['performAction', 'queueAction', 'move'], | player: ['performAction', 'queueAction', 'move'], | ||||
auth: ['login', 'register', 'play', 'getCharacterList', 'getCharacter', 'deleteCharacter', 'getSkinList', 'createCharacter', 'getCustomChannels'], | auth: ['login', 'register', 'play', 'getCharacterList', 'getCharacter', 'deleteCharacter', 'getSkinList', 'createCharacter', 'getCustomChannels'], | ||||
social: ['chat', 'getInvite', 'acceptInvite', 'declineInvite', 'removeFromParty', 'leaveParty'] | social: ['chat', 'getInvite', 'acceptInvite', 'declineInvite', 'removeFromParty', 'leaveParty'] | ||||
}, | }, | ||||
//Component methods that can be called with a targetId | |||||
// which means that we're not calling our own component method but instead, another object's component method | |||||
allowTargetId: { | |||||
social: ['getInvite', 'acceptInvite', 'declineInvite'] | |||||
}, | |||||
//Component methods that can be called on map threads through `performAction` or `queueAction` methods | |||||
secondaryAllowed: { | secondaryAllowed: { | ||||
dialogue: ['talk'], | dialogue: ['talk'], | ||||
gatherer: ['gather'], | gatherer: ['gather'], | ||||
@@ -20,21 +27,24 @@ const routerConfig = { | |||||
passives: ['tickNode', 'untickNode'], | passives: ['tickNode', 'untickNode'], | ||||
workbench: ['open', 'craft', 'getRecipe'] | workbench: ['open', 'craft', 'getRecipe'] | ||||
}, | }, | ||||
globalAllowed: { | |||||
clientConfig: ['getClientConfig'], | |||||
leaderboard: ['requestList'], | |||||
cons: ['unzone'], | |||||
rezoneManager: ['clientAck'], | |||||
instancer: ['clientAck'] | |||||
}, | |||||
allowTargetId: { | |||||
//Component methods that can be called on map threads with a targetId | |||||
// which means that we're not calling our own component method but instead, another object's component method | |||||
// These are called through `performAction` or `queueAction` methods | |||||
secondaryAllowTargetId: { | |||||
door: ['lock', 'unlock'], | door: ['lock', 'unlock'], | ||||
gatherer: ['gather'], | gatherer: ['gather'], | ||||
equipment: ['inspect'], | equipment: ['inspect'], | ||||
stash: ['open'], | stash: ['open'], | ||||
social: ['declineInvite'], | |||||
wardrobe: ['open', 'apply'], | wardrobe: ['open', 'apply'], | ||||
workbench: ['open', 'craft', 'getRecipe'] | workbench: ['open', 'craft', 'getRecipe'] | ||||
}, | |||||
//Global module methods that can be called on the main thread or map threads | |||||
globalAllowed: { | |||||
clientConfig: ['getClientConfig'], | |||||
leaderboard: ['requestList'], | |||||
cons: ['unzone'], | |||||
rezoneManager: ['clientAck'], | |||||
instancer: ['clientAck'] | |||||
} | } | ||||
}; | }; | ||||