feat: add wired monitor and variable protocol support

This commit is contained in:
Lorenzune
2026-04-02 04:44:04 +02:00
parent 52ed78e528
commit 190f02ebbe
19 changed files with 1149 additions and 396 deletions
@@ -0,0 +1,222 @@
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
export interface IWiredMonitorLogData
{
amount: number;
latestOccurrenceSeconds: number;
latestReason: string;
latestSourceId: number;
latestSourceLabel: string;
severity: string;
type: string;
}
export interface IWiredMonitorHistoryData
{
occurredAtSeconds: number;
reason: string;
sourceId: number;
sourceLabel: string;
severity: string;
type: string;
}
export class WiredMonitorDataParser implements IMessageParser
{
private _usageCurrentWindow: number;
private _usageLimitPerWindow: number;
private _isHeavy: boolean;
private _delayedEventsPending: number;
private _delayedEventsLimit: number;
private _averageExecutionMs: number;
private _peakExecutionMs: number;
private _recursionDepthCurrent: number;
private _recursionDepthLimit: number;
private _killedRemainingSeconds: number;
private _usageWindowMs: number;
private _overloadAverageThresholdMs: number;
private _overloadPeakThresholdMs: number;
private _heavyUsageThresholdPercent: number;
private _heavyConsecutiveWindowsThreshold: number;
private _overloadConsecutiveWindowsThreshold: number;
private _heavyDelayedThresholdPercent: number;
private _logs: IWiredMonitorLogData[];
private _history: IWiredMonitorHistoryData[];
public flush(): boolean
{
this._usageCurrentWindow = 0;
this._usageLimitPerWindow = 0;
this._isHeavy = false;
this._delayedEventsPending = 0;
this._delayedEventsLimit = 0;
this._averageExecutionMs = 0;
this._peakExecutionMs = 0;
this._recursionDepthCurrent = 0;
this._recursionDepthLimit = 0;
this._killedRemainingSeconds = 0;
this._usageWindowMs = 0;
this._overloadAverageThresholdMs = 0;
this._overloadPeakThresholdMs = 0;
this._heavyUsageThresholdPercent = 0;
this._heavyConsecutiveWindowsThreshold = 0;
this._overloadConsecutiveWindowsThreshold = 0;
this._heavyDelayedThresholdPercent = 0;
this._logs = [];
this._history = [];
return true;
}
public parse(wrapper: IMessageDataWrapper): boolean
{
if(!wrapper) return false;
this._usageCurrentWindow = wrapper.readInt();
this._usageLimitPerWindow = wrapper.readInt();
this._isHeavy = wrapper.readBoolean();
this._delayedEventsPending = wrapper.readInt();
this._delayedEventsLimit = wrapper.readInt();
this._averageExecutionMs = wrapper.readInt();
this._peakExecutionMs = wrapper.readInt();
this._recursionDepthCurrent = wrapper.readInt();
this._recursionDepthLimit = wrapper.readInt();
this._killedRemainingSeconds = wrapper.readInt();
this._usageWindowMs = wrapper.readInt();
this._overloadAverageThresholdMs = wrapper.readInt();
this._overloadPeakThresholdMs = wrapper.readInt();
this._heavyUsageThresholdPercent = wrapper.readInt();
this._heavyConsecutiveWindowsThreshold = wrapper.readInt();
this._overloadConsecutiveWindowsThreshold = wrapper.readInt();
this._heavyDelayedThresholdPercent = wrapper.readInt();
const totalLogs = wrapper.readInt();
this._logs = [];
this._history = [];
for(let i = 0; i < totalLogs; i++)
{
this._logs.push({
type: wrapper.readString(),
severity: wrapper.readString(),
amount: wrapper.readInt(),
latestOccurrenceSeconds: wrapper.readInt(),
latestReason: wrapper.readString(),
latestSourceLabel: wrapper.readString(),
latestSourceId: wrapper.readInt()
});
}
const totalHistory = wrapper.readInt();
for(let i = 0; i < totalHistory; i++)
{
this._history.push({
type: wrapper.readString(),
severity: wrapper.readString(),
occurredAtSeconds: wrapper.readInt(),
reason: wrapper.readString(),
sourceLabel: wrapper.readString(),
sourceId: wrapper.readInt()
});
}
return true;
}
public get usageCurrentWindow(): number
{
return this._usageCurrentWindow;
}
public get usageLimitPerWindow(): number
{
return this._usageLimitPerWindow;
}
public get isHeavy(): boolean
{
return this._isHeavy;
}
public get delayedEventsPending(): number
{
return this._delayedEventsPending;
}
public get delayedEventsLimit(): number
{
return this._delayedEventsLimit;
}
public get averageExecutionMs(): number
{
return this._averageExecutionMs;
}
public get peakExecutionMs(): number
{
return this._peakExecutionMs;
}
public get recursionDepthCurrent(): number
{
return this._recursionDepthCurrent;
}
public get recursionDepthLimit(): number
{
return this._recursionDepthLimit;
}
public get killedRemainingSeconds(): number
{
return this._killedRemainingSeconds;
}
public get usageWindowMs(): number
{
return this._usageWindowMs;
}
public get overloadAverageThresholdMs(): number
{
return this._overloadAverageThresholdMs;
}
public get overloadPeakThresholdMs(): number
{
return this._overloadPeakThresholdMs;
}
public get heavyUsageThresholdPercent(): number
{
return this._heavyUsageThresholdPercent;
}
public get heavyConsecutiveWindowsThreshold(): number
{
return this._heavyConsecutiveWindowsThreshold;
}
public get overloadConsecutiveWindowsThreshold(): number
{
return this._overloadConsecutiveWindowsThreshold;
}
public get heavyDelayedThresholdPercent(): number
{
return this._heavyDelayedThresholdPercent;
}
public get logs(): IWiredMonitorLogData[]
{
return this._logs;
}
public get history(): IWiredMonitorHistoryData[]
{
return this._history;
}
}
@@ -0,0 +1,67 @@
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
export class WiredRoomSettingsDataParser implements IMessageParser
{
private _roomId: number;
private _inspectMask: number;
private _modifyMask: number;
private _canInspect: boolean;
private _canModify: boolean;
private _canManageSettings: boolean;
public flush(): boolean
{
this._roomId = 0;
this._inspectMask = 0;
this._modifyMask = 0;
this._canInspect = false;
this._canModify = false;
this._canManageSettings = false;
return true;
}
public parse(wrapper: IMessageDataWrapper): boolean
{
if(!wrapper) return false;
this._roomId = wrapper.readInt();
this._inspectMask = wrapper.readInt();
this._modifyMask = wrapper.readInt();
this._canInspect = wrapper.readBoolean();
this._canModify = wrapper.readBoolean();
this._canManageSettings = wrapper.readBoolean();
return true;
}
public get roomId(): number
{
return this._roomId;
}
public get inspectMask(): number
{
return this._inspectMask;
}
public get modifyMask(): number
{
return this._modifyMask;
}
public get canInspect(): boolean
{
return this._canInspect;
}
public get canModify(): boolean
{
return this._canModify;
}
public get canManageSettings(): boolean
{
return this._canManageSettings;
}
}
@@ -0,0 +1,301 @@
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
export interface IWiredUserVariableDefinitionData
{
availability: number;
hasValue: boolean;
isReadOnly: boolean;
isTextConnected: boolean;
itemId: number;
name: string;
}
export interface IWiredUserVariableAssignmentData
{
createdAt: number;
hasValue: boolean;
updatedAt: number;
value: number | null;
variableItemId: number;
}
export interface IWiredUserVariablesUserData
{
assignments: IWiredUserVariableAssignmentData[];
userId: number;
}
export interface IWiredFurniVariableDefinitionData
{
availability: number;
hasValue: boolean;
isReadOnly: boolean;
isTextConnected: boolean;
itemId: number;
name: string;
}
export interface IWiredUserVariablesFurniData
{
assignments: IWiredUserVariableAssignmentData[];
furniId: number;
}
export interface IWiredRoomVariableDefinitionData
{
availability: number;
hasValue: boolean;
isReadOnly: boolean;
isTextConnected: boolean;
itemId: number;
name: string;
}
export interface IWiredRoomVariableAssignmentData
{
createdAt: number;
hasValue: boolean;
updatedAt: number;
value: number | null;
variableItemId: number;
}
export interface IWiredContextVariableDefinitionData
{
availability: number;
hasValue: boolean;
isReadOnly: boolean;
isTextConnected: boolean;
itemId: number;
name: string;
}
export class WiredUserVariablesDataParser implements IMessageParser
{
private _roomId: number;
private _definitions: IWiredUserVariableDefinitionData[];
private _users: IWiredUserVariablesUserData[];
private _furniDefinitions: IWiredFurniVariableDefinitionData[];
private _furnis: IWiredUserVariablesFurniData[];
private _roomDefinitions: IWiredRoomVariableDefinitionData[];
private _roomAssignments: IWiredRoomVariableAssignmentData[];
private _contextDefinitions: IWiredContextVariableDefinitionData[];
public flush(): boolean
{
this._roomId = 0;
this._definitions = [];
this._users = [];
this._furniDefinitions = [];
this._furnis = [];
this._roomDefinitions = [];
this._roomAssignments = [];
this._contextDefinitions = [];
return true;
}
public parse(wrapper: IMessageDataWrapper): boolean
{
if(!wrapper) return false;
this._roomId = wrapper.readInt();
let totalDefinitions = wrapper.readInt();
this._definitions = [];
this._users = [];
this._furniDefinitions = [];
this._furnis = [];
this._roomDefinitions = [];
this._roomAssignments = [];
this._contextDefinitions = [];
while(totalDefinitions > 0)
{
this._definitions.push({
itemId: wrapper.readInt(),
name: wrapper.readString(),
hasValue: wrapper.readBoolean(),
availability: wrapper.readInt(),
isTextConnected: wrapper.readBoolean(),
isReadOnly: wrapper.readBoolean()
});
totalDefinitions--;
}
let totalUsers = wrapper.readInt();
while(totalUsers > 0)
{
const userId = wrapper.readInt();
let totalAssignments = wrapper.readInt();
const assignments: IWiredUserVariableAssignmentData[] = [];
while(totalAssignments > 0)
{
const variableItemId = wrapper.readInt();
const hasValue = wrapper.readBoolean();
const rawValue = wrapper.readInt();
const createdAt = wrapper.readInt();
const updatedAt = wrapper.readInt();
assignments.push({
variableItemId,
hasValue,
value: (hasValue ? rawValue : null),
createdAt,
updatedAt
});
totalAssignments--;
}
this._users.push({ userId, assignments });
totalUsers--;
}
let totalFurniDefinitions = wrapper.readInt();
while(totalFurniDefinitions > 0)
{
this._furniDefinitions.push({
itemId: wrapper.readInt(),
name: wrapper.readString(),
hasValue: wrapper.readBoolean(),
availability: wrapper.readInt(),
isTextConnected: wrapper.readBoolean(),
isReadOnly: wrapper.readBoolean()
});
totalFurniDefinitions--;
}
let totalFurnis = wrapper.readInt();
while(totalFurnis > 0)
{
const furniId = wrapper.readInt();
let totalAssignments = wrapper.readInt();
const assignments: IWiredUserVariableAssignmentData[] = [];
while(totalAssignments > 0)
{
const variableItemId = wrapper.readInt();
const hasValue = wrapper.readBoolean();
const rawValue = wrapper.readInt();
const createdAt = wrapper.readInt();
const updatedAt = wrapper.readInt();
assignments.push({
variableItemId,
hasValue,
value: (hasValue ? rawValue : null),
createdAt,
updatedAt
});
totalAssignments--;
}
this._furnis.push({ furniId, assignments });
totalFurnis--;
}
let totalRoomDefinitions = wrapper.readInt();
while(totalRoomDefinitions > 0)
{
this._roomDefinitions.push({
itemId: wrapper.readInt(),
name: wrapper.readString(),
hasValue: wrapper.readBoolean(),
availability: wrapper.readInt(),
isTextConnected: wrapper.readBoolean(),
isReadOnly: wrapper.readBoolean()
});
totalRoomDefinitions--;
}
let totalRoomAssignments = wrapper.readInt();
while(totalRoomAssignments > 0)
{
const variableItemId = wrapper.readInt();
const hasValue = wrapper.readBoolean();
const rawValue = wrapper.readInt();
const createdAt = wrapper.readInt();
const updatedAt = wrapper.readInt();
this._roomAssignments.push({
variableItemId,
hasValue,
value: (hasValue ? rawValue : null),
createdAt,
updatedAt
});
totalRoomAssignments--;
}
let totalContextDefinitions = wrapper.readInt();
while(totalContextDefinitions > 0)
{
this._contextDefinitions.push({
itemId: wrapper.readInt(),
name: wrapper.readString(),
hasValue: wrapper.readBoolean(),
availability: wrapper.readInt(),
isTextConnected: wrapper.readBoolean(),
isReadOnly: wrapper.readBoolean()
});
totalContextDefinitions--;
}
return true;
}
public get roomId(): number
{
return this._roomId;
}
public get definitions(): IWiredUserVariableDefinitionData[]
{
return this._definitions;
}
public get users(): IWiredUserVariablesUserData[]
{
return this._users;
}
public get furniDefinitions(): IWiredFurniVariableDefinitionData[]
{
return this._furniDefinitions;
}
public get furnis(): IWiredUserVariablesFurniData[]
{
return this._furnis;
}
public get roomDefinitions(): IWiredRoomVariableDefinitionData[]
{
return this._roomDefinitions;
}
public get roomAssignments(): IWiredRoomVariableAssignmentData[]
{
return this._roomAssignments;
}
public get contextDefinitions(): IWiredContextVariableDefinitionData[]
{
return this._contextDefinitions;
}
}
@@ -5,7 +5,10 @@ export * from './WiredActionDefinition';
export * from './WiredFurniActionParser';
export * from './WiredFurniConditionParser';
export * from './WiredFurniTriggerParser';
export * from './WiredMonitorDataParser';
export * from './WiredRoomSettingsDataParser';
export * from './WiredOpenParser';
export * from './WiredRewardResultMessageParser';
export * from './WiredSaveSuccessParser';
export * from './WiredUserVariablesDataParser';
export * from './WiredValidationErrorParser';