From 536d978435c8e651ee52eacfbdd558d8c13a7f8d Mon Sep 17 00:00:00 2001 From: MyNameIsBatman Date: Fri, 26 Nov 2021 17:57:59 -0300 Subject: [PATCH] Perk event and parser --- .../communication/messages/incoming/index.ts | 1 + .../perk/PerkAllowancesMessageEvent.ts | 16 +++++++++ .../messages/incoming/perk/index.ts | 1 + .../communication/messages/parser/index.ts | 1 + .../perk/PerkAllowancesMessageParser.ts | 36 +++++++++++++++++++ .../messages/parser/perk/common/PerkData.ts | 28 +++++++++++++++ .../messages/parser/perk/index.ts | 1 + .../parser/user/access/UserPerksParser.ts | 16 --------- .../messages/parser/user/access/index.ts | 1 - 9 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 src/nitro/communication/messages/incoming/perk/PerkAllowancesMessageEvent.ts create mode 100644 src/nitro/communication/messages/incoming/perk/index.ts create mode 100644 src/nitro/communication/messages/parser/perk/PerkAllowancesMessageParser.ts create mode 100644 src/nitro/communication/messages/parser/perk/common/PerkData.ts create mode 100644 src/nitro/communication/messages/parser/perk/index.ts delete mode 100644 src/nitro/communication/messages/parser/user/access/UserPerksParser.ts diff --git a/src/nitro/communication/messages/incoming/index.ts b/src/nitro/communication/messages/incoming/index.ts index 610b0a37..a45dac4b 100644 --- a/src/nitro/communication/messages/incoming/index.ts +++ b/src/nitro/communication/messages/incoming/index.ts @@ -29,6 +29,7 @@ export * from './moderation'; export * from './mysterybox'; export * from './navigator'; export * from './notifications'; +export * from './perk'; export * from './poll'; export * from './quest'; export * from './room'; diff --git a/src/nitro/communication/messages/incoming/perk/PerkAllowancesMessageEvent.ts b/src/nitro/communication/messages/incoming/perk/PerkAllowancesMessageEvent.ts new file mode 100644 index 00000000..dc117805 --- /dev/null +++ b/src/nitro/communication/messages/incoming/perk/PerkAllowancesMessageEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '../../../../../core/communication/messages/IMessageEvent'; +import { MessageEvent } from '../../../../../core/communication/messages/MessageEvent'; +import { PerkAllowancesMessageParser } from './../../parser/perk/PerkAllowancesMessageParser'; + +export class PerkAllowancesMessageEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, PerkAllowancesMessageParser); + } + + public getParser(): PerkAllowancesMessageParser + { + return this.parser as PerkAllowancesMessageParser; + } +} diff --git a/src/nitro/communication/messages/incoming/perk/index.ts b/src/nitro/communication/messages/incoming/perk/index.ts new file mode 100644 index 00000000..b19fe4b9 --- /dev/null +++ b/src/nitro/communication/messages/incoming/perk/index.ts @@ -0,0 +1 @@ +export * from './PerkAllowancesMessageEvent'; diff --git a/src/nitro/communication/messages/parser/index.ts b/src/nitro/communication/messages/parser/index.ts index 15007bad..323d9c5e 100644 --- a/src/nitro/communication/messages/parser/index.ts +++ b/src/nitro/communication/messages/parser/index.ts @@ -21,6 +21,7 @@ export * from './moderation'; export * from './mysterybox'; export * from './navigator'; export * from './notifications'; +export * from './perk'; export * from './poll'; export * from './quest'; export * from './room'; diff --git a/src/nitro/communication/messages/parser/perk/PerkAllowancesMessageParser.ts b/src/nitro/communication/messages/parser/perk/PerkAllowancesMessageParser.ts new file mode 100644 index 00000000..9c5c7c8e --- /dev/null +++ b/src/nitro/communication/messages/parser/perk/PerkAllowancesMessageParser.ts @@ -0,0 +1,36 @@ +import { IMessageDataWrapper, IMessageParser } from '../../../../../core'; +import { PerkData } from './common/PerkData'; + +export class PerkAllowancesMessageParser implements IMessageParser +{ + private _perks: PerkData[]; + + public flush(): boolean + { + this._perks = []; + + return true; + } + + public parse(wrapper: IMessageDataWrapper): boolean + { + if(!wrapper) return false; + + this._perks = []; + + const size: number = wrapper.readInt(); + + for(let i = 0; i < size; i++) this._perks.push(new PerkData( + wrapper.readString(), + wrapper.readBoolean(), + wrapper.readString() + )); + + return true; + } + + public get perks(): PerkData[] + { + return this._perks; + } +} diff --git a/src/nitro/communication/messages/parser/perk/common/PerkData.ts b/src/nitro/communication/messages/parser/perk/common/PerkData.ts new file mode 100644 index 00000000..df206fc8 --- /dev/null +++ b/src/nitro/communication/messages/parser/perk/common/PerkData.ts @@ -0,0 +1,28 @@ +export class PerkData +{ + private _code: string; + private _isAllowed: boolean; + private _errorMessage: string; + + constructor(code: string, isAllowed: boolean, errorMessage: string) + { + this._code = code; + this._isAllowed = isAllowed; + this._errorMessage = errorMessage; + } + + public get code(): string + { + return this._code; + } + + public get isAllowed(): boolean + { + return this._isAllowed; + } + + public get errorMessage(): string + { + return this._errorMessage; + } +} diff --git a/src/nitro/communication/messages/parser/perk/index.ts b/src/nitro/communication/messages/parser/perk/index.ts new file mode 100644 index 00000000..a513d8fe --- /dev/null +++ b/src/nitro/communication/messages/parser/perk/index.ts @@ -0,0 +1 @@ +export * from './PerkAllowancesMessageParser'; diff --git a/src/nitro/communication/messages/parser/user/access/UserPerksParser.ts b/src/nitro/communication/messages/parser/user/access/UserPerksParser.ts deleted file mode 100644 index 41de9c92..00000000 --- a/src/nitro/communication/messages/parser/user/access/UserPerksParser.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IMessageDataWrapper, IMessageParser } from '../../../../../../core'; - -export class UserPerksParser implements IMessageParser -{ - public flush(): boolean - { - return true; - } - - public parse(wrapper: IMessageDataWrapper): boolean - { - if(!wrapper) return false; - - return true; - } -} diff --git a/src/nitro/communication/messages/parser/user/access/index.ts b/src/nitro/communication/messages/parser/user/access/index.ts index 0cf93775..7cb9b642 100644 --- a/src/nitro/communication/messages/parser/user/access/index.ts +++ b/src/nitro/communication/messages/parser/user/access/index.ts @@ -1,2 +1 @@ -export * from './UserPerksParser'; export * from './UserPermissionsParser';