From e00105a8cf066a7155f8f87e07eb35dce494888e Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Tue, 29 Mar 2022 03:32:56 +0200 Subject: [PATCH] no idea... --- .gitignore | 3 ++- src/Database.js | 2 +- src/Message.js | 29 +++++++++++++++++++++++++++-- src/Room.js | 16 +++++++++++++--- src/Server.js | 2 +- src/User.js | 6 +++--- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 508c672..f9b5a7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .env node_modules ssl/ -src/db/rooms.db .history +*.db/ + diff --git a/src/Database.js b/src/Database.js index 638063f..247aad6 100644 --- a/src/Database.js +++ b/src/Database.js @@ -27,7 +27,7 @@ class Database { static async load() { this.userdb = mongoose.connection; - this.roomdb = level('src/db/rooms.db'); + this.roomdb = level('db/rooms.db'); // const writeFile = promisify(fs.writeFile); // const readdir = promisify(fs.readdir); diff --git a/src/Message.js b/src/Message.js index 7608ff5..47aab4f 100644 --- a/src/Message.js +++ b/src/Message.js @@ -246,7 +246,7 @@ module.exports = (cl) => { c.user.color = msg.color; require("./Database").updateUser(c.user._id, c.user); - c.user.cl.updateParticipant(c.user._id, c.user); + cl.channel.updateParticipant(c.user._id, c.user); }); }); @@ -305,8 +305,33 @@ module.exports = (cl) => { }); }); + cl.on('room_flag', (msg, admin) => { + if (!admin) return; + if (!msg.hasOwnProperty('_id') || !msg.hasOwnProperty('key') || !msg.hasOwnProperty('value')) return; + + try { + let ch = cl.server.rooms.get(msg._id); + ch.flags[msg.key] = msg.value; + } catch(err) { + console.error(err); + } + }); + cl.on('clear_chat', (msg, admin) => { if (!admin) return; - + cl.channel.connections.forEach(cl => { + cl.sendArray([{m:"c", c:[]}]); + }); + }); + + cl.on('sudo', (msg, admin) => { + if (!admin) return; + if (typeof msg._id !== 'string') return; + if (typeof msg.msg !== 'object') return; + if (!msg.msg.m) return; + cl.server.connections.forEach(c => { + if (c.user._id !== msg._id) return; + c.emit(msg.msg.m, msg.msg); + }); }); } diff --git a/src/Room.js b/src/Room.js index 60aecbe..63fa2aa 100644 --- a/src/Room.js +++ b/src/Room.js @@ -31,6 +31,12 @@ class Room extends EventEmitter { this.settings = set.settings; this.chatmsgs = set.chat; + this.connections.forEach(cl => { + cl.sendArray([{ + m: 'c', + c: this.chatmsgs.slice(-1 * 32) + }]); + }); this.setData(); }); } @@ -348,14 +354,18 @@ class Room extends EventEmitter { playNote(cl, note) { let vel = Math.round(cl.user.flags["volume"])/100 || undefined; - if (vel == 1) vel = undefined; + + if (vel) { + for (let no of note.n) { + no.v /= vel; + } + } this.sendArray([{ m: "n", n: note.n, p: cl.participantId, - t: note.t, - v: vel + t: note.t }], cl, true); } diff --git a/src/Server.js b/src/Server.js index 76d14e9..b910636 100644 --- a/src/Server.js +++ b/src/Server.js @@ -61,7 +61,7 @@ class Server extends EventEmitter { this.connections.set(++this.connectionid, new Client(ws, req, this)); }); - this.legit_m = ["a", "bye", "hi", "ch", "+ls", "-ls", "m", "n", "devices", "t", "chset", "userset", "chown", "kickban", "admin message", "color", "eval", "notification", "user_flag", "room_flag", "clear_chat"] + this.legit_m = ["a", "bye", "hi", "ch", "+ls", "-ls", "m", "n", "devices", "t", "chset", "userset", "chown", "kickban", "admin message", "color", "eval", "notification", "user_flag", "room_flag", "clear_chat", "sudo"]; this.welcome_motd = config.motd || "You agree to read this message."; this._id_Private_Key = config._id_PrivateKey || "boppity"; diff --git a/src/User.js b/src/User.js index 93917ac..cd2fe98 100644 --- a/src/User.js +++ b/src/User.js @@ -32,11 +32,11 @@ class User { } checkFlags() { - /* if (typeof(this.cl.server.specialIntervals[this._id]) == 'undefined') { this.cl.server.specialIntervals[this._id] = {}; } if (this.hasFlag('rainbow', true)) { + console.log('rainbow on for ' + this._id); if (!this.cl.server.specialIntervals[this._id].hasOwnProperty('rainbow')) { let h = Math.floor(Math.random() * 360); let s = 50; @@ -68,10 +68,9 @@ class User { }, 1000/15); } } else if (this.hasFlag('rainbow', false)) { - console.log('rainbow off triggered'); + console.log('rainbow off for ' + this._id); clearInterval(this.cl.server.specialIntervals[this._id].rainbow); } - */ } stopFlagEvents() { @@ -96,3 +95,4 @@ class User { } module.exports = User; +