2024-10-03 00:32:38 +01:00
|
|
|
import { createWriter, Endian } from "bufferstuff";
|
2024-07-03 23:47:45 +01:00
|
|
|
import IMetric from "simple-prom/lib/interfaces/IMetric";
|
2024-10-03 00:32:38 +01:00
|
|
|
import { MessageType } from "../enums/MessageType";
|
2024-04-21 15:35:47 +01:00
|
|
|
|
|
|
|
export default class RemoteUser {
|
|
|
|
private static USER_IDS = 0;
|
|
|
|
|
2024-05-08 01:02:18 +01:00
|
|
|
public readonly socket:WebSocket;
|
|
|
|
public readonly connectionUUID:string;
|
2024-04-21 15:35:47 +01:00
|
|
|
public readonly id:number;
|
|
|
|
public readonly username:string;
|
|
|
|
public readonly currentURL:string;
|
|
|
|
public readonly rawURL:string = "";
|
2024-07-03 23:47:45 +01:00
|
|
|
private readonly dataOut:IMetric;
|
2024-09-26 10:31:24 +01:00
|
|
|
private readonly messagesOut:IMetric;
|
2024-04-21 15:35:47 +01:00
|
|
|
public cursorX:number = 0;
|
|
|
|
public cursorY:number = 0;
|
|
|
|
public allowedPings:number;
|
|
|
|
public lastPingReset:number;
|
2024-04-26 03:01:06 +01:00
|
|
|
public userId:number;
|
2024-05-06 15:41:26 +01:00
|
|
|
public groupId:number = Number.MIN_VALUE;
|
2024-04-26 03:01:06 +01:00
|
|
|
public groupName:string;
|
2024-05-08 01:02:18 +01:00
|
|
|
public lastKeepAliveTime:number;
|
2024-05-27 12:56:49 +01:00
|
|
|
public isAfk:boolean;
|
|
|
|
public timeLastMovedCursor: number;
|
2024-04-21 15:35:47 +01:00
|
|
|
|
2024-09-26 10:31:24 +01:00
|
|
|
constructor(socket:WebSocket, dataOut:IMetric, messagesOut:IMetric, connectionUUID:string, username:string, currentURL:string, rawURL:string, userId:number, groupId:number, groupName:string) {
|
2024-04-21 15:35:47 +01:00
|
|
|
this.socket = socket;
|
2024-05-08 01:02:18 +01:00
|
|
|
this.connectionUUID = connectionUUID;
|
2024-04-21 15:35:47 +01:00
|
|
|
this.id = RemoteUser.USER_IDS++;
|
|
|
|
this.username = username;
|
|
|
|
this.currentURL = currentURL;
|
|
|
|
this.rawURL = rawURL;
|
2024-07-03 23:47:45 +01:00
|
|
|
this.dataOut = dataOut;
|
2024-09-26 10:31:24 +01:00
|
|
|
this.messagesOut = messagesOut;
|
2024-04-21 15:35:47 +01:00
|
|
|
this.allowedPings = 10;
|
|
|
|
this.lastPingReset = Date.now();
|
2024-04-26 03:01:06 +01:00
|
|
|
this.userId = userId;
|
|
|
|
this.groupId = groupId;
|
|
|
|
this.groupName = groupName;
|
2024-05-08 01:02:18 +01:00
|
|
|
this.lastKeepAliveTime = Date.now();
|
2024-05-27 12:56:49 +01:00
|
|
|
this.isAfk = false;
|
|
|
|
this.timeLastMovedCursor = Date.now();
|
2024-04-21 15:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
send(data:Buffer) {
|
2024-07-03 23:47:45 +01:00
|
|
|
this.dataOut.add(data.length);
|
2024-09-26 10:31:24 +01:00
|
|
|
this.messagesOut.add(1);
|
2024-04-21 15:35:47 +01:00
|
|
|
this.socket.send(data);
|
|
|
|
}
|
2024-10-03 00:32:38 +01:00
|
|
|
|
|
|
|
sendBadge(name:string, description:string, imageUrl:string) {
|
|
|
|
const formattedDescription = description.replaceAll("\r", "").replaceAll("\n", "<br>");
|
|
|
|
this.send(createWriter(Endian.LE, 7 + name.length * 2 + formattedDescription.length * 2 + imageUrl.length * 2).writeByte(MessageType.BadgeUnlock).writeString16(name).writeString16(formattedDescription).writeString16(imageUrl).toBuffer());
|
|
|
|
}
|
2024-04-21 15:35:47 +01:00
|
|
|
}
|