You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 06:56:19 +00:00
feat(mentions): add MentionReceived/MentionsList packets + parsers and composers
This commit is contained in:
@@ -12,6 +12,7 @@ import { RareValuesEvent, RequestRareValuesComposer } from './messages';
|
||||
import { WheelBuySpinComposer, WheelDataEvent, WheelOpenComposer, WheelRecentWinsEvent, WheelResultEvent, WheelSpinComposer } from './messages';
|
||||
import { WheelAdminGetPrizesComposer, WheelAdminPrizesEvent, WheelAdminSavePrizesComposer } from './messages';
|
||||
import { SoundboardPlayEvent, SoundboardSettingsEvent, SoundboardPlayComposer, SoundboardSetEnabledComposer } from './messages';
|
||||
import { MarkMentionsReadComposer, MentionReceivedEvent, MentionsListEvent, RequestMentionsComposer } from './messages';
|
||||
export class NitroMessages implements IMessageConfiguration
|
||||
{
|
||||
private _events: Map<number, Function>;
|
||||
@@ -300,6 +301,10 @@ export class NitroMessages implements IMessageConfiguration
|
||||
this._events.set(IncomingHeader.MARKETPLACE_ITEMS_SEARCHED, MarketPlaceOffersEvent);
|
||||
this._events.set(IncomingHeader.MARKETPLACE_OWN_ITEMS, MarketplaceOwnOffersEvent);
|
||||
|
||||
// MENTIONS
|
||||
this._events.set(IncomingHeader.MENTION_RECEIVED, MentionReceivedEvent);
|
||||
this._events.set(IncomingHeader.MENTIONS_LIST, MentionsListEvent);
|
||||
|
||||
// MODERATION
|
||||
this._events.set(IncomingHeader.USER_BANNED, UserBannedMessageEvent);
|
||||
this._events.set(IncomingHeader.MODERATION_CAUTION, ModeratorCautionEvent);
|
||||
@@ -1153,6 +1158,10 @@ export class NitroMessages implements IMessageConfiguration
|
||||
this._composers.set(OutgoingHeader.REQUEST_SELL_ITEM, GetMarketplaceCanMakeOfferComposer);
|
||||
this._composers.set(OutgoingHeader.REQUEST_MARKETPLACE_ITEM_STATS, GetMarketplaceItemStatsComposer);
|
||||
|
||||
// MENTIONS
|
||||
this._composers.set(OutgoingHeader.REQUEST_MENTIONS, RequestMentionsComposer);
|
||||
this._composers.set(OutgoingHeader.MARK_MENTIONS_READ, MarkMentionsReadComposer);
|
||||
|
||||
// BOTS
|
||||
this._composers.set(OutgoingHeader.USER_BOTS, GetBotInventoryComposer);
|
||||
|
||||
|
||||
@@ -3,6 +3,10 @@ export class IncomingHeader
|
||||
// These packets do not belong to this revision, so these are custom packet ids
|
||||
public static AREA_HIDE = 6001;
|
||||
|
||||
// MENTIONS
|
||||
public static MENTION_RECEIVED = 4801;
|
||||
public static MENTIONS_LIST = 4802;
|
||||
|
||||
// Original packets
|
||||
public static ACHIEVEMENT_LIST = 305;
|
||||
public static AUTHENTICATED = 2491;
|
||||
|
||||
@@ -40,6 +40,7 @@ export * from './inventory/trading';
|
||||
export * from './landingview';
|
||||
export * from './landingview/votes';
|
||||
export * from './marketplace';
|
||||
export * from './mentions';
|
||||
export * from './moderation';
|
||||
export * from './mysterybox';
|
||||
export * from './navigator';
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IMessageEvent } from '@nitrots/api';
|
||||
import { MessageEvent } from '@nitrots/events';
|
||||
import { MentionReceivedParser } from '../../parser';
|
||||
|
||||
export class MentionReceivedEvent extends MessageEvent implements IMessageEvent
|
||||
{
|
||||
constructor(callBack: Function)
|
||||
{
|
||||
super(callBack, MentionReceivedParser);
|
||||
}
|
||||
|
||||
public getParser(): MentionReceivedParser
|
||||
{
|
||||
return this.parser as MentionReceivedParser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IMessageEvent } from '@nitrots/api';
|
||||
import { MessageEvent } from '@nitrots/events';
|
||||
import { MentionsListParser } from '../../parser';
|
||||
|
||||
export class MentionsListEvent extends MessageEvent implements IMessageEvent
|
||||
{
|
||||
constructor(callBack: Function)
|
||||
{
|
||||
super(callBack, MentionsListParser);
|
||||
}
|
||||
|
||||
public getParser(): MentionsListParser
|
||||
{
|
||||
return this.parser as MentionsListParser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './MentionReceivedEvent';
|
||||
export * from './MentionsListEvent';
|
||||
@@ -3,6 +3,10 @@ export class OutgoingHeader
|
||||
public static CLICK_FURNI = 6002;
|
||||
public static CLICK_USER = 10020;
|
||||
|
||||
// MENTIONS
|
||||
public static REQUEST_MENTIONS = 4803;
|
||||
public static MARK_MENTIONS_READ = 4804;
|
||||
|
||||
public static ACHIEVEMENT_LIST = 219;
|
||||
public static AUTHENTICATION = -1;
|
||||
public static BOT_CONFIGURATION = 1986;
|
||||
|
||||
@@ -36,6 +36,7 @@ export * from './inventory/unseen';
|
||||
export * from './landingview';
|
||||
export * from './landingview/votes';
|
||||
export * from './marketplace';
|
||||
export * from './mentions';
|
||||
export * from './moderation';
|
||||
export * from './mysterybox';
|
||||
export * from './navigator';
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { IMessageComposer } from '@nitrots/api';
|
||||
|
||||
export class MarkMentionsReadComposer implements IMessageComposer<ConstructorParameters<typeof MarkMentionsReadComposer>>
|
||||
{
|
||||
private _data: ConstructorParameters<typeof MarkMentionsReadComposer>;
|
||||
|
||||
constructor(mode: number, mentionId: number = 0)
|
||||
{
|
||||
this._data = [mode, mentionId];
|
||||
}
|
||||
|
||||
public getMessageArray()
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { IMessageComposer } from '@nitrots/api';
|
||||
|
||||
export class RequestMentionsComposer implements IMessageComposer<ConstructorParameters<typeof RequestMentionsComposer>>
|
||||
{
|
||||
private _data: ConstructorParameters<typeof RequestMentionsComposer>;
|
||||
|
||||
constructor()
|
||||
{
|
||||
this._data = [];
|
||||
}
|
||||
|
||||
public getMessageArray()
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './RequestMentionsComposer';
|
||||
export * from './MarkMentionsReadComposer';
|
||||
@@ -40,6 +40,7 @@ export * from './inventory/trading';
|
||||
export * from './landingview';
|
||||
export * from './landingview/votes';
|
||||
export * from './marketplace';
|
||||
export * from './mentions';
|
||||
export * from './moderation';
|
||||
export * from './mysterybox';
|
||||
export * from './navigator';
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { IMessageDataWrapper } from '@nitrots/api';
|
||||
|
||||
export class MentionListItem
|
||||
{
|
||||
private _mentionId: number;
|
||||
private _senderId: number;
|
||||
private _senderUsername: string;
|
||||
private _roomId: number;
|
||||
private _roomName: string;
|
||||
private _message: string;
|
||||
private _mentionType: number;
|
||||
private _timestamp: number;
|
||||
private _read: boolean;
|
||||
|
||||
constructor(wrapper: IMessageDataWrapper, withReadFlag: boolean)
|
||||
{
|
||||
this._mentionId = wrapper.readInt();
|
||||
this._senderId = wrapper.readInt();
|
||||
this._senderUsername = wrapper.readString();
|
||||
this._roomId = wrapper.readInt();
|
||||
this._roomName = wrapper.readString();
|
||||
this._message = wrapper.readString();
|
||||
this._mentionType = wrapper.readInt();
|
||||
this._timestamp = wrapper.readInt();
|
||||
this._read = withReadFlag ? wrapper.readBoolean() : false;
|
||||
}
|
||||
|
||||
public get mentionId(): number { return this._mentionId; }
|
||||
public get senderId(): number { return this._senderId; }
|
||||
public get senderUsername(): string { return this._senderUsername; }
|
||||
public get roomId(): number { return this._roomId; }
|
||||
public get roomName(): string { return this._roomName; }
|
||||
public get message(): string { return this._message; }
|
||||
public get mentionType(): number { return this._mentionType; }
|
||||
public get timestamp(): number { return this._timestamp; }
|
||||
public get read(): boolean { return this._read; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
|
||||
import { MentionListItem } from './MentionListItem';
|
||||
|
||||
export class MentionReceivedParser implements IMessageParser
|
||||
{
|
||||
private _mention: MentionListItem;
|
||||
|
||||
public flush(): boolean
|
||||
{
|
||||
this._mention = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public parse(wrapper: IMessageDataWrapper): boolean
|
||||
{
|
||||
if(!wrapper) return false;
|
||||
this._mention = new MentionListItem(wrapper, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public get mention(): MentionListItem { return this._mention; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { IMessageDataWrapper, IMessageParser } from '@nitrots/api';
|
||||
import { MentionListItem } from './MentionListItem';
|
||||
|
||||
export class MentionsListParser implements IMessageParser
|
||||
{
|
||||
private _mentions: MentionListItem[];
|
||||
|
||||
public flush(): boolean
|
||||
{
|
||||
this._mentions = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
public parse(wrapper: IMessageDataWrapper): boolean
|
||||
{
|
||||
if(!wrapper) return false;
|
||||
this._mentions = [];
|
||||
const count = wrapper.readInt();
|
||||
for(let i = 0; i < count; i++)
|
||||
{
|
||||
this._mentions.push(new MentionListItem(wrapper, true));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public get mentions(): MentionListItem[] { return this._mentions; }
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { BinaryReader, BinaryWriter } from '@nitrots/utils';
|
||||
import { MentionReceivedParser } from '../MentionReceivedParser';
|
||||
import { MentionsListParser } from '../MentionsListParser';
|
||||
|
||||
class TestWrapper
|
||||
{
|
||||
constructor(private reader: BinaryReader) {}
|
||||
readByte() { return this.reader.readByte(); }
|
||||
readBytes(n: number) { return this.reader.readBytes(n); }
|
||||
readBoolean() { return this.reader.readByte() === 1; }
|
||||
readShort() { return this.reader.readShort(); }
|
||||
readInt() { return this.reader.readInt(); }
|
||||
readFloat() { return this.reader.readFloat(); }
|
||||
readDouble() { return this.reader.readDouble(); }
|
||||
readString() { const len = this.reader.readShort(); return this.reader.readBytes(len).toString(); }
|
||||
header = 0;
|
||||
get bytesAvailable() { return this.reader.remaining() > 0; }
|
||||
}
|
||||
|
||||
describe('MentionReceivedParser', () =>
|
||||
{
|
||||
it('parses a single mention without read flag', () =>
|
||||
{
|
||||
const w = new BinaryWriter();
|
||||
w.writeInt(7); w.writeInt(42); w.writeString('Bob'); w.writeInt(99);
|
||||
w.writeString('My Room'); w.writeString('ciao @me'); w.writeInt(0); w.writeInt(1717000000);
|
||||
const parser = new MentionReceivedParser();
|
||||
parser.flush();
|
||||
parser.parse(new TestWrapper(new BinaryReader(w.getBuffer())) as any);
|
||||
const m = parser.mention;
|
||||
expect(m.mentionId).toBe(7);
|
||||
expect(m.senderId).toBe(42);
|
||||
expect(m.senderUsername).toBe('Bob');
|
||||
expect(m.roomId).toBe(99);
|
||||
expect(m.roomName).toBe('My Room');
|
||||
expect(m.message).toBe('ciao @me');
|
||||
expect(m.mentionType).toBe(0);
|
||||
expect(m.timestamp).toBe(1717000000);
|
||||
expect(m.read).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('MentionsListParser', () =>
|
||||
{
|
||||
it('parses a count-prefixed list with read flags', () =>
|
||||
{
|
||||
const w = new BinaryWriter();
|
||||
w.writeInt(1); w.writeInt(3); w.writeInt(42); w.writeString('Bob'); w.writeInt(99);
|
||||
w.writeString('My Room'); w.writeString('@all festa'); w.writeInt(1); w.writeInt(1717000000); w.writeByte(1);
|
||||
const parser = new MentionsListParser();
|
||||
parser.flush();
|
||||
parser.parse(new TestWrapper(new BinaryReader(w.getBuffer())) as any);
|
||||
expect(parser.mentions).toHaveLength(1);
|
||||
expect(parser.mentions[0].mentionId).toBe(3);
|
||||
expect(parser.mentions[0].senderUsername).toBe('Bob');
|
||||
expect(parser.mentions[0].read).toBe(true);
|
||||
expect(parser.mentions[0].mentionType).toBe(1);
|
||||
expect(parser.mentions[0].message).toBe('@all festa');
|
||||
});
|
||||
|
||||
it('parses an empty list', () =>
|
||||
{
|
||||
const w = new BinaryWriter();
|
||||
w.writeInt(0);
|
||||
const parser = new MentionsListParser();
|
||||
parser.flush();
|
||||
parser.parse(new TestWrapper(new BinaryReader(w.getBuffer())) as any);
|
||||
expect(parser.mentions).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './MentionListItem';
|
||||
export * from './MentionReceivedParser';
|
||||
export * from './MentionsListParser';
|
||||
Reference in New Issue
Block a user