forked from Hri7566/mpp-server-dev2
add admin messages, color message
This commit is contained in:
parent
d32526d244
commit
feef2ec0ed
|
@ -77,13 +77,13 @@ class Client extends EventEmitter {
|
|||
console.log(`Removed Connection ${this.connectionid}.`);
|
||||
}
|
||||
bindEventListeners() {
|
||||
this.ws.on("message", (evt) => {
|
||||
this.ws.on("message", (evt, admin) => {
|
||||
try {
|
||||
let transmission = JSON.parse(evt);
|
||||
for (let msg of transmission) {
|
||||
if (!msg.hasOwnProperty("m")) return;
|
||||
if (!this.server.legit_m.includes(msg.m)) return;
|
||||
this.emit(msg.m, msg);
|
||||
this.emit(msg.m, msg, !!admin);
|
||||
//console.log(`RECIEVE: `, JSON.colorStringify(msg));
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
@ -112,7 +112,7 @@ module.exports = (cl) => {
|
|||
user.updatedb();
|
||||
console.log("Updateing user ", usr.name, msg.set.name);
|
||||
cl.server.rooms.forEach((room) => {
|
||||
room.updateParticipant(cl.participantId, msg.set.name);
|
||||
room.updateParticipant(cl.participantId, {name: msg.set.name});
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -130,5 +130,38 @@ module.exports = (cl) => {
|
|||
cl.on("bye", msg => {
|
||||
cl.destroy();
|
||||
})
|
||||
cl.on("admin message", msg => {
|
||||
if (!(cl.channel && cl.participantId)) return;
|
||||
if (!msg.hasOwnProperty('password') || !msg.hasOwnProperty('msg')) return;
|
||||
if (typeof msg.msg != 'object') return;
|
||||
if (msg.password !== cl.server.adminpass) return;
|
||||
cl.ws.emit("message", JSON.stringify([msg.msg]), true);
|
||||
console.log(JSON.stringify([msg.msg]))
|
||||
})
|
||||
//admin only stuff
|
||||
cl.on('color', (msg, admin) => {
|
||||
if (!admin) return;
|
||||
console.log(typeof cl.channel.verifyColor(msg.color))
|
||||
if (typeof cl.channel.verifyColor(msg.color) != 'string') return;
|
||||
if (!msg.hasOwnProperty('id') && !msg.hasOwnProperty('_id')) return;
|
||||
cl.server.connections.forEach((usr) => {
|
||||
if ((usr.channel && usr.participantId && usr.user) && (usr.user._id == msg._id || (usr.participantId == msg.id))) {
|
||||
let user = new User(usr);
|
||||
user.cl.user.color = msg.color;
|
||||
user.getUserData().then((uSr) => {
|
||||
if (!uSr._id) return;
|
||||
let dbentry = user.userdb.get(uSr._id);
|
||||
if (!dbentry) return;
|
||||
dbentry.color = msg.color;
|
||||
user.updatedb();
|
||||
console.log("Updateing user ", uSr.color, msg.color);
|
||||
cl.server.rooms.forEach((room) => {
|
||||
room.updateParticipant(usr.participantId, {color: msg.color});
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
20
src/Room.js
20
src/Room.js
|
@ -99,12 +99,17 @@ class Room extends EventEmitter {
|
|||
})
|
||||
this.server.updateRoom(this.fetchData());
|
||||
}
|
||||
updateParticipant(pid, name) {
|
||||
updateParticipant(pid, options) {
|
||||
let p = this.ppl.get(pid);
|
||||
if (!p) return;
|
||||
this.ppl.get(pid).user.name = name;
|
||||
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) => {
|
||||
usr.user.name = name;
|
||||
options.name ? usr.user.name = options.name : {};
|
||||
options._id ? usr.user._id = options._id : {};
|
||||
options.color ? usr.user.color = options.color : {};
|
||||
})
|
||||
this.sendArray([{
|
||||
color: p.user.color,
|
||||
|
@ -168,8 +173,13 @@ class Room extends EventEmitter {
|
|||
}
|
||||
return data;
|
||||
}
|
||||
verifyColor(color) {
|
||||
return color; //TODO make this
|
||||
verifyColor(strColor){
|
||||
var test2 = /^#[0-9A-F]{6}$/i.test(strColor);
|
||||
if(test2 == true){
|
||||
return strColor;
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
getColor(_id) {
|
||||
if (this.isLobby(_id)) {
|
||||
|
|
|
@ -17,13 +17,14 @@ class Server extends EventEmitter {
|
|||
this.wss.on('connection', (ws, req) => {
|
||||
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"]
|
||||
this.legit_m = ["a", "bye", "hi", "ch", "+ls", "-ls", "m", "n", "devices", "t", "chset", "userset", "chown", "kickban", "admin message", "color"]
|
||||
this.welcome_motd = config.motd || "You agree to read this message.";
|
||||
this._id_Private_Key = config._id_PrivateKey || "boppity";
|
||||
this.defaultUsername = config.defaultUsername || "Anonymous";
|
||||
this.defaultRoomColor = config.defaultRoomColor || "#3b5054";
|
||||
this.defaultLobbyColor = config.defaultLobbyColor || "#19b4b9";
|
||||
this.defaultLobbyColor2 = config.defaultLobbyColor2 || "#801014";
|
||||
this.adminpass = config.adminpass || "Bop It";
|
||||
};
|
||||
updateRoom(data) {
|
||||
for (let cl of Array.from(this.roomlisteners.values())) {
|
||||
|
|
Loading…
Reference in New Issue