From 1602896928aeba1a0993158c7c92276e064c2dcd Mon Sep 17 00:00:00 2001 From: Chars chan <28523197+Charsy89@users.noreply.github.com> Date: Tue, 19 Nov 2019 19:46:15 -0700 Subject: [PATCH 1/4] Use newer isLobby --- src/Room.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Room.js b/src/Room.js index 818294b..efb0475 100644 --- a/src/Room.js +++ b/src/Room.js @@ -202,13 +202,19 @@ class Room extends EventEmitter { } isLobby(_id) { if (_id.startsWith("lobby")) { + let lobbynum = _id.split("lobby")[1]; if (_id == "lobby") { return true; - } else if (parseFloat(_id.split("lobby")[1] % 1) === 0) { - return true; - } else { - return false; - } + } + if (!(parseInt(lobbynum).toString() == lobbynum)) return false; + for (let i in lobbynum) { + if (parseInt(lobbynum[i]) >= 0) { + if (parseInt(i) + 1 == lobbynum.length) return true; + + } else { + return false; + } + } } else if (_id.startsWith("test/")) { if (_id == "test/") { return false; From ae93af21439eb2c18f388ea2c533155f7010f4e5 Mon Sep 17 00:00:00 2001 From: Charsy89 Date: Tue, 19 Nov 2019 22:08:47 -0700 Subject: [PATCH 2/4] Fix lobby creation bug --- index.js | 10 ++++++++++ src/Message.js | 11 ++--------- src/Room.js | 52 ++++++++++++++++++++++++++++---------------------- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index 18e9de6..62db0b2 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,16 @@ global.fs = require('fs'); global.createKeccakHash = require('keccak'); const AsyncConsole = require('asyncconsole') +global.isString = function(a){ + return typeof a === 'string'; +} +global.isBool = function(a){ + return typeof a === 'boolean'; +} +global.isObj = function(a){ + return typeof a === "object" && !Array.isArray(a) && a !== null; +} + let Server = require("./src/Server.js"); let config = require('./src/db/config.json'); global.SERVER = new Server(config); diff --git a/src/Message.js b/src/Message.js index 97bcfbd..b8b79d9 100644 --- a/src/Message.js +++ b/src/Message.js @@ -55,15 +55,8 @@ module.exports = (cl) => { cl.on("chset", msg => { if (!(cl.channel && cl.participantId)) return; if (!(cl.user._id == cl.channel.crown.userId)) return; - if (!msg.hasOwnProperty("set") || !msg.set) msg.set = {}; - let settings = {}; - settings.lobby = cl.channel.isLobby(cl.channel._id); - settings.visible = !!msg.set.visible; - settings.crownsolo = !!msg.set.crownsolo; - settings.chat = !!msg.set.chat; - settings.color = cl.channel.verifyColor(msg.set.color) || cl.channel.settings.color; - settings.color2 = cl.channel.verifyColor(msg.set.color2) || cl.channel.settings.color2; - cl.channel.settings = settings; + if (!msg.hasOwnProperty("set") || !msg.set) msg.set = cl.channel.verifySet(cl.channel._id,{}); + cl.channel.settings = msg.set; cl.channel.updateCh(); }) cl.on("a", msg => { diff --git a/src/Room.js b/src/Room.js index efb0475..a3019f1 100644 --- a/src/Room.js +++ b/src/Room.js @@ -11,14 +11,7 @@ class Room extends EventEmitter { this.server = server; this.crown = null; this.crowndropped = false; - this.settings = { - lobby: this.isLobby(_id), - visible: settings.hasOwnProperty('visible') ? settings.visible : true, - crownsolo: settings.crownsolo || false, - chat: settings.chat || true, - color: this.verifyColor(settings.color) || this.getColor(_id), - color2: this.verifyColor(settings.color) || this.getColor2(_id) - } + this.settings = this.verifySet(this._id,settings); this.chatmsgs = []; this.ppl = new Map(); this.connections = []; @@ -184,21 +177,6 @@ class Room extends EventEmitter { } else{ return false; } - } - getColor(_id) { - if (this.isLobby(_id)) { - return this.server.defaultLobbyColor; - } else { - return this.server.defaultRoomColor; - } - } - getColor2(_id) { - if (this.isLobby(_id)) { - return this.server.defaultLobbyColor2; - } else { - return; - delete this.settings.color2; - } } isLobby(_id) { if (_id.startsWith("lobby")) { @@ -408,6 +386,34 @@ class Room extends EventEmitter { this.chat(participant, msg); }) } + verifySet(_id,msg){ + if(!isObj(msg.set)) msg.set = {visible:true,color:this.server.defaultRoomColor,chat:true,crownsolo:false}; + if(isBool(msg.set.lobby)){ + if(!this.isLobby(_id)) delete msg.set.lobby; // keep it nice and clean + }else{ + if(this.isLobby(_id)) msg.set = {visible:true,color:this.server.defaultLobbyColor,color2:this.server.defaultLobbyColor2,chat:true,crownsolo:false,lobby:true}; + } + if(!isBool(msg.set.visible)){ + if(msg.set.visible == undefined) msg.set.visible = (room.settings.visible || true); + else msg.set.visible = true; + }; + if(!isBool(msg.set.chat)){ + if(msg.set.chat == undefined) msg.set.chat = (room.settings.chat || true); + else msg.set.chat = true; + }; + if(!isBool(msg.set.crownsolo)){ + if(msg.set.crownsolo == undefined) msg.set.crownsolo = (room.settings.crownsolo || false); + else msg.set.crownsolo = false; + }; + if(!isString(msg.set.color) || !/^#[0-9a-f]{6}$/i.test(msg.set.color)) msg.set.color = (room.settings.color || this.server.defaultRoomColor); + if(isString(msg.set.color2)){ + if(!/^#[0-9a-f]{6}$/i.test(msg.set.color2)){ + if(room.settings.color2) msg.set.color2 = room.settings.color2; + else delete msg.set.color2; // keep it nice and clean + } + }; + return msg.set; + } } module.exports = Room; From e27484a0398ef33020accc52c5a53c2fc8761345 Mon Sep 17 00:00:00 2001 From: Charsy89 Date: Wed, 20 Nov 2019 16:11:11 -0700 Subject: [PATCH 3/4] Fix verifySet, give msg syntax --- src/Room.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Room.js b/src/Room.js index a3019f1..e3322d5 100644 --- a/src/Room.js +++ b/src/Room.js @@ -11,7 +11,7 @@ class Room extends EventEmitter { this.server = server; this.crown = null; this.crowndropped = false; - this.settings = this.verifySet(this._id,settings); + this.settings = this.verifySet(this._id,{set:settings}); this.chatmsgs = []; this.ppl = new Map(); this.connections = []; @@ -102,7 +102,6 @@ class Room extends EventEmitter { options.name ? this.ppl.get(pid).user.name = options.name : {}; options._id ? this.ppl.get(pid).user._id = options._id : {}; options.color ? this.ppl.get(pid).user.color = options.color : {}; - options.name ? this.ppl.get(pid).user.name = options.name : {}; this.connections.filter((ofo) => ofo.participantId == p.participantId).forEach((usr) => { options.name ? usr.user.name = options.name : {}; options._id ? usr.user._id = options._id : {}; @@ -394,21 +393,21 @@ class Room extends EventEmitter { if(this.isLobby(_id)) msg.set = {visible:true,color:this.server.defaultLobbyColor,color2:this.server.defaultLobbyColor2,chat:true,crownsolo:false,lobby:true}; } if(!isBool(msg.set.visible)){ - if(msg.set.visible == undefined) msg.set.visible = (room.settings.visible || true); + if(msg.set.visible == undefined) msg.set.visible = (!isObj(this.settings) ? true : this.settings.visible); else msg.set.visible = true; }; if(!isBool(msg.set.chat)){ - if(msg.set.chat == undefined) msg.set.chat = (room.settings.chat || true); + if(msg.set.chat == undefined) msg.set.chat = (!isObj(this.settings) ? true : this.settings.chat); else msg.set.chat = true; }; if(!isBool(msg.set.crownsolo)){ - if(msg.set.crownsolo == undefined) msg.set.crownsolo = (room.settings.crownsolo || false); + if(msg.set.crownsolo == undefined) msg.set.crownsolo = (!isObj(this.settings) ? false : this.settings.crownsolo); else msg.set.crownsolo = false; }; - if(!isString(msg.set.color) || !/^#[0-9a-f]{6}$/i.test(msg.set.color)) msg.set.color = (room.settings.color || this.server.defaultRoomColor); + if(!isString(msg.set.color) || !/^#[0-9a-f]{6}$/i.test(msg.set.color)) msg.set.color = (!isObj(this.settings) ? this.server.defaultRoomColor : this.settings.color); if(isString(msg.set.color2)){ if(!/^#[0-9a-f]{6}$/i.test(msg.set.color2)){ - if(room.settings.color2) msg.set.color2 = room.settings.color2; + if(this.settings.color2) msg.set.color2 = this.settings.color2; else delete msg.set.color2; // keep it nice and clean } }; From effb568b51706cec6f167a828d9d610a63d230ec Mon Sep 17 00:00:00 2001 From: Charsy89 Date: Wed, 20 Nov 2019 16:13:20 -0700 Subject: [PATCH 4/4] gha forgot color2 --- src/Room.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Room.js b/src/Room.js index e3322d5..f6f6520 100644 --- a/src/Room.js +++ b/src/Room.js @@ -407,8 +407,10 @@ class Room extends EventEmitter { if(!isString(msg.set.color) || !/^#[0-9a-f]{6}$/i.test(msg.set.color)) msg.set.color = (!isObj(this.settings) ? this.server.defaultRoomColor : this.settings.color); if(isString(msg.set.color2)){ if(!/^#[0-9a-f]{6}$/i.test(msg.set.color2)){ - if(this.settings.color2) msg.set.color2 = this.settings.color2; - else delete msg.set.color2; // keep it nice and clean + if(this.settings){ + if(this.settings.color2) msg.set.color2 = this.settings.color2; + else delete msg.set.color2; // keep it nice and clean + } } }; return msg.set;