You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 15:06:20 +00:00
Move to Renderer V2
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": [ "@nitrots/eslint-config" ]
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# compiled output
|
||||
/dist
|
||||
/tmp
|
||||
/out-tsc
|
||||
# Only exists if Bazel was run
|
||||
/bazel-out
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# profiling files
|
||||
chrome-profiler-events*.json
|
||||
speed-measure-plugin*.json
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
.history/*
|
||||
|
||||
# misc
|
||||
/.sass-cache
|
||||
/connect.lock
|
||||
/coverage
|
||||
/libpeerconnection.log
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
testem.log
|
||||
/typings
|
||||
.git
|
||||
|
||||
# System Files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
*.zip
|
||||
*.as
|
||||
*.bin
|
||||
@@ -0,0 +1 @@
|
||||
export * from './src';
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "@nitrots/session",
|
||||
"description": "Nitro session module",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
"compile": "tsc --project ./tsconfig.json --noEmit false",
|
||||
"eslint": "eslint ./src --fix"
|
||||
},
|
||||
"main": "./index",
|
||||
"dependencies": {
|
||||
"@nitrots/api": "1.0.0",
|
||||
"@nitrots/assets": "1.0.0",
|
||||
"@nitrots/communication": "1.0.0",
|
||||
"@nitrots/configuration": "1.0.0",
|
||||
"@nitrots/eslint-config": "1.0.0",
|
||||
"@nitrots/events": "1.0.0",
|
||||
"@nitrots/localization": "1.0.0",
|
||||
"pixi.js": "^8.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "~5.4.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { RoomSessionManager } from './RoomSessionManager';
|
||||
|
||||
const roomSessionManager = new RoomSessionManager();
|
||||
|
||||
export const GetRoomSessionManager = () => roomSessionManager;
|
||||
@@ -0,0 +1,5 @@
|
||||
import { SessionDataManager } from './SessionDataManager';
|
||||
|
||||
const sessionDataManager = new SessionDataManager();
|
||||
|
||||
export const GetSessionDataManager = () => sessionDataManager;
|
||||
@@ -0,0 +1,30 @@
|
||||
import { IGroupInformationManager } from '@nitrots/api';
|
||||
import { GetCommunication, GetHabboGroupBadgesMessageComposer, HabboGroupBadgesMessageEvent, RoomReadyMessageEvent } from '@nitrots/communication';
|
||||
|
||||
export class GroupInformationManager implements IGroupInformationManager
|
||||
{
|
||||
private _groupBadges: Map<number, string> = new Map();
|
||||
|
||||
public init(): void
|
||||
{
|
||||
GetCommunication().registerMessageEvent(new RoomReadyMessageEvent(this.onRoomReadyMessageEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new HabboGroupBadgesMessageEvent(this.onGroupBadgesEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onRoomReadyMessageEvent(event: RoomReadyMessageEvent): void
|
||||
{
|
||||
GetCommunication().connection.send(new GetHabboGroupBadgesMessageComposer());
|
||||
}
|
||||
|
||||
private onGroupBadgesEvent(event: HabboGroupBadgesMessageEvent): void
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
for(const [groupId, badgeId] of parser.badges.entries()) this._groupBadges.set(groupId, badgeId);
|
||||
}
|
||||
|
||||
public getGroupBadge(groupId: number): string
|
||||
{
|
||||
return this._groupBadges.get(groupId) ?? '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export class HabboClubLevelEnum
|
||||
{
|
||||
public static NO_CLUB: number = 0;
|
||||
public static CLUB: number = 1;
|
||||
public static VIP: number = 2;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { IIgnoredUsersManager } from '@nitrots/api';
|
||||
import { GetCommunication, GetIgnoredUsersComposer, IgnoreResultEvent, IgnoreUserComposer, IgnoreUserIdComposer, IgnoredUsersEvent, UnignoreUserComposer } from '@nitrots/communication';
|
||||
|
||||
export class IgnoredUsersManager implements IIgnoredUsersManager
|
||||
{
|
||||
private _ignoredUsers: string[] = [];
|
||||
|
||||
public init(): void
|
||||
{
|
||||
GetCommunication().registerMessageEvent(new IgnoredUsersEvent(this.onIgnoredUsersEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new IgnoreResultEvent(this.onIgnoreResultEvent.bind(this)));
|
||||
}
|
||||
|
||||
public requestIgnoredUsers(username: string): void
|
||||
{
|
||||
GetCommunication().connection.send(new GetIgnoredUsersComposer(username));
|
||||
}
|
||||
|
||||
private onIgnoredUsersEvent(event: IgnoredUsersEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
this._ignoredUsers = parser.ignoredUsers;
|
||||
}
|
||||
|
||||
private onIgnoreResultEvent(event: IgnoreResultEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const name = parser.name;
|
||||
|
||||
switch(parser.result)
|
||||
{
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
this.addUserToIgnoreList(name);
|
||||
return;
|
||||
case 2:
|
||||
this.addUserToIgnoreList(name);
|
||||
this._ignoredUsers.shift();
|
||||
return;
|
||||
case 3:
|
||||
this.removeUserFromIgnoreList(name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private addUserToIgnoreList(name: string): void
|
||||
{
|
||||
if(this._ignoredUsers.indexOf(name) < 0) this._ignoredUsers.push(name);
|
||||
}
|
||||
|
||||
private removeUserFromIgnoreList(name: string): void
|
||||
{
|
||||
const index = this._ignoredUsers.indexOf(name);
|
||||
|
||||
if(index >= 0) this._ignoredUsers.splice(index, 1);
|
||||
}
|
||||
|
||||
public ignoreUserId(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new IgnoreUserIdComposer(id));
|
||||
}
|
||||
|
||||
public ignoreUser(name: string): void
|
||||
{
|
||||
GetCommunication().connection.send(new IgnoreUserComposer(name));
|
||||
}
|
||||
|
||||
public unignoreUser(name: string): void
|
||||
{
|
||||
GetCommunication().connection.send(new UnignoreUserComposer(name));
|
||||
}
|
||||
|
||||
public isIgnored(name: string): boolean
|
||||
{
|
||||
return (this._ignoredUsers.indexOf(name) >= 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
import { IRoomPetData } from '@nitrots/api';
|
||||
|
||||
export class RoomPetData implements IRoomPetData
|
||||
{
|
||||
private _id: number;
|
||||
private _level: number;
|
||||
private _maximumLevel: number;
|
||||
private _experience: number;
|
||||
private _levelExperienceGoal: number;
|
||||
private _energy: number;
|
||||
private _maximumEnergy: number;
|
||||
private _happyness: number;
|
||||
private _maximumHappyness: number;
|
||||
private _ownerId: number;
|
||||
private _ownerName: string;
|
||||
private _respect: number;
|
||||
private _age: number;
|
||||
private _unknownRarity: number;
|
||||
private _saddle: boolean;
|
||||
private _rider: boolean;
|
||||
private _breedable: boolean;
|
||||
private _skillThresholds: number[];
|
||||
private _publiclyRideable: number;
|
||||
private _fullyGrown: boolean;
|
||||
private _dead: boolean;
|
||||
private _maximumTimeToLive: number;
|
||||
private _remainingTimeToLive: number;
|
||||
private _remainingGrowTime: number;
|
||||
private _rarityLevel: number;
|
||||
private _publiclyBreedable: boolean;
|
||||
private _adultLevel: number = 7;
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public set id(k: number)
|
||||
{
|
||||
this._id = k;
|
||||
}
|
||||
|
||||
public get level(): number
|
||||
{
|
||||
return this._level;
|
||||
}
|
||||
|
||||
public set level(level: number)
|
||||
{
|
||||
this._level = level;
|
||||
}
|
||||
|
||||
public get maximumLevel(): number
|
||||
{
|
||||
return this._maximumLevel;
|
||||
}
|
||||
|
||||
public set maximumLevel(k: number)
|
||||
{
|
||||
this._maximumLevel = k;
|
||||
}
|
||||
|
||||
public get experience(): number
|
||||
{
|
||||
return this._experience;
|
||||
}
|
||||
|
||||
public set experience(experience: number)
|
||||
{
|
||||
this._experience = experience;
|
||||
}
|
||||
|
||||
public get levelExperienceGoal(): number
|
||||
{
|
||||
return this._levelExperienceGoal;
|
||||
}
|
||||
|
||||
public set levelExperienceGoal(k: number)
|
||||
{
|
||||
this._levelExperienceGoal = k;
|
||||
}
|
||||
|
||||
public get energy(): number
|
||||
{
|
||||
return this._energy;
|
||||
}
|
||||
|
||||
public set energy(energy: number)
|
||||
{
|
||||
this._energy = energy;
|
||||
}
|
||||
|
||||
public get maximumEnergy(): number
|
||||
{
|
||||
return this._maximumEnergy;
|
||||
}
|
||||
|
||||
public set maximumEnergy(k: number)
|
||||
{
|
||||
this._maximumEnergy = k;
|
||||
}
|
||||
|
||||
public get happyness(): number
|
||||
{
|
||||
return this._happyness;
|
||||
}
|
||||
|
||||
public set happyness(k: number)
|
||||
{
|
||||
this._happyness = k;
|
||||
}
|
||||
|
||||
public get maximumHappyness(): number
|
||||
{
|
||||
return this._maximumHappyness;
|
||||
}
|
||||
|
||||
public set maximumHappyness(k: number)
|
||||
{
|
||||
this._maximumHappyness = k;
|
||||
}
|
||||
|
||||
public get ownerId(): number
|
||||
{
|
||||
return this._ownerId;
|
||||
}
|
||||
|
||||
public set ownerId(k: number)
|
||||
{
|
||||
this._ownerId = k;
|
||||
}
|
||||
|
||||
public get ownerName(): string
|
||||
{
|
||||
return this._ownerName;
|
||||
}
|
||||
|
||||
public set ownerName(ownerName: string)
|
||||
{
|
||||
this._ownerName = ownerName;
|
||||
}
|
||||
|
||||
public get respect(): number
|
||||
{
|
||||
return this._respect;
|
||||
}
|
||||
|
||||
public set respect(k: number)
|
||||
{
|
||||
this._respect = k;
|
||||
}
|
||||
|
||||
public get age(): number
|
||||
{
|
||||
return this._age;
|
||||
}
|
||||
|
||||
public set age(age: number)
|
||||
{
|
||||
this._age = age;
|
||||
}
|
||||
|
||||
public get unknownRarity(): number
|
||||
{
|
||||
return this._unknownRarity;
|
||||
}
|
||||
|
||||
public set unknownRarity(k: number)
|
||||
{
|
||||
this._unknownRarity = k;
|
||||
}
|
||||
|
||||
public get saddle(): boolean
|
||||
{
|
||||
return this._saddle;
|
||||
}
|
||||
|
||||
public set saddle(k: boolean)
|
||||
{
|
||||
this._saddle = k;
|
||||
}
|
||||
|
||||
public get rider(): boolean
|
||||
{
|
||||
return this._rider;
|
||||
}
|
||||
|
||||
public set rider(k: boolean)
|
||||
{
|
||||
this._rider = k;
|
||||
}
|
||||
|
||||
public get skillTresholds(): number[]
|
||||
{
|
||||
return this._skillThresholds;
|
||||
}
|
||||
|
||||
public set skillTresholds(k: number[])
|
||||
{
|
||||
this._skillThresholds = k;
|
||||
}
|
||||
|
||||
public get publiclyRideable(): number
|
||||
{
|
||||
return this._publiclyRideable;
|
||||
}
|
||||
|
||||
public set publiclyRideable(k: number)
|
||||
{
|
||||
this._publiclyRideable = k;
|
||||
}
|
||||
|
||||
public get breedable(): boolean
|
||||
{
|
||||
return this._breedable;
|
||||
}
|
||||
|
||||
public set breedable(k: boolean)
|
||||
{
|
||||
this._breedable = k;
|
||||
}
|
||||
|
||||
public get fullyGrown(): boolean
|
||||
{
|
||||
return this._fullyGrown;
|
||||
}
|
||||
|
||||
public set fullyGrown(k: boolean)
|
||||
{
|
||||
this._fullyGrown = k;
|
||||
}
|
||||
|
||||
public get dead(): boolean
|
||||
{
|
||||
return this._dead;
|
||||
}
|
||||
|
||||
public set dead(k: boolean)
|
||||
{
|
||||
this._dead = k;
|
||||
}
|
||||
|
||||
public get rarityLevel(): number
|
||||
{
|
||||
return this._rarityLevel;
|
||||
}
|
||||
|
||||
public set rarityLevel(rarityLevel: number)
|
||||
{
|
||||
this._rarityLevel = rarityLevel;
|
||||
}
|
||||
|
||||
public get maximumTimeToLive(): number
|
||||
{
|
||||
return this._maximumTimeToLive;
|
||||
}
|
||||
|
||||
public set maximumTimeToLive(k: number)
|
||||
{
|
||||
this._maximumTimeToLive = k;
|
||||
}
|
||||
|
||||
public get remainingTimeToLive(): number
|
||||
{
|
||||
return this._remainingTimeToLive;
|
||||
}
|
||||
|
||||
public set remainingTimeToLive(k: number)
|
||||
{
|
||||
this._remainingTimeToLive = k;
|
||||
}
|
||||
|
||||
public get remainingGrowTime(): number
|
||||
{
|
||||
return this._remainingGrowTime;
|
||||
}
|
||||
|
||||
public set remainingGrowTime(k: number)
|
||||
{
|
||||
this._remainingGrowTime = k;
|
||||
}
|
||||
|
||||
public get publiclyBreedable(): boolean
|
||||
{
|
||||
return this._publiclyBreedable;
|
||||
}
|
||||
|
||||
public set publiclyBreedable(k: boolean)
|
||||
{
|
||||
this._publiclyBreedable = k;
|
||||
}
|
||||
|
||||
public get adultLevel(): number
|
||||
{
|
||||
return this._adultLevel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,413 @@
|
||||
import { IRoomSession, IUserDataManager, RoomControllerLevel, RoomTradingLevelEnum } from '@nitrots/api';
|
||||
import { BotRemoveComposer, ChangeQueueMessageComposer, CompostPlantMessageComposer, FurnitureMultiStateComposer, GetCommunication, GetPetCommandsComposer, HarvestPetMessageComposer, MoodlightSettingsComposer, MoodlightSettingsSaveComposer, MoodlightTogggleStateComposer, NewUserExperienceScriptProceedComposer, OpenPetPackageMessageComposer, OpenPresentComposer, PeerUsersClassificationMessageComposer, PetMountComposer, PetRemoveComposer, PollAnswerComposer, PollRejectComposer, PollStartComposer, RemovePetSaddleComposer, RoomAmbassadorAlertComposer, RoomBanUserComposer, RoomDoorbellAccessComposer, RoomEnterComposer, RoomGiveRightsComposer, RoomKickUserComposer, RoomModerationSettings, RoomMuteUserComposer, RoomTakeRightsComposer, RoomUnitActionComposer, RoomUnitChatComposer, RoomUnitChatShoutComposer, RoomUnitChatWhisperComposer, RoomUnitDanceComposer, RoomUnitPostureComposer, RoomUnitSignComposer, RoomUnitTypingStartComposer, RoomUnitTypingStopComposer, RoomUsersClassificationMessageComposer, SetClothingChangeDataMessageComposer, TogglePetBreedingComposer, TogglePetRidingComposer, UsePetProductComposer, UserMottoComposer, VotePollCounterMessageComposer } from '@nitrots/communication';
|
||||
import { RoomSessionEvent } from '@nitrots/events';
|
||||
import { UserDataManager } from './UserDataManager';
|
||||
|
||||
export class RoomSession implements IRoomSession
|
||||
{
|
||||
private _userData: IUserDataManager = new UserDataManager();
|
||||
|
||||
private _roomId: number = 0;
|
||||
private _password: string = null;
|
||||
private _state: string = RoomSessionEvent.CREATED;
|
||||
private _tradeMode: number = RoomTradingLevelEnum.NO_TRADING;
|
||||
private _doorMode: number = 0;
|
||||
private _allowPets: boolean = false;
|
||||
private _controllerLevel: number = RoomControllerLevel.NONE;
|
||||
private _ownRoomIndex: number = -1;
|
||||
private _isGuildRoom: boolean = false;
|
||||
private _isRoomOwner: boolean = false;
|
||||
private _isDecorating: boolean = false;
|
||||
private _isSpectator: boolean = false;
|
||||
|
||||
private _moderationSettings: RoomModerationSettings = null;
|
||||
|
||||
public setControllerLevel(level: number): void
|
||||
{
|
||||
if((level >= RoomControllerLevel.NONE) && (level <= RoomControllerLevel.MODERATOR))
|
||||
{
|
||||
this._controllerLevel = level;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._controllerLevel = RoomControllerLevel.NONE;
|
||||
}
|
||||
|
||||
public setOwnRoomIndex(roomIndex: number): void
|
||||
{
|
||||
this._ownRoomIndex = roomIndex;
|
||||
}
|
||||
|
||||
public setRoomOwner(): void
|
||||
{
|
||||
this._isRoomOwner = true;
|
||||
}
|
||||
|
||||
public start(): boolean
|
||||
{
|
||||
if(this._state !== RoomSessionEvent.CREATED || !GetCommunication().connection) return false;
|
||||
|
||||
this._state = RoomSessionEvent.STARTED;
|
||||
|
||||
return this.enterRoom();
|
||||
}
|
||||
|
||||
private enterRoom(): boolean
|
||||
{
|
||||
if(!GetCommunication().connection) return false;
|
||||
|
||||
GetCommunication().connection.send(new RoomEnterComposer(this._roomId, this._password));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public reset(roomId: number): void
|
||||
{
|
||||
if(roomId === this._roomId) return;
|
||||
|
||||
this._roomId = roomId;
|
||||
}
|
||||
|
||||
public sendChatMessage(text: string, styleId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomUnitChatComposer(text, styleId));
|
||||
}
|
||||
|
||||
public sendShoutMessage(text: string, styleId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomUnitChatShoutComposer(text, styleId));
|
||||
}
|
||||
|
||||
public sendWhisperMessage(recipientName: string, text: string, styleId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomUnitChatWhisperComposer(recipientName, text, styleId));
|
||||
}
|
||||
|
||||
public sendChatTypingMessage(isTyping: boolean): void
|
||||
{
|
||||
if(isTyping) GetCommunication().connection.send(new RoomUnitTypingStartComposer());
|
||||
else GetCommunication().connection.send(new RoomUnitTypingStopComposer());
|
||||
}
|
||||
|
||||
public sendMottoMessage(motto: string): void
|
||||
{
|
||||
GetCommunication().connection.send(new UserMottoComposer(motto));
|
||||
}
|
||||
|
||||
public sendDanceMessage(danceId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomUnitDanceComposer(danceId));
|
||||
}
|
||||
|
||||
public sendExpressionMessage(expression: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomUnitActionComposer(expression));
|
||||
}
|
||||
|
||||
public sendSignMessage(sign: number): void
|
||||
{
|
||||
if((sign < 0) || (sign > 17)) return;
|
||||
|
||||
GetCommunication().connection.send(new RoomUnitSignComposer(sign));
|
||||
}
|
||||
|
||||
public sendPostureMessage(posture: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomUnitPostureComposer(posture));
|
||||
}
|
||||
|
||||
public sendDoorbellApprovalMessage(userName: string, flag: boolean): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomDoorbellAccessComposer(userName, flag));
|
||||
}
|
||||
|
||||
public sendAmbassadorAlertMessage(userId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomAmbassadorAlertComposer(userId));
|
||||
}
|
||||
|
||||
public sendKickMessage(userId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomKickUserComposer(userId));
|
||||
}
|
||||
|
||||
public sendMuteMessage(userId: number, minutes: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomMuteUserComposer(userId, minutes, this._roomId));
|
||||
}
|
||||
|
||||
public sendBanMessage(userId: number, type: string): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomBanUserComposer(userId, this._roomId, type));
|
||||
}
|
||||
|
||||
public sendGiveRightsMessage(userId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomGiveRightsComposer(userId));
|
||||
}
|
||||
|
||||
public sendTakeRightsMessage(userId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomTakeRightsComposer(userId));
|
||||
}
|
||||
|
||||
public sendPollStartMessage(pollId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new PollStartComposer(pollId));
|
||||
}
|
||||
|
||||
public sendPollRejectMessage(pollId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new PollRejectComposer(pollId));
|
||||
}
|
||||
|
||||
public sendPollAnswerMessage(pollId: number, questionId: number, answers: string[]): void
|
||||
{
|
||||
GetCommunication().connection.send(new PollAnswerComposer(pollId, questionId, answers));
|
||||
}
|
||||
|
||||
public sendPeerUsersClassificationMessage(userClassType: string): void
|
||||
{
|
||||
GetCommunication().connection.send(new PeerUsersClassificationMessageComposer(userClassType));
|
||||
}
|
||||
|
||||
public sendOpenPetPackageMessage(objectId: number, petName: string): void
|
||||
{
|
||||
GetCommunication().connection.send(new OpenPetPackageMessageComposer(objectId, petName));
|
||||
}
|
||||
|
||||
public sendRoomUsersClassificationMessage(userClassType: string): void
|
||||
{
|
||||
GetCommunication().connection.send(new RoomUsersClassificationMessageComposer(userClassType));
|
||||
}
|
||||
|
||||
public updateMoodlightData(id: number, effectId: number, color: number, brightness: number, apply: boolean): void
|
||||
{
|
||||
let colorString = '000000' + color.toString(16).toUpperCase();
|
||||
colorString = '#' + colorString.substring((colorString.length - 6));
|
||||
|
||||
GetCommunication().connection.send(new MoodlightSettingsSaveComposer(id, effectId, colorString, brightness, apply));
|
||||
}
|
||||
|
||||
public toggleMoodlightState(): void
|
||||
{
|
||||
GetCommunication().connection.send(new MoodlightTogggleStateComposer());
|
||||
}
|
||||
|
||||
public pickupPet(id: number): void
|
||||
{
|
||||
if(!GetCommunication().connection) return;
|
||||
|
||||
GetCommunication().connection.send(new PetRemoveComposer(id));
|
||||
}
|
||||
|
||||
public pickupBot(id: number): void
|
||||
{
|
||||
if(!GetCommunication().connection) return;
|
||||
|
||||
GetCommunication().connection.send(new BotRemoveComposer(id));
|
||||
}
|
||||
|
||||
public requestMoodlightSettings(): void
|
||||
{
|
||||
if(!GetCommunication().connection) return;
|
||||
|
||||
GetCommunication().connection.send(new MoodlightSettingsComposer());
|
||||
}
|
||||
|
||||
public openGift(objectId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new OpenPresentComposer(objectId));
|
||||
}
|
||||
|
||||
public mountPet(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new PetMountComposer(id, true));
|
||||
}
|
||||
|
||||
public dismountPet(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new PetMountComposer(id, false));
|
||||
}
|
||||
|
||||
public usePetProduct(itemId: number, petId: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new UsePetProductComposer(itemId, petId));
|
||||
}
|
||||
|
||||
public removePetSaddle(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new RemovePetSaddleComposer(id));
|
||||
}
|
||||
|
||||
public togglePetBreeding(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new TogglePetBreedingComposer(id));
|
||||
}
|
||||
|
||||
public togglePetRiding(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new TogglePetRidingComposer(id));
|
||||
}
|
||||
|
||||
public useMultistateItem(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new FurnitureMultiStateComposer(id));
|
||||
}
|
||||
|
||||
public harvestPet(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new HarvestPetMessageComposer(id));
|
||||
}
|
||||
|
||||
public compostPlant(id: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new CompostPlantMessageComposer(id));
|
||||
}
|
||||
|
||||
public requestPetCommands(id: number):void
|
||||
{
|
||||
GetCommunication().connection.send(new GetPetCommandsComposer(id));
|
||||
}
|
||||
|
||||
public sendScriptProceed(): void
|
||||
{
|
||||
GetCommunication().connection.send(new NewUserExperienceScriptProceedComposer());
|
||||
}
|
||||
|
||||
public sendUpdateClothingChangeFurniture(objectId: number, gender: string, look: string):void
|
||||
{
|
||||
GetCommunication().connection.send(new SetClothingChangeDataMessageComposer(objectId, gender, look));
|
||||
}
|
||||
|
||||
public changeQueue(targetQueue: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new ChangeQueueMessageComposer(targetQueue));
|
||||
}
|
||||
|
||||
public votePoll(counter: number): void
|
||||
{
|
||||
GetCommunication().connection.send(new VotePollCounterMessageComposer(counter));
|
||||
}
|
||||
|
||||
public get userDataManager(): IUserDataManager
|
||||
{
|
||||
return this._userData;
|
||||
}
|
||||
|
||||
public get roomId(): number
|
||||
{
|
||||
return this._roomId;
|
||||
}
|
||||
|
||||
public set roomId(roomId: number)
|
||||
{
|
||||
this._roomId = roomId;
|
||||
}
|
||||
|
||||
public get password(): string
|
||||
{
|
||||
return this._password;
|
||||
}
|
||||
|
||||
public set password(password: string)
|
||||
{
|
||||
this._password = password;
|
||||
}
|
||||
|
||||
public get state(): string
|
||||
{
|
||||
return this._state;
|
||||
}
|
||||
|
||||
public get isPrivateRoom(): boolean
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public get tradeMode(): number
|
||||
{
|
||||
return this._tradeMode;
|
||||
}
|
||||
|
||||
public set tradeMode(mode: number)
|
||||
{
|
||||
this._tradeMode = mode;
|
||||
}
|
||||
|
||||
public get doorMode(): number
|
||||
{
|
||||
return this._doorMode;
|
||||
}
|
||||
|
||||
public set doorMode(mode: number)
|
||||
{
|
||||
this._doorMode = mode;
|
||||
}
|
||||
|
||||
public get allowPets(): boolean
|
||||
{
|
||||
return this._allowPets;
|
||||
}
|
||||
|
||||
public set allowPets(flag: boolean)
|
||||
{
|
||||
this._allowPets = flag;
|
||||
}
|
||||
|
||||
public get controllerLevel(): number
|
||||
{
|
||||
return this._controllerLevel;
|
||||
}
|
||||
|
||||
public get ownRoomIndex(): number
|
||||
{
|
||||
return this._ownRoomIndex;
|
||||
}
|
||||
|
||||
public get isGuildRoom(): boolean
|
||||
{
|
||||
return this._isGuildRoom;
|
||||
}
|
||||
|
||||
public set isGuildRoom(flag: boolean)
|
||||
{
|
||||
this._isGuildRoom = flag;
|
||||
}
|
||||
|
||||
public get isRoomOwner(): boolean
|
||||
{
|
||||
return this._isRoomOwner;
|
||||
}
|
||||
|
||||
public get isDecorating(): boolean
|
||||
{
|
||||
return this._isDecorating;
|
||||
}
|
||||
|
||||
public set isDecorating(flag: boolean)
|
||||
{
|
||||
this._isDecorating = flag;
|
||||
}
|
||||
|
||||
public get isSpectator(): boolean
|
||||
{
|
||||
return this._isSpectator;
|
||||
}
|
||||
|
||||
public set isSpectator(flag: boolean)
|
||||
{
|
||||
this._isSpectator = flag;
|
||||
}
|
||||
|
||||
public get moderationSettings(): RoomModerationSettings
|
||||
{
|
||||
return this._moderationSettings;
|
||||
}
|
||||
|
||||
public set moderationSettings(parser: RoomModerationSettings)
|
||||
{
|
||||
this._moderationSettings = parser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
import { IRoomHandlerListener, IRoomSession, IRoomSessionManager } from '@nitrots/api';
|
||||
import { GetCommunication } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionEvent } from '@nitrots/events';
|
||||
import { RoomSession } from './RoomSession';
|
||||
import { BaseHandler, GenericErrorHandler, PetPackageHandler, PollHandler, RoomChatHandler, RoomDataHandler, RoomDimmerPresetsHandler, RoomPermissionsHandler, RoomPresentHandler, RoomSessionHandler, RoomUsersHandler, WordQuizHandler } from './handler';
|
||||
|
||||
export class RoomSessionManager implements IRoomSessionManager, IRoomHandlerListener
|
||||
{
|
||||
private _handlers: BaseHandler[] = [];
|
||||
private _sessions: Map<string, IRoomSession> = new Map();
|
||||
private _pendingSession: IRoomSession = null;
|
||||
|
||||
private _sessionStarting: boolean = false;
|
||||
private _viewerSession: IRoomSession = null;
|
||||
|
||||
public async init(): Promise<void>
|
||||
{
|
||||
this.createHandlers();
|
||||
this.processPendingSession();
|
||||
}
|
||||
|
||||
private createHandlers(): void
|
||||
{
|
||||
const connection = GetCommunication().connection;
|
||||
|
||||
if(!connection) return;
|
||||
|
||||
this._handlers.push(
|
||||
new RoomChatHandler(connection, this),
|
||||
new RoomDataHandler(connection, this),
|
||||
new RoomDimmerPresetsHandler(connection, this),
|
||||
new RoomPermissionsHandler(connection, this),
|
||||
new RoomSessionHandler(connection, this),
|
||||
new RoomUsersHandler(connection, this),
|
||||
new RoomPresentHandler(connection, this),
|
||||
new GenericErrorHandler(connection, this),
|
||||
new WordQuizHandler(connection, this),
|
||||
new PollHandler(connection, this),
|
||||
new PetPackageHandler(connection, this),
|
||||
);
|
||||
}
|
||||
|
||||
private setHandlers(session: IRoomSession): void
|
||||
{
|
||||
if(!this._handlers || !this._handlers.length) return;
|
||||
|
||||
for(const handler of this._handlers)
|
||||
{
|
||||
if(!handler) continue;
|
||||
|
||||
handler.setRoomId(session.roomId);
|
||||
}
|
||||
}
|
||||
|
||||
private processPendingSession(): void
|
||||
{
|
||||
if(!this._pendingSession) return;
|
||||
|
||||
this.addSession(this._pendingSession);
|
||||
|
||||
this._pendingSession = null;
|
||||
}
|
||||
|
||||
public getSession(id: number): IRoomSession
|
||||
{
|
||||
const existing = this._sessions.get(this.getRoomId(id));
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
return existing;
|
||||
}
|
||||
|
||||
public createSession(roomId: number, password: string = null): boolean
|
||||
{
|
||||
const session = new RoomSession();
|
||||
|
||||
session.roomId = roomId;
|
||||
session.password = password;
|
||||
|
||||
return this.addSession(session);
|
||||
}
|
||||
|
||||
private addSession(roomSession: IRoomSession): boolean
|
||||
{
|
||||
this._sessionStarting = true;
|
||||
|
||||
if(this._sessions.get(this.getRoomId(roomSession.roomId))) this.removeSession(roomSession.roomId, false);
|
||||
|
||||
this._sessions.set(this.getRoomId(roomSession.roomId), roomSession);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionEvent(RoomSessionEvent.CREATED, roomSession));
|
||||
|
||||
this._viewerSession = roomSession;
|
||||
|
||||
this.startSession(this._viewerSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public startSession(session: IRoomSession): boolean
|
||||
{
|
||||
if(session.state === RoomSessionEvent.STARTED) return false;
|
||||
|
||||
this._sessionStarting = false;
|
||||
|
||||
if(!session.start())
|
||||
{
|
||||
this.removeSession(session.roomId);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionEvent(RoomSessionEvent.STARTED, session));
|
||||
|
||||
this.setHandlers(session);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public removeSession(id: number, openLandingView: boolean = true): void
|
||||
{
|
||||
const session = this.getSession(id);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
this._sessions.delete(this.getRoomId(id));
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionEvent(RoomSessionEvent.ENDED, session, openLandingView));
|
||||
}
|
||||
|
||||
public sessionUpdate(id: number, type: string): void
|
||||
{
|
||||
const session = this.getSession(id);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case RoomSessionHandler.RS_CONNECTED:
|
||||
return;
|
||||
case RoomSessionHandler.RS_READY:
|
||||
return;
|
||||
case RoomSessionHandler.RS_DISCONNECTED:
|
||||
this.removeSession(id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public sessionReinitialize(fromRoomId: number, toRoomId: number): void
|
||||
{
|
||||
const existing = this.getSession(fromRoomId);
|
||||
|
||||
if(!existing) return;
|
||||
|
||||
this._sessions.delete(this.getRoomId(fromRoomId));
|
||||
|
||||
existing.reset(toRoomId);
|
||||
|
||||
this._sessions.set(this.getRoomId(toRoomId), existing);
|
||||
|
||||
this.setHandlers(existing);
|
||||
}
|
||||
|
||||
private getRoomId(id: number): string
|
||||
{
|
||||
return 'hard_coded_room_id';
|
||||
}
|
||||
|
||||
public get viewerSession(): IRoomSession
|
||||
{
|
||||
return this._viewerSession;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
import { IRoomUserData } from '@nitrots/api';
|
||||
|
||||
export class RoomUserData implements IRoomUserData
|
||||
{
|
||||
private _roomIndex: number = -1;
|
||||
private _name: string = '';
|
||||
private _type: number = 0;
|
||||
private _sex: string = '';
|
||||
private _figure: string = '';
|
||||
private _custom: string = '';
|
||||
private _activityPoints: number;
|
||||
private _webID: number = 0;
|
||||
private _groupID: number = 0;
|
||||
private _groupStatus: number = 0;
|
||||
private _groupName: string = '';
|
||||
private _ownerId: number = 0;
|
||||
private _ownerName: string = '';
|
||||
private _petLevel: number = 0;
|
||||
private _rarityLevel: number = 0;
|
||||
private _hasSaddle: boolean;
|
||||
private _isRiding: boolean;
|
||||
private _canBreed: boolean;
|
||||
private _canHarvest: boolean;
|
||||
private _canRevive: boolean;
|
||||
private _hasBreedingPermission: boolean;
|
||||
private _botSkills: number[];
|
||||
private _isModerator: boolean;
|
||||
|
||||
constructor(k: number)
|
||||
{
|
||||
this._roomIndex = k;
|
||||
}
|
||||
|
||||
public get roomIndex(): number
|
||||
{
|
||||
return this._roomIndex;
|
||||
}
|
||||
|
||||
public get activityPoints(): number
|
||||
{
|
||||
return this._activityPoints;
|
||||
}
|
||||
|
||||
public set activityPoints(k: number)
|
||||
{
|
||||
this._activityPoints = k;
|
||||
}
|
||||
|
||||
public get name(): string
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public set name(k: string)
|
||||
{
|
||||
this._name = k;
|
||||
}
|
||||
|
||||
public get type(): number
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public set type(k: number)
|
||||
{
|
||||
this._type = k;
|
||||
}
|
||||
|
||||
public get sex(): string
|
||||
{
|
||||
return this._sex;
|
||||
}
|
||||
|
||||
public set sex(k: string)
|
||||
{
|
||||
this._sex = k;
|
||||
}
|
||||
|
||||
public get figure(): string
|
||||
{
|
||||
return this._figure;
|
||||
}
|
||||
|
||||
public set figure(k: string)
|
||||
{
|
||||
this._figure = k;
|
||||
}
|
||||
|
||||
public get custom(): string
|
||||
{
|
||||
return this._custom;
|
||||
}
|
||||
|
||||
public set custom(k: string)
|
||||
{
|
||||
this._custom = k;
|
||||
}
|
||||
|
||||
public get webID(): number
|
||||
{
|
||||
return this._webID;
|
||||
}
|
||||
|
||||
public set webID(k: number)
|
||||
{
|
||||
this._webID = k;
|
||||
}
|
||||
|
||||
public get groupId(): number
|
||||
{
|
||||
return this._groupID;
|
||||
}
|
||||
|
||||
public set groupId(groupId: number)
|
||||
{
|
||||
this._groupID = groupId;
|
||||
}
|
||||
|
||||
public get groupName(): string
|
||||
{
|
||||
return this._groupName;
|
||||
}
|
||||
|
||||
public set groupName(k: string)
|
||||
{
|
||||
this._groupName = k;
|
||||
}
|
||||
|
||||
public get groupStatus(): number
|
||||
{
|
||||
return this._groupStatus;
|
||||
}
|
||||
|
||||
public set groupStatus(k: number)
|
||||
{
|
||||
this._groupStatus = k;
|
||||
}
|
||||
|
||||
public get ownerId(): number
|
||||
{
|
||||
return this._ownerId;
|
||||
}
|
||||
|
||||
public set ownerId(k: number)
|
||||
{
|
||||
this._ownerId = k;
|
||||
}
|
||||
|
||||
public get ownerName(): string
|
||||
{
|
||||
return this._ownerName;
|
||||
}
|
||||
|
||||
public set ownerName(k: string)
|
||||
{
|
||||
this._ownerName = k;
|
||||
}
|
||||
|
||||
public get rarityLevel(): number
|
||||
{
|
||||
return this._rarityLevel;
|
||||
}
|
||||
|
||||
public set rarityLevel(k: number)
|
||||
{
|
||||
this._rarityLevel = k;
|
||||
}
|
||||
|
||||
public get hasSaddle(): boolean
|
||||
{
|
||||
return this._hasSaddle;
|
||||
}
|
||||
|
||||
public set hasSaddle(k: boolean)
|
||||
{
|
||||
this._hasSaddle = k;
|
||||
}
|
||||
|
||||
public get isRiding(): boolean
|
||||
{
|
||||
return this._isRiding;
|
||||
}
|
||||
|
||||
public set isRiding(k: boolean)
|
||||
{
|
||||
this._isRiding = k;
|
||||
}
|
||||
|
||||
public get canBreed(): boolean
|
||||
{
|
||||
return this._canBreed;
|
||||
}
|
||||
|
||||
public set canBreed(k: boolean)
|
||||
{
|
||||
this._canBreed = k;
|
||||
}
|
||||
|
||||
public get canHarvest(): boolean
|
||||
{
|
||||
return this._canHarvest;
|
||||
}
|
||||
|
||||
public set canHarvest(k: boolean)
|
||||
{
|
||||
this._canHarvest = k;
|
||||
}
|
||||
|
||||
public get canRevive(): boolean
|
||||
{
|
||||
return this._canRevive;
|
||||
}
|
||||
|
||||
public set canRevive(k: boolean)
|
||||
{
|
||||
this._canRevive = k;
|
||||
}
|
||||
|
||||
public get hasBreedingPermission(): boolean
|
||||
{
|
||||
return this._hasBreedingPermission;
|
||||
}
|
||||
|
||||
public set hasBreedingPermission(k: boolean)
|
||||
{
|
||||
this._hasBreedingPermission = k;
|
||||
}
|
||||
|
||||
public get petLevel(): number
|
||||
{
|
||||
return this._petLevel;
|
||||
}
|
||||
|
||||
public set petLevel(k: number)
|
||||
{
|
||||
this._petLevel = k;
|
||||
}
|
||||
|
||||
public get botSkills(): number[]
|
||||
{
|
||||
return this._botSkills;
|
||||
}
|
||||
|
||||
public set botSkills(k: number[])
|
||||
{
|
||||
this._botSkills = k;
|
||||
}
|
||||
|
||||
public get isModerator(): boolean
|
||||
{
|
||||
return this._isModerator;
|
||||
}
|
||||
|
||||
public set isModerator(k: boolean)
|
||||
{
|
||||
this._isModerator = k;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,532 @@
|
||||
import { ICommunicationManager, IFurnitureData, IGroupInformationManager, IMessageComposer, IProductData, ISessionDataManager, NoobnessLevelEnum, SecurityLevel } from '@nitrots/api';
|
||||
import { AccountSafetyLockStatusChangeMessageEvent, AccountSafetyLockStatusChangeParser, AvailabilityStatusMessageEvent, ChangeUserNameResultMessageEvent, EmailStatusResultEvent, FigureUpdateEvent, GetCommunication, GetUserTagsComposer, InClientLinkEvent, MysteryBoxKeysEvent, NoobnessLevelMessageEvent, PetRespectComposer, PetScratchFailedMessageEvent, RoomReadyMessageEvent, RoomUnitChatComposer, UserInfoEvent, UserNameChangeMessageEvent, UserPermissionsEvent, UserRespectComposer, UserTagsMessageEvent } from '@nitrots/communication';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { GetEventDispatcher, MysteryBoxKeysUpdateEvent, NitroSettingsEvent, SessionDataPreferencesEvent, UserNameUpdateEvent } from '@nitrots/events';
|
||||
import { CreateLinkEvent, HabboWebTools } from '@nitrots/utils';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { GroupInformationManager } from './GroupInformationManager';
|
||||
import { IgnoredUsersManager } from './IgnoredUsersManager';
|
||||
import { BadgeImageManager } from './badge/BadgeImageManager';
|
||||
import { FurnitureDataLoader } from './furniture/FurnitureDataLoader';
|
||||
import { ProductDataLoader } from './product/ProductDataLoader';
|
||||
|
||||
export class SessionDataManager implements ISessionDataManager
|
||||
{
|
||||
private _userId: number;
|
||||
private _name: string;
|
||||
private _figure: string;
|
||||
private _gender: string;
|
||||
private _realName: string;
|
||||
private _respectsReceived: number;
|
||||
private _respectsLeft: number;
|
||||
private _respectsPetLeft: number;
|
||||
private _canChangeName: boolean;
|
||||
private _safetyLocked: boolean;
|
||||
|
||||
private _ignoredUsersManager: IgnoredUsersManager = new IgnoredUsersManager();
|
||||
private _groupInformationManager: IGroupInformationManager = new GroupInformationManager();
|
||||
|
||||
private _clubLevel: number = 0;
|
||||
private _securityLevel: number = 0;
|
||||
private _isAmbassador: boolean = false;
|
||||
private _noobnessLevel: number = -1;
|
||||
private _isEmailVerified: boolean = false;
|
||||
|
||||
private _systemOpen: boolean = false;
|
||||
private _systemShutdown: boolean = false;
|
||||
private _isAuthenticHabbo: boolean = false;
|
||||
private _isRoomCameraFollowDisabled: boolean = false;
|
||||
private _uiFlags: number = 0;
|
||||
|
||||
private _floorItems: Map<number, IFurnitureData> = new Map();
|
||||
private _wallItems: Map<number, IFurnitureData> = new Map();
|
||||
private _products: Map<string, IProductData> = new Map();
|
||||
private _furnitureData: FurnitureDataLoader = new FurnitureDataLoader(this._floorItems, this._wallItems);
|
||||
private _productData: ProductDataLoader = new ProductDataLoader(this._products);
|
||||
private _tags: string[] = [];
|
||||
|
||||
private _badgeImageManager: BadgeImageManager = new BadgeImageManager();
|
||||
|
||||
constructor()
|
||||
{
|
||||
this.resetUserInfo();
|
||||
|
||||
this.onNitroSettingsEvent = this.onNitroSettingsEvent.bind(this);
|
||||
}
|
||||
|
||||
public async init(): Promise<void>
|
||||
{
|
||||
await Promise.all([
|
||||
this._furnitureData.init(),
|
||||
this._productData.init(),
|
||||
this._badgeImageManager.init(),
|
||||
this._ignoredUsersManager.init(),
|
||||
this._groupInformationManager.init()
|
||||
]);
|
||||
|
||||
GetCommunication().registerMessageEvent(new FigureUpdateEvent((event: FigureUpdateEvent) =>
|
||||
{
|
||||
this._figure = event.getParser().figure;
|
||||
this._gender = event.getParser().gender;
|
||||
|
||||
HabboWebTools.updateFigure(this._figure);
|
||||
}));
|
||||
|
||||
GetCommunication().registerMessageEvent(new UserInfoEvent(this.onUserInfoEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new UserPermissionsEvent(this.onUserPermissionsEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new AvailabilityStatusMessageEvent(this.onAvailabilityStatusMessageEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new PetScratchFailedMessageEvent(this.onPetRespectFailed.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new ChangeUserNameResultMessageEvent(this.onChangeNameUpdateEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new UserNameChangeMessageEvent(this.onUserNameChangeMessageEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new UserTagsMessageEvent(this.onUserTags.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new RoomReadyMessageEvent(this.onRoomModelNameEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new InClientLinkEvent(this.onInClientLinkEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new MysteryBoxKeysEvent(this.onMysteryBoxKeysEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new NoobnessLevelMessageEvent(this.onNoobnessLevelMessageEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new AccountSafetyLockStatusChangeMessageEvent(this.onAccountSafetyLockStatusChangeMessageEvent.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new EmailStatusResultEvent(this.onEmailStatus.bind(this)));
|
||||
|
||||
GetEventDispatcher().addEventListener(NitroSettingsEvent.SETTINGS_UPDATED, this.onNitroSettingsEvent);
|
||||
}
|
||||
|
||||
private resetUserInfo(): void
|
||||
{
|
||||
this._userId = 0;
|
||||
this._name = null;
|
||||
this._figure = null;
|
||||
this._gender = null;
|
||||
this._realName = null;
|
||||
this._canChangeName = false;
|
||||
this._safetyLocked = false;
|
||||
}
|
||||
|
||||
public getAllFurnitureData(): IFurnitureData[]
|
||||
{
|
||||
return [ ...Array.from(this._floorItems.values()), ...Array.from(this._wallItems.values()) ];
|
||||
}
|
||||
|
||||
private onUserInfoEvent(event: UserInfoEvent): void
|
||||
{
|
||||
if(!event || !event.connection) return;
|
||||
|
||||
this.resetUserInfo();
|
||||
|
||||
const userInfo = event.getParser().userInfo;
|
||||
|
||||
if(!userInfo) return;
|
||||
|
||||
this._userId = userInfo.userId;
|
||||
this._name = userInfo.username;
|
||||
this._figure = userInfo.figure;
|
||||
this._gender = userInfo.gender;
|
||||
this._realName = userInfo.realName;
|
||||
this._respectsReceived = userInfo.respectsReceived;
|
||||
this._respectsLeft = userInfo.respectsRemaining;
|
||||
this._respectsPetLeft = userInfo.respectsPetRemaining;
|
||||
this._canChangeName = userInfo.canChangeName;
|
||||
this._safetyLocked = userInfo.safetyLocked;
|
||||
|
||||
this._ignoredUsersManager.requestIgnoredUsers(userInfo.username);
|
||||
}
|
||||
|
||||
private onUserPermissionsEvent(event: UserPermissionsEvent): void
|
||||
{
|
||||
if(!event || !event.connection) return;
|
||||
|
||||
this._clubLevel = event.getParser().clubLevel;
|
||||
this._securityLevel = event.getParser().securityLevel;
|
||||
this._isAmbassador = event.getParser().isAmbassador;
|
||||
}
|
||||
|
||||
private onAvailabilityStatusMessageEvent(event: AvailabilityStatusMessageEvent): void
|
||||
{
|
||||
if(!event || !event.connection) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
this._systemOpen = parser.isOpen;
|
||||
this._systemShutdown = parser.onShutdown;
|
||||
this._isAuthenticHabbo = parser.isAuthenticUser;
|
||||
}
|
||||
|
||||
private onPetRespectFailed(event: PetScratchFailedMessageEvent): void
|
||||
{
|
||||
if(!event || !event.connection) return;
|
||||
|
||||
this._respectsPetLeft++;
|
||||
}
|
||||
|
||||
private onChangeNameUpdateEvent(event: ChangeUserNameResultMessageEvent): void
|
||||
{
|
||||
if(!event || !event.connection) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
if(parser.resultCode !== ChangeUserNameResultMessageEvent.NAME_OK) return;
|
||||
|
||||
this._canChangeName = false;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new UserNameUpdateEvent(parser.name));
|
||||
}
|
||||
|
||||
private onUserNameChangeMessageEvent(event: UserNameChangeMessageEvent): void
|
||||
{
|
||||
if(!event || !event.connection) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
if(parser.webId !== this.userId) return;
|
||||
|
||||
this._name = parser.newName;
|
||||
this._canChangeName = false;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new UserNameUpdateEvent(this._name));
|
||||
}
|
||||
|
||||
private onUserTags(event: UserTagsMessageEvent): void
|
||||
{
|
||||
if(!event || !event.connection) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
this._tags = parser.tags;
|
||||
}
|
||||
|
||||
private onRoomModelNameEvent(event: RoomReadyMessageEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
HabboWebTools.roomVisited(parser.roomId);
|
||||
}
|
||||
|
||||
private onInClientLinkEvent(event: InClientLinkEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
CreateLinkEvent(parser.link);
|
||||
}
|
||||
|
||||
private onMysteryBoxKeysEvent(event: MysteryBoxKeysEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new MysteryBoxKeysUpdateEvent(parser.boxColor, parser.keyColor));
|
||||
}
|
||||
|
||||
private onNoobnessLevelMessageEvent(event: NoobnessLevelMessageEvent): void
|
||||
{
|
||||
this._noobnessLevel = event.getParser().noobnessLevel;
|
||||
|
||||
if(this._noobnessLevel !== NoobnessLevelEnum.OLD_IDENTITY) GetConfiguration().setValue<number>('new.identity', 1);
|
||||
}
|
||||
|
||||
private onAccountSafetyLockStatusChangeMessageEvent(event: AccountSafetyLockStatusChangeMessageEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
this._safetyLocked = (parser.status === AccountSafetyLockStatusChangeParser.SAFETY_LOCK_STATUS_LOCKED);
|
||||
}
|
||||
|
||||
private onEmailStatus(event: EmailStatusResultEvent): void
|
||||
{
|
||||
this._isEmailVerified = event?.getParser()?.isVerified ?? false;
|
||||
}
|
||||
|
||||
private onNitroSettingsEvent(event: NitroSettingsEvent): void
|
||||
{
|
||||
this._isRoomCameraFollowDisabled = event.cameraFollow;
|
||||
this._uiFlags = event.flags;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new SessionDataPreferencesEvent(this._uiFlags));
|
||||
}
|
||||
|
||||
public getFloorItemData(id: number): IFurnitureData
|
||||
{
|
||||
const existing = this._floorItems.get(id);
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
return existing;
|
||||
}
|
||||
|
||||
public getFloorItemDataByName(name: string): IFurnitureData
|
||||
{
|
||||
if(!name || !this._floorItems || !this._floorItems.size) return null;
|
||||
|
||||
for(const item of this._floorItems.values())
|
||||
{
|
||||
if(!item || (item.className !== name)) continue;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getWallItemData(id: number): IFurnitureData
|
||||
{
|
||||
const existing = this._wallItems.get(id);
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
return existing;
|
||||
}
|
||||
|
||||
public getWallItemDataByName(name: string): IFurnitureData
|
||||
{
|
||||
if(!name || !this._wallItems || !this._wallItems.size) return null;
|
||||
|
||||
for(const item of this._wallItems.values())
|
||||
{
|
||||
if(!item || (item.className !== name)) continue;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getProductData(type: string): IProductData
|
||||
{
|
||||
return this._products.get(type);
|
||||
}
|
||||
|
||||
public getBadgeUrl(name: string): string
|
||||
{
|
||||
return this._badgeImageManager.getBadgeUrl(name);
|
||||
}
|
||||
|
||||
public getGroupBadgeUrl(name: string): string
|
||||
{
|
||||
return this._badgeImageManager.getBadgeUrl(name, BadgeImageManager.GROUP_BADGE);
|
||||
}
|
||||
|
||||
public getBadgeImage(name: string): Texture
|
||||
{
|
||||
return this._badgeImageManager.getBadgeImage(name);
|
||||
}
|
||||
|
||||
public getGroupBadgeImage(name: string): Texture
|
||||
{
|
||||
return this._badgeImageManager.getBadgeImage(name, BadgeImageManager.GROUP_BADGE);
|
||||
}
|
||||
|
||||
public getUserTags(roomUnitId: number): string[]
|
||||
{
|
||||
if(roomUnitId < 0) return;
|
||||
|
||||
this.send(new GetUserTagsComposer(roomUnitId));
|
||||
}
|
||||
|
||||
public loadBadgeImage(name: string): string
|
||||
{
|
||||
return this._badgeImageManager.loadBadgeImage(name);
|
||||
}
|
||||
|
||||
public loadGroupBadgeImage(name: string): string
|
||||
{
|
||||
return this._badgeImageManager.loadBadgeImage(name, BadgeImageManager.GROUP_BADGE);
|
||||
}
|
||||
|
||||
public hasSecurity(level: number): boolean
|
||||
{
|
||||
return (this._securityLevel >= level);
|
||||
}
|
||||
|
||||
public giveRespect(userId: number): void
|
||||
{
|
||||
if((userId < 0) || (this._respectsLeft <= 0)) return;
|
||||
|
||||
this.send(new UserRespectComposer(userId));
|
||||
|
||||
this._respectsLeft--;
|
||||
}
|
||||
|
||||
public givePetRespect(petId: number): void
|
||||
{
|
||||
if((petId < 0) || (this._respectsPetLeft <= 0)) return;
|
||||
|
||||
this.send(new PetRespectComposer(petId));
|
||||
|
||||
this._respectsPetLeft--;
|
||||
}
|
||||
|
||||
public sendSpecialCommandMessage(text: string, styleId: number = 0): void
|
||||
{
|
||||
this.send(new RoomUnitChatComposer(text));
|
||||
}
|
||||
|
||||
public ignoreUser(name: string): void
|
||||
{
|
||||
this._ignoredUsersManager.ignoreUser(name);
|
||||
}
|
||||
|
||||
public unignoreUser(name: string): void
|
||||
{
|
||||
this._ignoredUsersManager.unignoreUser(name);
|
||||
}
|
||||
|
||||
public isUserIgnored(name: string): boolean
|
||||
{
|
||||
return this._ignoredUsersManager.isIgnored(name);
|
||||
}
|
||||
|
||||
public getGroupBadge(groupId: number): string
|
||||
{
|
||||
return this._groupInformationManager.getGroupBadge(groupId);
|
||||
}
|
||||
|
||||
public send(composer: IMessageComposer<unknown[]>): void
|
||||
{
|
||||
GetCommunication().connection.send(composer);
|
||||
}
|
||||
|
||||
public get communication(): ICommunicationManager
|
||||
{
|
||||
return GetCommunication();
|
||||
}
|
||||
|
||||
public get userId(): number
|
||||
{
|
||||
return this._userId;
|
||||
}
|
||||
|
||||
public get userName(): string
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get figure(): string
|
||||
{
|
||||
return this._figure;
|
||||
}
|
||||
|
||||
public get gender(): string
|
||||
{
|
||||
return this._gender;
|
||||
}
|
||||
|
||||
public get realName(): string
|
||||
{
|
||||
return this._realName;
|
||||
}
|
||||
|
||||
public get ignoredUsersManager(): IgnoredUsersManager
|
||||
{
|
||||
return this._ignoredUsersManager;
|
||||
}
|
||||
|
||||
public get groupInformationManager(): IGroupInformationManager
|
||||
{
|
||||
return this._groupInformationManager;
|
||||
}
|
||||
|
||||
public get respectsReceived(): number
|
||||
{
|
||||
return this._respectsReceived;
|
||||
}
|
||||
|
||||
public get respectsLeft(): number
|
||||
{
|
||||
return this._respectsLeft;
|
||||
}
|
||||
|
||||
public get respectsPetLeft(): number
|
||||
{
|
||||
return this._respectsPetLeft;
|
||||
}
|
||||
|
||||
public get canChangeName(): boolean
|
||||
{
|
||||
return this._canChangeName;
|
||||
}
|
||||
|
||||
public get clubLevel(): number
|
||||
{
|
||||
return this._clubLevel;
|
||||
}
|
||||
|
||||
public get securityLevel(): number
|
||||
{
|
||||
return this._securityLevel;
|
||||
}
|
||||
|
||||
public get isAmbassador(): boolean
|
||||
{
|
||||
return this._isAmbassador;
|
||||
}
|
||||
|
||||
public get isEmailVerified(): boolean
|
||||
{
|
||||
return this._isEmailVerified;
|
||||
}
|
||||
|
||||
public get isNoob(): boolean
|
||||
{
|
||||
return (this._noobnessLevel !== NoobnessLevelEnum.OLD_IDENTITY);
|
||||
}
|
||||
|
||||
public get isRealNoob(): boolean
|
||||
{
|
||||
return (this._noobnessLevel === NoobnessLevelEnum.REAL_NOOB);
|
||||
}
|
||||
|
||||
public get isSystemOpen(): boolean
|
||||
{
|
||||
return this._systemOpen;
|
||||
}
|
||||
|
||||
public get isSystemShutdown(): boolean
|
||||
{
|
||||
return this._systemShutdown;
|
||||
}
|
||||
|
||||
public get isAuthenticHabbo(): boolean
|
||||
{
|
||||
return this._isAuthenticHabbo;
|
||||
}
|
||||
|
||||
public get isModerator(): boolean
|
||||
{
|
||||
return (this._securityLevel >= SecurityLevel.MODERATOR);
|
||||
}
|
||||
|
||||
public get isCameraFollowDisabled(): boolean
|
||||
{
|
||||
return this._isRoomCameraFollowDisabled;
|
||||
}
|
||||
|
||||
public get uiFlags(): number
|
||||
{
|
||||
return this._uiFlags;
|
||||
}
|
||||
|
||||
public get tags(): string[]
|
||||
{
|
||||
return this._tags;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
import { IRoomUserData, IUserDataManager } from '@nitrots/api';
|
||||
import { GetCommunication, RequestPetInfoComposer, UserCurrentBadgesComposer } from '@nitrots/communication';
|
||||
|
||||
export class UserDataManager implements IUserDataManager
|
||||
{
|
||||
private static TYPE_USER: number = 1;
|
||||
private static TYPE_PET: number = 2;
|
||||
private static TYPE_BOT: number = 3;
|
||||
private static TYPE_RENTABLE_BOT: number = 4;
|
||||
|
||||
private _userDataByType: Map<number, Map<number, IRoomUserData>> = new Map();
|
||||
private _userDataByRoomIndex: Map<number, IRoomUserData> = new Map();
|
||||
private _userBadges: Map<number, string[]> = new Map();
|
||||
|
||||
public getUserData(webID: number): IRoomUserData
|
||||
{
|
||||
return this.getDataByType(webID, UserDataManager.TYPE_USER);
|
||||
}
|
||||
|
||||
public getPetData(webID: number): IRoomUserData
|
||||
{
|
||||
return this.getDataByType(webID, UserDataManager.TYPE_PET);
|
||||
}
|
||||
|
||||
public getBotData(webID: number): IRoomUserData
|
||||
{
|
||||
return this.getDataByType(webID, UserDataManager.TYPE_BOT);
|
||||
}
|
||||
|
||||
public getRentableBotData(webID: number): IRoomUserData
|
||||
{
|
||||
return this.getDataByType(webID, UserDataManager.TYPE_RENTABLE_BOT);
|
||||
}
|
||||
|
||||
public getDataByType(webID: number, type: number): IRoomUserData
|
||||
{
|
||||
const existing = this._userDataByType.get(type);
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
const userData = existing.get(webID);
|
||||
|
||||
if(!userData) return null;
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
public getUserDataByIndex(roomIndex: number): IRoomUserData
|
||||
{
|
||||
const existing = this._userDataByRoomIndex.get(roomIndex);
|
||||
|
||||
if(!existing) return null;
|
||||
|
||||
return existing;
|
||||
}
|
||||
|
||||
public getUserDataByName(name: string): IRoomUserData
|
||||
{
|
||||
for(const userData of this._userDataByRoomIndex.values())
|
||||
{
|
||||
if(!userData || (userData.name !== name)) continue;
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public updateUserData(data: IRoomUserData): void
|
||||
{
|
||||
if(!data) return;
|
||||
|
||||
this.removeUserData(data.roomIndex);
|
||||
|
||||
let existingType = this._userDataByType.get(data.type);
|
||||
|
||||
if(!existingType)
|
||||
{
|
||||
existingType = new Map();
|
||||
|
||||
this._userDataByType.set(data.type, existingType);
|
||||
}
|
||||
|
||||
existingType.set(data.webID, data);
|
||||
|
||||
this._userDataByRoomIndex.set(data.roomIndex, data);
|
||||
}
|
||||
|
||||
public removeUserData(roomIndex: number): void
|
||||
{
|
||||
const existing = this.getUserDataByIndex(roomIndex);
|
||||
|
||||
if(!existing) return;
|
||||
|
||||
this._userDataByRoomIndex.delete(roomIndex);
|
||||
|
||||
const existingType = this._userDataByType.get(existing.type);
|
||||
|
||||
if(existingType) existingType.delete(existing.webID);
|
||||
}
|
||||
|
||||
public getUserBadges(userId: number): string[]
|
||||
{
|
||||
GetCommunication().connection.send(new UserCurrentBadgesComposer(userId));
|
||||
|
||||
const badges = this._userBadges.get(userId);
|
||||
|
||||
if(!badges) return [];
|
||||
|
||||
return badges;
|
||||
}
|
||||
|
||||
public setUserBadges(userId: number, badges: string[]): void
|
||||
{
|
||||
this._userBadges.set(userId, badges);
|
||||
}
|
||||
|
||||
public updateFigure(roomIndex: number, figure: string, sex: string, hasSaddle: boolean, isRiding: boolean): void
|
||||
{
|
||||
const userData = this.getUserDataByIndex(roomIndex);
|
||||
|
||||
if(!userData) return;
|
||||
|
||||
userData.figure = figure;
|
||||
userData.sex = sex;
|
||||
userData.hasSaddle = hasSaddle;
|
||||
userData.isRiding = isRiding;
|
||||
}
|
||||
|
||||
public updateName(roomIndex: number, name: string): void
|
||||
{
|
||||
const userData = this.getUserDataByIndex(roomIndex);
|
||||
|
||||
if(!userData) return;
|
||||
|
||||
userData.name = name;
|
||||
}
|
||||
|
||||
public updateMotto(roomIndex: number, custom: string): void
|
||||
{
|
||||
const userData = this.getUserDataByIndex(roomIndex);
|
||||
|
||||
if(!userData) return;
|
||||
|
||||
userData.custom = custom;
|
||||
}
|
||||
|
||||
public updateAchievementScore(roomIndex: number, score: number): void
|
||||
{
|
||||
const userData = this.getUserDataByIndex(roomIndex);
|
||||
|
||||
if(!userData) return;
|
||||
|
||||
userData.activityPoints = score;
|
||||
}
|
||||
|
||||
public updatePetLevel(roomIndex: number, level: number): void
|
||||
{
|
||||
const userData = this.getUserDataByIndex(roomIndex);
|
||||
|
||||
if(userData) userData.petLevel = level;
|
||||
}
|
||||
|
||||
public updatePetBreedingStatus(roomIndex: number, canBreed: boolean, canHarvest: boolean, canRevive: boolean, hasBreedingPermission: boolean): void
|
||||
{
|
||||
const userData = this.getUserDataByIndex(roomIndex);
|
||||
|
||||
if(!userData) return;
|
||||
|
||||
userData.canBreed = canBreed;
|
||||
userData.canHarvest = canHarvest;
|
||||
userData.canRevive = canRevive;
|
||||
userData.hasBreedingPermission = hasBreedingPermission;
|
||||
}
|
||||
|
||||
public requestPetInfo(id: number): void
|
||||
{
|
||||
const petData = this.getPetData(id);
|
||||
|
||||
if(!petData) return;
|
||||
|
||||
GetCommunication().connection.send(new RequestPetInfoComposer(id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { GetCommunication, GroupBadgePartsEvent } from '@nitrots/communication';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { BadgeImageReadyEvent, GetEventDispatcher } from '@nitrots/events';
|
||||
import { TextureUtils } from '@nitrots/utils';
|
||||
import { Container, Sprite, Texture } from 'pixi.js';
|
||||
import { BadgeInfo } from './BadgeInfo';
|
||||
import { GroupBadge } from './GroupBadge';
|
||||
import { GroupBadgePart } from './GroupBadgePart';
|
||||
|
||||
export class BadgeImageManager
|
||||
{
|
||||
public static GROUP_BADGE: string = 'group_badge';
|
||||
public static NORMAL_BADGE: string = 'normal_badge';
|
||||
|
||||
private _groupBases: Map<number, string[]> = new Map();
|
||||
private _groupSymbols: Map<number, string[]> = new Map();
|
||||
private _groupPartColors: Map<number, string> = new Map();
|
||||
private _requestedBadges: Map<string, boolean> = new Map();
|
||||
private _groupBadgesQueue: Map<string, boolean> = new Map();
|
||||
private _readyToGenerateGroupBadges: boolean = false;
|
||||
|
||||
public init(): void
|
||||
{
|
||||
GetCommunication().registerMessageEvent(new GroupBadgePartsEvent(this.onGroupBadgePartsEvent.bind(this)));
|
||||
}
|
||||
|
||||
public getBadgeImage(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE, load: boolean = true): Texture
|
||||
{
|
||||
return this.getBadgeTexture(badgeName, type);
|
||||
}
|
||||
|
||||
public getBadgeInfo(k: string): BadgeInfo
|
||||
{
|
||||
const badge = this.getBadgeTexture(k);
|
||||
|
||||
return (badge) ? new BadgeInfo(badge, false) : new BadgeInfo(this.getBadgePlaceholder(), true);
|
||||
}
|
||||
|
||||
public loadBadgeImage(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE): string
|
||||
{
|
||||
if(GetAssetManager().getTexture(this.getBadgeUrl(badgeName, type))) return badgeName;
|
||||
|
||||
this.getBadgeTexture(badgeName, type);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private getBadgeTexture(badgeName: string, type: string = BadgeImageManager.NORMAL_BADGE): Texture
|
||||
{
|
||||
const url = this.getBadgeUrl(badgeName, type);
|
||||
|
||||
if(!url || !url.length) return null;
|
||||
|
||||
const texture = GetAssetManager().getTexture(url);
|
||||
|
||||
if(texture) return texture;
|
||||
|
||||
if(type === BadgeImageManager.NORMAL_BADGE)
|
||||
{
|
||||
const loadBadge = async () =>
|
||||
{
|
||||
await GetAssetManager().downloadAsset(url);
|
||||
|
||||
const texture = GetAssetManager().getTexture(url);
|
||||
|
||||
if(texture) GetEventDispatcher().dispatchEvent(new BadgeImageReadyEvent(badgeName, texture));
|
||||
};
|
||||
|
||||
loadBadge();
|
||||
}
|
||||
|
||||
else if(type === BadgeImageManager.GROUP_BADGE)
|
||||
{
|
||||
if(this._groupBadgesQueue.get(badgeName)) return;
|
||||
|
||||
this._groupBadgesQueue.set(badgeName, true);
|
||||
|
||||
if(this._readyToGenerateGroupBadges) this.loadGroupBadge(badgeName);
|
||||
}
|
||||
|
||||
return this.getBadgePlaceholder();
|
||||
}
|
||||
|
||||
private getBadgePlaceholder(): Texture
|
||||
{
|
||||
return GetAssetManager().getTexture(GetConfiguration().getValue<string>('images.url') + '/loading_icon.png');
|
||||
}
|
||||
|
||||
public getBadgeUrl(badge: string, type: string = BadgeImageManager.NORMAL_BADGE): string
|
||||
{
|
||||
let url = null;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case BadgeImageManager.NORMAL_BADGE:
|
||||
url = (GetConfiguration().getValue<string>('badge.asset.url')).replace('%badgename%', badge);
|
||||
break;
|
||||
case BadgeImageManager.GROUP_BADGE:
|
||||
url = badge;
|
||||
break;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
private loadGroupBadge(badgeCode: string): void
|
||||
{
|
||||
const groupBadge = new GroupBadge(badgeCode);
|
||||
const partMatches = [...badgeCode.matchAll(/[b|s][0-9]{4,6}/g)];
|
||||
|
||||
for(const partMatch of partMatches)
|
||||
{
|
||||
const partCode = partMatch[0];
|
||||
const shortMethod = (partCode.length === 6);
|
||||
const partType = partCode[0];
|
||||
const partId = parseInt(partCode.slice(1, shortMethod ? 3 : 4));
|
||||
const partColor = parseInt(partCode.slice(shortMethod ? 3 : 4, shortMethod ? 5 : 6));
|
||||
const partPosition = partCode.length < 6 ? 0 : parseInt(partCode.slice(shortMethod ? 5 : 6, shortMethod ? 6 : 7)); // sometimes position is ommitted
|
||||
const part = new GroupBadgePart(partType, partId, partColor, partPosition);
|
||||
|
||||
groupBadge.parts.push(part);
|
||||
}
|
||||
|
||||
this.renderGroupBadge(groupBadge);
|
||||
}
|
||||
|
||||
private renderGroupBadge(groupBadge: GroupBadge): void
|
||||
{
|
||||
const container = new Container();
|
||||
const tempSprite = new Sprite(Texture.EMPTY);
|
||||
|
||||
tempSprite.width = GroupBadgePart.IMAGE_WIDTH;
|
||||
tempSprite.height = GroupBadgePart.IMAGE_HEIGHT;
|
||||
|
||||
container.addChild(tempSprite);
|
||||
|
||||
for(const part of groupBadge.parts)
|
||||
{
|
||||
let isFirst = true;
|
||||
|
||||
const partNames = ((part.type === 'b') ? this._groupBases.get(part.key) : this._groupSymbols.get(part.key));
|
||||
|
||||
if(partNames)
|
||||
{
|
||||
for(const partName of partNames)
|
||||
{
|
||||
if(!partName || !partName.length) continue;
|
||||
|
||||
const texture = GetAssetManager().getTexture(`badgepart_${partName}`);
|
||||
|
||||
if(!texture) continue;
|
||||
|
||||
const { x, y } = part.calculatePosition(texture);
|
||||
const sprite = new Sprite(texture);
|
||||
|
||||
sprite.position.set(x, y);
|
||||
|
||||
if(isFirst) sprite.tint = parseInt(this._groupPartColors.get(part.color), 16);
|
||||
|
||||
isFirst = false;
|
||||
|
||||
container.addChild(sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._requestedBadges.delete(groupBadge.code);
|
||||
this._groupBadgesQueue.delete(groupBadge.code);
|
||||
|
||||
const texture = TextureUtils.generateTexture(container);
|
||||
GetAssetManager().setTexture(groupBadge.code, texture);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new BadgeImageReadyEvent(groupBadge.code, texture));
|
||||
}
|
||||
|
||||
private onGroupBadgePartsEvent(event: GroupBadgePartsEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const data = event.getParser();
|
||||
|
||||
if(!data) return;
|
||||
|
||||
data.bases.forEach((names, id) => this._groupBases.set(id, names.map(val => val.replace('.png', '').replace('.gif', ''))));
|
||||
|
||||
data.symbols.forEach((names, id) => this._groupSymbols.set(id, names.map(val => val.replace('.png', '').replace('.gif', ''))));
|
||||
|
||||
this._groupPartColors = data.partColors;
|
||||
this._readyToGenerateGroupBadges = true;
|
||||
|
||||
for(const badgeCode of this._groupBadgesQueue.keys()) this.loadGroupBadge(badgeCode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Texture } from 'pixi.js';
|
||||
|
||||
export class BadgeInfo
|
||||
{
|
||||
private _image: Texture;
|
||||
private _placeHolder: boolean;
|
||||
|
||||
constructor(image: Texture, placeHolder: boolean)
|
||||
{
|
||||
this._image = image;
|
||||
this._placeHolder = placeHolder;
|
||||
}
|
||||
|
||||
public get image(): Texture
|
||||
{
|
||||
return this._image;
|
||||
}
|
||||
|
||||
public get placeHolder(): boolean
|
||||
{
|
||||
return this._placeHolder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { GroupBadgePart } from './GroupBadgePart';
|
||||
|
||||
export class GroupBadge
|
||||
{
|
||||
private _code: string;
|
||||
private _parts: GroupBadgePart[];
|
||||
|
||||
constructor(code: string)
|
||||
{
|
||||
this._code = code;
|
||||
this._parts = [];
|
||||
}
|
||||
|
||||
public get code(): string
|
||||
{
|
||||
return this._code;
|
||||
}
|
||||
|
||||
public get parts(): GroupBadgePart[]
|
||||
{
|
||||
return this._parts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Point, Texture } from 'pixi.js';
|
||||
|
||||
export class GroupBadgePart
|
||||
{
|
||||
public static BASE: string = 'b';
|
||||
public static SYMBOL: string = 's';
|
||||
public static SYMBOL_ALT: string = 't';
|
||||
public static BASE_PART: number = 0;
|
||||
public static LAYER_PART: number = 1;
|
||||
public static IMAGE_WIDTH: number = 39;
|
||||
public static IMAGE_HEIGHT: number = 39;
|
||||
public static CELL_WIDTH: number = 13;
|
||||
public static CELL_HEIGHT: number = 13;
|
||||
|
||||
public type: string;
|
||||
public key: number;
|
||||
public color: number;
|
||||
public position: number;
|
||||
|
||||
constructor(type: string, key: number = 0, color: number = 0, position: number = 0)
|
||||
{
|
||||
this.type = type;
|
||||
this.key = key;
|
||||
this.color = color;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public get code(): string
|
||||
{
|
||||
if(this.key === 0) return null;
|
||||
|
||||
return GroupBadgePart.getCode(this.type, this.key, this.color, this.position);
|
||||
}
|
||||
|
||||
public static getCode(type: string, key: number, color: number, position: number): string
|
||||
{
|
||||
return (type === GroupBadgePart.BASE ? type : key >= 100 ? GroupBadgePart.SYMBOL_ALT : GroupBadgePart.SYMBOL) + (key < 10 ? '0' : '') + (type === GroupBadgePart.BASE ? key : key >= 100 ? key - 100 : key) + (color < 10 ? '0' : '') + color + position;
|
||||
}
|
||||
|
||||
public calculatePosition(asset: Texture): Point
|
||||
{
|
||||
const gridPos = this.calculateGridPos(this.position);
|
||||
|
||||
let x: number = (((GroupBadgePart.CELL_WIDTH * gridPos.x) + (GroupBadgePart.CELL_WIDTH / 2)) - (asset.width / 2));
|
||||
let y: number = (((GroupBadgePart.CELL_HEIGHT * gridPos.y) + (GroupBadgePart.CELL_HEIGHT / 2)) - (asset.height / 2));
|
||||
|
||||
if(x < 0) x = 0;
|
||||
|
||||
if((x + asset.width) > GroupBadgePart.IMAGE_WIDTH) x = (GroupBadgePart.IMAGE_WIDTH - asset.width);
|
||||
|
||||
if(y < 0) y = 0;
|
||||
|
||||
if((y + asset.height) > GroupBadgePart.IMAGE_HEIGHT) y = (GroupBadgePart.IMAGE_HEIGHT - asset.height);
|
||||
|
||||
return new Point(Math.floor(x), Math.floor(y));
|
||||
}
|
||||
|
||||
private calculateGridPos(gridVal: number): Point
|
||||
{
|
||||
const point = new Point();
|
||||
point.x = Math.floor((gridVal % 3));
|
||||
point.y = Math.floor((gridVal / 3));
|
||||
|
||||
return point;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './BadgeImageManager';
|
||||
export * from './BadgeInfo';
|
||||
export * from './GroupBadge';
|
||||
export * from './GroupBadgePart';
|
||||
@@ -0,0 +1,222 @@
|
||||
import { IFurnitureData } from '@nitrots/api';
|
||||
|
||||
export class FurnitureData implements IFurnitureData
|
||||
{
|
||||
private _type: string;
|
||||
private _id: number;
|
||||
private _className: string;
|
||||
private _fullName: string;
|
||||
private _category: string;
|
||||
private _hasIndexedColor: boolean;
|
||||
private _colourIndex: number;
|
||||
private _revision: number;
|
||||
private _tileSizeX: number;
|
||||
private _tileSizeY: number;
|
||||
private _tileSizeZ: number;
|
||||
private _colors: number[];
|
||||
private _localizedName: string;
|
||||
private _description: string;
|
||||
private _adUrl: string;
|
||||
private _purchaseOfferId: number;
|
||||
private _rentOfferId: number;
|
||||
private _customParams: string;
|
||||
private _specialType: number;
|
||||
private _purchaseCouldBeUsedForBuyout: boolean;
|
||||
private _rentCouldBeUsedForBuyout: boolean;
|
||||
private _availableForBuildersClub: boolean;
|
||||
private _canStandOn: boolean;
|
||||
private _canSitOn: boolean;
|
||||
private _canLayOn: boolean;
|
||||
private _excludedFromDynamic: boolean;
|
||||
private _furniLine: string;
|
||||
private _environment: string;
|
||||
private _rare: boolean;
|
||||
|
||||
constructor(type: string, id: number, fullName: string, className: string, category: string, localizedName: string, description: string, revision: number, tileSizeX: number, tileSizeY: number, tileSizeZ: number, colors: number[], hadIndexedColor: boolean, colorIndex: number, adUrl: string, purchaseOfferId: number, purchaseCouldBeUsedForBuyout: boolean, rentOfferId: number, rentCouldBeUsedForBuyout: boolean, availableForBuildersClub: boolean, customParams: string, specialType: number, canStandOn: boolean, canSitOn: boolean, canLayOn: boolean, excludedfromDynamic: boolean, furniLine: string, environment: string, rare: boolean)
|
||||
{
|
||||
this._type = type;
|
||||
this._id = id;
|
||||
this._fullName = fullName;
|
||||
this._className = className;
|
||||
this._category = category;
|
||||
this._revision = revision;
|
||||
this._tileSizeX = tileSizeX;
|
||||
this._tileSizeY = tileSizeY;
|
||||
this._tileSizeZ = tileSizeZ;
|
||||
this._colors = colors;
|
||||
this._hasIndexedColor = hadIndexedColor;
|
||||
this._colourIndex = colorIndex;
|
||||
this._localizedName = localizedName;
|
||||
this._description = description;
|
||||
this._adUrl = adUrl;
|
||||
this._purchaseOfferId = purchaseOfferId;
|
||||
this._purchaseCouldBeUsedForBuyout = purchaseCouldBeUsedForBuyout;
|
||||
this._rentOfferId = rentOfferId;
|
||||
this._rentCouldBeUsedForBuyout = rentCouldBeUsedForBuyout;
|
||||
this._customParams = customParams;
|
||||
this._specialType = specialType;
|
||||
this._availableForBuildersClub = availableForBuildersClub;
|
||||
this._canStandOn = canStandOn;
|
||||
this._canSitOn = canSitOn;
|
||||
this._canLayOn = canLayOn;
|
||||
this._excludedFromDynamic = excludedfromDynamic;
|
||||
this._furniLine = furniLine;
|
||||
this._environment = environment;
|
||||
this._rare = rare;
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get className(): string
|
||||
{
|
||||
return this._className;
|
||||
}
|
||||
|
||||
public set className(k: string)
|
||||
{
|
||||
this._className = k;
|
||||
}
|
||||
|
||||
public get fullName(): string
|
||||
{
|
||||
return this._fullName;
|
||||
}
|
||||
|
||||
public get category(): string
|
||||
{
|
||||
return this._category;
|
||||
}
|
||||
|
||||
public get hasIndexedColor(): boolean
|
||||
{
|
||||
return this._hasIndexedColor;
|
||||
}
|
||||
|
||||
public get colorIndex(): number
|
||||
{
|
||||
return this._colourIndex;
|
||||
}
|
||||
|
||||
public get revision(): number
|
||||
{
|
||||
return this._revision;
|
||||
}
|
||||
|
||||
public get tileSizeX(): number
|
||||
{
|
||||
return this._tileSizeX;
|
||||
}
|
||||
|
||||
public get tileSizeY(): number
|
||||
{
|
||||
return this._tileSizeY;
|
||||
}
|
||||
|
||||
public get tileSizeZ(): number
|
||||
{
|
||||
return this._tileSizeZ;
|
||||
}
|
||||
|
||||
public get colors(): number[]
|
||||
{
|
||||
return this._colors;
|
||||
}
|
||||
|
||||
public get name(): string
|
||||
{
|
||||
return this._localizedName;
|
||||
}
|
||||
|
||||
public get description(): string
|
||||
{
|
||||
return this._description;
|
||||
}
|
||||
|
||||
public get adUrl(): string
|
||||
{
|
||||
return this._adUrl;
|
||||
}
|
||||
|
||||
public get purchaseOfferId(): number
|
||||
{
|
||||
return this._purchaseOfferId;
|
||||
}
|
||||
|
||||
public get customParams(): string
|
||||
{
|
||||
return this._customParams;
|
||||
}
|
||||
|
||||
public get specialType(): number
|
||||
{
|
||||
return this._specialType;
|
||||
}
|
||||
|
||||
public get rentOfferId(): number
|
||||
{
|
||||
return this._rentOfferId;
|
||||
}
|
||||
|
||||
public get purchaseCouldBeUsedForBuyout(): boolean
|
||||
{
|
||||
return this._purchaseCouldBeUsedForBuyout;
|
||||
}
|
||||
|
||||
public get rentCouldBeUsedForBuyout(): boolean
|
||||
{
|
||||
return this._rentCouldBeUsedForBuyout;
|
||||
}
|
||||
|
||||
public get availableForBuildersClub(): boolean
|
||||
{
|
||||
return this._availableForBuildersClub;
|
||||
}
|
||||
|
||||
public get canStandOn(): boolean
|
||||
{
|
||||
return this._canStandOn;
|
||||
}
|
||||
|
||||
public get canSitOn(): boolean
|
||||
{
|
||||
return this._canSitOn;
|
||||
}
|
||||
|
||||
public get canLayOn(): boolean
|
||||
{
|
||||
return this._canLayOn;
|
||||
}
|
||||
|
||||
public get isExternalImage(): boolean
|
||||
{
|
||||
return !(this._className.indexOf('external_image') === -1);
|
||||
}
|
||||
|
||||
public get excludeDynamic(): boolean
|
||||
{
|
||||
return this._excludedFromDynamic;
|
||||
}
|
||||
|
||||
public get furniLine(): string
|
||||
{
|
||||
return this._furniLine;
|
||||
}
|
||||
|
||||
public get environment(): string
|
||||
{
|
||||
return this._environment;
|
||||
}
|
||||
|
||||
public get rare(): boolean
|
||||
{
|
||||
return this._rare;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import { FurnitureType, IFurnitureData } from '@nitrots/api';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { GetLocalizationManager } from '@nitrots/localization';
|
||||
import { FurnitureData } from './FurnitureData';
|
||||
|
||||
export class FurnitureDataLoader
|
||||
{
|
||||
private _floorItems: Map<number, IFurnitureData>;
|
||||
private _wallItems: Map<number, IFurnitureData>;
|
||||
|
||||
constructor(floorItems: Map<number, IFurnitureData>, wallItems: Map<number, IFurnitureData>)
|
||||
{
|
||||
this._floorItems = floorItems;
|
||||
this._wallItems = wallItems;
|
||||
}
|
||||
|
||||
public async init(): Promise<void>
|
||||
{
|
||||
const url = GetConfiguration().getValue<string>('furnidata.url');
|
||||
|
||||
if(!url || !url.length) throw new Error('invalid furni data url');
|
||||
|
||||
const response = await fetch(url);
|
||||
|
||||
if(response.status !== 200) throw new Error('Invalid furni data file');
|
||||
|
||||
const responseData = await response.json();
|
||||
|
||||
if(responseData.roomitemtypes) this.parseFloorItems(responseData.roomitemtypes);
|
||||
|
||||
if(responseData.wallitemtypes) this.parseWallItems(responseData.wallitemtypes);
|
||||
}
|
||||
|
||||
private parseFloorItems(data: any): void
|
||||
{
|
||||
if(!data || !data.furnitype) return;
|
||||
|
||||
for(const furniture of data.furnitype)
|
||||
{
|
||||
if(!furniture) continue;
|
||||
|
||||
const colors: number[] = [];
|
||||
|
||||
if(furniture.partcolors)
|
||||
{
|
||||
for(const color of furniture.partcolors.color)
|
||||
{
|
||||
let colorCode = (color as string);
|
||||
|
||||
if(colorCode.charAt(0) === '#')
|
||||
{
|
||||
colorCode = colorCode.replace('#', '');
|
||||
|
||||
colors.push(parseInt(colorCode, 16));
|
||||
}
|
||||
else
|
||||
{
|
||||
colors.push((parseInt(colorCode, 16)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const classSplit = (furniture.classname as string).split('*');
|
||||
const className = classSplit[0];
|
||||
const colorIndex = ((classSplit.length > 1) ? parseInt(classSplit[1]) : 0);
|
||||
const hasColorIndex = (classSplit.length > 1);
|
||||
|
||||
const furnitureData = new FurnitureData(FurnitureType.FLOOR, furniture.id, furniture.classname, className, furniture.category, furniture.name, furniture.description, furniture.revision, furniture.xdim, furniture.ydim, 0, colors, hasColorIndex, colorIndex, furniture.adurl, furniture.offerid, furniture.buyout, furniture.rentofferid, furniture.rentbuyout, furniture.bc, furniture.customparams, furniture.specialtype, furniture.canstandon, furniture.cansiton, furniture.canlayon, furniture.excludeddynamic, furniture.furniline, furniture.environment, furniture.rare);
|
||||
|
||||
this._floorItems.set(furnitureData.id, furnitureData);
|
||||
|
||||
this.updateLocalizations(furnitureData);
|
||||
}
|
||||
}
|
||||
|
||||
private parseWallItems(data: any): void
|
||||
{
|
||||
if(!data || !data.furnitype) return;
|
||||
|
||||
for(const furniture of data.furnitype)
|
||||
{
|
||||
if(!furniture) continue;
|
||||
|
||||
const furnitureData = new FurnitureData(FurnitureType.WALL, furniture.id, furniture.classname, furniture.classname, furniture.category, furniture.name, furniture.description, furniture.revision, 0, 0, 0, null, false, 0, furniture.adurl, furniture.offerid, furniture.buyout, furniture.rentofferid, furniture.rentbuyout, furniture.bc, null, furniture.specialtype, false, false, false, furniture.excludeddynamic, furniture.furniline, furniture.environment, furniture.rare);
|
||||
|
||||
this._wallItems.set(furnitureData.id, furnitureData);
|
||||
|
||||
this.updateLocalizations(furnitureData);
|
||||
}
|
||||
}
|
||||
|
||||
private updateLocalizations(furniture: FurnitureData): void
|
||||
{
|
||||
switch(furniture.type)
|
||||
{
|
||||
case FurnitureType.FLOOR:
|
||||
GetLocalizationManager().setValue(('roomItem.name.' + furniture.id), furniture.name);
|
||||
GetLocalizationManager().setValue(('roomItem.desc.' + furniture.id), furniture.description);
|
||||
return;
|
||||
case FurnitureType.WALL:
|
||||
GetLocalizationManager().setValue(('wallItem.name.' + furniture.id), furniture.name);
|
||||
GetLocalizationManager().setValue(('wallItem.desc.' + furniture.id), furniture.description);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './FurnitureData';
|
||||
export * from './FurnitureDataLoader';
|
||||
@@ -0,0 +1,41 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
|
||||
export class BaseHandler
|
||||
{
|
||||
private _connection: IConnection;
|
||||
private _listener: IRoomHandlerListener;
|
||||
private _roomId: number;
|
||||
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
this._connection = connection;
|
||||
this._listener = listener;
|
||||
this._roomId = 0;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._connection = null;
|
||||
this._listener = null;
|
||||
}
|
||||
|
||||
public setRoomId(id: number): void
|
||||
{
|
||||
this._roomId = id;
|
||||
}
|
||||
|
||||
public get connection(): IConnection
|
||||
{
|
||||
return this._connection;
|
||||
}
|
||||
|
||||
public get listener(): IRoomHandlerListener
|
||||
{
|
||||
return this._listener;
|
||||
}
|
||||
|
||||
public get roomId(): number
|
||||
{
|
||||
return this._roomId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { GenericErrorEnum, IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { GenericErrorEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionErrorMessageEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class GenericErrorHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new GenericErrorEvent(this.onRoomGenericError.bind(this)));
|
||||
}
|
||||
|
||||
private onRoomGenericError(event: GenericErrorEvent): void
|
||||
{
|
||||
if(!(event instanceof GenericErrorEvent)) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const roomSession = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!roomSession) return;
|
||||
|
||||
let type: string = '';
|
||||
|
||||
switch(parser.errorCode)
|
||||
{
|
||||
case GenericErrorEnum.KICKED_OUT_OF_ROOM:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_KICKED;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if(!type || type.length == 0) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionErrorMessageEvent(type, roomSession));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { GetCommunication, OpenPetPackageRequestedMessageEvent, OpenPetPackageResultMessageEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionPetPackageEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class PetPackageHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
GetCommunication().registerMessageEvent(new OpenPetPackageRequestedMessageEvent(this.onOpenPetPackageRequested.bind(this)));
|
||||
GetCommunication().registerMessageEvent(new OpenPetPackageResultMessageEvent(this.onOpenPetPackageResult.bind(this)));
|
||||
}
|
||||
|
||||
private onOpenPetPackageRequested(event: OpenPetPackageRequestedMessageEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPetPackageEvent(RoomSessionPetPackageEvent.RSOPPE_OPEN_PET_PACKAGE_REQUESTED, session, parser.objectId, parser.figureData, 0, null));
|
||||
}
|
||||
|
||||
private onOpenPetPackageResult(event: OpenPetPackageResultMessageEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPetPackageEvent(RoomSessionPetPackageEvent.RSOPPE_OPEN_PET_PACKAGE_RESULT, session, parser.objectId, null, parser.nameValidationStatus, parser.nameValidationInfo));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { PollContentsEvent, PollErrorEvent, PollOfferEvent, RoomPollResultEvent, StartRoomPollEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionPollEvent, RoomSessionVoteEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class PollHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new PollContentsEvent(this.onPollContentsEvent.bind(this)));
|
||||
connection.addMessageEvent(new PollOfferEvent(this.onPollOfferEvent.bind(this)));
|
||||
connection.addMessageEvent(new PollErrorEvent(this.onPollErrorEvent.bind(this)));
|
||||
connection.addMessageEvent(new StartRoomPollEvent(this.onStartRoomPollEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomPollResultEvent(this.onRoomPollResultEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onPollContentsEvent(event: PollContentsEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const pollEvent = new RoomSessionPollEvent(RoomSessionPollEvent.CONTENT, session, parser.id);
|
||||
|
||||
pollEvent.startMessage = parser.startMessage;
|
||||
pollEvent.endMessage = parser.endMessage;
|
||||
pollEvent.numQuestions = parser.numQuestions;
|
||||
pollEvent.questionArray = parser.questionArray;
|
||||
pollEvent.npsPoll = parser.npsPoll;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(pollEvent);
|
||||
}
|
||||
|
||||
private onPollOfferEvent(event: PollOfferEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const pollEvent = new RoomSessionPollEvent(RoomSessionPollEvent.OFFER, session, parser.id);
|
||||
|
||||
pollEvent.summary = parser.headline;
|
||||
pollEvent.summary = parser.summary;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(pollEvent);
|
||||
}
|
||||
|
||||
private onPollErrorEvent(event: PollErrorEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const pollEvent = new RoomSessionPollEvent(RoomSessionPollEvent.ERROR, session, -1);
|
||||
pollEvent.headline = '???';
|
||||
pollEvent.summary = '???';
|
||||
|
||||
GetEventDispatcher().dispatchEvent(pollEvent);
|
||||
}
|
||||
|
||||
private onStartRoomPollEvent(event: StartRoomPollEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const pollEvent = new RoomSessionVoteEvent(RoomSessionVoteEvent.VOTE_QUESTION, session, parser.question, parser.choices);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(pollEvent);
|
||||
}
|
||||
|
||||
private onRoomPollResultEvent(event: RoomPollResultEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const pollEvent = new RoomSessionVoteEvent(RoomSessionVoteEvent.VOTE_RESULT, session, parser.question, parser.choices, parser.SafeStr_7651, parser.SafeStr_7654);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(pollEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
import { IConnection, IRoomHandlerListener, SystemChatStyleEnum } from '@nitrots/api';
|
||||
import { FloodControlEvent, PetRespectNoficationEvent, PetSupplementTypeEnum, PetSupplementedNotificationEvent, RemainingMuteEvent, RespectReceivedEvent, RoomUnitChatEvent, RoomUnitChatShoutEvent, RoomUnitChatWhisperEvent, RoomUnitHandItemReceivedEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionChatEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class RoomChatHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new RoomUnitChatEvent(this.onRoomUnitChatEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomUnitChatShoutEvent(this.onRoomUnitChatEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomUnitChatWhisperEvent(this.onRoomUnitChatEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomUnitHandItemReceivedEvent(this.onRoomUnitHandItemReceivedEvent.bind(this)));
|
||||
connection.addMessageEvent(new RespectReceivedEvent(this.onRespectReceivedEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetRespectNoficationEvent(this.onPetRespectNoficationEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetSupplementedNotificationEvent(this.onPetSupplementedNotificationEvent.bind(this)));
|
||||
connection.addMessageEvent(new FloodControlEvent(this.onFloodControlEvent.bind(this)));
|
||||
connection.addMessageEvent(new RemainingMuteEvent(this.onRemainingMuteEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onRoomUnitChatEvent(event: RoomUnitChatEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
let chatType: number = RoomSessionChatEvent.CHAT_TYPE_SPEAK;
|
||||
|
||||
if(event instanceof RoomUnitChatShoutEvent) chatType = RoomSessionChatEvent.CHAT_TYPE_SHOUT;
|
||||
else if(event instanceof RoomUnitChatWhisperEvent) chatType = RoomSessionChatEvent.CHAT_TYPE_WHISPER;
|
||||
|
||||
const chatEvent = new RoomSessionChatEvent(RoomSessionChatEvent.CHAT_EVENT, session, parser.roomIndex, parser.message, chatType, parser.bubble);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(chatEvent);
|
||||
}
|
||||
|
||||
private onRoomUnitHandItemReceivedEvent(event: RoomUnitHandItemReceivedEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionChatEvent(RoomSessionChatEvent.CHAT_EVENT, session, parser.giverUserId, '', RoomSessionChatEvent.CHAT_TYPE_HAND_ITEM_RECEIVED, SystemChatStyleEnum.GENERIC, [], parser.handItemType));
|
||||
}
|
||||
|
||||
private onRespectReceivedEvent(event: RespectReceivedEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const userData = session.userDataManager.getUserData(parser.userId);
|
||||
|
||||
if(!userData) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionChatEvent(RoomSessionChatEvent.CHAT_EVENT, session, userData.roomIndex, '', RoomSessionChatEvent.CHAT_TYPE_RESPECT, SystemChatStyleEnum.GENERIC));
|
||||
}
|
||||
|
||||
private onPetRespectNoficationEvent(event: PetRespectNoficationEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const petData = session.userDataManager.getPetData(parser.petData.id);
|
||||
|
||||
if(!petData) return;
|
||||
|
||||
let chatType = RoomSessionChatEvent.CHAT_TYPE_PETRESPECT;
|
||||
|
||||
if(parser.isTreat) chatType = RoomSessionChatEvent.CHAT_TYPE_PETTREAT;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionChatEvent(RoomSessionChatEvent.CHAT_EVENT, session, petData.roomIndex, '', chatType, SystemChatStyleEnum.GENERIC));
|
||||
}
|
||||
|
||||
private onPetSupplementedNotificationEvent(event: PetSupplementedNotificationEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const petData = session.userDataManager.getPetData(parser.petId);
|
||||
|
||||
if(!petData) return;
|
||||
|
||||
let userRoomIndex = -1;
|
||||
|
||||
const userData = session.userDataManager.getUserData(parser.userId);
|
||||
|
||||
if(userData) userRoomIndex = userData.roomIndex;
|
||||
|
||||
let chatType = RoomSessionChatEvent.CHAT_TYPE_PETREVIVE;
|
||||
|
||||
switch(parser.supplementType)
|
||||
{
|
||||
case PetSupplementTypeEnum.REVIVE:
|
||||
chatType = RoomSessionChatEvent.CHAT_TYPE_PETREVIVE;
|
||||
break;
|
||||
case PetSupplementTypeEnum.REBREED_FERTILIZER:
|
||||
chatType = RoomSessionChatEvent.CHAT_TYPE_PET_REBREED_FERTILIZE;
|
||||
break;
|
||||
case PetSupplementTypeEnum.SPEED_FERTILIZER:
|
||||
chatType = RoomSessionChatEvent.CHAT_TYPE_PET_SPEED_FERTILIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionChatEvent(RoomSessionChatEvent.CHAT_EVENT, session, petData.roomIndex, '', chatType, SystemChatStyleEnum.GENERIC, null, userRoomIndex));
|
||||
}
|
||||
|
||||
private onFloodControlEvent(event: FloodControlEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const seconds = parser.seconds;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionChatEvent(RoomSessionChatEvent.FLOOD_EVENT, session, -1, seconds.toString(), 0, 0));
|
||||
}
|
||||
|
||||
private onRemainingMuteEvent(event: RemainingMuteEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionChatEvent(RoomSessionChatEvent.CHAT_EVENT, session, session.ownRoomIndex, '', RoomSessionChatEvent.CHAT_TYPE_MUTE_REMAINING, SystemChatStyleEnum.GENERIC, [], parser.seconds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { GetGuestRoomResultEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionEvent, RoomSessionPropertyUpdateEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class RoomDataHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new GetGuestRoomResultEvent(this.onGetGuestRoomResultEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onGetGuestRoomResultEvent(event: GetGuestRoomResultEvent): void
|
||||
{
|
||||
if(!(event instanceof GetGuestRoomResultEvent)) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
if(parser.roomForward) return;
|
||||
|
||||
const roomSession = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!roomSession) return;
|
||||
|
||||
const roomData = parser.data;
|
||||
|
||||
roomSession.tradeMode = roomData.tradeMode;
|
||||
roomSession.isGuildRoom = (roomData.habboGroupId !== 0);
|
||||
roomSession.doorMode = roomData.doorMode;
|
||||
roomSession.allowPets = roomData.allowPets;
|
||||
roomSession.moderationSettings = parser.moderation;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPropertyUpdateEvent(RoomSessionPropertyUpdateEvent.RSDUE_ALLOW_PETS, roomSession));
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionEvent(RoomSessionEvent.ROOM_DATA, roomSession));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { RoomDimmerPresetsEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionDimmerPresetsEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class RoomDimmerPresetsHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new RoomDimmerPresetsEvent(this.onRoomDimmerPresets.bind(this)));
|
||||
}
|
||||
|
||||
private onRoomDimmerPresets(event: RoomDimmerPresetsEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const presetEvent = new RoomSessionDimmerPresetsEvent(RoomSessionDimmerPresetsEvent.ROOM_DIMMER_PRESETS, session);
|
||||
|
||||
presetEvent.selectedPresetId = parser.selectedPresetId;
|
||||
|
||||
let i = 0;
|
||||
|
||||
while(i < parser.presetCount)
|
||||
{
|
||||
const preset = parser.getPreset(i);
|
||||
|
||||
if(preset) presetEvent.storePreset(preset.id, preset.type, preset.color, preset.brightness);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
GetEventDispatcher().dispatchEvent(presetEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { IConnection, IRoomHandlerListener, RoomControllerLevel } from '@nitrots/api';
|
||||
import { RoomRightsClearEvent, RoomRightsEvent, RoomRightsOwnerEvent } from '@nitrots/communication';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class RoomPermissionsHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new RoomRightsEvent(this.onRoomRightsEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomRightsClearEvent(this.onRoomRightsClearEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomRightsOwnerEvent(this.onRoomRightsOwnerEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onRoomRightsEvent(event: RoomRightsEvent): void
|
||||
{
|
||||
if(!(event instanceof RoomRightsEvent)) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.setControllerLevel(event.getParser().controllerLevel);
|
||||
}
|
||||
|
||||
private onRoomRightsClearEvent(event: RoomRightsClearEvent): void
|
||||
{
|
||||
if(!(event instanceof RoomRightsClearEvent)) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.setControllerLevel(RoomControllerLevel.NONE);
|
||||
}
|
||||
|
||||
private onRoomRightsOwnerEvent(event: RoomRightsOwnerEvent): void
|
||||
{
|
||||
if(!(event instanceof RoomRightsOwnerEvent)) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.setRoomOwner();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { PresentOpenedMessageEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionPresentEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class RoomPresentHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
if(!connection) return;
|
||||
|
||||
connection.addMessageEvent(new PresentOpenedMessageEvent(this.onFurnitureGiftOpenedEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onFurnitureGiftOpenedEvent(event: PresentOpenedMessageEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPresentEvent(RoomSessionPresentEvent.RSPE_PRESENT_OPENED, session, parser.classId, parser.itemType, parser.productCode, parser.placedItemId, parser.placedItemType, parser.placedInRoom, parser.petFigureString));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { DesktopViewEvent, FlatAccessDeniedMessageEvent, GoToFlatMessageComposer, RoomDoorbellAcceptedEvent, RoomEnterEvent, RoomReadyMessageEvent, YouAreSpectatorMessageEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionDoorbellEvent, RoomSessionSpectatorModeEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class RoomSessionHandler extends BaseHandler
|
||||
{
|
||||
public static RS_CONNECTED: string = 'RS_CONNECTED';
|
||||
public static RS_READY: string = 'RS_READY';
|
||||
public static RS_DISCONNECTED: string = 'RS_DISCONNECTED';
|
||||
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new RoomEnterEvent(this.onRoomEnterEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomReadyMessageEvent(this.onRoomReadyMessageEvent.bind(this)));
|
||||
connection.addMessageEvent(new DesktopViewEvent(this.onDesktopViewEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomDoorbellAcceptedEvent(this.onRoomDoorbellAcceptedEvent.bind(this)));
|
||||
connection.addMessageEvent(new FlatAccessDeniedMessageEvent(this.onRoomDoorbellRejectedEvent.bind(this)));
|
||||
connection.addMessageEvent(new YouAreSpectatorMessageEvent(this.onYouAreSpectatorMessageEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onRoomEnterEvent(event: RoomEnterEvent): void
|
||||
{
|
||||
if(!(event instanceof RoomEnterEvent)) return;
|
||||
|
||||
if(this.listener) this.listener.sessionUpdate(this.roomId, RoomSessionHandler.RS_CONNECTED);
|
||||
}
|
||||
|
||||
private onRoomReadyMessageEvent(event: RoomReadyMessageEvent): void
|
||||
{
|
||||
if(!(event instanceof RoomReadyMessageEvent)) return;
|
||||
|
||||
const fromRoomId = this.roomId;
|
||||
const toRoomId = event.getParser().roomId;
|
||||
|
||||
if(this.listener)
|
||||
{
|
||||
this.listener.sessionReinitialize(fromRoomId, toRoomId);
|
||||
this.listener.sessionUpdate(this.roomId, RoomSessionHandler.RS_READY);
|
||||
}
|
||||
}
|
||||
|
||||
private onDesktopViewEvent(event: DesktopViewEvent): void
|
||||
{
|
||||
if(!(event instanceof DesktopViewEvent)) return;
|
||||
|
||||
if(this.listener) this.listener.sessionUpdate(this.roomId, RoomSessionHandler.RS_DISCONNECTED);
|
||||
}
|
||||
|
||||
private onRoomDoorbellAcceptedEvent(event: RoomDoorbellAcceptedEvent): void
|
||||
{
|
||||
if(!(event instanceof RoomDoorbellAcceptedEvent) || !this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const username = parser.userName;
|
||||
|
||||
if(!username || !username.length)
|
||||
{
|
||||
this.connection.send(new GoToFlatMessageComposer(this.roomId));
|
||||
}
|
||||
else
|
||||
{
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionDoorbellEvent(RoomSessionDoorbellEvent.RSDE_ACCEPTED, session, username));
|
||||
}
|
||||
}
|
||||
|
||||
private onRoomDoorbellRejectedEvent(event: FlatAccessDeniedMessageEvent): void
|
||||
{
|
||||
if(!(event instanceof FlatAccessDeniedMessageEvent) || !this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const username = parser.userName;
|
||||
|
||||
if(!username || !username.length)
|
||||
{
|
||||
this.listener.sessionUpdate(this.roomId, RoomSessionHandler.RS_DISCONNECTED);
|
||||
}
|
||||
else
|
||||
{
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionDoorbellEvent(RoomSessionDoorbellEvent.RSDE_REJECTED, session, username));
|
||||
}
|
||||
}
|
||||
|
||||
private onYouAreSpectatorMessageEvent(event: YouAreSpectatorMessageEvent): void
|
||||
{
|
||||
if(this.listener)
|
||||
{
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.isSpectator = true;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionSpectatorModeEvent(RoomSessionSpectatorModeEvent.SPECTATOR_MODE, session));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
import { IConnection, IRoomHandlerListener, IRoomUserData } from '@nitrots/api';
|
||||
import { BotErrorEvent, ConfirmBreedingRequestEvent, ConfirmBreedingResultEvent, DoorbellMessageEvent, FavoriteMembershipUpdateMessageEvent, NestBreedingSuccessEvent, NewFriendRequestEvent, PetBreedingMessageEvent, PetBreedingResultEvent, PetFigureUpdateEvent, PetInfoEvent, PetLevelUpdateMessageEvent, PetPlacingErrorEvent, PetStatusUpdateEvent, RoomUnitDanceEvent, RoomUnitEvent, RoomUnitInfoEvent, RoomUnitRemoveEvent, UserCurrentBadgesEvent, UserNameChangeMessageEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionConfirmPetBreedingEvent, RoomSessionConfirmPetBreedingResultEvent, RoomSessionDanceEvent, RoomSessionDoorbellEvent, RoomSessionErrorMessageEvent, RoomSessionFavoriteGroupUpdateEvent, RoomSessionFriendRequestEvent, RoomSessionNestBreedingSuccessEvent, RoomSessionPetBreedingEvent, RoomSessionPetBreedingResultEvent, RoomSessionPetFigureUpdateEvent, RoomSessionPetInfoUpdateEvent, RoomSessionPetLevelUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserDataUpdateEvent, RoomSessionUserFigureUpdateEvent } from '@nitrots/events';
|
||||
import { RoomPetData } from '../RoomPetData';
|
||||
import { RoomUserData } from '../RoomUserData';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class RoomUsersHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new RoomUnitEvent(this.onRoomUnitEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomUnitInfoEvent(this.onRoomUnitInfoEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomUnitRemoveEvent(this.onRoomUnitRemoveEvent.bind(this)));
|
||||
connection.addMessageEvent(new RoomUnitDanceEvent(this.onRoomUnitDanceEvent.bind(this)));
|
||||
connection.addMessageEvent(new UserCurrentBadgesEvent(this.onUserCurrentBadgesEvent.bind(this)));
|
||||
connection.addMessageEvent(new DoorbellMessageEvent(this.onRoomDoorbellEvent.bind(this)));
|
||||
connection.addMessageEvent(new UserNameChangeMessageEvent(this.onUserNameChangeMessageEvent.bind(this)));
|
||||
connection.addMessageEvent(new NewFriendRequestEvent(this.onNewFriendRequestEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetInfoEvent(this.onPetInfoEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetStatusUpdateEvent(this.onPetStatusUpdateEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetBreedingMessageEvent(this.onPetBreedingMessageEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetLevelUpdateMessageEvent(this.onPetLevelUpdateMessageEvent.bind(this)));
|
||||
connection.addMessageEvent(new ConfirmBreedingResultEvent(this.onConfirmBreedingResultEvent.bind(this)));
|
||||
connection.addMessageEvent(new NestBreedingSuccessEvent(this.onNestBreedingSuccessEvent.bind(this)));
|
||||
connection.addMessageEvent(new ConfirmBreedingRequestEvent(this.onConfirmBreedingRequestEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetFigureUpdateEvent(this.onPetFigureUpdateEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetBreedingResultEvent(this.onPetBreedingResultEvent.bind(this)));
|
||||
connection.addMessageEvent(new PetPlacingErrorEvent(this.onPetPlacingError.bind(this)));
|
||||
connection.addMessageEvent(new BotErrorEvent(this.onBotError.bind(this)));
|
||||
connection.addMessageEvent(new FavoriteMembershipUpdateMessageEvent(this.onFavoriteMembershipUpdateMessageEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onRoomUnitEvent(event: RoomUnitEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const users = event.getParser().users;
|
||||
|
||||
const usersToAdd: IRoomUserData[] = [];
|
||||
|
||||
if(users && users.length)
|
||||
{
|
||||
for(const user of users)
|
||||
{
|
||||
if(!user) continue;
|
||||
|
||||
const userData = new RoomUserData(user.roomIndex);
|
||||
|
||||
userData.name = user.name;
|
||||
userData.custom = user.custom;
|
||||
userData.activityPoints = user.activityPoints;
|
||||
userData.figure = user.figure;
|
||||
userData.type = user.userType;
|
||||
userData.webID = user.webID;
|
||||
userData.groupId = user.groupID;
|
||||
userData.groupName = user.groupName;
|
||||
userData.groupStatus = user.groupStatus;
|
||||
userData.sex = user.sex;
|
||||
userData.ownerId = user.ownerId;
|
||||
userData.ownerName = user.ownerName;
|
||||
userData.rarityLevel = user.rarityLevel;
|
||||
userData.hasSaddle = user.hasSaddle;
|
||||
userData.isRiding = user.isRiding;
|
||||
userData.canBreed = user.canBreed;
|
||||
userData.canHarvest = user.canHarvest;
|
||||
userData.canRevive = user.canRevive;
|
||||
userData.hasBreedingPermission = user.hasBreedingPermission;
|
||||
userData.petLevel = user.petLevel;
|
||||
userData.botSkills = user.botSkills;
|
||||
userData.isModerator = user.isModerator;
|
||||
|
||||
if(!session.userDataManager.getUserData(user.roomIndex)) usersToAdd.push(userData);
|
||||
|
||||
session.userDataManager.updateUserData(userData);
|
||||
}
|
||||
}
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionUserDataUpdateEvent(session, usersToAdd));
|
||||
}
|
||||
|
||||
private onRoomUnitInfoEvent(event: RoomUnitInfoEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
session.userDataManager.updateFigure(parser.unitId, parser.figure, parser.gender, false, false);
|
||||
session.userDataManager.updateMotto(parser.unitId, parser.motto);
|
||||
session.userDataManager.updateAchievementScore(parser.unitId, parser.achievementScore);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionUserFigureUpdateEvent(session, parser.unitId, parser.figure, parser.gender, parser.motto, parser.achievementScore));
|
||||
|
||||
}
|
||||
|
||||
private onRoomUnitRemoveEvent(event: RoomUnitRemoveEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.userDataManager.removeUserData(event.getParser().unitId);
|
||||
}
|
||||
|
||||
private onRoomUnitDanceEvent(event: RoomUnitDanceEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionDanceEvent(session, parser.unitId, parser.danceId));
|
||||
}
|
||||
|
||||
private onUserCurrentBadgesEvent(event: UserCurrentBadgesEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.userDataManager.setUserBadges(parser.userId, parser.badges);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionUserBadgesEvent(session, parser.userId, parser.badges));
|
||||
}
|
||||
|
||||
private onRoomDoorbellEvent(event: DoorbellMessageEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const username = parser.userName;
|
||||
|
||||
if(!username || !username.length) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionDoorbellEvent(RoomSessionDoorbellEvent.DOORBELL, session, username));
|
||||
}
|
||||
|
||||
private onUserNameChangeMessageEvent(event: UserNameChangeMessageEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.userDataManager.updateName(parser.id, parser.newName);
|
||||
}
|
||||
|
||||
private onNewFriendRequestEvent(event: NewFriendRequestEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const request = parser.request;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionFriendRequestEvent(session, request.requestId, request.requesterUserId, request.requesterName));
|
||||
}
|
||||
|
||||
private onPetInfoEvent(event: PetInfoEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const petData = new RoomPetData();
|
||||
|
||||
petData.id = parser.id;
|
||||
petData.level = parser.level;
|
||||
petData.maximumLevel = parser.maximumLevel;
|
||||
petData.experience = parser.experience;
|
||||
petData.levelExperienceGoal = parser.levelExperienceGoal;
|
||||
petData.energy = parser.energy;
|
||||
petData.maximumEnergy = parser.maximumEnergy;
|
||||
petData.happyness = parser.happyness;
|
||||
petData.maximumHappyness = parser.maximumHappyness;
|
||||
petData.ownerId = parser.ownerId;
|
||||
petData.ownerName = parser.ownerName;
|
||||
petData.respect = parser.respect;
|
||||
petData.age = parser.age;
|
||||
petData.unknownRarity = parser.unknownRarity;
|
||||
petData.saddle = parser.saddle;
|
||||
petData.rider = parser.rider;
|
||||
petData.breedable = parser.breedable;
|
||||
petData.fullyGrown = parser.fullyGrown;
|
||||
petData.rarityLevel = parser.rarityLevel;
|
||||
petData.dead = parser.dead;
|
||||
petData.skillTresholds = parser.skillTresholds;
|
||||
petData.publiclyRideable = parser.publiclyRideable;
|
||||
petData.maximumTimeToLive = parser.maximumTimeToLive;
|
||||
petData.remainingTimeToLive = parser.remainingTimeToLive;
|
||||
petData.remainingGrowTime = parser.remainingGrowTime;
|
||||
petData.publiclyBreedable = parser.publiclyBreedable;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPetInfoUpdateEvent(session, petData));
|
||||
}
|
||||
|
||||
private onPetStatusUpdateEvent(event: PetStatusUpdateEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.userDataManager.updatePetBreedingStatus(parser.roomIndex, parser.canBreed, parser.canHarvest, parser.canRevive, parser.hasBreedingPermission);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPetStatusUpdateEvent(session, parser.petId, parser.canBreed, parser.canHarvest, parser.canRevive, parser.hasBreedingPermission));
|
||||
}
|
||||
|
||||
private onPetBreedingMessageEvent(event: PetBreedingMessageEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPetBreedingEvent(session, parser.state, parser.ownPetId, parser.otherPetId));
|
||||
}
|
||||
|
||||
private onPetLevelUpdateMessageEvent(event: PetLevelUpdateMessageEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
session.userDataManager.updatePetLevel(parser.roomIndex, parser.level);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPetLevelUpdateEvent(session, parser.petId, parser.level));
|
||||
}
|
||||
|
||||
private onConfirmBreedingResultEvent(event: ConfirmBreedingResultEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionConfirmPetBreedingResultEvent(session, parser.breedingNestStuffId, parser.result));
|
||||
}
|
||||
|
||||
private onNestBreedingSuccessEvent(event: NestBreedingSuccessEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionNestBreedingSuccessEvent(session, parser.petId, parser.rarityCategory));
|
||||
}
|
||||
|
||||
private onConfirmBreedingRequestEvent(event: ConfirmBreedingRequestEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionConfirmPetBreedingEvent(session, parser.nestId, parser.pet1, parser.pet2, parser.rarityCategories, parser.resultPetType));
|
||||
}
|
||||
|
||||
private onPetFigureUpdateEvent(event: PetFigureUpdateEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const figure = parser.figureData.figuredata;
|
||||
|
||||
session.userDataManager.updateFigure(parser.roomIndex, figure, '', parser.hasSaddle, parser.isRiding);
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPetFigureUpdateEvent(session, parser.petId, figure));
|
||||
}
|
||||
|
||||
private onPetBreedingResultEvent(event: PetBreedingResultEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionPetBreedingResultEvent(session, parser.resultData, parser.otherResultData));
|
||||
}
|
||||
|
||||
private onPetPlacingError(event: PetPlacingErrorEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
let type: string = '';
|
||||
|
||||
switch(parser.errorCode)
|
||||
{
|
||||
case 0:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_PETS_FORBIDDEN_IN_HOTEL;
|
||||
break;
|
||||
case 1:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_PETS_FORBIDDEN_IN_FLAT;
|
||||
break;
|
||||
case 2:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_MAX_PETS;
|
||||
break;
|
||||
case 3:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_NO_FREE_TILES_FOR_PET;
|
||||
break;
|
||||
case 4:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_SELECTED_TILE_NOT_FREE_FOR_PET;
|
||||
break;
|
||||
case 5:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_MAX_NUMBER_OF_OWN_PETS;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!type || type.length == 0) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionErrorMessageEvent(type, session));
|
||||
}
|
||||
|
||||
private onBotError(event: BotErrorEvent): void
|
||||
{
|
||||
if(!event) return;
|
||||
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
let type: string = '';
|
||||
|
||||
switch(parser.errorCode)
|
||||
{
|
||||
case 0:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_BOTS_FORBIDDEN_IN_HOTEL;
|
||||
break;
|
||||
case 1:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_BOTS_FORBIDDEN_IN_FLAT;
|
||||
break;
|
||||
case 2:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_BOT_LIMIT_REACHED;
|
||||
break;
|
||||
case 3:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_SELECTED_TILE_NOT_FREE_FOR_BOT;
|
||||
break;
|
||||
case 4:
|
||||
type = RoomSessionErrorMessageEvent.RSEME_BOT_NAME_NOT_ACCEPTED;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!type || type.length == 0) return;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionErrorMessageEvent(type, session));
|
||||
}
|
||||
|
||||
private onFavoriteMembershipUpdateMessageEvent(event: FavoriteMembershipUpdateMessageEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const userData = session.userDataManager.getUserDataByIndex(parser.roomIndex);
|
||||
|
||||
if(!userData) return;
|
||||
|
||||
userData.groupId = parser.groupId;
|
||||
userData.groupName = parser.groupName;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new RoomSessionFavoriteGroupUpdateEvent(session, parser.roomIndex, parser.groupId, parser.status, parser.groupName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { IConnection, IRoomHandlerListener } from '@nitrots/api';
|
||||
import { QuestionAnsweredEvent, QuestionEvent, QuestionFinishedEvent } from '@nitrots/communication';
|
||||
import { GetEventDispatcher, RoomSessionWordQuizEvent } from '@nitrots/events';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class WordQuizHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new QuestionEvent(this.onQuestionEvent.bind(this)));
|
||||
connection.addMessageEvent(new QuestionAnsweredEvent(this.onQuestionAnsweredEvent.bind(this)));
|
||||
connection.addMessageEvent(new QuestionFinishedEvent(this.onQuestionFinishedEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onQuestionEvent(event: QuestionEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.QUESTION, session, parser.pollId);
|
||||
|
||||
quizEvent.question = parser.question;
|
||||
quizEvent.duration = parser.duration;
|
||||
quizEvent.pollType = parser.pollType;
|
||||
quizEvent.questionId = parser.questionId;
|
||||
quizEvent.pollId = parser.pollId;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(quizEvent);
|
||||
}
|
||||
|
||||
private onQuestionAnsweredEvent(event: QuestionAnsweredEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.ANSWERED, session, parser.userId);
|
||||
|
||||
quizEvent.value = parser.value;
|
||||
quizEvent.userId = parser.userId;
|
||||
quizEvent.answerCounts = parser.answerCounts;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(quizEvent);
|
||||
}
|
||||
|
||||
private onQuestionFinishedEvent(event: QuestionFinishedEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.FINISHED, session);
|
||||
quizEvent.questionId = parser.questionId;
|
||||
quizEvent.answerCounts = parser.answerCounts;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(quizEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export * from './BaseHandler';
|
||||
export * from './GenericErrorHandler';
|
||||
export * from './PetPackageHandler';
|
||||
export * from './PollHandler';
|
||||
export * from './RoomChatHandler';
|
||||
export * from './RoomDataHandler';
|
||||
export * from './RoomDimmerPresetsHandler';
|
||||
export * from './RoomPermissionsHandler';
|
||||
export * from './RoomPresentHandler';
|
||||
export * from './RoomSessionHandler';
|
||||
export * from './RoomUsersHandler';
|
||||
export * from './WordQuizHandler';
|
||||
@@ -0,0 +1,15 @@
|
||||
export * from './GetRoomSessionManager';
|
||||
export * from './GetSessionDataManager';
|
||||
export * from './GroupInformationManager';
|
||||
export * from './HabboClubLevelEnum';
|
||||
export * from './IgnoredUsersManager';
|
||||
export * from './RoomPetData';
|
||||
export * from './RoomSession';
|
||||
export * from './RoomSessionManager';
|
||||
export * from './RoomUserData';
|
||||
export * from './SessionDataManager';
|
||||
export * from './UserDataManager';
|
||||
export * from './badge';
|
||||
export * from './furniture';
|
||||
export * from './handler';
|
||||
export * from './product';
|
||||
@@ -0,0 +1,30 @@
|
||||
import { IProductData } from '@nitrots/api';
|
||||
|
||||
export class ProductData implements IProductData
|
||||
{
|
||||
private _type: string;
|
||||
private _name: string;
|
||||
private _description: string;
|
||||
|
||||
constructor(type: string, name: string, description: string)
|
||||
{
|
||||
this._type = type;
|
||||
this._name = name;
|
||||
this._description = description;
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get name(): string
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get description(): string
|
||||
{
|
||||
return this._description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { IProductData } from '@nitrots/api';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { ProductData } from './ProductData';
|
||||
|
||||
export class ProductDataLoader
|
||||
{
|
||||
private _products: Map<string, IProductData>;
|
||||
|
||||
constructor(products: Map<string, IProductData>)
|
||||
{
|
||||
this._products = products;
|
||||
}
|
||||
|
||||
public async init(): Promise<void>
|
||||
{
|
||||
const url = GetConfiguration().getValue<string>('productdata.url');
|
||||
|
||||
if(!url || !url.length) throw new Error('invalid product data url');
|
||||
|
||||
const response = await fetch(url);
|
||||
|
||||
if(response.status !== 200) throw new Error('Invalid product data file');
|
||||
|
||||
const responseData = await response.json();
|
||||
|
||||
this.parseProducts(responseData.productdata);
|
||||
}
|
||||
|
||||
private parseProducts(data: { [index: string]: any }): void
|
||||
{
|
||||
if(!data) return;
|
||||
|
||||
for(const product of data.product) (product && this._products.set(product.code, new ProductData(product.code, product.name, product.description)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './ProductData';
|
||||
export * from './ProductDataLoader';
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./src",
|
||||
"outDir": "./dist",
|
||||
"sourceMap": false,
|
||||
"declaration": true,
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "Node",
|
||||
"esModuleInterop": true,
|
||||
"importHelpers": true,
|
||||
"isolatedModules": true,
|
||||
"resolveJsonModule": true,
|
||||
"downlevelIteration": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true,
|
||||
"strict": false,
|
||||
"strictNullChecks": false,
|
||||
"target": "ES6",
|
||||
"lib": [
|
||||
"DOM",
|
||||
"DOM.Iterable",
|
||||
"ESNext"
|
||||
],
|
||||
"module": "ES6"
|
||||
},
|
||||
"include": [
|
||||
"src" ]
|
||||
}
|
||||
Reference in New Issue
Block a user