2019-06-06 19:22:43 +02:00
|
|
|
const User = require("./User.js");
|
|
|
|
const Room = require("./Room.js");
|
2019-06-09 20:10:25 +02:00
|
|
|
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;
|
|
|
|
})
|
2019-06-06 19:22:43 +02:00
|
|
|
})
|
2019-06-09 20:10:25 +02:00
|
|
|
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)
|
2019-06-07 23:10:38 +02:00
|
|
|
|
2019-06-09 20:10:25 +02:00
|
|
|
})
|
|
|
|
cl.on("chown", msg => {
|
|
|
|
if (!(cl.channel && cl.participantId)) return;
|
2019-06-09 21:05:52 +02:00
|
|
|
//console.log((Date.now() - cl.channel.crown.time))
|
|
|
|
//console.log(!(cl.channel.crown.userId != cl.user._id), !((Date.now() - cl.channel.crown.time) > 15000));
|
2019-06-09 20:10:25 +02:00
|
|
|
if (!(cl.channel.crown.userId == cl.user._id) && !((Date.now() - cl.channel.crown.time) > 15000)) return;
|
|
|
|
if (msg.hasOwnProperty("id")) {
|
2019-06-09 21:05:52 +02:00
|
|
|
// console.log(cl.channel.crown)
|
|
|
|
if (cl.user._id == cl.channel.crown.userId || cl.channel.crowndropped)
|
|
|
|
cl.channel.chown(msg.id);
|
2019-06-09 20:10:25 +02:00
|
|
|
} else {
|
2019-06-09 21:05:52 +02:00
|
|
|
if (cl.user._id == cl.channel.crown.userId || cl.channel.crowndropped)
|
|
|
|
cl.channel.chown();
|
2019-06-09 20:10:25 +02:00
|
|
|
}
|
|
|
|
})
|
2019-06-09 21:05:52 +02:00
|
|
|
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();
|
|
|
|
})
|
2019-06-06 19:22:43 +02:00
|
|
|
}
|