highLevel syncs across chans, shows in userlist

This commit is contained in:
rainbow napkin 2024-12-03 20:27:37 -05:00
parent 279640a7e7
commit 8ccb9003cc
8 changed files with 102 additions and 38 deletions

View file

@ -28,15 +28,13 @@ module.exports = class{
defineListeners(socket){
socket.on("chatMessage", (data) => {this.relayChat(socket, data)});
socket.on("setFlair", async (data) => {this.setFlair(socket, data)});
socket.on("setFlair", (data) => {this.setFlair(socket, data)});
socket.on("setHighLevel", (data) => {this.setHighLevel(socket, data)});
}
relayChat(socket, data){
//Trim and Sanatize for XSS
const msg = validator.trim(validator.escape(data.msg));
//make sure high is an int
const high = validator.toInt(data.high);
const user = this.server.getSocketInfo(socket);
//nuke the message if its empty or huge
@ -44,12 +42,7 @@ module.exports = class{
return;
}
//nuke the message if the high number is wrong
if(high < 0 || high > 10){
return;
}
this.server.io.in(socket.chan).emit("chatMessage", {user: socket.user.user, flair: user.flair, high, msg});
this.server.io.in(socket.chan).emit("chatMessage", {user: user.user, flair: user.flair, highLevel: user.highLevel, msg});
}
async setFlair(socket, data){
@ -60,8 +53,10 @@ module.exports = class{
//We can take this data raw since our schema checks it against existing flairs, and mongoose sanatizes queries
const flairDB = await userDB.setFlair(data.flair);
//GetConnects across all channels
const connections = this.server.getConnections(socket.user.user);
//For each connection
connections.forEach((conn) => {
conn.updateFlair(flairDB.name);
});
@ -70,4 +65,27 @@ module.exports = class{
}
}
}
async setHighLevel(socket, data){
var userDB = await userModel.findOne({user: socket.user.user});
if(userDB){
try{
//Set high level
userDB.highLevel = data.highLevel;
//Save user DB Document
await userDB.save();
//GetConnects across all channels
const connections = this.server.getConnections(socket.user.user);
//For each connection
connections.forEach((conn) => {
conn.updateHighLevel(userDB.highLevel);
});
}catch(err){
return loggerUtils.socketExceptionHandler(socket, err);
}
}
}
}