tons of cursor-shit cleaning, finished implementing cnxId in observer

This commit is contained in:
STEINNI
2026-06-27 17:24:41 +00:00
parent 4c9e989bda
commit a1dba5060a
28 changed files with 213 additions and 224 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ export const dispatchMessage = createDispatchMessage({
eventHandlers,
actionRules(redisCnx) {
const observer = redisCnx.config.observer ?? {}
const arenaChannel = observer.bus?.arena?.actionsChannel
const arenaChannel = observer.arenaActionsChannel
return({
channels: arenaChannel ? [arenaChannel] : [],
})
+3 -3
View File
@@ -1,13 +1,13 @@
export const eventHandlers = {
'arena:lifecycle': {
onYourMarks(msg, chan) {
onYourMarks(msg, chan, sender, cnxId) {
this.observerSrv?.onYourMarks()
},
bigBang(msg, chan) {
bigBang(msg, chan, sender, cnxId) {
this.observerSrv?.onBigBang()
},
simulationStopped(msg, chan) {
simulationStopped(msg, chan, sender, cnxId) {
this.observerSrv?.onSimulationStopped(msg.payload ?? {})
},
},
+1 -1
View File
@@ -11,7 +11,7 @@ export const dispatchMessage = createDispatchMessage({
actionRules(redisCnx) {
const observer = redisCnx.config.observer ?? {}
return({
channels: [observer.observerActionsChannel].filter(Boolean),
channels: [observer.ActionsChannel].filter(Boolean),
})
},
})
+25 -18
View File
@@ -4,66 +4,66 @@ import { Frustum } from '../../frustum.js'
export const actions = {
async action_GETAGENTPOSITION(action, payload, reqid, sender, roles) {
async action_GETAGENTPOSITION(action, payload, reqid, sender, cnxId, roles) {
const reader = this.observerSrv.gpsStorageReader
if(!reader) {
replyToAction(this, { action, reqid, sender, success: false, err: 'GPS storage reader not ready' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'GPS storage reader not ready' })
return
}
if(!this.observerSrv.isLive()) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Simulation not live' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Simulation not live' })
return
}
const agentId = payload?.agentId
if(!agentId || typeof(agentId) !== 'string') {
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid agentId' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing or invalid agentId' })
return
}
const at = parseSimTime(payload, () => this.observerSrv.now())
if(at === null) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Invalid simulation time' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Invalid simulation time' })
return
}
const agent = await reader.getAgentPosition(agentId, at)
if(!agent) {
replyToAction(this, { action, reqid, sender, success: false, err: `Unknown agent: ${agentId}` })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: `Unknown agent: ${agentId}` })
return
}
replyToAction(this, { action, reqid, sender, success: true, payload: { agent } })
replyToAction(this, { action, reqid, sender, cnxId, success: true, payload: { agent } })
},
async action_GETAGENTSINFRUSTUM(action, payload, reqid, sender, roles) {
async action_GETAGENTSINFRUSTUM(action, payload, reqid, sender, cnxId, roles) {
const registry = this.observerSrv.requestorRegistry
if(!registry) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Requestor registry not ready' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Requestor registry not ready' })
return
}
if(!this.observerSrv.isLive()) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Simulation not live' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Simulation not live' })
return
}
const frustum = Frustum.fromPlanes(payload?.planes)
if(!frustum) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid frustum planes (expected 6)' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing or invalid frustum planes (expected 6)' })
return
}
const at = parseSimTime(payload, () => this.observerSrv.now())
if(at === null) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Invalid simulation time' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Invalid simulation time' })
return
}
const result = await registry.evaluateOnce({ frustum, t: at })
if(!result.ok) {
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: result.err })
return
}
@@ -71,6 +71,7 @@ export const actions = {
action,
reqid,
sender,
cnxId,
success: true,
payload: {
agents: result.agents,
@@ -79,24 +80,29 @@ export const actions = {
})
},
async action_SUBSCRIBEFRUSTUM(action, payload, reqid, sender, roles) {
async action_SUBSCRIBEFRUSTUM(action, payload, reqid, sender, cnxId, roles) {
const registry = this.observerSrv.requestorRegistry
if(!registry) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Requestor registry not ready' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Requestor registry not ready' })
return
}
if(!this.observerSrv.isLive()) {
replyToAction(this, { action, reqid, sender, success: false, err: 'Simulation not live' })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Simulation not live' })
return
}
const result = await registry.subscribeFrustum(sender, {
if(!cnxId || typeof(cnxId) !== 'string') {
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing or invalid cnxId' })
return
}
const result = await registry.subscribeFrustum(cnxId, {
planes: payload?.planes,
frequency: payload?.frequency,
})
if(!result.ok) {
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: result.err })
return
}
@@ -104,6 +110,7 @@ export const actions = {
action,
reqid,
sender,
cnxId,
success: true,
payload: {
frequency: result.frequency,
+4 -3
View File
@@ -2,16 +2,17 @@ import { replyToAction } from '../../../bus/publishActionReply.js'
export const actions = {
async action_RELOADCONFIG(action, payload, reqid, sender, roles) {
async action_RELOADCONFIG(action, payload, reqid, sender, cnxId, roles) {
this.reloadAccessRights()
replyToAction(this, { action, reqid, sender, success: true })
replyToAction(this, { action, reqid, sender, cnxId, success: true })
},
async action_GETCONFIG(action, payload, reqid, sender, roles) {
async action_GETCONFIG(action, payload, reqid, sender, cnxId, roles) {
replyToAction(this, {
action,
reqid,
sender,
cnxId,
success: true,
payload: this.getAccessRights(),
})
+13 -29
View File
@@ -7,10 +7,12 @@ export class observerServer {
constructor(configHelper, allRediscnx, debug) {
this.configHelper = configHelper
this.observerConfig = configHelper.config
this.rootConfig = configHelper.config
this.observerConfig = configHelper.config.observer ?? {}
this.gpsConfig = configHelper.config.gps ?? {}
this.allRediscnx = allRediscnx
this.debug = debug
this.accessRights = new AccesRights(this.observerConfig, debug)
this.accessRights = new AccesRights(this.rootConfig, debug)
this.arenaCnx = null
this.arenaCnxs = []
this.systemCnx = null
@@ -20,27 +22,8 @@ export class observerServer {
this.bigBangEpoch = null
}
getObserverSettings() {
const observer = this.observerConfig.observer ?? {}
return({
senderId: observer.senderId ?? 'observer',
scanIntervalMs: observer.scanIntervalMs ?? 300,
frustumEventsChannel: observer.observerFrustumEventsChannel
?? 'system:observer:subscribed[UID]:agents',
lifecycle: {
arenaChannel: observer.lifecycle?.arenaChannel ?? 'arena:lifecycle',
godsReadyChannel: observer.lifecycle?.godsReadyChannel ?? 'arena:gods:ready',
},
})
}
getGpsStorageSettings() {
const gps = this.observerConfig.gps ?? {}
return(gps.GPSstorage ?? null)
}
initGpsStorageReader() {
const gpsStorage = this.getGpsStorageSettings()
const gpsStorage = this.gpsConfig.GPSstorage
if(gpsStorage && this.systemCnx) {
this.gpsStorageReader = new GpsStorageReader(this.systemCnx, gpsStorage, this.debug)
this.initRequestorRegistry()
@@ -49,7 +32,7 @@ export class observerServer {
initRequestorRegistry() {
if(!this.gpsStorageReader || this.requestorRegistry) return
const { scanIntervalMs } = this.getObserverSettings()
const { scanIntervalMs } = this.observerConfig
this.requestorRegistry = new RequestorRegistry(
this.gpsStorageReader,
() => this.now(),
@@ -67,9 +50,9 @@ export class observerServer {
if(!this.systemCnx || !subscriberId) return
if(!Array.isArray(agents) || !agents.length) return
const { frustumEventsChannel } = this.getObserverSettings()
const chan = frustumEventsChannel.replace(/\[UID\]/g, subscriberId)
const senderId = this.getObserverSettings().senderId
const chan = this.observerConfig.FrustumEventsChannel
.replace(/\[CUID\]/g, subscriberId)
const senderId = this.observerConfig.senderId
for(const agent of agents) {
if(!agent?.id || !agent?.position) continue
@@ -77,6 +60,7 @@ export class observerServer {
await this.systemCnx.redisPublish(chan, {
eventType: 'move',
sender: senderId,
cnxId: this.systemCnx.cnxId,
payload: {
aid: agent.id,
coords: {
@@ -147,12 +131,12 @@ export class observerServer {
async reloadAccessRights() {
await this.configHelper.refreshAccessRights()
this.observerConfig.accessRights = this.configHelper.config.accessRights
this.accessRights.refreshAccessRights(this.observerConfig)
this.rootConfig.accessRights = this.configHelper.config.accessRights
this.accessRights.refreshAccessRights(this.rootConfig)
}
getAccessRights() {
return(this.observerConfig.accessRights)
return(this.rootConfig.accessRights)
}
}