diff options
author | WlodekM <[email protected]> | 2024-09-14 22:09:57 +0300 |
---|---|---|
committer | WlodekM <[email protected]> | 2024-09-14 22:09:57 +0300 |
commit | 43c5346643380756560ef7ba8c4c4d0c44c871fe (patch) | |
tree | b844de06a069dc67b6255064c7897a1d51bc0027 /user.js | |
parent | 496fdda80d4f82ddb2e233b0f0b504826d7a0f0a (diff) |
wip index.js rewrite 2: electric boogaloo
Diffstat (limited to 'user.js')
-rw-r--r-- | user.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/user.js b/user.js new file mode 100644 index 0000000..eb8d090 --- /dev/null +++ b/user.js @@ -0,0 +1,32 @@ +// because why not make *more files + +import { getRandomInt } from "./lib.js"; +import cuid from "cuid"; + +export default class User { + /** + * + * @param {import("http").IncomingMessage} request request + * @param {import("./server.js").Server} server the server + */ + constructor (request, socket, server) { + this.id = cuid(); + let anonID = getRandomInt(0, 99999); + let annonNum = "0".repeat(5 - anonID.toString().length) + anonID.toString() + this.username = server.config.annonFormat ? server.config.annonFormat.replace('[num]', annonNum) : 'Anonymous' + annonNum; + this.nickname = server.config.annonFormat ? server.config.annonFormat.replace('[num]', annonNum) : 'Anonymous' + annonNum; + this.guest = true; + this.socket = socket; + this.joinReq = request; + this.ip = request.headers["x-forwarded-for"] || request.socket.remoteAddress; + this.t = { + js: Number(new Date()), + unix: Math.floor(new Date().getTime() / 1000), + str: String(new Date()), + }; + this.channel = "home"; + this.name = function () { + return this.nickname != "" ? this.nickname : this.username; + }; + } +} \ No newline at end of file |