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
File diff suppressed because one or more lines are too long
@@ -269,6 +269,9 @@ export class IncomingHeader
public static WIRED_ACTION = 1434;
public static WIRED_CONDITION = 1108;
public static WIRED_ERROR = 156;
public static WIRED_MONITOR_DATA = 5101;
public static WIRED_ROOM_SETTINGS_DATA = 5102;
public static WIRED_USER_VARIABLES_DATA = 5103;
public static WIRED_OPEN = 1830;
public static WIRED_REWARD = 178;
public static WIRED_SAVE = 1155;
@@ -0,0 +1,16 @@
import { IMessageEvent } from '@nitrots/api';
import { MessageEvent } from '@nitrots/events';
import { WiredMonitorDataParser } from '../../parser';
export class WiredMonitorDataEvent extends MessageEvent implements IMessageEvent
{
constructor(callBack: Function)
{
super(callBack, WiredMonitorDataParser);
}
public getParser(): WiredMonitorDataParser
{
return this.parser as WiredMonitorDataParser;
}
}
@@ -0,0 +1,16 @@
import { IMessageEvent } from '@nitrots/api';
import { MessageEvent } from '@nitrots/events';
import { WiredRoomSettingsDataParser } from '../../parser';
export class WiredRoomSettingsDataEvent extends MessageEvent implements IMessageEvent
{
constructor(callBack: Function)
{
super(callBack, WiredRoomSettingsDataParser);
}
public getParser(): WiredRoomSettingsDataParser
{
return this.parser as WiredRoomSettingsDataParser;
}
}
@@ -0,0 +1,16 @@
import { IMessageEvent } from '@nitrots/api';
import { MessageEvent } from '@nitrots/events';
import { WiredUserVariablesDataParser } from '../../parser';
export class WiredUserVariablesDataEvent extends MessageEvent implements IMessageEvent
{
constructor(callBack: Function)
{
super(callBack, WiredUserVariablesDataParser);
}
public getParser(): WiredUserVariablesDataParser
{
return this.parser as WiredUserVariablesDataParser;
}
}
@@ -1,7 +1,10 @@
export * from './WiredFurniActionEvent';
export * from './WiredFurniConditionEvent';
export * from './WiredFurniTriggerEvent';
export * from './WiredMonitorDataEvent';
export * from './WiredOpenEvent';
export * from './WiredRoomSettingsDataEvent';
export * from './WiredRewardResultMessageEvent';
export * from './WiredSaveSuccessEvent';
export * from './WiredUserVariablesDataEvent';
export * from './WiredValidationErrorEvent';
@@ -271,6 +271,12 @@ export class OutgoingHeader
public static WIRED_ACTION_SAVE = 2281;
public static WIRED_APPLY_SNAPSHOT = 3373;
public static WIRED_CONDITION_SAVE = 3203;
public static WIRED_MONITOR_REQUEST = 10021;
public static WIRED_ROOM_SETTINGS_REQUEST = 10022;
public static WIRED_ROOM_SETTINGS_SAVE = 10023;
public static WIRED_USER_VARIABLES_REQUEST = 10024;
public static WIRED_USER_VARIABLE_UPDATE = 10025;
public static WIRED_USER_VARIABLE_MANAGE = 10026;
public static WIRED_OPEN = 768;
public static WIRED_TRIGGER_SAVE = 1520;
public static GET_ITEM_DATA = 3964;
@@ -0,0 +1,21 @@
import { IMessageComposer } from '@nitrots/api';
export class WiredMonitorRequestComposer implements IMessageComposer<ConstructorParameters<typeof WiredMonitorRequestComposer>>
{
private _data: ConstructorParameters<typeof WiredMonitorRequestComposer>;
constructor(action: number = 0)
{
this._data = [ action ];
}
public getMessageArray()
{
return this._data;
}
public dispose(): void
{
return;
}
}
@@ -0,0 +1,14 @@
import { IMessageComposer } from '@nitrots/api';
export class WiredRoomSettingsRequestComposer implements IMessageComposer<ConstructorParameters<typeof WiredRoomSettingsRequestComposer>>
{
public getMessageArray()
{
return [];
}
public dispose(): void
{
return;
}
}
@@ -0,0 +1,21 @@
import { IMessageComposer } from '@nitrots/api';
export class WiredRoomSettingsSaveComposer implements IMessageComposer<ConstructorParameters<typeof WiredRoomSettingsSaveComposer>>
{
private _data: ConstructorParameters<typeof WiredRoomSettingsSaveComposer>;
constructor(inspectMask: number, modifyMask: number)
{
this._data = [ inspectMask, modifyMask ];
}
public getMessageArray()
{
return this._data;
}
public dispose(): void
{
return;
}
}
@@ -0,0 +1,21 @@
import { IMessageComposer } from '@nitrots/api';
export class WiredUserVariableManageComposer implements IMessageComposer<ConstructorParameters<typeof WiredUserVariableManageComposer>>
{
private _data: ConstructorParameters<typeof WiredUserVariableManageComposer>;
constructor(action: number, targetType: number, targetId: number, variableItemId: number, value: number)
{
this._data = [ action, targetType, targetId, variableItemId, value ];
}
public getMessageArray()
{
return this._data;
}
public dispose(): void
{
return;
}
}
@@ -0,0 +1,21 @@
import { IMessageComposer } from '@nitrots/api';
export class WiredUserVariableUpdateComposer implements IMessageComposer<ConstructorParameters<typeof WiredUserVariableUpdateComposer>>
{
private _data: ConstructorParameters<typeof WiredUserVariableUpdateComposer>;
constructor(targetType: number, targetId: number, variableItemId: number, value: number)
{
this._data = [ targetType, targetId, variableItemId, value ];
}
public getMessageArray()
{
return this._data;
}
public dispose(): void
{
return;
}
}
@@ -0,0 +1,14 @@
import { IMessageComposer } from '@nitrots/api';
export class WiredUserVariablesRequestComposer implements IMessageComposer<ConstructorParameters<typeof WiredUserVariablesRequestComposer>>
{
public getMessageArray()
{
return [];
}
public dispose(): void
{
return;
}
}
@@ -4,3 +4,9 @@ export * from './RoomMuteComposer';
export * from './UpdateActionMessageComposer';
export * from './UpdateConditionMessageComposer';
export * from './UpdateTriggerMessageComposer';
export * from './WiredMonitorRequestComposer';
export * from './WiredRoomSettingsRequestComposer';
export * from './WiredRoomSettingsSaveComposer';
export * from './WiredUserVariableManageComposer';
export * from './WiredUserVariablesRequestComposer';
export * from './WiredUserVariableUpdateComposer';
@@ -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';