Perk event and parser

This commit is contained in:
MyNameIsBatman 2021-11-26 17:57:59 -03:00
parent d3458229fd
commit 536d978435
9 changed files with 84 additions and 17 deletions

View File

@ -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';

View File

@ -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;
}
}

View File

@ -0,0 +1 @@
export * from './PerkAllowancesMessageEvent';

View File

@ -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';

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1 @@
export * from './PerkAllowancesMessageParser';

View File

@ -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;
}
}

View File

@ -1,2 +1 @@
export * from './UserPerksParser';
export * from './UserPermissionsParser';