Added channel-kicks. added up disconnect message
This commit is contained in:
parent
796bb033a7
commit
5c30508e96
|
|
@ -59,7 +59,8 @@ module.exports = class{
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//Toss out anon's
|
//Toss out anon's
|
||||||
socket.disconnect("Unauthenticated");
|
socket.emit("kick", {type: "Unauthorized", reason: "You must log-in to join this channel!"});
|
||||||
|
socket.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,26 @@ module.exports = class{
|
||||||
this.sockets = [socket.id];
|
this.sockets = [socket.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(eventName, args){
|
socketCrawl(cb){
|
||||||
//Crawl through user's sockets (lol)
|
//Crawl through user's sockets (lol)
|
||||||
this.sockets.forEach((sockid) => {
|
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);
|
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(){
|
async sendClientMetadata(){
|
||||||
//Get flairList from DB and setup flairList array
|
//Get flairList from DB and setup flairList array
|
||||||
const flairListDB = await flairModel.find({});
|
const flairListDB = await flairModel.find({});
|
||||||
|
|
|
||||||
|
|
@ -28,5 +28,6 @@ module.exports.socketExceptionHandler = function(socket, err){
|
||||||
|
|
||||||
module.exports.socketCriticalExceptionHandler = 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.
|
//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();
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +43,14 @@ class channel{
|
||||||
document.title = `${this.channelName} - Connected`
|
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("clientMetadata", this.handleClientInfo.bind(this));
|
||||||
|
|
||||||
this.socket.on("error", console.log);
|
this.socket.on("error", console.log);
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,10 @@ class userList{
|
||||||
this.client.socket.on('userList', (data) => {
|
this.client.socket.on('userList', (data) => {
|
||||||
this.updateList(data);
|
this.updateList(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.client.socket.on("disconnect", () => {
|
||||||
|
this.updateList([]);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
updateList(list){
|
updateList(list){
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue