From 99b6437a4adf860b22006f6becf953bf5957fec8 Mon Sep 17 00:00:00 2001 From: dank074 Date: Thu, 14 Oct 2021 00:19:56 -0500 Subject: [PATCH] fix mod chatlog parser --- .../modtool/ModtoolRoomChatlogParser.ts | 48 +------- .../parser/modtool/utils/ChatRecordData.ts | 110 ++++++++++++++++++ .../modtool/utils/ModtoolRoomChatlogLine.ts | 11 +- .../messages/parser/modtool/utils/index.ts | 1 + 4 files changed, 125 insertions(+), 45 deletions(-) create mode 100644 src/nitro/communication/messages/parser/modtool/utils/ChatRecordData.ts diff --git a/src/nitro/communication/messages/parser/modtool/ModtoolRoomChatlogParser.ts b/src/nitro/communication/messages/parser/modtool/ModtoolRoomChatlogParser.ts index 7023fcd4..ddce381d 100644 --- a/src/nitro/communication/messages/parser/modtool/ModtoolRoomChatlogParser.ts +++ b/src/nitro/communication/messages/parser/modtool/ModtoolRoomChatlogParser.ts @@ -1,19 +1,13 @@ import { IMessageDataWrapper, IMessageParser } from '../../../../../core'; -import { ModtoolRoomChatlogLine } from './utils/ModtoolRoomChatlogLine'; +import { ChatRecordData } from './utils/ChatRecordData'; export class ModtoolRoomChatlogParser implements IMessageParser { - private _id: number; - private _name: string; - private _chatlogCount: number; - private _chatlogs: ModtoolRoomChatlogLine[] = []; + private _data: ChatRecordData; public flush(): boolean { - this._id = null; - this._name = null; - this._chatlogCount = 0; - this._chatlogs = []; + this._data = null; return true; } @@ -21,43 +15,13 @@ export class ModtoolRoomChatlogParser implements IMessageParser { if(!wrapper) return false; - wrapper.readByte(); - wrapper.readShort(); - wrapper.readString(); - wrapper.readByte(); - this._name = wrapper.readString(); - wrapper.readString(); - wrapper.readByte(); - this._id = wrapper.readInt(); - this._chatlogCount = wrapper.readShort(); - - for(let i = 0; i < this._chatlogCount; i++) - { - const timestamp = wrapper.readString(); - const habboId = wrapper.readInt(); - const username = wrapper.readString(); - const message = wrapper.readString(); - const boolean = wrapper.readBoolean(); - - this._chatlogs.push(new ModtoolRoomChatlogLine(timestamp, habboId, username, message, boolean)); - } + this._data = new ChatRecordData(wrapper); return true; } - public get id(): number + public get data(): ChatRecordData { - return this._id; + return this._data; } - - public get name(): string - { - return this._name; - } - - public get chatlogs(): ModtoolRoomChatlogLine[] - { - return this._chatlogs; - } - } diff --git a/src/nitro/communication/messages/parser/modtool/utils/ChatRecordData.ts b/src/nitro/communication/messages/parser/modtool/utils/ChatRecordData.ts new file mode 100644 index 00000000..129bdff4 --- /dev/null +++ b/src/nitro/communication/messages/parser/modtool/utils/ChatRecordData.ts @@ -0,0 +1,110 @@ +import { IMessageDataWrapper } from '../../../../../..'; +import { ModtoolRoomChatlogLine } from './ModtoolRoomChatlogLine'; + +export class ChatRecordData +{ + public static readonly TYPE_SIMPLE = 0; + public static readonly TYPE_ROOM_CHAT = 1; + public static readonly TYPE_IM_SESSION = 2; + public static readonly TYPE_DISCUSSION_THREAD = 3; + public static readonly TYPE_DISCUSSION_MESSAGE = 4; + public static readonly TYPE_SELFIE = 5; + public static readonly TYPE_PHOTO = 6; + + private _recordType:number; + private _context:Map; + private _chatlog:ModtoolRoomChatlogLine[]; + + constructor(wrapper: IMessageDataWrapper) + { + this._context = new Map(); + this._chatlog = []; + + this._recordType = wrapper.readByte(); + const contextCount = wrapper.readShort(); + + for(let i = 0; i < contextCount; i++) + { + const key = wrapper.readString(); + const type = wrapper.readByte(); + + switch(type) + { + case 0: + this._context.set(key, wrapper.readBoolean()); + break; + case 1: + this._context.set(key, wrapper.readInt()); + break; + case 2: + this._context.set(key, wrapper.readString()); + break; + default: + throw new Error('Unknown data type ' + type); + } + } + + const chatCount = wrapper.readShort(); + + for(let i = 0; i < chatCount; i++) + { + const timestamp = wrapper.readString(); + const habboId = wrapper.readInt(); + const username = wrapper.readString(); + const message = wrapper.readString(); + const hasHighlighting = wrapper.readBoolean(); + + this._chatlog.push(new ModtoolRoomChatlogLine(timestamp, habboId, username, message, hasHighlighting)); + } + } + + public get recordType():number + { + return this._recordType; + } + + public get context():Map + { + return this._context; + } + + public get chatlog():ModtoolRoomChatlogLine[] + { + return this._chatlog; + } + + public get roomId():number + { + return this.getInt('roomId'); + } + + public get roomName():string + { + return this._context['roomName'] as string; + } + + public get groupId():number + { + return this.getInt('groupId'); + } + + public get threadId():number + { + return this.getInt('threadId'); + } + + public get messageId(): number + { + return this.getInt('messageId'); + } + + private getInt(k:string): number + { + const value = this._context.get(k); + if(!value) + { + return 0; + } + return value as number; + } +} diff --git a/src/nitro/communication/messages/parser/modtool/utils/ModtoolRoomChatlogLine.ts b/src/nitro/communication/messages/parser/modtool/utils/ModtoolRoomChatlogLine.ts index 8a52900a..a7fdb798 100644 --- a/src/nitro/communication/messages/parser/modtool/utils/ModtoolRoomChatlogLine.ts +++ b/src/nitro/communication/messages/parser/modtool/utils/ModtoolRoomChatlogLine.ts @@ -6,15 +6,15 @@ export class ModtoolRoomChatlogLine implements IChatlog private readonly _habboId: number; private readonly _username: string; private readonly _message: string; - private _boolean: boolean; + private readonly _hasHighlighting: boolean; - constructor(timestamp: string, habboId: number, username: string, message: string, boolean: boolean) + constructor(timestamp: string, habboId: number, username: string, message: string, hasHighlighting: boolean) { this._timestamp = timestamp; this._habboId = habboId; this._username = username; this._message = message; - this._boolean = boolean; + this._hasHighlighting = hasHighlighting; } public get timestamp(): string @@ -36,4 +36,9 @@ export class ModtoolRoomChatlogLine implements IChatlog { return this._message; } + + public get hasHighlighting(): boolean + { + return this._hasHighlighting; + } } diff --git a/src/nitro/communication/messages/parser/modtool/utils/index.ts b/src/nitro/communication/messages/parser/modtool/utils/index.ts index 180c8620..171b01c9 100644 --- a/src/nitro/communication/messages/parser/modtool/utils/index.ts +++ b/src/nitro/communication/messages/parser/modtool/utils/index.ts @@ -1,4 +1,5 @@ export * from './CallForHelpCategoryData'; +export * from './ChatRecordData'; export * from './IChatlog'; export * from './IssueInfoMessageParser'; export * from './IssueMessageData';