From 0d37f16003e11b8f4bceee70f43120cf9ee3064d Mon Sep 17 00:00:00 2001 From: Dank074 Date: Fri, 13 Aug 2021 01:28:21 -0500 Subject: [PATCH] fix relationship parser --- src/nitro/communication/NitroMessages.ts | 4 +- .../user/data/RelationshipStatusInfoEvent.ts | 16 +++++ .../user/data/UserRelationshipsEvent.ts | 16 ----- .../messages/incoming/user/data/index.ts | 2 +- .../user/data/RelationshipStatusInfo.ts | 68 ++++++++++++++++++ .../RelationshipStatusInfoMessageParser.ts | 48 +++++++++++++ .../parser/user/data/UserProfileParser.ts | 26 ++++--- .../user/data/UserRelationshipDataParser.ts | 61 ---------------- .../user/data/UserRelationshipsParser.ts | 72 ------------------- .../messages/parser/user/data/index.ts | 4 +- 10 files changed, 153 insertions(+), 164 deletions(-) create mode 100644 src/nitro/communication/messages/incoming/user/data/RelationshipStatusInfoEvent.ts delete mode 100644 src/nitro/communication/messages/incoming/user/data/UserRelationshipsEvent.ts create mode 100644 src/nitro/communication/messages/parser/user/data/RelationshipStatusInfo.ts create mode 100644 src/nitro/communication/messages/parser/user/data/RelationshipStatusInfoMessageParser.ts delete mode 100644 src/nitro/communication/messages/parser/user/data/UserRelationshipDataParser.ts delete mode 100644 src/nitro/communication/messages/parser/user/data/UserRelationshipsParser.ts diff --git a/src/nitro/communication/NitroMessages.ts b/src/nitro/communication/NitroMessages.ts index 3d17724f..b7b5aecd 100644 --- a/src/nitro/communication/NitroMessages.ts +++ b/src/nitro/communication/NitroMessages.ts @@ -213,12 +213,12 @@ import { WiredValidationErrorEvent } from './messages/incoming/roomevents/WiredV import { AuthenticatedEvent } from './messages/incoming/security/AuthenticatedEvent'; import { UserPerksEvent } from './messages/incoming/user/access/UserPerksEvent'; import { UserPermissionsEvent } from './messages/incoming/user/access/UserPermissionsEvent'; +import { RelationshipStatusInfoEvent } from './messages/incoming/user/data/RelationshipStatusInfoEvent'; import { UserCurrentBadgesEvent } from './messages/incoming/user/data/UserCurrentBadgesEvent'; import { UserFigureEvent } from './messages/incoming/user/data/UserFigureEvent'; import { UserInfoEvent } from './messages/incoming/user/data/UserInfoEvent'; import { UserNameChangeMessageEvent } from './messages/incoming/user/data/UserNameChangeMessageEvent'; import { UserProfileEvent } from './messages/incoming/user/data/UserProfileEvent'; -import { UserRelationshipsEvent } from './messages/incoming/user/data/UserRelationshipsEvent'; import { UserSettingsEvent } from './messages/incoming/user/data/UserSettingsEvent'; import { IgnoredUsersEvent } from './messages/incoming/user/IgnoredUsersEvent'; import { IgnoreResultEvent } from './messages/incoming/user/IgnoreResultEvent'; @@ -736,7 +736,7 @@ export class NitroMessages implements IMessageConfiguration this._events.set(IncomingHeader.UNIT_CHANGE_NAME, UserNameChangeMessageEvent); this._events.set(IncomingHeader.USER_SETTINGS, UserSettingsEvent); this._events.set(IncomingHeader.USER_PROFILE, UserProfileEvent); - this._events.set(IncomingHeader.MESSENGER_RELATIONSHIPS, UserRelationshipsEvent); + this._events.set(IncomingHeader.MESSENGER_RELATIONSHIPS, RelationshipStatusInfoEvent); // GIFTS this._events.set(IncomingHeader.GIFT_OPENED, PresentOpenedMessageEvent); diff --git a/src/nitro/communication/messages/incoming/user/data/RelationshipStatusInfoEvent.ts b/src/nitro/communication/messages/incoming/user/data/RelationshipStatusInfoEvent.ts new file mode 100644 index 00000000..513ac49f --- /dev/null +++ b/src/nitro/communication/messages/incoming/user/data/RelationshipStatusInfoEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; +import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; +import { RelationshipStatusInfoMessageParser } from '../../../parser/user/data/RelationshipStatusInfoMessageParser'; + +export class RelationshipStatusInfoEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, RelationshipStatusInfoMessageParser); + } + + public getParser(): RelationshipStatusInfoMessageParser + { + return this.parser as RelationshipStatusInfoMessageParser; + } +} diff --git a/src/nitro/communication/messages/incoming/user/data/UserRelationshipsEvent.ts b/src/nitro/communication/messages/incoming/user/data/UserRelationshipsEvent.ts deleted file mode 100644 index f44e2936..00000000 --- a/src/nitro/communication/messages/incoming/user/data/UserRelationshipsEvent.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; -import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; -import { UserRelationshipsParser } from '../../../parser/user/data/UserRelationshipsParser'; - -export class UserRelationshipsEvent extends MessageEvent implements IMessageEvent -{ - constructor(callBack: Function) - { - super(callBack, UserRelationshipsParser); - } - - public getParser(): UserRelationshipsParser - { - return this.parser as UserRelationshipsParser; - } -} \ No newline at end of file diff --git a/src/nitro/communication/messages/incoming/user/data/index.ts b/src/nitro/communication/messages/incoming/user/data/index.ts index cdfd9bb1..f18b232c 100644 --- a/src/nitro/communication/messages/incoming/user/data/index.ts +++ b/src/nitro/communication/messages/incoming/user/data/index.ts @@ -1,7 +1,7 @@ +export * from './RelationshipStatusInfoEvent'; export * from './UserCurrentBadgesEvent'; export * from './UserFigureEvent'; export * from './UserInfoEvent'; export * from './UserNameChangeMessageEvent'; export * from './UserProfileEvent'; -export * from './UserRelationshipsEvent'; export * from './UserSettingsEvent'; diff --git a/src/nitro/communication/messages/parser/user/data/RelationshipStatusInfo.ts b/src/nitro/communication/messages/parser/user/data/RelationshipStatusInfo.ts new file mode 100644 index 00000000..13687ba9 --- /dev/null +++ b/src/nitro/communication/messages/parser/user/data/RelationshipStatusInfo.ts @@ -0,0 +1,68 @@ +import { IMessageDataWrapper } from '../../../../../../core/communication/messages/IMessageDataWrapper'; +import { RelationshipStatusEnum } from '../../../../../enums/RelationshipStatusEnum'; + +export class RelationshipStatusInfo +{ + private _relationshipStatusType: RelationshipStatusEnum; + private _friendCount: number; + private _randomFriendId: number; + private _randomFriendName: string; + private _randomFriendFigure: string; + + constructor(wrapper: IMessageDataWrapper) + { + if(!wrapper) throw new Error('invalid_wrapper'); + + this.flush(); + this.parse(wrapper); + } + + public flush(): boolean + { + this._relationshipStatusType = RelationshipStatusEnum.NONE; + this._friendCount = 0; + this._randomFriendId = 0; + this._randomFriendFigure = null; + this._randomFriendName = null; + + return true; + } + + public parse(wrapper: IMessageDataWrapper): boolean + { + if(!wrapper) return false; + + this._relationshipStatusType = wrapper.readInt(); + this._friendCount = wrapper.readInt(); + this._randomFriendId = wrapper.readInt(); + this._randomFriendName = wrapper.readString(); + this._randomFriendFigure = wrapper.readString(); + + return true; + } + + public get relationshipStatusType(): RelationshipStatusEnum + { + return this._relationshipStatusType; + } + + public get friendCount(): number + { + return this._friendCount; + } + + public get randomFriendId(): number + { + return this._randomFriendId; + } + + public get randomFriendName(): string + { + return this._randomFriendName; + } + + public get randomFriendFigure(): string + { + return this._randomFriendFigure; + } +} diff --git a/src/nitro/communication/messages/parser/user/data/RelationshipStatusInfoMessageParser.ts b/src/nitro/communication/messages/parser/user/data/RelationshipStatusInfoMessageParser.ts new file mode 100644 index 00000000..180f169e --- /dev/null +++ b/src/nitro/communication/messages/parser/user/data/RelationshipStatusInfoMessageParser.ts @@ -0,0 +1,48 @@ +import { IMessageDataWrapper } from '../../../../../../core/communication/messages/IMessageDataWrapper'; +import { IMessageParser } from '../../../../../../core/communication/messages/IMessageParser'; +import { AdvancedMap } from '../../../../../../core/utils/AdvancedMap'; +import { RelationshipStatusEnum } from '../../../../../enums/RelationshipStatusEnum'; +import { RelationshipStatusInfo } from './RelationshipStatusInfo'; + +export class RelationshipStatusInfoMessageParser implements IMessageParser +{ + private _userId: number; + private _relationshipStatusMap: AdvancedMap; + + public flush(): boolean + { + this._userId = 0; + this._relationshipStatusMap = null; + + return true; + } + + public parse(wrapper: IMessageDataWrapper): boolean + { + if(!wrapper) return false; + + this._userId = wrapper.readInt(); + this._relationshipStatusMap = new AdvancedMap(); + + const relationshipsCount = wrapper.readInt(); + + for(let i = 0; i < relationshipsCount; i++) + { + const relationship = new RelationshipStatusInfo(wrapper); + + this._relationshipStatusMap.add(relationship.relationshipStatusType, relationship); + } + + return true; + } + + public get userId(): number + { + return this._userId; + } + + public get relationshipStatusMap(): AdvancedMap + { + return this._relationshipStatusMap; + } +} diff --git a/src/nitro/communication/messages/parser/user/data/UserProfileParser.ts b/src/nitro/communication/messages/parser/user/data/UserProfileParser.ts index 344e4a7b..981d3589 100644 --- a/src/nitro/communication/messages/parser/user/data/UserProfileParser.ts +++ b/src/nitro/communication/messages/parser/user/data/UserProfileParser.ts @@ -15,7 +15,8 @@ export class UserProfileParser implements IMessageParser private _requestSent: boolean; private _isOnline: boolean; private _groups: GroupDataParser[]; - private _lastVisit: number; + private _secondsSinceLastVisit: number; + private _openProfileWindow: boolean; public flush(): boolean { @@ -30,7 +31,8 @@ export class UserProfileParser implements IMessageParser this._requestSent = false; this._isOnline = false; this._groups = []; - this._lastVisit = 0; + this._secondsSinceLastVisit = 0; + this._openProfileWindow = false; return true; } @@ -49,16 +51,15 @@ export class UserProfileParser implements IMessageParser this._isMyFriend = wrapper.readBoolean(); this._requestSent = wrapper.readBoolean(); this._isOnline = wrapper.readBoolean(); - let groupsCount = wrapper.readInt(); + const groupsCount = wrapper.readInt(); - while(groupsCount > 0) + for(let i = 0; i < groupsCount; i++) { this._groups.push(new GroupDataParser(wrapper)); - - groupsCount--; } - this._lastVisit = wrapper.readInt(); + this._secondsSinceLastVisit = wrapper.readInt(); + this._openProfileWindow = wrapper.readBoolean(); return true; } @@ -118,8 +119,13 @@ export class UserProfileParser implements IMessageParser return this._groups; } - public get lastVisit(): number + public get secondsSinceLastVisit(): number { - return this._lastVisit; + return this._secondsSinceLastVisit; } -} \ No newline at end of file + + public get openProfileWindow(): boolean + { + return this._openProfileWindow; + } +} diff --git a/src/nitro/communication/messages/parser/user/data/UserRelationshipDataParser.ts b/src/nitro/communication/messages/parser/user/data/UserRelationshipDataParser.ts deleted file mode 100644 index 29d842b9..00000000 --- a/src/nitro/communication/messages/parser/user/data/UserRelationshipDataParser.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { IMessageDataWrapper } from '../../../../../../core/communication/messages/IMessageDataWrapper'; -import { RelationshipStatusEnum } from '../../../../../enums/RelationshipStatusEnum'; - -export class UserRelationshipDataParser -{ - private _level: RelationshipStatusEnum; - private _userId: number; - private _username: string; - private _figure: string; - - constructor(wrapper: IMessageDataWrapper) - { - if(!wrapper) throw new Error('invalid_wrapper'); - - this.flush(); - this.parse(wrapper); - } - - public flush(): boolean - { - this._level = RelationshipStatusEnum.NONE; - this._userId = 0; - this._username = null; - this._figure = null; - - return true; - } - - public parse(wrapper: IMessageDataWrapper): boolean - { - if(!wrapper) return false; - - this._level = wrapper.readInt(); - wrapper.readInt(); - this._userId = wrapper.readInt(); - this._username = wrapper.readString(); - this._figure = wrapper.readString(); - - return true; - } - - public get level(): RelationshipStatusEnum - { - return this._level; - } - - public get userId(): number - { - return this._userId; - } - - public get username(): string - { - return this._username; - } - - public get figure(): string - { - return this._figure; - } -} diff --git a/src/nitro/communication/messages/parser/user/data/UserRelationshipsParser.ts b/src/nitro/communication/messages/parser/user/data/UserRelationshipsParser.ts deleted file mode 100644 index 60ce1a84..00000000 --- a/src/nitro/communication/messages/parser/user/data/UserRelationshipsParser.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { IMessageDataWrapper } from '../../../../../../core/communication/messages/IMessageDataWrapper'; -import { IMessageParser } from '../../../../../../core/communication/messages/IMessageParser'; -import { RelationshipStatusEnum } from '../../../../../enums/RelationshipStatusEnum'; -import { UserRelationshipDataParser } from './UserRelationshipDataParser'; - -export class UserRelationshipsParser implements IMessageParser -{ - private _id: number; - private _hearts: UserRelationshipDataParser[]; - private _smiles: UserRelationshipDataParser[]; - private _bobbas: UserRelationshipDataParser[]; - - public flush(): boolean - { - this._id = 0; - this._hearts = []; - this._smiles = []; - this._bobbas = []; - - return true; - } - - public parse(wrapper: IMessageDataWrapper): boolean - { - if(!wrapper) return false; - - this._id = wrapper.readInt(); - let relationshipsCount = wrapper.readInt(); - - while(relationshipsCount > 0) - { - const relationship = new UserRelationshipDataParser(wrapper); - - if(relationship.level === RelationshipStatusEnum.HEART) - { - this._hearts.push(relationship); - } - else if(relationship.level === RelationshipStatusEnum.SMILE) - { - this._smiles.push(relationship); - } - else if(relationship.level === RelationshipStatusEnum.BOBBA) - { - this._bobbas.push(relationship); - } - - relationshipsCount--; - } - - return true; - } - - public get id(): number - { - return this._id; - } - - public get hearts(): UserRelationshipDataParser[] - { - return this._hearts; - } - - public get smiles(): UserRelationshipDataParser[] - { - return this._smiles; - } - - public get bobbas(): UserRelationshipDataParser[] - { - return this._bobbas; - } -} diff --git a/src/nitro/communication/messages/parser/user/data/index.ts b/src/nitro/communication/messages/parser/user/data/index.ts index 171d6269..879b7b0c 100644 --- a/src/nitro/communication/messages/parser/user/data/index.ts +++ b/src/nitro/communication/messages/parser/user/data/index.ts @@ -1,9 +1,9 @@ +export * from './RelationshipStatusInfo'; +export * from './RelationshipStatusInfoMessageParser'; export * from './UserCurrentBadgesParser'; export * from './UserFigureParser'; export * from './UserInfoDataParser'; export * from './UserInfoParser'; export * from './UserNameChangeMessageParser'; export * from './UserProfileParser'; -export * from './UserRelationshipDataParser'; -export * from './UserRelationshipsParser'; export * from './UserSettingsParser';