const User = require("./User.js"); const Room = require("./Room.js"); module.exports = (cl) => { cl.once("hi", () => { let user = new User(cl); user.getUserData().then((data) => { let msg = {}; msg.m = "hi"; msg.motd = cl.server.welcome_motd; msg.t = Date.now(); msg.u = data; msg.v = "1.0 Alpha"; cl.sendArray([msg]) cl.user = data; }) }) cl.on("t", msg => { if (msg.hasOwnProperty("e") && !isNaN(msg.e)) cl.sendArray([{ m: "t", t: Date.now(), e: msg.e }]) }) cl.on("ch", msg => { if (!msg.hasOwnProperty("set") || !msg.set) msg.set = {}; if (msg.hasOwnProperty("_id") && typeof msg._id == "string") { if (msg._id.length > 512) return; cl.setChannel(msg._id, msg.set); } }) cl.on("m", msg => { if (!(cl.channel && cl.participantId)) return; if (!msg.hasOwnProperty("x")) msg.x = null; if (!msg.hasOwnProperty("y")) msg.y = null; if (parseInt(msg.x) == NaN) msg.x = null; if (parseInt(msg.y) == NaN) msg.y = null; cl.channel.emit("m", cl, msg.x, msg.y) }) cl.on("chown", msg => { if (!(cl.channel && cl.participantId)) return; //console.log((Date.now() - cl.channel.crown.time)) //console.log(!(cl.channel.crown.userId != cl.user._id), !((Date.now() - cl.channel.crown.time) > 15000)); if (!(cl.channel.crown.userId == cl.user._id) && !((Date.now() - cl.channel.crown.time) > 15000)) return; if (msg.hasOwnProperty("id")) { // console.log(cl.channel.crown) if (cl.user._id == cl.channel.crown.userId || cl.channel.crowndropped) cl.channel.chown(msg.id); } else { if (cl.user._id == cl.channel.crown.userId || cl.channel.crowndropped) cl.channel.chown(); } }) 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; console.log(settings) cl.channel.updateCh(); }) }