blob: c85c2f63e770119a1bd7ffb099a4653aca316e05 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// because why not make *more files
import { getRandomInt } from "./lib.ts";
import cuid2 from "@paralleldrive/cuid2";
import type { WebSocket } from 'ws'
import type { IncomingMessage } from "node:http";
import type Server from "./server.ts";
import Timespamp from "./timestamp.ts";
const cuid = cuid2.init()
export default class User {
id: string = cuid();
username: string;
nickname: string;
guest: boolean;
socket: WebSocket;
joinReq: IncomingMessage;
ip: string;
t: Timespamp;
channel: string;
client?: string = undefined;
admin: boolean = false;
/**
* the user class
*/
constructor (request: IncomingMessage, socket: WebSocket, server: Server) {
const anonID = getRandomInt(0, 99999);
const annonNum = "0".repeat(5 - anonID.toString().length) + anonID.toString()
this.username = server.config.accounts.annonFormat ? server.config.accounts.annonFormat.replace('[num]', annonNum) : 'Anonymous' + annonNum;
this.nickname = server.config.accounts.annonFormat ? server.config.accounts.annonFormat.replace('[num]', annonNum) : 'Anonymous' + annonNum;
this.guest = true;
this.socket = socket;
this.joinReq = request;
this.ip = (request.headers["x-forwarded-for"] ?? [null])[0] ?? request.socket.remoteAddress ?? '';
this.t = new Timespamp(new Date());
this.channel = "home";
}
name () {
return this.nickname != "" ? this.nickname : this.username;
}
}
|