diff --git a/src/app/channel/channelManager.js b/src/app/channel/channelManager.js index 525c94f..cddc5dd 100644 --- a/src/app/channel/channelManager.js +++ b/src/app/channel/channelManager.js @@ -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; } } diff --git a/src/app/channel/connectedUser.js b/src/app/channel/connectedUser.js index 31fcadd..0484827 100644 --- a/src/app/channel/connectedUser.js +++ b/src/app/channel/connectedUser.js @@ -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({}); diff --git a/src/utils/loggerUtils.js b/src/utils/loggerUtils.js index 7e246c5..d55db00 100644 --- a/src/utils/loggerUtils.js +++ b/src/utils/loggerUtils.js @@ -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(); } \ No newline at end of file diff --git a/www/js/channel/channel.js b/www/js/channel/channel.js index 9169c2e..25b9951 100644 --- a/www/js/channel/channel.js +++ b/www/js/channel/channel.js @@ -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); diff --git a/www/js/channel/userlist.js b/www/js/channel/userlist.js index 9bce9f7..55b9c23 100644 --- a/www/js/channel/userlist.js +++ b/www/js/channel/userlist.js @@ -56,6 +56,10 @@ class userList{ this.client.socket.on('userList', (data) => { this.updateList(data); }); + + this.client.socket.on("disconnect", () => { + this.updateList([]); + }) } updateList(list){