You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 23:16:20 +00:00
Merge remote-tracking branch 'origin/main'
# Conflicts: # packages/communication/src/NitroMessages.ts
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ICommunicationManager, IConnection, IMessageConfiguration, IMessageEvent } from '@nitrots/api';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { GetEventDispatcher, NitroEventType } from '@nitrots/events';
|
||||
import { GetTickerTime } from '@nitrots/utils';
|
||||
import { GetEventDispatcher, NitroEvent, NitroEventType } from '@nitrots/events';
|
||||
import { GetTickerTime, NitroLogger } from '@nitrots/utils';
|
||||
import { NitroMessages } from './NitroMessages';
|
||||
import { SocketConnection } from './SocketConnection';
|
||||
import { AuthenticatedEvent, ClientHelloMessageComposer, ClientPingEvent, InfoRetrieveMessageComposer, PongMessageComposer, SSOTicketMessageComposer, UniqueIDMessageComposer } from './messages';
|
||||
@@ -17,7 +17,11 @@ export class CommunicationManager implements ICommunicationManager
|
||||
private _socketClosedCallback: () => void = null;
|
||||
private _socketOpenedCallback: () => void = null;
|
||||
private _socketErrorCallback: () => void = null;
|
||||
|
||||
private _socketReconnectedCallback: () => void = null;
|
||||
|
||||
private _machineId: string = null;
|
||||
private _initResolved: boolean = false;
|
||||
|
||||
private getGpu(): string {
|
||||
const e = document.createElement('canvas');
|
||||
let t, s, i, r;
|
||||
@@ -41,7 +45,7 @@ export class CommunicationManager implements ICommunicationManager
|
||||
return '<mathroutines>Error</mathroutines>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private getCanvas(): any {
|
||||
const e = document.createElement('canvas'), t = e.getContext('2d'), userAgent = navigator.userAgent, screenInfo = '${window.screen.width}x${window.screen.height}', currentDate = new Date().toString(), s = 'ThiosIsVerrySeCuRe02938883721moreStuff! | ${userAgent} | ${screenInfo} | ${currentDate}';
|
||||
t.textBaseline = 'top';
|
||||
@@ -67,24 +71,33 @@ export class CommunicationManager implements ICommunicationManager
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
private generateMachineID(): string {
|
||||
const fp = new ClientJS();
|
||||
const uniqueId = fp.getCustomFingerprint(
|
||||
fp.getAvailableResolution(),
|
||||
fp.getAvailableResolution(),
|
||||
fp.getOS(),
|
||||
fp.getCPU(),
|
||||
fp.getColorDepth(),
|
||||
this.getGpu(),
|
||||
fp.getSilverlightVersion(),
|
||||
fp.getOSVersion(),
|
||||
this.getMathResult(),
|
||||
fp.getCanvasPrint(),
|
||||
fp.getCPU(),
|
||||
fp.getColorDepth(),
|
||||
this.getGpu(),
|
||||
fp.getSilverlightVersion(),
|
||||
fp.getOSVersion(),
|
||||
this.getMathResult(),
|
||||
fp.getCanvasPrint(),
|
||||
this.getCanvas()
|
||||
);
|
||||
return uniqueId == null ? 'FAILED' : `IID-${uniqueId}`;
|
||||
}
|
||||
|
||||
private sendHandshake(): void
|
||||
{
|
||||
if(!this._machineId) this._machineId = this.generateMachineID();
|
||||
|
||||
this._connection.send(new ClientHelloMessageComposer(null, null, null, null));
|
||||
this._connection.send(new SSOTicketMessageComposer(GetConfiguration().getValue('sso.ticket', null), GetTickerTime()));
|
||||
this._connection.send(new UniqueIDMessageComposer(this._machineId, '', ''));
|
||||
}
|
||||
|
||||
constructor()
|
||||
{
|
||||
this._connection.registerMessages(this._messages);
|
||||
@@ -99,6 +112,17 @@ export class CommunicationManager implements ICommunicationManager
|
||||
};
|
||||
GetEventDispatcher().addEventListener(NitroEventType.SOCKET_CLOSED, this._socketClosedCallback);
|
||||
|
||||
// Handle reconnection - re-authenticate when socket reconnects
|
||||
this._socketReconnectedCallback = () =>
|
||||
{
|
||||
NitroLogger.log('[CommunicationManager] Socket reconnected, re-authenticating...');
|
||||
|
||||
if(GetConfiguration().getValue<boolean>('system.pong.manually', false)) this.startPong();
|
||||
|
||||
this.sendHandshake();
|
||||
};
|
||||
GetEventDispatcher().addEventListener(NitroEventType.SOCKET_RECONNECTED, this._socketReconnectedCallback);
|
||||
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
// Store callback for cleanup
|
||||
@@ -106,18 +130,14 @@ export class CommunicationManager implements ICommunicationManager
|
||||
{
|
||||
if(GetConfiguration().getValue<boolean>('system.pong.manually', false)) this.startPong();
|
||||
|
||||
const machineId = this.generateMachineID();
|
||||
|
||||
this._connection.send(new ClientHelloMessageComposer(null, null, null, null));
|
||||
this._connection.send(new SSOTicketMessageComposer(GetConfiguration().getValue('sso.ticket', null), GetTickerTime()));
|
||||
this._connection.send(new UniqueIDMessageComposer(machineId, '', ''));
|
||||
this.sendHandshake();
|
||||
};
|
||||
GetEventDispatcher().addEventListener(NitroEventType.SOCKET_OPENED, this._socketOpenedCallback);
|
||||
|
||||
// Store callback for cleanup
|
||||
this._socketErrorCallback = () =>
|
||||
{
|
||||
reject();
|
||||
if(!this._initResolved) reject();
|
||||
};
|
||||
GetEventDispatcher().addEventListener(NitroEventType.SOCKET_ERROR, this._socketErrorCallback);
|
||||
|
||||
@@ -125,11 +145,30 @@ export class CommunicationManager implements ICommunicationManager
|
||||
const pingEvent = new ClientPingEvent((event: ClientPingEvent) => this.sendPong());
|
||||
const authEvent = new AuthenticatedEvent((event: AuthenticatedEvent) =>
|
||||
{
|
||||
const isReconnect = this._initResolved;
|
||||
|
||||
NitroLogger.log('[CommunicationManager] AuthenticatedEvent received (isReconnect=' + isReconnect + ')');
|
||||
|
||||
this._connection.authenticated();
|
||||
|
||||
resolve();
|
||||
if(!this._initResolved)
|
||||
{
|
||||
this._initResolved = true;
|
||||
resolve();
|
||||
}
|
||||
|
||||
if(isReconnect)
|
||||
{
|
||||
this._connection.ready();
|
||||
}
|
||||
|
||||
event.connection.send(new InfoRetrieveMessageComposer());
|
||||
|
||||
if(isReconnect)
|
||||
{
|
||||
NitroLogger.log('[CommunicationManager] Dispatching SOCKET_REAUTHENTICATED');
|
||||
GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_REAUTHENTICATED));
|
||||
}
|
||||
});
|
||||
|
||||
this._messageEvents.push(pingEvent, authEvent);
|
||||
@@ -164,6 +203,12 @@ export class CommunicationManager implements ICommunicationManager
|
||||
this._socketErrorCallback = null;
|
||||
}
|
||||
|
||||
if(this._socketReconnectedCallback)
|
||||
{
|
||||
GetEventDispatcher().removeEventListener(NitroEventType.SOCKET_RECONNECTED, this._socketReconnectedCallback);
|
||||
this._socketReconnectedCallback = null;
|
||||
}
|
||||
|
||||
// Remove message events
|
||||
for(const event of this._messageEvents)
|
||||
{
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
import { ICodec, IConnection, IMessageComposer, IMessageConfiguration, IMessageDataWrapper, IMessageEvent, WebSocketEventEnum } from '@nitrots/api';
|
||||
import { GetEventDispatcher, NitroEvent, NitroEventType } from '@nitrots/events';
|
||||
import { GetEventDispatcher, NitroEvent, NitroEventType, ReconnectEvent } from '@nitrots/events';
|
||||
import { NitroLogger } from '@nitrots/utils';
|
||||
import { EvaWireFormat } from './codec';
|
||||
import { MessageClassManager } from './messages';
|
||||
@@ -23,19 +23,39 @@ export class SocketConnection implements IConnection
|
||||
private _onErrorCallback: (event: Event) => void = null;
|
||||
private _onMessageCallback: (event: MessageEvent) => void = null;
|
||||
|
||||
// Reconnection state
|
||||
private _socketUrl: string = null;
|
||||
private _reconnectAttempt: number = 0;
|
||||
private _reconnectTimer: ReturnType<typeof setTimeout> = null;
|
||||
private _isReconnecting: boolean = false;
|
||||
private _intentionalClose: boolean = false;
|
||||
private _wasAuthenticated: boolean = false;
|
||||
|
||||
public static readonly MAX_RECONNECT_ATTEMPTS: number = 7;
|
||||
public static readonly BASE_RECONNECT_DELAY_MS: number = 1000;
|
||||
public static readonly MAX_RECONNECT_DELAY_MS: number = 30000;
|
||||
|
||||
public init(socketUrl: string): void
|
||||
{
|
||||
if(!socketUrl || !socketUrl.length) return;
|
||||
|
||||
this._socketUrl = socketUrl;
|
||||
this._intentionalClose = false;
|
||||
|
||||
this.createSocket(socketUrl);
|
||||
}
|
||||
|
||||
private createSocket(socketUrl: string): void
|
||||
{
|
||||
this._dataBuffer = new ArrayBuffer(0);
|
||||
|
||||
this._socket = new WebSocket(socketUrl);
|
||||
this._socket.binaryType = 'arraybuffer';
|
||||
|
||||
// Store callbacks for cleanup
|
||||
this._onOpenCallback = () => GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_OPENED));
|
||||
this._onCloseCallback = () => GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_CLOSED));
|
||||
this._onErrorCallback = () => GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_ERROR));
|
||||
this._onOpenCallback = () => this.onSocketOpened();
|
||||
this._onCloseCallback = (event: Event) => this.onSocketClosed(event as CloseEvent);
|
||||
this._onErrorCallback = () => this.onSocketError();
|
||||
this._onMessageCallback = (event: MessageEvent) =>
|
||||
{
|
||||
this._dataBuffer = this.concatArrayBuffers(this._dataBuffer, event.data);
|
||||
@@ -48,29 +68,152 @@ export class SocketConnection implements IConnection
|
||||
this._socket.addEventListener(WebSocketEventEnum.CONNECTION_MESSAGE, this._onMessageCallback);
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
private onSocketOpened(): void
|
||||
{
|
||||
if(this._socket)
|
||||
if(this._isReconnecting)
|
||||
{
|
||||
// Remove all event listeners
|
||||
if(this._onOpenCallback) this._socket.removeEventListener(WebSocketEventEnum.CONNECTION_OPENED, this._onOpenCallback);
|
||||
if(this._onCloseCallback) this._socket.removeEventListener(WebSocketEventEnum.CONNECTION_CLOSED, this._onCloseCallback);
|
||||
if(this._onErrorCallback) this._socket.removeEventListener(WebSocketEventEnum.CONNECTION_ERROR, this._onErrorCallback);
|
||||
if(this._onMessageCallback) this._socket.removeEventListener(WebSocketEventEnum.CONNECTION_MESSAGE, this._onMessageCallback);
|
||||
NitroLogger.log('[SocketConnection] Reconnected successfully after ' + this._reconnectAttempt + ' attempt(s)');
|
||||
|
||||
// Close socket if still open
|
||||
if(this._socket.readyState === WebSocket.OPEN || this._socket.readyState === WebSocket.CONNECTING)
|
||||
{
|
||||
this._socket.close();
|
||||
}
|
||||
this._reconnectAttempt = 0;
|
||||
this._isReconnecting = false;
|
||||
|
||||
this._socket = null;
|
||||
GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_RECONNECTED));
|
||||
}
|
||||
else
|
||||
{
|
||||
GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_OPENED));
|
||||
}
|
||||
}
|
||||
|
||||
private onSocketClosed(event: CloseEvent): void
|
||||
{
|
||||
NitroLogger.log('[SocketConnection] Socket closed, code: ' + (event?.code ?? 'unknown') + ', reason: ' + (event?.reason || 'none'));
|
||||
|
||||
if(this._intentionalClose)
|
||||
{
|
||||
GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_CLOSED));
|
||||
return;
|
||||
}
|
||||
|
||||
const code = event?.code ?? 0;
|
||||
|
||||
if(code === 1000 || code === 1001)
|
||||
{
|
||||
NitroLogger.log('[SocketConnection] Server closed cleanly (code ' + code + ') - not reconnecting');
|
||||
|
||||
this._isAuthenticated = false;
|
||||
this._isReady = false;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_CLOSED));
|
||||
return;
|
||||
}
|
||||
|
||||
if(this._isAuthenticated) this._wasAuthenticated = true;
|
||||
|
||||
this._isAuthenticated = false;
|
||||
this._isReady = false;
|
||||
this._pendingClientMessages = [];
|
||||
this._pendingServerMessages = [];
|
||||
|
||||
this.attemptReconnect();
|
||||
}
|
||||
|
||||
private onSocketError(): void
|
||||
{
|
||||
if(this._isReconnecting)
|
||||
{
|
||||
NitroLogger.log('[SocketConnection] Reconnect attempt ' + this._reconnectAttempt + ' failed');
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this._wasAuthenticated && !this._isAuthenticated)
|
||||
{
|
||||
GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
private attemptReconnect(): void
|
||||
{
|
||||
if(this._reconnectAttempt >= SocketConnection.MAX_RECONNECT_ATTEMPTS)
|
||||
{
|
||||
NitroLogger.log('[SocketConnection] Max reconnect attempts reached (' + SocketConnection.MAX_RECONNECT_ATTEMPTS + ')');
|
||||
|
||||
this._isReconnecting = false;
|
||||
this._wasAuthenticated = false;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new ReconnectEvent(
|
||||
NitroEventType.SOCKET_RECONNECT_FAILED,
|
||||
this._reconnectAttempt,
|
||||
SocketConnection.MAX_RECONNECT_ATTEMPTS
|
||||
));
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new NitroEvent(NitroEventType.SOCKET_CLOSED));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._isReconnecting = true;
|
||||
this._reconnectAttempt++;
|
||||
|
||||
const delay = Math.min(
|
||||
SocketConnection.BASE_RECONNECT_DELAY_MS * Math.pow(2, this._reconnectAttempt - 1) + Math.random() * 1000,
|
||||
SocketConnection.MAX_RECONNECT_DELAY_MS
|
||||
);
|
||||
|
||||
NitroLogger.log('[SocketConnection] Reconnecting in ' + Math.round(delay) + 'ms (attempt ' + this._reconnectAttempt + '/' + SocketConnection.MAX_RECONNECT_ATTEMPTS + ')');
|
||||
|
||||
GetEventDispatcher().dispatchEvent(new ReconnectEvent(
|
||||
NitroEventType.SOCKET_RECONNECTING,
|
||||
this._reconnectAttempt,
|
||||
SocketConnection.MAX_RECONNECT_ATTEMPTS
|
||||
));
|
||||
|
||||
this._reconnectTimer = setTimeout(() =>
|
||||
{
|
||||
this._reconnectTimer = null;
|
||||
|
||||
this.cleanupSocket();
|
||||
|
||||
this.createSocket(this._socketUrl);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
private cleanupSocket(): void
|
||||
{
|
||||
if(!this._socket) return;
|
||||
|
||||
if(this._onOpenCallback) this._socket.removeEventListener(WebSocketEventEnum.CONNECTION_OPENED, this._onOpenCallback);
|
||||
if(this._onCloseCallback) this._socket.removeEventListener(WebSocketEventEnum.CONNECTION_CLOSED, this._onCloseCallback);
|
||||
if(this._onErrorCallback) this._socket.removeEventListener(WebSocketEventEnum.CONNECTION_ERROR, this._onErrorCallback);
|
||||
if(this._onMessageCallback) this._socket.removeEventListener(WebSocketEventEnum.CONNECTION_MESSAGE, this._onMessageCallback);
|
||||
|
||||
if(this._socket.readyState === WebSocket.OPEN || this._socket.readyState === WebSocket.CONNECTING)
|
||||
{
|
||||
try { this._socket.close(); } catch(e) { /* ignore */ }
|
||||
}
|
||||
|
||||
this._socket = null;
|
||||
this._onOpenCallback = null;
|
||||
this._onCloseCallback = null;
|
||||
this._onErrorCallback = null;
|
||||
this._onMessageCallback = null;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
this._intentionalClose = true;
|
||||
|
||||
if(this._reconnectTimer)
|
||||
{
|
||||
clearTimeout(this._reconnectTimer);
|
||||
this._reconnectTimer = null;
|
||||
}
|
||||
|
||||
this._isReconnecting = false;
|
||||
this._reconnectAttempt = 0;
|
||||
this._wasAuthenticated = false;
|
||||
|
||||
this.cleanupSocket();
|
||||
|
||||
this._pendingClientMessages = [];
|
||||
this._pendingServerMessages = [];
|
||||
@@ -142,7 +285,7 @@ export class SocketConnection implements IConnection
|
||||
|
||||
private write(buffer: ArrayBuffer): void
|
||||
{
|
||||
if(this._socket.readyState !== WebSocket.OPEN) return;
|
||||
if(!this._socket || this._socket.readyState !== WebSocket.OPEN) return;
|
||||
|
||||
this._socket.send(buffer);
|
||||
}
|
||||
@@ -286,6 +429,16 @@ export class SocketConnection implements IConnection
|
||||
return this._isAuthenticated;
|
||||
}
|
||||
|
||||
public get isReconnecting(): boolean
|
||||
{
|
||||
return this._isReconnecting;
|
||||
}
|
||||
|
||||
public get wasAuthenticated(): boolean
|
||||
{
|
||||
return this._wasAuthenticated;
|
||||
}
|
||||
|
||||
public get dataBuffer(): ArrayBuffer
|
||||
{
|
||||
return this._dataBuffer;
|
||||
|
||||
@@ -15,6 +15,7 @@ export * from './messages/incoming/camera';
|
||||
export * from './messages/incoming/campaign';
|
||||
export * from './messages/incoming/catalog';
|
||||
export * from './messages/incoming/client';
|
||||
export * from './messages/incoming/commands';
|
||||
export * from './messages/incoming/competition';
|
||||
export * from './messages/incoming/crafting';
|
||||
export * from './messages/incoming/desktop';
|
||||
@@ -37,6 +38,7 @@ export * from './messages/incoming/inventory/clothes';
|
||||
export * from './messages/incoming/inventory/furni';
|
||||
export * from './messages/incoming/inventory/furni/gifts';
|
||||
export * from './messages/incoming/inventory/pets';
|
||||
export * from './messages/incoming/inventory/prefixes';
|
||||
export * from './messages/incoming/inventory/trading';
|
||||
export * from './messages/incoming/landingview';
|
||||
export * from './messages/incoming/landingview/votes';
|
||||
@@ -109,6 +111,7 @@ export * from './messages/outgoing/inventory/badges';
|
||||
export * from './messages/outgoing/inventory/bots';
|
||||
export * from './messages/outgoing/inventory/furni';
|
||||
export * from './messages/outgoing/inventory/pets';
|
||||
export * from './messages/outgoing/inventory/prefixes';
|
||||
export * from './messages/outgoing/inventory/trading';
|
||||
export * from './messages/outgoing/inventory/unseen';
|
||||
export * from './messages/outgoing/landingview';
|
||||
@@ -165,6 +168,7 @@ export * from './messages/parser/camera';
|
||||
export * from './messages/parser/campaign';
|
||||
export * from './messages/parser/catalog';
|
||||
export * from './messages/parser/client';
|
||||
export * from './messages/parser/commands';
|
||||
export * from './messages/parser/competition';
|
||||
export * from './messages/parser/crafting';
|
||||
export * from './messages/parser/desktop';
|
||||
@@ -187,6 +191,7 @@ export * from './messages/parser/inventory/badges';
|
||||
export * from './messages/parser/inventory/clothing';
|
||||
export * from './messages/parser/inventory/furniture';
|
||||
export * from './messages/parser/inventory/pets';
|
||||
export * from './messages/parser/inventory/prefixes';
|
||||
export * from './messages/parser/inventory/purse';
|
||||
export * from './messages/parser/inventory/trading';
|
||||
export * from './messages/parser/landingview';
|
||||
|
||||
@@ -7,6 +7,7 @@ export class IncomingHeader
|
||||
public static ACHIEVEMENT_LIST = 305;
|
||||
public static AUTHENTICATED = 2491;
|
||||
public static AUTHENTICATION = -1;
|
||||
public static AVAILABLE_COMMANDS = 4050;
|
||||
public static AVAILABILITY_STATUS = 2033;
|
||||
public static BUILDERS_CLUB_EXPIRED = 1452;
|
||||
public static CLUB_OFFERS = 2405;
|
||||
@@ -474,4 +475,9 @@ export class IncomingHeader
|
||||
public static WEEKLY_GAME2_LEADERBOARD = 2196;
|
||||
public static RENTABLE_FURNI_RENT_OR_BUYOUT_OFFER = 35;
|
||||
public static HANDSHAKE_IDENTITY_ACCOUNT = 3523;
|
||||
|
||||
// Custom Prefixes
|
||||
public static USER_PREFIXES = 7001;
|
||||
public static PREFIX_RECEIVED = 7002;
|
||||
public static ACTIVE_PREFIX_UPDATED = 7003;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IMessageEvent } from '@nitrots/api';
|
||||
import { MessageEvent } from '@nitrots/events';
|
||||
import { AvailableCommandsParser } from '../../parser';
|
||||
|
||||
export class AvailableCommandsEvent extends MessageEvent implements IMessageEvent
|
||||
{
|
||||
constructor(callBack: Function)
|
||||
{
|
||||
super(callBack, AvailableCommandsParser);
|
||||
}
|
||||
|
||||
public getParser(): AvailableCommandsParser
|
||||
{
|
||||
return this.parser as AvailableCommandsParser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './AvailableCommandsEvent';
|
||||
@@ -8,6 +8,7 @@ export * from './camera';
|
||||
export * from './campaign';
|
||||
export * from './catalog';
|
||||
export * from './client';
|
||||
export * from './commands';
|
||||
export * from './competition';
|
||||
export * from './crafting';
|
||||
export * from './desktop';
|
||||
|
||||
@@ -5,4 +5,5 @@ export * from './clothes';
|
||||
export * from './furni';
|
||||
export * from './furni/gifts';
|
||||
export * from './pets';
|
||||
export * from './prefixes';
|
||||
export * from './trading';
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { IMessageEvent } from '@nitrots/api';
|
||||
import { MessageEvent } from '@nitrots/events';
|
||||
import { ActivePrefixUpdatedParser } from '../../../parser';
|
||||
|
||||
export class ActivePrefixUpdatedEvent extends MessageEvent implements IMessageEvent
|
||||
{
|
||||
constructor(callBack: Function)
|
||||
{
|
||||
super(callBack, ActivePrefixUpdatedParser);
|
||||
}
|
||||
|
||||
public getParser(): ActivePrefixUpdatedParser
|
||||
{
|
||||
return this.parser as ActivePrefixUpdatedParser;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { IMessageEvent } from '@nitrots/api';
|
||||
import { MessageEvent } from '@nitrots/events';
|
||||
import { PrefixReceivedParser } from '../../../parser';
|
||||
|
||||
export class PrefixReceivedEvent extends MessageEvent implements IMessageEvent
|
||||
{
|
||||
constructor(callBack: Function)
|
||||
{
|
||||
super(callBack, PrefixReceivedParser);
|
||||
}
|
||||
|
||||
public getParser(): PrefixReceivedParser
|
||||
{
|
||||
return this.parser as PrefixReceivedParser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IMessageEvent } from '@nitrots/api';
|
||||
import { MessageEvent } from '@nitrots/events';
|
||||
import { UserPrefixesParser } from '../../../parser';
|
||||
|
||||
export class UserPrefixesEvent extends MessageEvent implements IMessageEvent
|
||||
{
|
||||
constructor(callBack: Function)
|
||||
{
|
||||
super(callBack, UserPrefixesParser);
|
||||
}
|
||||
|
||||
public getParser(): UserPrefixesParser
|
||||
{
|
||||
return this.parser as UserPrefixesParser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './ActivePrefixUpdatedEvent';
|
||||
export * from './PrefixReceivedEvent';
|
||||
export * from './UserPrefixesEvent';
|
||||
@@ -478,4 +478,10 @@ export class OutgoingHeader
|
||||
public static DELETE_ITEM = 10018;
|
||||
public static DELETE_PET = 10030;
|
||||
public static DELETE_BADGE = 10031;
|
||||
|
||||
// Custom Prefixes
|
||||
public static REQUEST_PREFIXES = 7011;
|
||||
public static SET_ACTIVE_PREFIX = 7012;
|
||||
public static DELETE_PREFIX = 7013;
|
||||
public static PURCHASE_PREFIX = 7014;
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ export * from './badges';
|
||||
export * from './bots';
|
||||
export * from './furni';
|
||||
export * from './pets';
|
||||
export * from './prefixes';
|
||||
export * from './trading';
|
||||
export * from './unseen';
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { IMessageComposer } from '@nitrots/api';
|
||||
|
||||
export class DeletePrefixComposer implements IMessageComposer<ConstructorParameters<typeof DeletePrefixComposer>>
|
||||
{
|
||||
private _data: ConstructorParameters<typeof DeletePrefixComposer>;
|
||||
|
||||
constructor(prefixId: number)
|
||||
{
|
||||
this._data = [ prefixId ];
|
||||
}
|
||||
|
||||
public getMessageArray()
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { IMessageComposer } from '@nitrots/api';
|
||||
|
||||
export class PurchasePrefixComposer implements IMessageComposer<ConstructorParameters<typeof PurchasePrefixComposer>>
|
||||
{
|
||||
private _data: ConstructorParameters<typeof PurchasePrefixComposer>;
|
||||
|
||||
constructor(text: string, color: string, icon: string = '', effect: string = '')
|
||||
{
|
||||
this._data = [ text, color, icon, effect ];
|
||||
}
|
||||
|
||||
public getMessageArray()
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { IMessageComposer } from '@nitrots/api';
|
||||
|
||||
export class RequestPrefixesComposer implements IMessageComposer<ConstructorParameters<typeof RequestPrefixesComposer>>
|
||||
{
|
||||
private _data: ConstructorParameters<typeof RequestPrefixesComposer>;
|
||||
|
||||
constructor()
|
||||
{
|
||||
this._data = [];
|
||||
}
|
||||
|
||||
public getMessageArray()
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { IMessageComposer } from '@nitrots/api';
|
||||
|
||||
export class SetActivePrefixComposer implements IMessageComposer<ConstructorParameters<typeof SetActivePrefixComposer>>
|
||||
{
|
||||
private _data: ConstructorParameters<typeof SetActivePrefixComposer>;
|
||||
|
||||
constructor(prefixId: number)
|
||||
{
|
||||
this._data = [ prefixId ];
|
||||
}
|
||||
|
||||
public getMessageArray()
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './DeletePrefixComposer';
|
||||
export * from './PurchasePrefixComposer';
|
||||
export * from './RequestPrefixesComposer';
|
||||
export * from './SetActivePrefixComposer';
|
||||
@@ -0,0 +1,37 @@
|
||||
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
|
||||
|
||||
export class AvailableCommandsParser implements IMessageParser
|
||||
{
|
||||
private _commands: { key: string; description: string }[];
|
||||
|
||||
public flush(): boolean
|
||||
{
|
||||
this._commands = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public parse(wrapper: IMessageDataWrapper): boolean
|
||||
{
|
||||
if(!wrapper) return false;
|
||||
|
||||
this._commands = [];
|
||||
|
||||
const count = wrapper.readInt();
|
||||
|
||||
for(let i = 0; i < count; i++)
|
||||
{
|
||||
this._commands.push({
|
||||
key: wrapper.readString(),
|
||||
description: wrapper.readString()
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public get commands(): { key: string; description: string }[]
|
||||
{
|
||||
return this._commands;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './AvailableCommandsParser';
|
||||
@@ -7,6 +7,7 @@ export * from './camera';
|
||||
export * from './campaign';
|
||||
export * from './catalog';
|
||||
export * from './client';
|
||||
export * from './commands';
|
||||
export * from './competition';
|
||||
export * from './crafting';
|
||||
export * from './desktop';
|
||||
|
||||
@@ -4,5 +4,6 @@ export * from './badges';
|
||||
export * from './clothing';
|
||||
export * from './furniture';
|
||||
export * from './pets';
|
||||
export * from './prefixes';
|
||||
export * from './purse';
|
||||
export * from './trading';
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
|
||||
|
||||
export class ActivePrefixUpdatedParser implements IMessageParser
|
||||
{
|
||||
private _prefixId: number;
|
||||
private _text: string;
|
||||
private _color: string;
|
||||
private _icon: string;
|
||||
private _effect: string;
|
||||
|
||||
public flush(): boolean
|
||||
{
|
||||
this._prefixId = 0;
|
||||
this._text = '';
|
||||
this._color = '';
|
||||
this._icon = '';
|
||||
this._effect = '';
|
||||
return true;
|
||||
}
|
||||
|
||||
public parse(wrapper: IMessageDataWrapper): boolean
|
||||
{
|
||||
if(!wrapper) return false;
|
||||
|
||||
this._prefixId = wrapper.readInt();
|
||||
this._text = wrapper.readString();
|
||||
this._color = wrapper.readString();
|
||||
this._icon = wrapper.readString();
|
||||
this._effect = wrapper.readString();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public get prefixId(): number { return this._prefixId; }
|
||||
public get text(): string { return this._text; }
|
||||
public get color(): string { return this._color; }
|
||||
public get icon(): string { return this._icon; }
|
||||
public get effect(): string { return this._effect; }
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
|
||||
|
||||
export class PrefixReceivedParser implements IMessageParser
|
||||
{
|
||||
private _id: number;
|
||||
private _text: string;
|
||||
private _color: string;
|
||||
private _icon: string;
|
||||
private _effect: string;
|
||||
|
||||
public flush(): boolean
|
||||
{
|
||||
this._id = 0;
|
||||
this._text = '';
|
||||
this._color = '';
|
||||
this._icon = '';
|
||||
this._effect = '';
|
||||
return true;
|
||||
}
|
||||
|
||||
public parse(wrapper: IMessageDataWrapper): boolean
|
||||
{
|
||||
if(!wrapper) return false;
|
||||
|
||||
this._id = wrapper.readInt();
|
||||
this._text = wrapper.readString();
|
||||
this._color = wrapper.readString();
|
||||
this._icon = wrapper.readString();
|
||||
this._effect = wrapper.readString();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public get id(): number { return this._id; }
|
||||
public get text(): string { return this._text; }
|
||||
public get color(): string { return this._color; }
|
||||
public get icon(): string { return this._icon; }
|
||||
public get effect(): string { return this._effect; }
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
|
||||
|
||||
export interface IPrefixData
|
||||
{
|
||||
id: number;
|
||||
text: string;
|
||||
color: string;
|
||||
icon: string;
|
||||
effect: string;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export class UserPrefixesParser implements IMessageParser
|
||||
{
|
||||
private _prefixes: IPrefixData[];
|
||||
|
||||
public flush(): boolean
|
||||
{
|
||||
this._prefixes = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
public parse(wrapper: IMessageDataWrapper): boolean
|
||||
{
|
||||
if(!wrapper) return false;
|
||||
|
||||
this._prefixes = [];
|
||||
|
||||
let count = wrapper.readInt();
|
||||
|
||||
while(count > 0)
|
||||
{
|
||||
this._prefixes.push({
|
||||
id: wrapper.readInt(),
|
||||
text: wrapper.readString(),
|
||||
color: wrapper.readString(),
|
||||
icon: wrapper.readString(),
|
||||
effect: wrapper.readString(),
|
||||
active: wrapper.readInt() === 1
|
||||
});
|
||||
|
||||
count--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public get prefixes(): IPrefixData[]
|
||||
{
|
||||
return this._prefixes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './ActivePrefixUpdatedParser';
|
||||
export * from './PrefixReceivedParser';
|
||||
export * from './UserPrefixesParser';
|
||||
@@ -9,6 +9,10 @@ export class RoomUnitChatParser implements IMessageParser
|
||||
private _urls: string[];
|
||||
private _chatColours: string;
|
||||
private _messageLength: number;
|
||||
private _prefixText: string;
|
||||
private _prefixColor: string;
|
||||
private _prefixIcon: string;
|
||||
private _prefixEffect: string;
|
||||
|
||||
public flush(): boolean
|
||||
{
|
||||
@@ -19,6 +23,10 @@ export class RoomUnitChatParser implements IMessageParser
|
||||
this._urls = [];
|
||||
this._chatColours = null;
|
||||
this._messageLength = 0;
|
||||
this._prefixText = '';
|
||||
this._prefixColor = '';
|
||||
this._prefixIcon = '';
|
||||
this._prefixEffect = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -33,9 +41,13 @@ export class RoomUnitChatParser implements IMessageParser
|
||||
this._bubble = wrapper.readInt();
|
||||
|
||||
this.parseUrls(wrapper);
|
||||
|
||||
|
||||
this._chatColours = wrapper.readString();
|
||||
this._messageLength = wrapper.readInt();
|
||||
this._prefixText = wrapper.readString();
|
||||
this._prefixColor = wrapper.readString();
|
||||
this._prefixIcon = wrapper.readString();
|
||||
this._prefixEffect = wrapper.readString();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -82,7 +94,7 @@ export class RoomUnitChatParser implements IMessageParser
|
||||
{
|
||||
return this._urls;
|
||||
}
|
||||
|
||||
|
||||
public get chatColours(): string
|
||||
{
|
||||
return this._chatColours;
|
||||
@@ -92,4 +104,24 @@ export class RoomUnitChatParser implements IMessageParser
|
||||
{
|
||||
return this._messageLength;
|
||||
}
|
||||
|
||||
public get prefixText(): string
|
||||
{
|
||||
return this._prefixText;
|
||||
}
|
||||
|
||||
public get prefixColor(): string
|
||||
{
|
||||
return this._prefixColor;
|
||||
}
|
||||
|
||||
public get prefixIcon(): string
|
||||
{
|
||||
return this._prefixIcon;
|
||||
}
|
||||
|
||||
public get prefixEffect(): string
|
||||
{
|
||||
return this._prefixEffect;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user