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
|
||||||
|
|
53
lib/user.js
53
lib/user.js
|
@ -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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -57,15 +57,13 @@ User.prototype.noflood = function(name, hz) {
|
||||||
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
|
||||||
|
@ -83,7 +81,7 @@ 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())
|
||||||
|
@ -103,19 +101,20 @@ 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;
|
||||||
|
@ -227,7 +226,7 @@ User.prototype.initCallbacks = function() {
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
@ -322,7 +321,7 @@ User.prototype.initCallbacks = function() {
|
||||||
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", {
|
||||||
|
@ -360,8 +359,7 @@ User.prototype.initCallbacks = function() {
|
||||||
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -454,7 +452,7 @@ User.prototype.initCallbacks = function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
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"
|
||||||
|
@ -469,7 +467,7 @@ User.prototype.initCallbacks = function() {
|
||||||
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
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -518,7 +516,7 @@ User.prototype.initCallbacks = function() {
|
||||||
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
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -545,7 +543,7 @@ User.prototype.initCallbacks = function() {
|
||||||
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
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -574,7 +572,7 @@ User.prototype.initCallbacks = function() {
|
||||||
self.channel.broadcastUserUpdate(self);
|
self.channel.broadcastUserUpdate(self);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
var lastguestlogin = {};
|
var lastguestlogin = {};
|
||||||
User.prototype.guestLogin = function (name) {
|
User.prototype.guestLogin = function (name) {
|
||||||
|
@ -587,7 +585,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -650,12 +648,13 @@ User.prototype.guestLogin = function (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;
|
||||||
|
@ -729,6 +728,6 @@ User.prototype.login = function(name, pw, session) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = User;
|
module.exports = User;
|
||||||
|
|
Loading…
Reference in New Issue