Fix lobby creation bug

This commit is contained in:
Charsy89 2019-11-19 22:08:47 -07:00
parent 93253a2bc9
commit a19f145ca4
3 changed files with 41 additions and 32 deletions

View File

@ -5,6 +5,16 @@ global.fs = require('fs');
global.createKeccakHash = require('keccak'); global.createKeccakHash = require('keccak');
const AsyncConsole = require('asyncconsole') 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 Server = require("./src/Server.js");
let config = require('./src/db/config.json'); let config = require('./src/db/config.json');
global.SERVER = new Server(config); global.SERVER = new Server(config);

View File

@ -55,15 +55,8 @@ module.exports = (cl) => {
cl.on("chset", msg => { cl.on("chset", msg => {
if (!(cl.channel && cl.participantId)) return; if (!(cl.channel && cl.participantId)) return;
if (!(cl.user._id == cl.channel.crown.userId)) return; if (!(cl.user._id == cl.channel.crown.userId)) return;
if (!msg.hasOwnProperty("set") || !msg.set) msg.set = {}; if (!msg.hasOwnProperty("set") || !msg.set) msg.set = cl.channel.verifySet(cl.channel._id,{});
let settings = {}; cl.channel.settings = msg.set;
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;
cl.channel.updateCh(); cl.channel.updateCh();
}) })
cl.on("a", msg => { cl.on("a", msg => {

View File

@ -11,14 +11,7 @@ class Room extends EventEmitter {
this.server = server; this.server = server;
this.crown = null; this.crown = null;
this.crowndropped = false; this.crowndropped = false;
this.settings = { this.settings = this.verifySet(this._id,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.chatmsgs = []; this.chatmsgs = [];
this.ppl = new Map(); this.ppl = new Map();
this.connections = []; this.connections = [];
@ -185,21 +178,6 @@ class Room extends EventEmitter {
return false; 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) { isLobby(_id) {
if (_id.startsWith("lobby")) { if (_id.startsWith("lobby")) {
let lobbynum = _id.split("lobby")[1]; let lobbynum = _id.split("lobby")[1];
@ -408,6 +386,34 @@ class Room extends EventEmitter {
this.chat(participant, msg); 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; module.exports = Room;