mirror of https://github.com/calzoneman/sync.git
Code style cleanup on user.js
This commit is contained in:
parent
379522f2df
commit
6e18e25139
|
@ -1,3 +1,6 @@
|
||||||
|
Thu Sep 26 13:29 2013 CDT
|
||||||
|
* lib/user.js: Some code style cleanup
|
||||||
|
|
||||||
Thu Sep 26 13:17 2013 CDT
|
Thu Sep 26 13:17 2013 CDT
|
||||||
* lib/user.js: A few minor cleanups to login functions
|
* lib/user.js: A few minor cleanups to login functions
|
||||||
* lib/api.js: Pass the login failure reason to the action log
|
* lib/api.js: Pass the login failure reason to the action log
|
||||||
|
|
327
lib/user.js
327
lib/user.js
|
@ -15,7 +15,7 @@ var Logger = require("./logger.js");
|
||||||
var $util = require("./utilities");
|
var $util = require("./utilities");
|
||||||
|
|
||||||
// Represents a client connected via socket.io
|
// Represents a client connected via socket.io
|
||||||
var User = function(socket, Server) {
|
var User = function (socket, Server) {
|
||||||
this.ip = socket._ip;
|
this.ip = socket._ip;
|
||||||
this.server = Server;
|
this.server = Server;
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
|
@ -42,7 +42,7 @@ var User = function(socket, Server) {
|
||||||
this.autoAFK();
|
this.autoAFK();
|
||||||
|
|
||||||
this.initCallbacks();
|
this.initCallbacks();
|
||||||
if(Server.announcement != null) {
|
if (Server.announcement !== null) {
|
||||||
this.socket.emit("announcement", Server.announcement);
|
this.socket.emit("announcement", Server.announcement);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -52,27 +52,25 @@ User.prototype.inChannel = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Throttling/cooldown
|
// Throttling/cooldown
|
||||||
User.prototype.noflood = function(name, hz) {
|
User.prototype.noflood = function (name, hz) {
|
||||||
var time = new Date().getTime();
|
var time = new Date().getTime();
|
||||||
if(!(name in this.throttle)) {
|
if (!(name in this.throttle)) {
|
||||||
this.throttle[name] = [time];
|
this.throttle[name] = [time];
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (name in this.flooded && time < this.flooded[name]) {
|
||||||
else if(name in this.flooded && time < this.flooded[name]) {
|
|
||||||
this.socket.emit("noflood", {
|
this.socket.emit("noflood", {
|
||||||
action: name,
|
action: name,
|
||||||
msg: "You're still on cooldown!"
|
msg: "You're still on cooldown!"
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.throttle[name].push(time);
|
this.throttle[name].push(time);
|
||||||
var diff = (time - this.throttle[name][0]) / 1000.0;
|
var diff = (time - this.throttle[name][0]) / 1000.0;
|
||||||
// Twice might be an accident, more than that is probably spam
|
// Twice might be an accident, more than that is probably spam
|
||||||
if(this.throttle[name].length > 2) {
|
if (this.throttle[name].length > 2) {
|
||||||
var rate = this.throttle[name].length / diff;
|
var rate = this.throttle[name].length / diff;
|
||||||
this.throttle[name] = [time];
|
this.throttle[name] = [time];
|
||||||
if(rate > hz) {
|
if (rate > hz) {
|
||||||
this.flooded[name] = time + 5000;
|
this.flooded[name] = time + 5000;
|
||||||
this.socket.emit("noflood", {
|
this.socket.emit("noflood", {
|
||||||
action: name,
|
action: name,
|
||||||
|
@ -83,17 +81,17 @@ User.prototype.noflood = function(name, hz) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
User.prototype.setAFK = function (afk) {
|
User.prototype.setAFK = function (afk) {
|
||||||
if(!this.inChannel())
|
if (!this.inChannel())
|
||||||
return;
|
return;
|
||||||
if(this.meta.afk === afk)
|
if (this.meta.afk === afk)
|
||||||
return;
|
return;
|
||||||
var chan = this.channel;
|
var chan = this.channel;
|
||||||
this.meta.afk = afk;
|
this.meta.afk = afk;
|
||||||
if(afk) {
|
if (afk) {
|
||||||
if(chan.voteskip)
|
if (chan.voteskip)
|
||||||
chan.voteskip.unvote(this.ip);
|
chan.voteskip.unvote(this.ip);
|
||||||
} else {
|
} else {
|
||||||
this.autoAFK();
|
this.autoAFK();
|
||||||
|
@ -103,34 +101,35 @@ User.prototype.setAFK = function (afk) {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
afk: afk
|
afk: afk
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
User.prototype.autoAFK = function () {
|
User.prototype.autoAFK = function () {
|
||||||
if(this.awaytimer)
|
var self = this;
|
||||||
clearTimeout(this.awaytimer);
|
if (self.awaytimer)
|
||||||
|
clearTimeout(self.awaytimer);
|
||||||
|
|
||||||
if(!this.inChannel() || this.channel.opts.afk_timeout == 0)
|
if (!self.inChannel() || self.channel.opts.afk_timeout === 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.awaytimer = setTimeout(function () {
|
self.awaytimer = setTimeout(function () {
|
||||||
this.setAFK(true);
|
self.setAFK(true);
|
||||||
}.bind(this), this.channel.opts.afk_timeout * 1000);
|
}, self.channel.opts.afk_timeout * 1000);
|
||||||
}
|
};
|
||||||
|
|
||||||
User.prototype.initCallbacks = function() {
|
User.prototype.initCallbacks = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.socket.on("disconnect", function() {
|
self.socket.on("disconnect", function () {
|
||||||
self.awaytimer && clearTimeout(self.awaytimer);
|
self.awaytimer && clearTimeout(self.awaytimer);
|
||||||
if(self.inChannel())
|
if (self.inChannel())
|
||||||
self.channel.userLeave(self);
|
self.channel.userLeave(self);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("joinChannel", function(data) {
|
self.socket.on("joinChannel", function (data) {
|
||||||
if(self.inChannel())
|
if (self.inChannel())
|
||||||
return;
|
return;
|
||||||
if(typeof data.name != "string")
|
if (typeof data.name != "string")
|
||||||
return;
|
return;
|
||||||
if(!data.name.match(/^[\w-_]{1,30}$/)) {
|
if (!data.name.match(/^[\w-_]{1,30}$/)) {
|
||||||
self.socket.emit("errorMsg", {
|
self.socket.emit("errorMsg", {
|
||||||
msg: "Invalid channel name. Channel names may consist of"+
|
msg: "Invalid channel name. Channel names may consist of"+
|
||||||
" 1-30 characters in the set a-z, A-Z, 0-9, -, and _"
|
" 1-30 characters in the set a-z, A-Z, 0-9, -, and _"
|
||||||
|
@ -143,9 +142,9 @@ User.prototype.initCallbacks = function() {
|
||||||
}
|
}
|
||||||
data.name = data.name.toLowerCase();
|
data.name = data.name.toLowerCase();
|
||||||
self.channel = self.server.getChannel(data.name);
|
self.channel = self.server.getChannel(data.name);
|
||||||
if(self.loggedIn) {
|
if (self.loggedIn) {
|
||||||
self.channel.getRank(self.name, function (err, rank) {
|
self.channel.getRank(self.name, function (err, rank) {
|
||||||
if(!err && rank > self.rank)
|
if (!err && rank > self.rank)
|
||||||
self.rank = rank;
|
self.rank = rank;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -153,11 +152,11 @@ User.prototype.initCallbacks = function() {
|
||||||
self.autoAFK();
|
self.autoAFK();
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("login", function(data) {
|
self.socket.on("login", function (data) {
|
||||||
var name = data.name || "";
|
var name = data.name || "";
|
||||||
var pw = data.pw || "";
|
var pw = data.pw || "";
|
||||||
var session = data.session || "";
|
var session = data.session || "";
|
||||||
if(pw.length > 100)
|
if (pw.length > 100)
|
||||||
pw = pw.substring(0, 100);
|
pw = pw.substring(0, 100);
|
||||||
|
|
||||||
if (self.loggedIn)
|
if (self.loggedIn)
|
||||||
|
@ -183,51 +182,51 @@ User.prototype.initCallbacks = function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("assignLeader", function(data) {
|
self.socket.on("assignLeader", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryChangeLeader(self, data);
|
self.channel.tryChangeLeader(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("promote", function(data) {
|
self.socket.on("promote", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryPromoteUser(self, data);
|
self.channel.tryPromoteUser(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("demote", function(data) {
|
self.socket.on("demote", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryDemoteUser(self, data);
|
self.channel.tryDemoteUser(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("setChannelRank", function(data) {
|
self.socket.on("setChannelRank", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.trySetRank(self, data);
|
self.channel.trySetRank(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("banName", function(data) {
|
self.socket.on("banName", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.banName(self, data.name || "");
|
self.channel.banName(self, data.name || "");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("banIP", function(data) {
|
self.socket.on("banIP", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryIPBan(self, data);
|
self.channel.tryIPBan(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("unban", function(data) {
|
self.socket.on("unban", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryUnban(self, data);
|
self.channel.tryUnban(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("chatMsg", function(data) {
|
self.socket.on("chatMsg", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
if(data.msg.indexOf("/afk") != 0) {
|
if (data.msg.indexOf("/afk") !== 0) {
|
||||||
self.setAFK(false);
|
self.setAFK(false);
|
||||||
self.autoAFK();
|
self.autoAFK();
|
||||||
}
|
}
|
||||||
|
@ -235,96 +234,96 @@ User.prototype.initCallbacks = function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("newPoll", function(data) {
|
self.socket.on("newPoll", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryOpenPoll(self, data);
|
self.channel.tryOpenPoll(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("playerReady", function() {
|
self.socket.on("playerReady", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.sendMediaUpdate(self);
|
self.channel.sendMediaUpdate(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("requestPlaylist", function() {
|
self.socket.on("requestPlaylist", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.sendPlaylist(self);
|
self.channel.sendPlaylist(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("queue", function(data) {
|
self.socket.on("queue", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryQueue(self, data);
|
self.channel.tryQueue(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("setTemp", function(data) {
|
self.socket.on("setTemp", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.trySetTemp(self, data);
|
self.channel.trySetTemp(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("delete", function(data) {
|
self.socket.on("delete", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryDequeue(self, data);
|
self.channel.tryDequeue(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("uncache", function(data) {
|
self.socket.on("uncache", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryUncache(self, data);
|
self.channel.tryUncache(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("moveMedia", function(data) {
|
self.socket.on("moveMedia", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryMove(self, data);
|
self.channel.tryMove(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("jumpTo", function(data) {
|
self.socket.on("jumpTo", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryJumpTo(self, data);
|
self.channel.tryJumpTo(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("playNext", function() {
|
self.socket.on("playNext", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryPlayNext(self);
|
self.channel.tryPlayNext(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("clearPlaylist", function() {
|
self.socket.on("clearPlaylist", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryClearqueue(self);
|
self.channel.tryClearqueue(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("shufflePlaylist", function() {
|
self.socket.on("shufflePlaylist", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryShufflequeue(self);
|
self.channel.tryShufflequeue(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("togglePlaylistLock", function() {
|
self.socket.on("togglePlaylistLock", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryToggleLock(self);
|
self.channel.tryToggleLock(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("mediaUpdate", function(data) {
|
self.socket.on("mediaUpdate", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryUpdate(self, data);
|
self.channel.tryUpdate(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("searchMedia", function(data) {
|
self.socket.on("searchMedia", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
if(data.source == "yt") {
|
if (data.source == "yt") {
|
||||||
var searchfn = self.server.infogetter.Getters["ytSearch"];
|
var searchfn = self.server.infogetter.Getters.ytSearch;
|
||||||
searchfn(data.query.split(" "), function (e, vids) {
|
searchfn(data.query.split(" "), function (e, vids) {
|
||||||
if(!e) {
|
if (!e) {
|
||||||
self.socket.emit("searchResults", {
|
self.socket.emit("searchResults", {
|
||||||
source: "yt",
|
source: "yt",
|
||||||
results: vids
|
results: vids
|
||||||
|
@ -342,119 +341,118 @@ User.prototype.initCallbacks = function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("closePoll", function() {
|
self.socket.on("closePoll", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryClosePoll(self);
|
self.channel.tryClosePoll(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("vote", function(data) {
|
self.socket.on("vote", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryVote(self, data);
|
self.channel.tryVote(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("registerChannel", function(data) {
|
self.socket.on("registerChannel", function (data) {
|
||||||
if(!self.inChannel()) {
|
if (!self.inChannel()) {
|
||||||
self.socket.emit("channelRegistration", {
|
self.socket.emit("channelRegistration", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "You're not in any channel!"
|
error: "You're not in any channel!"
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
self.channel.tryRegister(self);
|
self.channel.tryRegister(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("unregisterChannel", function() {
|
self.socket.on("unregisterChannel", function () {
|
||||||
if(!self.inChannel()) {
|
if (!self.inChannel()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.channel.unregister(self);
|
self.channel.unregister(self);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("setOptions", function(data) {
|
self.socket.on("setOptions", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryUpdateOptions(self, data);
|
self.channel.tryUpdateOptions(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("setPermissions", function(data) {
|
self.socket.on("setPermissions", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryUpdatePermissions(self, data);
|
self.channel.tryUpdatePermissions(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("setChannelCSS", function(data) {
|
self.socket.on("setChannelCSS", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.trySetCSS(self, data);
|
self.channel.trySetCSS(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("setChannelJS", function(data) {
|
self.socket.on("setChannelJS", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.trySetJS(self, data);
|
self.channel.trySetJS(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("updateFilter", function(data) {
|
self.socket.on("updateFilter", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryUpdateFilter(self, data);
|
self.channel.tryUpdateFilter(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("removeFilter", function(data) {
|
self.socket.on("removeFilter", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryRemoveFilter(self, data);
|
self.channel.tryRemoveFilter(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("moveFilter", function(data) {
|
self.socket.on("moveFilter", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryMoveFilter(self, data);
|
self.channel.tryMoveFilter(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("setMotd", function(data) {
|
self.socket.on("setMotd", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryUpdateMotd(self, data);
|
self.channel.tryUpdateMotd(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("requestLoginHistory", function() {
|
self.socket.on("requestLoginHistory", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.sendLoginHistory(self);
|
self.channel.sendLoginHistory(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("requestBanlist", function() {
|
self.socket.on("requestBanlist", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.sendBanlist(self);
|
self.channel.sendBanlist(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("requestChatFilters", function() {
|
self.socket.on("requestChatFilters", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.sendChatFilters(self);
|
self.channel.sendChatFilters(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("requestChannelRanks", function() {
|
self.socket.on("requestChannelRanks", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
if(self.noflood("requestChannelRanks", 0.25))
|
if (self.noflood("requestChannelRanks", 0.25))
|
||||||
return;
|
return;
|
||||||
self.channel.sendChannelRanks(self);
|
self.channel.sendChannelRanks(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("voteskip", function(data) {
|
self.socket.on("voteskip", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryVoteskip(self);
|
self.channel.tryVoteskip(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("listPlaylists", function(data) {
|
self.socket.on("listPlaylists", function (data) {
|
||||||
if(self.name == "" || self.rank < 1) {
|
if (self.name === "" || self.rank < 1) {
|
||||||
self.socket.emit("listPlaylists", {
|
self.socket.emit("listPlaylists", {
|
||||||
pllist: [],
|
pllist: [],
|
||||||
error: "You must be logged in to manage playlists"
|
error: "You must be logged in to manage playlists"
|
||||||
|
@ -463,19 +461,19 @@ User.prototype.initCallbacks = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.server.db.listUserPlaylists(self.name, function (err, list) {
|
self.server.db.listUserPlaylists(self.name, function (err, list) {
|
||||||
if(err)
|
if (err)
|
||||||
list = [];
|
list = [];
|
||||||
for(var i = 0; i < list.length; i++) {
|
for(var i = 0; i < list.length; i++) {
|
||||||
list[i].time = $util.formatTime(list[i].time);
|
list[i].time = $util.formatTime(list[i].time);
|
||||||
}
|
}
|
||||||
self.socket.emit("listPlaylists", {
|
self.socket.emit("listPlaylists", {
|
||||||
pllist: list,
|
pllist: list
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("savePlaylist", function(data) {
|
self.socket.on("savePlaylist", function (data) {
|
||||||
if(self.rank < 1) {
|
if (self.rank < 1) {
|
||||||
self.socket.emit("savePlaylist", {
|
self.socket.emit("savePlaylist", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "You must be logged in to manage playlists"
|
error: "You must be logged in to manage playlists"
|
||||||
|
@ -483,7 +481,7 @@ User.prototype.initCallbacks = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!self.inChannel()) {
|
if (!self.inChannel()) {
|
||||||
self.socket.emit("savePlaylist", {
|
self.socket.emit("savePlaylist", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Not in a channel"
|
error: "Not in a channel"
|
||||||
|
@ -491,14 +489,14 @@ User.prototype.initCallbacks = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof data.name != "string") {
|
if (typeof data.name != "string") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pl = self.channel.playlist.items.toArray();
|
var pl = self.channel.playlist.items.toArray();
|
||||||
self.server.db.saveUserPlaylist(pl, self.name, data.name,
|
self.server.db.saveUserPlaylist(pl, self.name, data.name,
|
||||||
function (err, res) {
|
function (err, res) {
|
||||||
if(err) {
|
if (err) {
|
||||||
self.socket.emit("savePlaylist", {
|
self.socket.emit("savePlaylist", {
|
||||||
success: false,
|
success: false,
|
||||||
error: err
|
error: err
|
||||||
|
@ -512,26 +510,26 @@ User.prototype.initCallbacks = function() {
|
||||||
|
|
||||||
self.server.db.listUserPlaylists(self.name,
|
self.server.db.listUserPlaylists(self.name,
|
||||||
function (err, list) {
|
function (err, list) {
|
||||||
if(err)
|
if (err)
|
||||||
list = [];
|
list = [];
|
||||||
for(var i = 0; i < list.length; i++) {
|
for(var i = 0; i < list.length; i++) {
|
||||||
list[i].time = $util.formatTime(list[i].time);
|
list[i].time = $util.formatTime(list[i].time);
|
||||||
}
|
}
|
||||||
self.socket.emit("listPlaylists", {
|
self.socket.emit("listPlaylists", {
|
||||||
pllist: list,
|
pllist: list
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("queuePlaylist", function(data) {
|
self.socket.on("queuePlaylist", function (data) {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryQueuePlaylist(self, data);
|
self.channel.tryQueuePlaylist(self, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("deletePlaylist", function(data) {
|
self.socket.on("deletePlaylist", function (data) {
|
||||||
if(typeof data.name != "string") {
|
if (typeof data.name != "string") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -539,42 +537,42 @@ User.prototype.initCallbacks = function() {
|
||||||
function () {
|
function () {
|
||||||
self.server.db.listUserPlaylists(self.name,
|
self.server.db.listUserPlaylists(self.name,
|
||||||
function (err, list) {
|
function (err, list) {
|
||||||
if(err)
|
if (err)
|
||||||
list = [];
|
list = [];
|
||||||
for(var i = 0; i < list.length; i++) {
|
for(var i = 0; i < list.length; i++) {
|
||||||
list[i].time = $util.formatTime(list[i].time);
|
list[i].time = $util.formatTime(list[i].time);
|
||||||
}
|
}
|
||||||
self.socket.emit("listPlaylists", {
|
self.socket.emit("listPlaylists", {
|
||||||
pllist: list,
|
pllist: list
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("readChanLog", function () {
|
self.socket.on("readChanLog", function () {
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.tryReadLog(self);
|
self.channel.tryReadLog(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("acp-init", function() {
|
self.socket.on("acp-init", function () {
|
||||||
if(self.global_rank >= Rank.Siteadmin)
|
if (self.global_rank >= Rank.Siteadmin)
|
||||||
self.server.acp.init(self);
|
self.server.acp.init(self);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on("borrow-rank", function(rank) {
|
self.socket.on("borrow-rank", function (rank) {
|
||||||
if(self.global_rank < 255)
|
if (self.global_rank < 255)
|
||||||
return;
|
return;
|
||||||
if(rank > self.global_rank)
|
if (rank > self.global_rank)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.rank = rank;
|
self.rank = rank;
|
||||||
self.socket.emit("rank", rank);
|
self.socket.emit("rank", rank);
|
||||||
if(self.inChannel())
|
if (self.inChannel())
|
||||||
self.channel.broadcastUserUpdate(self);
|
self.channel.broadcastUserUpdate(self);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
var lastguestlogin = {};
|
var lastguestlogin = {};
|
||||||
User.prototype.guestLogin = function (name) {
|
User.prototype.guestLogin = function (name) {
|
||||||
|
@ -587,13 +585,13 @@ User.prototype.guestLogin = function (name) {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Guest logins are restricted to one per IP address "+
|
error: "Guest logins are restricted to one per IP address "+
|
||||||
"per " + self.server.cfg["guest-login-delay"] +
|
"per " + self.server.cfg["guest-login-delay"] +
|
||||||
" seconds.",
|
" seconds."
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$util.isValidUserName(name)) {
|
if (!$util.isValidUserName(name)) {
|
||||||
self.socket.emit("login", {
|
self.socket.emit("login", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Invalid username. Usernames must be 1-20 characters "+
|
error: "Invalid username. Usernames must be 1-20 characters "+
|
||||||
|
@ -607,7 +605,7 @@ User.prototype.guestLogin = function (name) {
|
||||||
self.loggingIn = true;
|
self.loggingIn = true;
|
||||||
self.server.db.isUsernameTaken(name, function (err, taken) {
|
self.server.db.isUsernameTaken(name, function (err, taken) {
|
||||||
self.loggingIn = false;
|
self.loggingIn = false;
|
||||||
if(err) {
|
if (err) {
|
||||||
self.socket.emit("login", {
|
self.socket.emit("login", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Internal error: " + err
|
error: "Internal error: " + err
|
||||||
|
@ -615,7 +613,7 @@ User.prototype.guestLogin = function (name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(taken) {
|
if (taken) {
|
||||||
self.socket.emit("login", {
|
self.socket.emit("login", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "That username is registered and protected."
|
error: "That username is registered and protected."
|
||||||
|
@ -623,9 +621,9 @@ User.prototype.guestLogin = function (name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
for(var i = 0; i < self.channel.users.length; i++) {
|
for(var i = 0; i < self.channel.users.length; i++) {
|
||||||
if(self.channel.users[i].name == name) {
|
if (self.channel.users[i].name == name) {
|
||||||
self.socket.emit("login", {
|
self.socket.emit("login", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "That name is already in use on this channel"
|
error: "That name is already in use on this channel"
|
||||||
|
@ -645,22 +643,23 @@ User.prototype.guestLogin = function (name) {
|
||||||
name: name
|
name: name
|
||||||
});
|
});
|
||||||
self.socket.emit("rank", self.rank);
|
self.socket.emit("rank", self.rank);
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.logger.log(self.ip + " signed in as " + name);
|
self.channel.logger.log(self.ip + " signed in as " + name);
|
||||||
self.channel.broadcastNewUser(self);
|
self.channel.broadcastNewUser(self);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Attempt to login
|
// Attempt to login
|
||||||
User.prototype.login = function(name, pw, session) {
|
User.prototype.login = function (name, pw, session) {
|
||||||
var self = this;
|
var self = this;
|
||||||
// No password => try guest login
|
// No password => try guest login
|
||||||
if(pw == "" && session == "") {
|
if (pw === "" && session === "") {
|
||||||
this.guestLogin(name);
|
this.guestLogin(name);
|
||||||
} else {
|
} else {
|
||||||
self.loggingIn = true;
|
self.loggingIn = true;
|
||||||
self.server.db.userLogin(name, pw, session, function (err, row) {
|
self.server.db.userLogin(name, pw, session, function (err, row) {
|
||||||
if(err) {
|
if (err) {
|
||||||
self.loggingIn = false;
|
self.loggingIn = false;
|
||||||
self.server.actionlog.record(self.ip, name, "login-failure",
|
self.server.actionlog.record(self.ip, name, "login-failure",
|
||||||
err);
|
err);
|
||||||
|
@ -670,10 +669,10 @@ User.prototype.login = function(name, pw, session) {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
var n = name.toLowerCase();
|
var n = name.toLowerCase();
|
||||||
for(var i = 0; i < self.channel.users.length; i++) {
|
for(var i = 0; i < self.channel.users.length; i++) {
|
||||||
if(self.channel.users[i].name.toLowerCase() === n) {
|
if (self.channel.users[i].name.toLowerCase() === n) {
|
||||||
if (self.channel.users[i] === self) {
|
if (self.channel.users[i] === self) {
|
||||||
Logger.errlog.log("Wat: user.login() but user "+
|
Logger.errlog.log("Wat: user.login() but user "+
|
||||||
"already logged in on channel");
|
"already logged in on channel");
|
||||||
|
@ -685,7 +684,7 @@ User.prototype.login = function(name, pw, session) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Record logins for administrator accounts
|
// Record logins for administrator accounts
|
||||||
if(self.global_rank >= 255)
|
if (self.global_rank >= 255)
|
||||||
self.server.actionlog.record(self.ip, name, "login-success");
|
self.server.actionlog.record(self.ip, name, "login-success");
|
||||||
self.loggedIn = true;
|
self.loggedIn = true;
|
||||||
self.loggingIn = false;
|
self.loggingIn = false;
|
||||||
|
@ -704,15 +703,15 @@ User.prototype.login = function(name, pw, session) {
|
||||||
var afterRankLookup = function () {
|
var afterRankLookup = function () {
|
||||||
self.socket.emit("rank", self.rank);
|
self.socket.emit("rank", self.rank);
|
||||||
self.name = name;
|
self.name = name;
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.logger.log(self.ip + " logged in as " +
|
self.channel.logger.log(self.ip + " logged in as " +
|
||||||
name);
|
name);
|
||||||
self.channel.broadcastNewUser(self);
|
self.channel.broadcastNewUser(self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if(self.inChannel()) {
|
if (self.inChannel()) {
|
||||||
self.channel.getRank(name, function (err, rank) {
|
self.channel.getRank(name, function (err, rank) {
|
||||||
if(!err) {
|
if (!err) {
|
||||||
self.saverank = true;
|
self.saverank = true;
|
||||||
self.rank = rank;
|
self.rank = rank;
|
||||||
} else {
|
} else {
|
||||||
|
@ -729,6 +728,6 @@ User.prototype.login = function(name, pw, session) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = User;
|
module.exports = User;
|
||||||
|
|
Loading…
Reference in New Issue