diff --git a/packages/communication/src/NitroMessages.ts b/packages/communication/src/NitroMessages.ts index 2b4f35c..5dec50b 100644 --- a/packages/communication/src/NitroMessages.ts +++ b/packages/communication/src/NitroMessages.ts @@ -7,7 +7,7 @@ import { ConfInvisStateMessageEvent } from './messages'; import { HanditemBlockStateMessageEvent } from './messages'; import { TranslationLanguagesEvent, TranslationLanguagesRequestComposer, TranslationResultEvent, TranslationTextRequestComposer } from './messages'; import { YouTubeRoomBroadcastEvent, YouTubeRoomPlayComposer, YouTubeRoomSettingsComposer, YouTubeRoomSettingsEvent, YouTubeRoomWatchersEvent, YouTubeRoomWatchingComposer } from './messages'; -import { HousekeepingFindUserByIdComposer, HousekeepingFindUserByNameComposer, HousekeepingUserDetailEvent } from './messages'; +import { HousekeepingActionResultEvent, HousekeepingBanUserComposer, HousekeepingFindUserByIdComposer, HousekeepingFindUserByNameComposer, HousekeepingUserDetailEvent } from './messages'; export class NitroMessages implements IMessageConfiguration { private _events: Map; @@ -509,6 +509,7 @@ export class NitroMessages implements IMessageConfiguration // Housekeeping (in-client admin panel) this._events.set(IncomingHeader.HOUSEKEEPING_USER_DETAIL, HousekeepingUserDetailEvent); + this._events.set(IncomingHeader.HOUSEKEEPING_ACTION_RESULT, HousekeepingActionResultEvent); this._events.set(IncomingHeader.WIRED_REWARD, WiredRewardResultMessageEvent); this._events.set(IncomingHeader.WIRED_SAVE, WiredSaveSuccessEvent); this._events.set(IncomingHeader.WIRED_ERROR, WiredValidationErrorEvent); @@ -1263,6 +1264,7 @@ export class NitroMessages implements IMessageConfiguration // Housekeeping (in-client admin panel) this._composers.set(OutgoingHeader.HOUSEKEEPING_FIND_USER_BY_NAME, HousekeepingFindUserByNameComposer); this._composers.set(OutgoingHeader.HOUSEKEEPING_FIND_USER_BY_ID, HousekeepingFindUserByIdComposer); + this._composers.set(OutgoingHeader.HOUSEKEEPING_BAN_USER, HousekeepingBanUserComposer); } public get events(): Map diff --git a/packages/communication/src/messages/incoming/IncomingHeader.ts b/packages/communication/src/messages/incoming/IncomingHeader.ts index 5433111..78db29a 100644 --- a/packages/communication/src/messages/incoming/IncomingHeader.ts +++ b/packages/communication/src/messages/incoming/IncomingHeader.ts @@ -506,4 +506,5 @@ export class IncomingHeader // Housekeeping (in-client admin panel) — IDs 9200..9299 reserved public static HOUSEKEEPING_USER_DETAIL = 9200; + public static HOUSEKEEPING_ACTION_RESULT = 9201; } diff --git a/packages/communication/src/messages/incoming/housekeeping/HousekeepingActionResultEvent.ts b/packages/communication/src/messages/incoming/housekeeping/HousekeepingActionResultEvent.ts new file mode 100644 index 0000000..cf197ff --- /dev/null +++ b/packages/communication/src/messages/incoming/housekeeping/HousekeepingActionResultEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '@nitrots/api'; +import { MessageEvent } from '@nitrots/events'; +import { HousekeepingActionResultParser } from '../../parser'; + +export class HousekeepingActionResultEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, HousekeepingActionResultParser); + } + + public getParser(): HousekeepingActionResultParser + { + return this.parser as HousekeepingActionResultParser; + } +} diff --git a/packages/communication/src/messages/incoming/housekeeping/index.ts b/packages/communication/src/messages/incoming/housekeeping/index.ts index 1b31bba..0b9a86a 100644 --- a/packages/communication/src/messages/incoming/housekeeping/index.ts +++ b/packages/communication/src/messages/incoming/housekeeping/index.ts @@ -1 +1,2 @@ +export * from './HousekeepingActionResultEvent'; export * from './HousekeepingUserDetailEvent'; diff --git a/packages/communication/src/messages/outgoing/OutgoingHeader.ts b/packages/communication/src/messages/outgoing/OutgoingHeader.ts index bdc599d..2d03ba4 100644 --- a/packages/communication/src/messages/outgoing/OutgoingHeader.ts +++ b/packages/communication/src/messages/outgoing/OutgoingHeader.ts @@ -526,4 +526,5 @@ export class OutgoingHeader // Housekeeping (in-client admin panel) — IDs 9100..9199 reserved public static HOUSEKEEPING_FIND_USER_BY_NAME = 9100; public static HOUSEKEEPING_FIND_USER_BY_ID = 9101; + public static HOUSEKEEPING_BAN_USER = 9102; } diff --git a/packages/communication/src/messages/outgoing/housekeeping/HousekeepingBanUserComposer.ts b/packages/communication/src/messages/outgoing/housekeeping/HousekeepingBanUserComposer.ts new file mode 100644 index 0000000..e5d31db --- /dev/null +++ b/packages/communication/src/messages/outgoing/housekeeping/HousekeepingBanUserComposer.ts @@ -0,0 +1,21 @@ +import { IMessageComposer } from '@nitrots/api'; + +export class HousekeepingBanUserComposer implements IMessageComposer> +{ + private _data: ConstructorParameters; + + constructor(userId: number, reason: string, hours: number) + { + this._data = [userId, reason, hours]; + } + + public getMessageArray() + { + return this._data; + } + + public dispose(): void + { + return; + } +} diff --git a/packages/communication/src/messages/outgoing/housekeeping/index.ts b/packages/communication/src/messages/outgoing/housekeeping/index.ts index 4eaf71f..3b1550c 100644 --- a/packages/communication/src/messages/outgoing/housekeeping/index.ts +++ b/packages/communication/src/messages/outgoing/housekeeping/index.ts @@ -1,2 +1,3 @@ +export * from './HousekeepingBanUserComposer'; export * from './HousekeepingFindUserByIdComposer'; export * from './HousekeepingFindUserByNameComposer'; diff --git a/packages/communication/src/messages/parser/housekeeping/HousekeepingActionResultParser.ts b/packages/communication/src/messages/parser/housekeeping/HousekeepingActionResultParser.ts new file mode 100644 index 0000000..57ef31f --- /dev/null +++ b/packages/communication/src/messages/parser/housekeeping/HousekeepingActionResultParser.ts @@ -0,0 +1,42 @@ +import { IMessageDataWrapper, IMessageParser } from '@nitrots/api'; + +/** + * Generic ack for any housekeeping action (ban, mute, kick, give-credits, + * room-close, …). Carries an `actionKey` string so a single event handler + * can multiplex over many in-flight actions and resolve the right Promise + * via an `accept` predicate. + */ +export class HousekeepingActionResultParser implements IMessageParser +{ + private _actionKey: string = ''; + private _ok: boolean = false; + private _actionId: number = 0; + private _message: string = ''; + + public flush(): boolean + { + this._actionKey = ''; + this._ok = false; + this._actionId = 0; + this._message = ''; + + return true; + } + + public parse(wrapper: IMessageDataWrapper): boolean + { + if(!wrapper) return false; + + this._actionKey = wrapper.readString(); + this._ok = wrapper.readBoolean(); + this._actionId = wrapper.readInt(); + this._message = wrapper.readString(); + + return true; + } + + public get actionKey(): string { return this._actionKey; } + public get ok(): boolean { return this._ok; } + public get actionId(): number { return this._actionId; } + public get message(): string { return this._message; } +} diff --git a/packages/communication/src/messages/parser/housekeeping/index.ts b/packages/communication/src/messages/parser/housekeeping/index.ts index 571cbe2..6dbabb1 100644 --- a/packages/communication/src/messages/parser/housekeeping/index.ts +++ b/packages/communication/src/messages/parser/housekeeping/index.ts @@ -1,2 +1,3 @@ +export * from './HousekeepingActionResultParser'; export * from './HousekeepingUserDetailData'; export * from './HousekeepingUserDetailParser';