fix stuff

This commit is contained in:
BopItFreak 2019-07-05 19:25:13 -04:00
parent 58291fb3a7
commit c094582f9e
4 changed files with 112 additions and 17 deletions

View File

@ -69,13 +69,21 @@ module.exports = (cl) => {
cl.on("a", msg => {
if (!(cl.channel && cl.participantId)) return;
if (!msg.hasOwnProperty('message')) return;
if (cl.channel.settings.chat) {
cl.channel.emit('a', cl, msg);
}
})
cl.on('n', msg => {
if (!(cl.channel && cl.participantId)) return;
if (!msg.hasOwnProperty('t') || !msg.hasOwnProperty('n')) return;
if (typeof msg.t != 'number' || typeof msg.n != 'object') return;
if (cl.channel.settings.crownsolo) {
if ((cl.channel.crown.userId == cl.user._id) && !cl.channel.crowndropped) {
cl.channel.playNote(cl, msg);
}
} else {
cl.channel.playNote(cl, msg);
}
})
cl.on('+ls', msg => {
if (!(cl.channel && cl.participantId)) return;
@ -86,7 +94,7 @@ module.exports = (cl) => {
if (room.bans.get(cl.user._id)) {
data.banned = true;
}
rooms.push(data);
if (room.settings.visible) rooms.push(data);
}
cl.sendArray([{
"m": "ls",
@ -110,9 +118,10 @@ module.exports = (cl) => {
if (!dbentry) return;
dbentry.name = msg.set.name;
user.updatedb();
console.log("Updateing user ", usr.name, msg.set.name);
cl.server.rooms.forEach((room) => {
room.updateParticipant(cl.participantId, {name: msg.set.name});
room.updateParticipant(cl.participantId, {
name: msg.set.name
});
})
})
@ -136,12 +145,10 @@ module.exports = (cl) => {
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) => {
@ -154,9 +161,10 @@ module.exports = (cl) => {
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});
room.updateParticipant(usr.participantId, {
color: msg.color
});
})
})
}

View File

@ -1 +1,87 @@
//noteQuota.js
class Quota {
constructor(cb) {
this.cb = cb;
this.setParams();
this.resetPoints();
};
static NQ_PARAMS_LOBBY = {
allowance: 200,
max: 600
};
static NQ_PARAMS_NORMAL = {
allowance: 400,
max: 1200
};
static NQ_PARAMS_RIDICULOUS = {
allowance: 600,
max: 1800
};
static NQ_PARAMS_OFFLINE = {
allowance: 8000,
max: 24000,
maxHistLen: 3
};
static CH_PARAMS = {
allowance: 8000,
max: 24000,
maxHistLen: 3
}
getParams() {
return {
m: "nq",
allowance: this.allowance,
max: this.max,
maxHistLen: this.maxHistLen
};
};
setParams(params) {
params = params || NoteQuota.PARAMS_OFFLINE;
var allowance = params.allowance || this.allowance || NoteQuota.PARAMS_OFFLINE.allowance;
var max = params.max || this.max || NoteQuota.PARAMS_OFFLINE.max;
var maxHistLen = params.maxHistLen || this.maxHistLen || NoteQuota.PARAMS_OFFLINE.maxHistLen;
if (allowance !== this.allowance || max !== this.max || maxHistLen !== this.maxHistLen) {
this.allowance = allowance;
this.max = max;
this.maxHistLen = maxHistLen;
this.resetPoints();
return true;
}
return false;
};
resetPoints() {
this.points = this.max;
this.history = [];
for (var i = 0; i < this.maxHistLen; i++)
this.history.unshift(this.points);
if (this.cb) this.cb(this.points);
};
tick() {
// keep a brief history
this.history.unshift(this.points);
this.history.length = this.maxHistLen;
// hook a brother up with some more quota
if (this.points < this.max) {
this.points += this.allowance;
if (this.points > this.max) this.points = this.max;
// fire callback
if (this.cb) this.cb(this.points);
}
};
spend(needed) {
// check whether aggressive limitation is needed
var sum = 0;
for (var i in this.history) {
sum += this.history[i];
}
if (sum <= 0) needed *= this.allowance;
// can they afford it? spend
if (this.points < needed) {
return false;
} else {
this.points -= needed;
if (this.cb) this.cb(this.points); // fire callback
return true;
}
};
}
module.exports = Quota;

View File

@ -13,7 +13,7 @@ class Room extends EventEmitter {
this.crowndropped = false;
this.settings = {
lobby: this.isLobby(_id),
visible: settings.visible || true,
visible: settings.visible,
crownsolo: settings.crownsolo || false,
chat: settings.chat || true,
color: this.verifyColor(settings.color) || this.getColor(_id),
@ -294,7 +294,7 @@ class Room extends EventEmitter {
m: "n",
n: note.n,
p: cl.participantId,
t: Date.now()
t: note.t
}], cl, true);
}
kickban(_id, ms) {

View File

@ -27,6 +27,7 @@ class Server extends EventEmitter {
this.adminpass = config.adminpass || "Bop It";
};
updateRoom(data) {
if (!data.ch.settings.visible) return;
for (let cl of Array.from(this.roomlisteners.values())) {
cl.sendArray([{
"m": "ls",