From 609e05b90215b461334313a1e8358fb4225a192c Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Mon, 4 Jul 2022 00:38:42 +0200 Subject: [PATCH] idk --- src/Client.js | 14 ++++++++++++++ src/Message.js | 39 ++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/Client.js b/src/Client.js index 56ece3d..e32b94a 100644 --- a/src/Client.js +++ b/src/Client.js @@ -90,6 +90,20 @@ class Client extends EventEmitter { } } + userset(name, admin) { + if (name.length > 40 && !admin) return; + if(!this.quotas.userset.attempt()) return; + this.user.name = name; + Database.getUserData(this, this.server).then((usr) => { + Database.updateUser(this.user._id, this.user); + this.server.rooms.forEach((room) => { + room.updateParticipant(this.user._id, { + name: name + }); + }); + }); + } + initParticipantQuotas() { this.quotas = { //"chat": new Quota(Quota.PARAMS_A_NORMAL), diff --git a/src/Message.js b/src/Message.js index 1829809..1fc99c6 100644 --- a/src/Message.js +++ b/src/Message.js @@ -200,26 +200,11 @@ module.exports = (cl) => { cl.server.roomlisteners.delete(cl.connectionid); }); - cl.on("userset", msg => { + cl.on("userset", (msg, admin) => { if (!(cl.channel && cl.participantId)) return; if (!msg.hasOwnProperty("set") || !msg.set) msg.set = {}; if (msg.set.hasOwnProperty('name') && typeof msg.set.name == "string") { - if (msg.set.name.length > 40) return; - if(!cl.quotas.userset.attempt()) return; - cl.user.name = msg.set.name; - Database.getUserData(cl, cl.server).then((usr) => { - // let dbentry = Database.userdb.get(cl.user._id); - // if (!dbentry) return; - // dbentry.name = msg.set.name; - // Database.update(); - Database.updateUser(cl.user._id, cl.user); - cl.server.rooms.forEach((room) => { - room.updateParticipant(cl.user._id, { - name: msg.set.name - }); - }) - }) - + cl.userset(msg.set.name, admin); } }); @@ -392,4 +377,24 @@ module.exports = (cl) => { if (!ch) return; ch.emit(msg.m, msg); }); + + cl.on('name', (msg, admin) => { + if (!admin) return; + + if (!msg.hasOwnProperty('_id')) return; + if (!msg.hasOwnProperty('name')) return; + + let c; + + for (const conn of cl.server.connections) { + if (conn.user._id == msg._id) { + c = conn; + break; + } + } + + if (!c) return; + + c.userset(msg.name, true); + }); }