fix mod chatlog parser

This commit is contained in:
dank074 2021-10-14 00:19:56 -05:00
parent f7dc87f721
commit 99b6437a4a
4 changed files with 125 additions and 45 deletions

View File

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

View File

@ -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<string, any>;
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<string, any>
{
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;
}
}

View File

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

View File

@ -1,4 +1,5 @@
export * from './CallForHelpCategoryData';
export * from './ChatRecordData';
export * from './IChatlog';
export * from './IssueInfoMessageParser';
export * from './IssueMessageData';