Change channel checks in user.js

This commit is contained in:
calzoneman 2013-09-18 18:27:42 -05:00
parent 39fe452e96
commit 1d9845f6d5
2 changed files with 61 additions and 53 deletions

View File

@ -1,3 +1,7 @@
Wed Sep 18 18:26 2013 CDT
* lib/user.js: Change channel checks to include checking for whether
the channel is dead
Wed Sep 18 18:14 2013 CDT
* lib/channel.js: Add a bunch of checks to prevent callbacks from doing
things with a dead channel

View File

@ -47,6 +47,10 @@ var User = function(socket, Server) {
}
};
User.prototype.inChannel = function () {
return this.channel !== null && !this.channel.dead;
};
// Throttling/cooldown
User.prototype.noflood = function(name, hz) {
var time = new Date().getTime();
@ -82,7 +86,7 @@ User.prototype.noflood = function(name, hz) {
}
User.prototype.setAFK = function (afk) {
if(this.channel === null)
if(!this.inChannel())
return;
if(this.meta.afk === afk)
return;
@ -105,7 +109,7 @@ User.prototype.autoAFK = function () {
if(this.awaytimer)
clearTimeout(this.awaytimer);
if(this.channel === null || this.channel.opts.afk_timeout == 0)
if(!this.inChannel() || this.channel.opts.afk_timeout == 0)
return;
this.awaytimer = setTimeout(function () {
@ -117,12 +121,12 @@ User.prototype.initCallbacks = function() {
var self = this;
self.socket.on("disconnect", function() {
self.awaytimer && clearTimeout(self.awaytimer);
if(self.channel != null)
if(self.inChannel())
self.channel.userLeave(self);
});
self.socket.on("joinChannel", function(data) {
if(self.channel != null)
if(self.inChannel())
return;
if(typeof data.name != "string")
return;
@ -180,49 +184,49 @@ User.prototype.initCallbacks = function() {
});
self.socket.on("assignLeader", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryChangeLeader(self, data);
}
});
self.socket.on("promote", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryPromoteUser(self, data);
}
});
self.socket.on("demote", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryDemoteUser(self, data);
}
});
self.socket.on("setChannelRank", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.trySetRank(self, data);
}
});
self.socket.on("banName", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.banName(self, data.name || "");
}
});
self.socket.on("banIP", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryIPBan(self, data);
}
});
self.socket.on("unban", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryUnban(self, data);
}
});
self.socket.on("chatMsg", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
if(data.msg.indexOf("/afk") != 0) {
self.setAFK(false);
self.autoAFK();
@ -232,91 +236,91 @@ User.prototype.initCallbacks = function() {
});
self.socket.on("newPoll", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryOpenPoll(self, data);
}
});
self.socket.on("playerReady", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.sendMediaUpdate(self);
}
});
self.socket.on("requestPlaylist", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.sendPlaylist(self);
}
});
self.socket.on("queue", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryQueue(self, data);
}
});
self.socket.on("setTemp", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.trySetTemp(self, data);
}
});
self.socket.on("delete", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryDequeue(self, data);
}
});
self.socket.on("uncache", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryUncache(self, data);
}
});
self.socket.on("moveMedia", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryMove(self, data);
}
});
self.socket.on("jumpTo", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryJumpTo(self, data);
}
});
self.socket.on("playNext", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryPlayNext(self);
}
});
self.socket.on("clearPlaylist", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryClearqueue(self);
}
});
self.socket.on("shufflePlaylist", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryShufflequeue(self);
}
});
self.socket.on("togglePlaylistLock", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryToggleLock(self);
}
});
self.socket.on("mediaUpdate", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryUpdate(self, data);
}
});
self.socket.on("searchMedia", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
if(data.source == "yt") {
var searchfn = self.server.infogetter.Getters["ytSearch"];
searchfn(data.query.split(" "), function (e, vids) {
@ -337,19 +341,19 @@ User.prototype.initCallbacks = function() {
});
self.socket.on("closePoll", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryClosePoll(self);
}
});
self.socket.on("vote", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryVote(self, data);
}
});
self.socket.on("registerChannel", function(data) {
if(self.channel == null) {
if(!self.inChannel()) {
self.socket.emit("channelRegistration", {
success: false,
error: "You're not in any channel!"
@ -361,80 +365,80 @@ User.prototype.initCallbacks = function() {
});
self.socket.on("unregisterChannel", function() {
if(self.channel == null) {
if(!self.inChannel()) {
return;
}
self.channel.unregister(self);
});
self.socket.on("setOptions", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryUpdateOptions(self, data);
}
});
self.socket.on("setPermissions", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryUpdatePermissions(self, data);
}
});
self.socket.on("setChannelCSS", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.trySetCSS(self, data);
}
});
self.socket.on("setChannelJS", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.trySetJS(self, data);
}
});
self.socket.on("updateFilter", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryUpdateFilter(self, data);
}
});
self.socket.on("removeFilter", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryRemoveFilter(self, data);
}
});
self.socket.on("moveFilter", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryMoveFilter(self, data);
}
});
self.socket.on("setMotd", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryUpdateMotd(self, data);
}
});
self.socket.on("requestLoginHistory", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.sendLoginHistory(self);
}
});
self.socket.on("requestBanlist", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.sendBanlist(self);
}
});
self.socket.on("requestChatFilters", function() {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.sendChatFilters(self);
}
});
self.socket.on("requestChannelRanks", function() {
if(self.channel != null) {
if(self.inChannel()) {
if(self.noflood("requestChannelRanks", 0.25))
return;
self.channel.sendChannelRanks(self);
@ -442,7 +446,7 @@ User.prototype.initCallbacks = function() {
});
self.socket.on("voteskip", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryVoteskip(self);
}
});
@ -477,7 +481,7 @@ User.prototype.initCallbacks = function() {
return;
}
if(self.channel == null) {
if(!self.inChannel()) {
self.socket.emit("savePlaylist", {
success: false,
error: "Not in a channel"
@ -519,7 +523,7 @@ User.prototype.initCallbacks = function() {
});
self.socket.on("queuePlaylist", function(data) {
if(self.channel != null) {
if(self.inChannel()) {
self.channel.tryQueuePlaylist(self, data);
}
});
@ -546,7 +550,7 @@ User.prototype.initCallbacks = function() {
});
self.socket.on("readChanLog", function () {
if(self.channel !== null) {
if(self.inChannel()) {
self.channel.tryReadLog(self);
}
});
@ -564,7 +568,7 @@ User.prototype.initCallbacks = function() {
self.rank = rank;
self.socket.emit("rank", rank);
if(self.channel != null)
if(self.inChannel())
self.channel.broadcastUserUpdate(self);
});
@ -615,7 +619,7 @@ User.prototype.login = function(name, pw, session) {
return;
}
if(self.channel != null) {
if(self.inChannel()) {
for(var i = 0; i < self.channel.users.length; i++) {
if(self.channel.users[i].name == name) {
self.socket.emit("login", {
@ -637,7 +641,7 @@ User.prototype.login = function(name, pw, session) {
name: name
});
self.socket.emit("rank", self.rank);
if(self.channel != null) {
if(self.inChannel()) {
self.channel.logger.log(self.ip + " signed in as " + name);
self.channel.broadcastNewUser(self);
}
@ -654,7 +658,7 @@ User.prototype.login = function(name, pw, session) {
});
return;
}
if(self.channel !== null && !self.channel.dead) {
if(self.inChannel()) {
for(var i = 0; i < self.channel.users.length; i++) {
if(self.channel.users[i].name.toLowerCase() == name.toLowerCase()) {
if (self.channel.users[i] == self) {
@ -685,13 +689,13 @@ User.prototype.login = function(name, pw, session) {
var afterRankLookup = function () {
self.socket.emit("rank", self.rank);
self.name = name;
if(self.channel != null) {
if(self.inChannel()) {
self.channel.logger.log(self.ip + " logged in as " +
name);
self.channel.broadcastNewUser(self);
}
};
if(self.channel !== null) {
if(self.inChannel()) {
self.channel.getRank(name, function (err, rank) {
if(!err) {
self.saverank = true;