Added channel-kicks. added up disconnect message
This commit is contained in:
parent
796bb033a7
commit
5c30508e96
5 changed files with 30 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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({});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue