diff --git a/.env b/.env index 866b19c..28e4f74 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ ADMINPASS=burgerass SALT=๖ۣۜH͜r̬i͡7566 -MONGO_URL=mongodb://127.0.0.1/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false +MONGO_URL=mongodb://7566:Phillies11@127.0.0.1/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false SSL=true diff --git a/config.js b/config.js index 727305a..a9ee164 100644 --- a/config.js +++ b/config.js @@ -4,10 +4,13 @@ module.exports = Object.seal({ _id_PrivateKey: process.env.SALT, defaultUsername: "Anonymous", // defaultRoomColor: "#3b5054", + defaultRoomColor: "#480505", // defaultLobbyColor: "#19b4b9", - defaultLobbyColor: "#76b0db", + // defaultLobbyColor: "#76b0db", // defaultLobbyColor2: "#801014", - defaultLobbyColor2: "#276491", + // defaultLobbyColor2: "#276491", + defaultLobbyColor: "#9900ff", + defaultLobbyColor2: "#5900af", adminpass: process.env.ADMINPASS, ssl: process.env.SSL, defaultRoomSettings: { diff --git a/src/Channel.js b/src/Channel.js index cba1eed..415c639 100644 --- a/src/Channel.js +++ b/src/Channel.js @@ -10,7 +10,7 @@ const Notification = require('./Notification'); class Channel extends EventEmitter { constructor(server, _id, settings) { super(); - this.logger = new Logger(`Room - ${ftc.normalise(_id)}`); + this.logger = new Logger(`Room - ${_id}`); this._id = _id; this.server = server; this.crown; @@ -23,6 +23,7 @@ class Channel extends EventEmitter { this.server.rooms.set(_id, this); this.bans = new Map(); this.flags = {} + this.destroyed = false; this.logger.log('Created'); @@ -191,7 +192,9 @@ class Channel extends EventEmitter { } destroy() { //destroy room + if (this.destroyed) return; if (this.ppl.size > 0) return; + this.destroyed = true; this._id; console.log(`Deleted room ${this._id}`); this.settings = undefined; diff --git a/src/Client.js b/src/Client.js index c4fac69..c13de7a 100644 --- a/src/Client.js +++ b/src/Client.js @@ -15,6 +15,8 @@ class Client extends EventEmitter { this.server = server; this.participantId; this.channel; + this.isSubscribedToAdminStream = false; + this.adminStreamInterval; this.staticQuotas = { room: new RateLimit(quotas.room.time) @@ -152,6 +154,22 @@ class Client extends EventEmitter { } }); } + + sendAdminData() { + let data = {}; + data.m = "data"; + + let channels = []; + this.server.rooms.forEach(ch => { + channels.push(ch.fetchChannelData()); + }); + + data.channelManager = { + channels + }; + + this.sendArray([data]); + } } module.exports = Client; diff --git a/src/Message.js b/src/Message.js index 72aea81..f00d773 100644 --- a/src/Message.js +++ b/src/Message.js @@ -334,6 +334,28 @@ module.exports = (cl) => { }); cl.on('subscribe to admin stream', (msg, admin) => { - if (!admin) return; + // if (!admin) return; + if (!('password' in msg)) return; + if (msg.password !== cl.server.adminpass) return; + cl.isSubscribedToAdminStream = true; + let interval = 8000; + if ('interval_ms' in msg) interval = msg['interval_ms']; + cl.adminStreamInterval = setInterval(() => { + if (cl.isSubscribedToAdminStream == true) cl.sendAdminData(); + }, interval); + }); + + cl.on('unsubscribe from admin stream', (msg, admin) => { + // if (!admin) return; + if (!('password' in msg)) return; + if (msg.password !== cl.server.adminpass) return; + cl.isSubscribedToAdminStream = false; + if (cl.adminStreamInterval) { + clearInterval(cl.adminStreamInterval); + cl.adminStreamInterval = undefined; + while (cl.adminStreamInterval !== undefined) { + cl.adminStreamInterval = undefined; + } + } }); } diff --git a/src/Server.js b/src/Server.js index b910636..4f19cdc 100644 --- a/src/Server.js +++ b/src/Server.js @@ -61,12 +61,39 @@ 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", "sudo"]; + 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", + "subscribe to admin stream", + "unsubscribe from admin stream", + "data" + ]; + this.welcome_motd = config.motd || "You agree to read this message."; - this._id_Private_Key = config._id_PrivateKey || "boppity"; + this._id_Private_Key = config._id_PrivateKey || "amogus"; - this.adminpass = config.adminpass || "Bop It"; + this.adminpass = config.adminpass || "123123sucks"; } updateRoom(data) {