first GodDaemons group commit
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
import { publishActionReply, parseAt } from '../../actionsHelper.js'
|
||||
|
||||
export const methods = {
|
||||
|
||||
/* Event-Rx:
|
||||
{
|
||||
"action": "GETAGENTPOSITION",
|
||||
"reqid": "6az5e4r6a",
|
||||
"payload": {
|
||||
"agentId": "agent42",
|
||||
"at": "2026-06-07T12:00:00.000Z"
|
||||
}
|
||||
}
|
||||
Event-Tx:
|
||||
{
|
||||
"action": "GETAGENTPOSITION",
|
||||
"success": true,
|
||||
"reqid": "6az5e4r6a",
|
||||
"payload": {
|
||||
"agent": {
|
||||
"id": "agent42",
|
||||
"position": { "x": 1, "y": 2, "z": 3 },
|
||||
"vector": { "x": 0, "y": 0, "z": 0 },
|
||||
"since": 1717750800,
|
||||
"generation": 2,
|
||||
"at": "2026-06-07T12:00:00.000Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
async action_GETAGENTPOSITION(action, payload, reqid, sender, roles) {
|
||||
const replyOpts = {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
replyChannel: this.config.gps.gpsActionsReply,
|
||||
}
|
||||
if(!this.accessRights.canDo(roles, action)) {
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: false,
|
||||
err: 'Unauthorized action !',
|
||||
} })
|
||||
return
|
||||
}
|
||||
|
||||
const agentId = payload?.agentId
|
||||
if(!agentId || typeof(agentId) !== 'string') {
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: false,
|
||||
err: 'Missing or invalid agentId',
|
||||
} })
|
||||
return
|
||||
}
|
||||
|
||||
const at = parseAt(payload, () => this.gpsSrv.now())
|
||||
if(at === null) {
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: false,
|
||||
err: 'Invalid at timestamp',
|
||||
} })
|
||||
return
|
||||
}
|
||||
|
||||
const agent = this.gpsSrv.getAgentPosition(agentId, at)
|
||||
if(!agent) {
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: false,
|
||||
err: `Unknown agent: ${agentId}`,
|
||||
} })
|
||||
return
|
||||
}
|
||||
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: true,
|
||||
payload: { agent },
|
||||
} })
|
||||
},
|
||||
|
||||
/* Event-Rx:
|
||||
{
|
||||
"action": "GETAGENTSINPRISM",
|
||||
"reqid": "6az5e4r6a",
|
||||
"payload": {
|
||||
"prism": {
|
||||
"xMin": -10, "xMax": 10,
|
||||
"yMin": -10, "yMax": 10,
|
||||
"zMin": 0, "zMax": 5
|
||||
},
|
||||
"at": "2026-06-07T12:00:00.000Z"
|
||||
}
|
||||
}
|
||||
Event-Tx:
|
||||
{
|
||||
"action": "GETAGENTSINPRISM",
|
||||
"success": true,
|
||||
"reqid": "6az5e4r6a",
|
||||
"payload": {
|
||||
"agents": [ ... ],
|
||||
"at": "2026-06-07T12:00:00.000Z"
|
||||
}
|
||||
}
|
||||
*/
|
||||
async action_GETAGENTSINPRISM(action, payload, reqid, sender, roles) {
|
||||
const replyOpts = {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
replyChannel: this.config.gps.gpsActionsReply,
|
||||
}
|
||||
if(!this.accessRights.canDo(roles, action)) {
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: false,
|
||||
err: 'Unauthorized action !',
|
||||
} })
|
||||
return
|
||||
}
|
||||
|
||||
const prism = payload?.prism
|
||||
if(!this.gpsSrv.isValidPrism(prism)) {
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: false,
|
||||
err: 'Missing or invalid prism bounds',
|
||||
} })
|
||||
return
|
||||
}
|
||||
|
||||
const at = parseAt(payload, () => this.gpsSrv.now())
|
||||
if(at === null) {
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: false,
|
||||
err: 'Invalid at timestamp',
|
||||
} })
|
||||
return
|
||||
}
|
||||
|
||||
const agents = this.gpsSrv.getAgentsInPrism(prism, at)
|
||||
publishActionReply(this, { ...replyOpts, reply: {
|
||||
success: true,
|
||||
payload: {
|
||||
agents,
|
||||
at: new Date(at * 1000).toISOString(),
|
||||
},
|
||||
} })
|
||||
},
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user