diff --git a/src/nitro/communication/NitroMessages.ts b/src/nitro/communication/NitroMessages.ts index 416de5d2..c417c7b1 100644 --- a/src/nitro/communication/NitroMessages.ts +++ b/src/nitro/communication/NitroMessages.ts @@ -1,5 +1,5 @@ import { IMessageConfiguration } from '../../core/communication/messages/IMessageConfiguration'; -import { AchievementNotificationMessageEvent, ActivityPointNotificationMessageEvent, AddJukeboxDiskComposer, ApproveNameMessageComposer, ApproveNameMessageEvent, AvailabilityTimeMessageEvent, BadgeReceivedEvent, BonusRareInfoMessageEvent, BuildersClubFurniCountMessageEvent, BuildersClubSubscriptionStatusMessageEvent, BundleDiscountRulesetMessageEvent, ChangeUserNameMessageComposer, ChangeUserNameResultMessageEvent, CheckUserNameMessageComposer, CheckUserNameResultMessageEvent, ClubGiftNotificationEvent, DirectSMSClubBuyAvailableMessageEvent, FigureUpdateEvent, FurnitureGroupInfoComposer, GetBonusRareInfoMessageComposer, GetCatalogPageExpirationComposer, GetCatalogPageWithEarliestExpiryComposer, GetDirectClubBuyAvailableComposer, GetHabboBasicMembershipExtendOfferComposer, GetHabboClubExtendOfferMessageComposer, GetInterstitialMessageComposer, GetJukeboxPlayListMessageComposer, GetLimitedOfferAppearingNextComposer, GetNextTargetedOfferComposer, GetNowPlayingMessageComposer, GetOfficialSongIdMessageComposer, GetRoomAdPurchaseInfoComposer, GetSeasonalCalendarDailyOfferComposer, GetSongInfoMessageComposer, GetSoundMachinePlayListMessageComposer, GetUserSongDisksMessageComposer, HabboClubExtendOfferMessageEvent, HotelClosedAndOpensEvent, HotelClosesAndWillOpenAtEvent, HotelWillCloseInMinutesEvent, InfoFeedEnableMessageEvent, InterstitialMessageEvent, InterstitialShownMessageComposer, IsOfferGiftableMessageEvent, JukeboxPlayListFullMessageEvent, JukeboxSongDisksMessageEvent, LimitedOfferAppearingNextMessageEvent, MaintenanceStatusMessageEvent, MarkCatalogNewAdditionsPageOpenedComposer, MarketplaceBuyOfferComposer, MarketplaceRedeemCreditsComposer, MarketplaceRequesstItemStatsComposer, MarketplaceRequestComposer, MarketplaceRequestOffersComposer, MarketplaceRequestOwnItemsComposer, MarketplaceTakeItemBackComposer, MysteryBoxKeysEvent, NotEnoughBalanceMessageEvent, NowPlayingMessageEvent, OfficialSongIdMessageEvent, OpenCampaignCalendarDoorAsStaffComposer, OpenCampaignCalendarDoorComposer, PetExperienceEvent, PetMountComposer, PetSupplementComposer, PlayListMessageEvent, PlayListSongAddedMessageEvent, PurchaseBasicMembershipExtensionComposer, PurchaseRoomAdMessageComposer, PurchaseTargetedOfferComposer, PurchaseVipMembershipExtensionComposer, RemoveAllRightsMessageComposer, RemoveJukeboxDiskComposer, RemoveOwnRoomRightsRoomMessageComposer, RemovePetSaddleComposer, RoomAdErrorEvent, RoomAdPurchaseInfoEvent, RoomUnitGiveHandItemPetComposer, SeasonalCalendarDailyOfferMessageEvent, SellablePetPalettesMessageEvent, SetTargetedOfferStateComposer, ShopTargetedOfferViewedComposer, TargetedOfferEvent, TargetedOfferNotFoundEvent, TogglePetBreedingComposer, TogglePetRidingComposer, TraxSongInfoMessageEvent, UnseenResetCategoryComposer, UnseenResetItemsComposer, UsePetProductComposer, UserSongDisksInventoryMessageEvent, WardrobeMessageEvent } from './messages'; +import { AchievementNotificationMessageEvent, ActivityPointNotificationMessageEvent, AddJukeboxDiskComposer, ApproveNameMessageComposer, ApproveNameMessageEvent, AvailabilityTimeMessageEvent, BadgeReceivedEvent, BonusRareInfoMessageEvent, BuildersClubFurniCountMessageEvent, BuildersClubSubscriptionStatusMessageEvent, BundleDiscountRulesetMessageEvent, ChangeUserNameMessageComposer, ChangeUserNameResultMessageEvent, CheckUserNameMessageComposer, CheckUserNameResultMessageEvent, ClubGiftNotificationEvent, DirectSMSClubBuyAvailableMessageEvent, FigureUpdateEvent, FurnitureGroupInfoComposer, GetBonusRareInfoMessageComposer, GetCatalogPageExpirationComposer, GetCatalogPageWithEarliestExpiryComposer, GetDirectClubBuyAvailableComposer, GetHabboBasicMembershipExtendOfferComposer, GetHabboClubExtendOfferMessageComposer, GetInterstitialMessageComposer, GetJukeboxPlayListMessageComposer, GetLimitedOfferAppearingNextComposer, GetNextTargetedOfferComposer, GetNowPlayingMessageComposer, GetOfficialSongIdMessageComposer, GetRoomAdPurchaseInfoComposer, GetSeasonalCalendarDailyOfferComposer, GetSongInfoMessageComposer, GetSoundMachinePlayListMessageComposer, GetUserSongDisksMessageComposer, GroupBadgesComposer, GroupBadgesEvent, HabboClubExtendOfferMessageEvent, HotelClosedAndOpensEvent, HotelClosesAndWillOpenAtEvent, HotelWillCloseInMinutesEvent, InfoFeedEnableMessageEvent, InterstitialMessageEvent, InterstitialShownMessageComposer, IsOfferGiftableMessageEvent, JukeboxPlayListFullMessageEvent, JukeboxSongDisksMessageEvent, LimitedOfferAppearingNextMessageEvent, MaintenanceStatusMessageEvent, MarkCatalogNewAdditionsPageOpenedComposer, MarketplaceBuyOfferComposer, MarketplaceRedeemCreditsComposer, MarketplaceRequesstItemStatsComposer, MarketplaceRequestComposer, MarketplaceRequestOffersComposer, MarketplaceRequestOwnItemsComposer, MarketplaceTakeItemBackComposer, MysteryBoxKeysEvent, NotEnoughBalanceMessageEvent, NowPlayingMessageEvent, OfficialSongIdMessageEvent, OpenCampaignCalendarDoorAsStaffComposer, OpenCampaignCalendarDoorComposer, PetExperienceEvent, PetMountComposer, PetSupplementComposer, PlayListMessageEvent, PlayListSongAddedMessageEvent, PurchaseBasicMembershipExtensionComposer, PurchaseRoomAdMessageComposer, PurchaseTargetedOfferComposer, PurchaseVipMembershipExtensionComposer, RemoveAllRightsMessageComposer, RemoveJukeboxDiskComposer, RemoveOwnRoomRightsRoomMessageComposer, RemovePetSaddleComposer, RoomAdErrorEvent, RoomAdPurchaseInfoEvent, RoomUnitGiveHandItemPetComposer, SeasonalCalendarDailyOfferMessageEvent, SellablePetPalettesMessageEvent, SetTargetedOfferStateComposer, ShopTargetedOfferViewedComposer, TargetedOfferEvent, TargetedOfferNotFoundEvent, TogglePetBreedingComposer, TogglePetRidingComposer, TraxSongInfoMessageEvent, UnseenResetCategoryComposer, UnseenResetItemsComposer, UsePetProductComposer, UserSongDisksInventoryMessageEvent, WardrobeMessageEvent } from './messages'; import { AvailabilityStatusMessageEvent } from './messages/incoming/availability/AvailabilityStatusMessageEvent'; import { CfhSanctionMessageEvent, CfhTopicsInitEvent, SanctionStatusEvent } from './messages/incoming/callforhelp'; import { CameraPublishStatusMessageEvent } from './messages/incoming/camera/CameraPublishStatusMessageEvent'; @@ -278,6 +278,7 @@ import { GroupBuyComposer } from './messages/outgoing/group/GroupBuyComposer'; import { GroupBuyDataComposer } from './messages/outgoing/group/GroupBuyDataComposer'; import { GroupConfirmRemoveMemberComposer } from './messages/outgoing/group/GroupConfirmRemoveMemberComposer'; import { GroupDeleteComposer } from './messages/outgoing/group/GroupDeleteComposer'; +import { GroupFavoriteComposer } from './messages/outgoing/group/GroupFavoriteComposer'; import { GroupInformationComposer } from './messages/outgoing/group/GroupInformationComposer'; import { GroupJoinComposer } from './messages/outgoing/group/GroupJoinComposer'; import { GroupMembersComposer } from './messages/outgoing/group/GroupMembersComposer'; @@ -584,6 +585,7 @@ export class NitroMessages implements IMessageConfiguration this._events.set(IncomingHeader.GROUP_BADGE_PARTS, GroupBadgePartsEvent); this._events.set(IncomingHeader.GROUP_SETTINGS, GroupSettingsEvent); this._events.set(IncomingHeader.GROUP_PURCHASED, GroupPurchasedEvent); + this._events.set(IncomingHeader.GROUP_BADGES, GroupBadgesEvent); // HELP this._events.set(IncomingHeader.CFH_RESULT_MESSAGE, CallForHelpResultMessageEvent); @@ -971,6 +973,8 @@ export class NitroMessages implements IMessageConfiguration this._composers.set(OutgoingHeader.GROUP_SAVE_COLORS, GroupSaveColorsComposer); this._composers.set(OutgoingHeader.GROUP_SAVE_INFORMATION, GroupSaveInformationComposer); this._composers.set(OutgoingHeader.GROUP_SAVE_PREFERENCES, GroupSavePreferencesComposer); + this._composers.set(OutgoingHeader.GROUP_FAVORITE, GroupFavoriteComposer); + this._composers.set(OutgoingHeader.GROUP_BADGES, GroupBadgesComposer); // SECURITY this._composers.set(OutgoingHeader.SECURITY_TICKET, SecurityTicketComposer); diff --git a/src/nitro/communication/messages/incoming/IncomingHeader.ts b/src/nitro/communication/messages/incoming/IncomingHeader.ts index bdcab2fc..0460359b 100644 --- a/src/nitro/communication/messages/incoming/IncomingHeader.ts +++ b/src/nitro/communication/messages/incoming/IncomingHeader.ts @@ -37,7 +37,7 @@ export class IncomingHeader public static GENERIC_ALERT = 3801; public static MODERATOR_MESSAGE = 2030; public static GENERIC_ERROR = 1600; - public static GIFT_WRAPPER_CONFIG = 2234; + public static GIFT_WRAPPER_CONFIG = 2234; public static GROUP_BADGES = 2402; public static GROUP_CREATE_OPTIONS = 2159; public static GROUP_FORUM_INFO = 3011; diff --git a/src/nitro/communication/messages/incoming/group/GroupBadgesEvent.ts b/src/nitro/communication/messages/incoming/group/GroupBadgesEvent.ts new file mode 100644 index 00000000..4eb278d3 --- /dev/null +++ b/src/nitro/communication/messages/incoming/group/GroupBadgesEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '../../../../../core/communication/messages/IMessageEvent'; +import { MessageEvent } from '../../../../../core/communication/messages/MessageEvent'; +import { GroupBadgesParser } from '../../parser/group/GroupBadgesParser'; + +export class GroupBadgesEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, GroupBadgesParser); + } + + public getParser(): GroupBadgesParser + { + return this.parser as GroupBadgesParser; + } +} diff --git a/src/nitro/communication/messages/incoming/group/index.ts b/src/nitro/communication/messages/incoming/group/index.ts index ac39ba28..607855e1 100644 --- a/src/nitro/communication/messages/incoming/group/index.ts +++ b/src/nitro/communication/messages/incoming/group/index.ts @@ -1,4 +1,5 @@ export * from './GroupBadgePartsEvent'; +export * from './GroupBadgesEvent'; export * from './GroupBuyDataEvent'; export * from './GroupConfirmMemberRemoveEvent'; export * from './GroupInformationEvent'; diff --git a/src/nitro/communication/messages/outgoing/OutgoingHeader.ts b/src/nitro/communication/messages/outgoing/OutgoingHeader.ts index 43ce08c0..8ebd3888 100644 --- a/src/nitro/communication/messages/outgoing/OutgoingHeader.ts +++ b/src/nitro/communication/messages/outgoing/OutgoingHeader.ts @@ -40,6 +40,7 @@ export class OutgoingHeader public static GROUP_ADMIN_ADD = 2894; public static GROUP_ADMIN_REMOVE = 722; public static GROUP_CREATE_OPTIONS = 798; + public static GROUP_FAVORITE = 3549; public static GROUP_FORUM_INFO = 3149; public static GROUP_FORUM_LIST = 873; public static GROUP_FORUM_THREADS = 436; @@ -59,6 +60,7 @@ export class OutgoingHeader public static GROUP_SAVE_BADGE = 1991; public static GROUP_SAVE_COLORS = 1764; public static GROUP_SAVE_PREFERENCES = 3435; + public static GROUP_BADGES = 21; public static INVENTORY_UNKNOWN = 1371; public static ITEM_CLOTHING_REDEEM = 3374; public static ITEM_COLOR_WHEEL_CLICK = 2144; diff --git a/src/nitro/communication/messages/outgoing/group/GroupBadgesComposer.ts b/src/nitro/communication/messages/outgoing/group/GroupBadgesComposer.ts new file mode 100644 index 00000000..f43c167e --- /dev/null +++ b/src/nitro/communication/messages/outgoing/group/GroupBadgesComposer.ts @@ -0,0 +1,21 @@ +import { IMessageComposer } from '../../../../../core/communication/messages/IMessageComposer'; + +export class GroupBadgesComposer implements IMessageComposer> +{ + private _data: ConstructorParameters; + + constructor() + { + this._data = []; + } + + public getMessageArray() + { + return this._data; + } + + public dispose(): void + { + return; + } +} diff --git a/src/nitro/communication/messages/outgoing/group/GroupFavoriteComposer.ts b/src/nitro/communication/messages/outgoing/group/GroupFavoriteComposer.ts new file mode 100644 index 00000000..b8a941d3 --- /dev/null +++ b/src/nitro/communication/messages/outgoing/group/GroupFavoriteComposer.ts @@ -0,0 +1,21 @@ +import { IMessageComposer } from '../../../../../core/communication/messages/IMessageComposer'; + +export class GroupFavoriteComposer implements IMessageComposer> +{ + private _data: ConstructorParameters; + + constructor(groupId: number) + { + this._data = [ groupId ]; + } + + public getMessageArray() + { + return this._data; + } + + public dispose(): void + { + return; + } +} diff --git a/src/nitro/communication/messages/outgoing/group/index.ts b/src/nitro/communication/messages/outgoing/group/index.ts index f830f016..bf1b8fc3 100644 --- a/src/nitro/communication/messages/outgoing/group/index.ts +++ b/src/nitro/communication/messages/outgoing/group/index.ts @@ -1,10 +1,12 @@ export * from './GroupAdminGiveComposer'; export * from './GroupAdminTakeComposer'; export * from './GroupBadgePartsComposer'; +export * from './GroupBadgesComposer'; export * from './GroupBuyComposer'; export * from './GroupBuyDataComposer'; export * from './GroupConfirmRemoveMemberComposer'; export * from './GroupDeleteComposer'; +export * from './GroupFavoriteComposer'; export * from './GroupInformationComposer'; export * from './GroupJoinComposer'; export * from './GroupMembersComposer'; diff --git a/src/nitro/communication/messages/parser/group/GroupBadgesParser.ts b/src/nitro/communication/messages/parser/group/GroupBadgesParser.ts new file mode 100644 index 00000000..85789225 --- /dev/null +++ b/src/nitro/communication/messages/parser/group/GroupBadgesParser.ts @@ -0,0 +1,36 @@ +import { IMessageDataWrapper, IMessageParser } from '../../../../../core'; + +export class GroupBadgesParser implements IMessageParser +{ + private _badges: Map; + + flush(): boolean + { + this._badges = new Map(); + + return true; + } + + parse(wrapper: IMessageDataWrapper): boolean + { + if(!wrapper) return false; + + let badgesCount = wrapper.readInt(); + + while(badgesCount > 0) + { + const id = wrapper.readInt(); + const badge = wrapper.readString(); + + this._badges.set(id, badge); + badgesCount--; + } + + return true; + } + + public get badges(): Map + { + return this._badges; + } +} diff --git a/src/nitro/communication/messages/parser/group/index.ts b/src/nitro/communication/messages/parser/group/index.ts index 6ece4610..1c04c870 100644 --- a/src/nitro/communication/messages/parser/group/index.ts +++ b/src/nitro/communication/messages/parser/group/index.ts @@ -1,4 +1,5 @@ export * from './GroupBadgePartsParser'; +export * from './GroupBadgesParser'; export * from './GroupBuyDataParser'; export * from './GroupConfirmMemberRemoveParser'; export * from './GroupInformationParser'; diff --git a/src/nitro/session/GroupInformationManager.ts b/src/nitro/session/GroupInformationManager.ts new file mode 100644 index 00000000..a989551a --- /dev/null +++ b/src/nitro/session/GroupInformationManager.ts @@ -0,0 +1,72 @@ +import { IDisposable } from '../../core/common/disposable/IDisposable'; +import { IMessageEvent } from '../../core/communication/messages/IMessageEvent'; +import { GroupBadgesEvent } from '../communication/messages/incoming/group/GroupBadgesEvent'; +import { GroupBadgesComposer } from '../communication/messages/outgoing/group/GroupBadgesComposer'; +import { SessionDataManager } from './SessionDataManager'; + +export class GroupInformationManager implements IDisposable +{ + private _sessionDataManager: SessionDataManager; + private _groupBadges: Map; + + private _messages: IMessageEvent[]; + + constructor(sessionDataManager: SessionDataManager) + { + this._sessionDataManager = sessionDataManager; + this._groupBadges = new Map(); + } + + public init(): void + { + if(this._sessionDataManager && this._sessionDataManager.communication) + { + this._messages = [ + new GroupBadgesEvent(this.onGroupBadgesEvent.bind(this)) + ]; + + for(const message of this._messages) this._sessionDataManager.communication.registerMessageEvent(message); + } + } + + public dispose(): void + { + if(this.disposed) return; + + if(this._messages && this._messages.length) + { + for(const message of this._messages) this._sessionDataManager.communication.removeMessageEvent(message); + + this._messages = null; + } + + this._groupBadges = null; + this._sessionDataManager = null; + } + + public requestGroupBadges(): void + { + this._sessionDataManager.send(new GroupBadgesComposer()); + } + + private onGroupBadgesEvent(event: GroupBadgesEvent): void + { + if(!event) return; + + const parser = event.getParser(); + + if(!parser) return; + + this._groupBadges = parser.badges; + } + + public getGroupBadge(groupId: number): string + { + return this._groupBadges.get(groupId); + } + + public get disposed(): boolean + { + return !!this._sessionDataManager; + } +} diff --git a/src/nitro/session/ISessionDataManager.ts b/src/nitro/session/ISessionDataManager.ts index 51a598c3..22e5000a 100644 --- a/src/nitro/session/ISessionDataManager.ts +++ b/src/nitro/session/ISessionDataManager.ts @@ -3,6 +3,7 @@ import { INitroManager } from '../../core/common/INitroManager'; import { INitroCommunicationManager } from '../communication/INitroCommunicationManager'; import { IFurnitureData } from './furniture/IFurnitureData'; import { IFurnitureDataListener } from './furniture/IFurnitureDataListener'; +import { GroupInformationManager } from './GroupInformationManager'; import { IgnoredUsersManager } from './IgnoredUsersManager'; import { IProductData } from './product/IProductData'; @@ -29,6 +30,7 @@ export interface ISessionDataManager extends INitroManager ignoreUser(name: string): void; unignoreUser(name: string): void; isUserIgnored(name: string): boolean; + getGroupBadge(groupId: number): string; communication: INitroCommunicationManager; userId: number; userName: string; @@ -37,6 +39,7 @@ export interface ISessionDataManager extends INitroManager isGodMode: boolean; realName: string; ignoredUsersManager: IgnoredUsersManager; + groupInformationManager: GroupInformationManager; respectsReceived: number; respectsLeft: number; respectsPetLeft: number; diff --git a/src/nitro/session/SessionDataManager.ts b/src/nitro/session/SessionDataManager.ts index 47c468a9..7b78bb8a 100644 --- a/src/nitro/session/SessionDataManager.ts +++ b/src/nitro/session/SessionDataManager.ts @@ -26,6 +26,7 @@ import { UserNameUpdateEvent } from './events/UserNameUpdateEvent'; import { FurnitureDataLoader } from './furniture/FurnitureDataLoader'; import { IFurnitureData } from './furniture/IFurnitureData'; import { IFurnitureDataListener } from './furniture/IFurnitureDataListener'; +import { GroupInformationManager } from './GroupInformationManager'; import { IgnoredUsersManager } from './IgnoredUsersManager'; import { ISessionDataManager } from './ISessionDataManager'; import { IProductData } from './product/IProductData'; @@ -47,6 +48,7 @@ export class SessionDataManager extends NitroManager implements ISessionDataMana private _canChangeName: boolean; private _ignoredUsersManager: IgnoredUsersManager; + private _groupInformationManager: GroupInformationManager; private _clubLevel: number; private _securityLevel: number; @@ -82,6 +84,7 @@ export class SessionDataManager extends NitroManager implements ISessionDataMana this.resetUserInfo(); this._ignoredUsersManager = new IgnoredUsersManager(this); + this._groupInformationManager = new GroupInformationManager(this); this._clubLevel = 0; this._securityLevel = 0; @@ -111,6 +114,7 @@ export class SessionDataManager extends NitroManager implements ISessionDataMana this.onProductDataReadyEvent = this.onProductDataReadyEvent.bind(this); this.onNitroSettingsEvent = this.onNitroSettingsEvent.bind(this); } + groupInformationManager: GroupInformationManager; protected onInit(): void { @@ -119,6 +123,7 @@ export class SessionDataManager extends NitroManager implements ISessionDataMana this.loadBadgeImageManager(); (this._ignoredUsersManager && this._ignoredUsersManager.init()); + (this._groupInformationManager && this._groupInformationManager.init()); this._communication.registerMessageEvent(new FigureUpdateEvent(this.onUserFigureEvent.bind(this))); this._communication.registerMessageEvent(new UserInfoEvent(this.onUserInfoEvent.bind(this))); @@ -144,6 +149,13 @@ export class SessionDataManager extends NitroManager implements ISessionDataMana this._ignoredUsersManager = null; } + if(this._groupInformationManager) + { + this._groupInformationManager.dispose(); + + this._groupInformationManager = null; + } + Nitro.instance.events.removeEventListener(NitroSettingsEvent.SETTINGS_UPDATED, this.onNitroSettingsEvent); super.onDispose(); @@ -541,6 +553,11 @@ export class SessionDataManager extends NitroManager implements ISessionDataMana return (this._ignoredUsersManager && this._ignoredUsersManager.isIgnored(name)); } + public getGroupBadge(groupId: number): string + { + return (this._groupInformationManager && this._groupInformationManager.getGroupBadge(groupId)); + } + public send(composer: IMessageComposer): void { this._communication.connection.send(composer);