Added channel-kicks. added up disconnect message

This commit is contained in:
rainbow napkin 2024-11-27 03:02:58 -05:00
parent 796bb033a7
commit 5c30508e96
5 changed files with 30 additions and 5 deletions

View file

@ -59,7 +59,8 @@ module.exports = class{
}
}else{
//Toss out anon's
socket.disconnect("Unauthenticated");
socket.emit("kick", {type: "Unauthorized", reason: "You must log-in to join this channel!"});
socket.disconnect();
return;
}
}

View file

@ -29,15 +29,26 @@ module.exports = class{
this.sockets = [socket.id];
}
emit(eventName, args){
socketCrawl(cb){
//Crawl through user's sockets (lol)
this.sockets.forEach((sockid) => {
//Send event out to each one
//get socket based on ID
const socket = this.channel.server.io.sockets.sockets.get(sockid);
socket.emit(eventName, args);
//Callback with socket
cb(socket);
});
}
emit(eventName, args){
this.socketCrawl((socket)=>{socket.emit(eventName, args)});
}
//generic disconnect function, defaults to kick
disconnect(reason, type = "kick"){
this.emit("kick",{type, reason});
this.socketCrawl((socket)=>{socket.disconnect()});
}
async sendClientMetadata(){
//Get flairList from DB and setup flairList array
const flairListDB = await flairModel.find({});

View file

@ -28,5 +28,6 @@ module.exports.socketExceptionHandler = function(socket, err){
module.exports.socketCriticalExceptionHandler = function(socket, err){
//if not yell at the browser for fucking up, and tell it what it did wrong.
return socket.disconnect("error", {errors: [{type: "Caught Exception", msg: err.message, date: new Date()}]});
socket.emit("kick", {type: "error", reason: err.message});
return socket.disconnect();
}

View file

@ -43,6 +43,14 @@ class channel{
document.title = `${this.channelName} - Connected`
});
this.socket.on("kick", (data) => {
if(data.type == "kick"){
window.alert(`You have been kicked from the channel for the following reason:\n\n${data.reason}`);
}else{
window.alert(`You have been disconnceted from the channel by the server!\nType: ${data.type}\nReason: ${data.reason}`);
}
});
this.socket.on("clientMetadata", this.handleClientInfo.bind(this));
this.socket.on("error", console.log);

View file

@ -56,6 +56,10 @@ class userList{
this.client.socket.on('userList', (data) => {
this.updateList(data);
});
this.client.socket.on("disconnect", () => {
this.updateList([]);
})
}
updateList(list){