28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
|
|
export const eventHandlers = {
|
|
'arena:agents:*': {
|
|
change(msg, chan, sender, cnxId) {
|
|
const agentId = msg.sender
|
|
if(!agentId || typeof(agentId) !== 'string') {
|
|
console.warn(`[${this.redisId}] Agent event without sender`)
|
|
return
|
|
}
|
|
const newVector = msg.payload?.newVector
|
|
if(!newVector || typeof(newVector.x) !== 'number' || typeof(newVector.y) !== 'number' || typeof(newVector.z) !== 'number') {
|
|
console.warn(`[${this.redisId}] Invalid newVector from ${agentId}`)
|
|
return
|
|
}
|
|
const newPosition = msg.payload?.newPosition ?? null
|
|
this.gpsSrv?.onVectorChange(agentId, newVector, newPosition)
|
|
},
|
|
remove(msg, chan, sender, cnxId) {
|
|
const agentId = msg.sender
|
|
if(!agentId || typeof(agentId) !== 'string') {
|
|
console.warn(`[${this.redisId}] Agent event without sender`)
|
|
return
|
|
}
|
|
this.gpsSrv?.onAgentRemove(agentId)
|
|
},
|
|
},
|
|
}
|