Start fixing things

This commit is contained in:
calzoneman 2013-08-18 12:21:34 -05:00
parent 42e89dc557
commit 2f4621dab9
5 changed files with 312 additions and 273 deletions

2
acp.js
View file

@ -9,6 +9,8 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
var Logger = require("./logger");
module.exports = function (Server) { module.exports = function (Server) {
var db = Server.db; var db = Server.db;
var ActionLog = Server.actionlog; var ActionLog = Server.actionlog;

3
api.js
View file

@ -141,6 +141,7 @@ module.exports = function (Server) {
/* login */ /* login */
app.post("/api/login", function (req, res) { app.post("/api/login", function (req, res) {
res.type("application/jsonp"); res.type("application/jsonp");
res.setHeader("Access-Control-Allow-Origin", "*");
var name = req.body.name; var name = req.body.name;
var pw = req.body.pw; var pw = req.body.pw;
var session = req.body.session; var session = req.body.session;
@ -567,8 +568,6 @@ module.exports = function (Server) {
res.jsonp(actions); res.jsonp(actions);
}); });
var actions = ActionLog.readLog(types);
res.jsonp(actions);
}); });
}); });

View file

@ -25,6 +25,7 @@ var Channel = function(name, Server) {
var self = this; var self = this;
Logger.syslog.log("Opening channel " + name); Logger.syslog.log("Opening channel " + name);
self.initialized = false; self.initialized = false;
self.dbloaded = false;
self.server = Server; self.server = Server;
self.name = name; self.name = name;
@ -117,6 +118,7 @@ var Channel = function(name, Server) {
} }
Server.db.loadChannelData(self, function () { Server.db.loadChannelData(self, function () {
self.dbloaded = true;
if(self.registered) { if(self.registered) {
self.loadDump(); self.loadDump();
} }
@ -658,13 +660,13 @@ Channel.prototype.search = function(query, callback) {
res = []; res = [];
} }
results.sort(function(a, b) { res.sort(function(a, b) {
var x = a.title.toLowerCase(); var x = a.title.toLowerCase();
var y = b.title.toLowerCase(); var y = b.title.toLowerCase();
return (x == y) ? 0 : (x < y ? -1 : 1); return (x == y) ? 0 : (x < y ? -1 : 1);
}); });
callback(results); callback(res);
}); });
} }
@ -700,7 +702,7 @@ Channel.prototype.userJoin = function(user) {
// If the channel is empty and isn't registered, the first person // If the channel is empty and isn't registered, the first person
// gets ownership of the channel (temporarily) // gets ownership of the channel (temporarily)
if(this.users.length == 0 && !this.registered) { if(this.dbloaded && this.users.length == 0 && !this.registered) {
user.rank = (user.rank < Rank.Owner) ? 10 : user.rank; user.rank = (user.rank < Rank.Owner) ? 10 : user.rank;
user.socket.emit("channelNotRegistered"); user.socket.emit("channelNotRegistered");
} }
@ -948,7 +950,7 @@ Channel.prototype.broadcastNewUser = function(user) {
self.ip_alias[user.ip] = aliases; self.ip_alias[user.ip] = aliases;
aliases.forEach(function (alias) { aliases.forEach(function (alias) {
chan.name_alias[alias] = aliases; self.name_alias[alias] = aliases;
}); });
self.login_hist.unshift({ self.login_hist.unshift({

View file

@ -10,7 +10,8 @@ var Database = function (cfg) {
host: cfg["mysql-server"], host: cfg["mysql-server"],
user: cfg["mysql-user"], user: cfg["mysql-user"],
password: cfg["mysql-pw"], password: cfg["mysql-pw"],
database: cfg["mysql-db"] database: cfg["mysql-db"],
multipleStatements: true
}); });
// Test the connection // Test the connection
@ -43,6 +44,7 @@ Database.prototype.query = function (query, sub, callback) {
function cback(err, res) { function cback(err, res) {
if(err) { if(err) {
if(self.cfg["debug"]) { if(self.cfg["debug"]) {
console.log(query);
console.log(err); console.log(err);
} }
callback("Database failure", null); callback("Database failure", null);
@ -52,9 +54,9 @@ Database.prototype.query = function (query, sub, callback) {
conn.end(); conn.end();
} }
if(sub) if(sub) {
conn.query(query, sub, cback); conn.query(query, sub, cback);
else { } else {
conn.query(query, cback); conn.query(query, cback);
} }
} }
@ -296,11 +298,11 @@ Database.prototype.searchChannel = function (field, value, callback) {
var query = "SELECT * FROM channels WHERE "; var query = "SELECT * FROM channels WHERE ";
if(field === "owner") if(field === "owner")
query += "owner LIKE %?%"; query += "owner LIKE ?";
else if(field === "name") else if(field === "name")
query += "name LIKE %?%"; query += "name LIKE ?";
self.query(query, [value], callback); self.query(query, ["%" + value + "%"], callback);
}; };
Database.prototype.channelExists = function (name, callback) { Database.prototype.channelExists = function (name, callback) {
@ -611,9 +613,9 @@ Database.prototype.searchLibrary = function (channame, term, callback) {
} }
var query = "SELECT id, title, seconds, type FROM " + var query = "SELECT id, title, seconds, type FROM " +
"`chan_" + channame + "_library` WHERE title LIKE %?%"; "`chan_" + channame + "_library` WHERE title LIKE ?";
self.query(query, [term], callback); self.query(query, ["%" + term + "%"], callback);
}; };
Database.prototype.addChannelBan = function (channame, ip, name, banBy, Database.prototype.addChannelBan = function (channame, ip, name, banBy,
@ -889,7 +891,7 @@ Database.prototype.getGlobalRank = function (name, callback) {
return; return;
var query = "SELECT global_rank FROM registrations WHERE uname=?"; var query = "SELECT global_rank FROM registrations WHERE uname=?";
self.query(query, function (err, res) { self.query(query, [name], function (err, res) {
if(err) { if(err) {
callback(err, null); callback(err, null);
return; return;
@ -917,9 +919,9 @@ Database.prototype.searchUser = function (name, callback) {
// the user's password hash // the user's password hash
var query = "SELECT id, uname, global_rank, profile_image, " + var query = "SELECT id, uname, global_rank, profile_image, " +
"profile_text, email FROM registrations WHERE " + "profile_text, email FROM registrations WHERE " +
"uname LIKE %?%"; "uname LIKE ?";
self.query(query, [name], callback); self.query(query, ["%" + name + "%"], callback);
}; };
/* rank */ /* rank */
@ -1221,7 +1223,7 @@ Database.prototype.listAliases = function (ip, callback) {
if(!err) { if(!err) {
names = []; names = [];
res.forEach(function (row) { res.forEach(function (row) {
names.append(row.name); names.push(row.name);
}); });
} }
@ -1338,7 +1340,7 @@ Database.prototype.listActions = function (types, callback) {
list.push("?"); list.push("?");
var actionlist = "(" + list.join(",") + ")"; var actionlist = "(" + list.join(",") + ")";
var query = "SELECT * FROM actionlog WHERE action IN " + actiontypes; var query = "SELECT * FROM actionlog WHERE action IN " + actionlist;
self.query(query, types, callback); self.query(query, types, callback);
}; };

504
user.js
View file

@ -116,188 +116,188 @@ User.prototype.autoAFK = function () {
} }
User.prototype.initCallbacks = function() { User.prototype.initCallbacks = function() {
this.socket.on("disconnect", function() { var self = this;
this.awaytimer && clearTimeout(this.awaytimer); self.socket.on("disconnect", function() {
if(this.channel != null) self.awaytimer && clearTimeout(self.awaytimer);
this.channel.userLeave(this); if(self.channel != null)
}.bind(this)); self.channel.userLeave(self);
});
this.socket.on("joinChannel", function(data) { self.socket.on("joinChannel", function(data) {
if(this.channel != null) if(self.channel != null)
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}$/)) {
this.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 _"
}); });
this.socket.emit("kick", { self.socket.emit("kick", {
reason: "Bad channel name" reason: "Bad channel name"
}); });
return; return;
} }
data.name = data.name.toLowerCase(); data.name = data.name.toLowerCase();
this.channel = this.server.getChannel(data.name); self.channel = self.server.getChannel(data.name);
if(this.loggedIn) { if(self.loggedIn) {
var chanrank = this.channel.getRank(this.name); self.channel.getRank(self.name, function (err, rank) {
if(chanrank > this.rank) { if(!err && rank > self.rank)
this.rank = chanrank; self.rank = rank;
});
} }
} self.channel.userJoin(self);
this.channel.userJoin(this); });
}.bind(this));
this.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(this.name == "") if(self.name == "")
this.login(name, pw, session); self.login(name, pw, session);
}.bind(this)); });
this.socket.on("assignLeader", function(data) { self.socket.on("assignLeader", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryChangeLeader(this, data); self.channel.tryChangeLeader(self, data);
} }
}.bind(this)); });
this.socket.on("promote", function(data) { self.socket.on("promote", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryPromoteUser(this, data); self.channel.tryPromoteUser(self, data);
} }
}.bind(this)); });
this.socket.on("demote", function(data) { self.socket.on("demote", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryDemoteUser(this, data); self.channel.tryDemoteUser(self, data);
} }
}.bind(this)); });
this.socket.on("setChannelRank", function(data) { self.socket.on("setChannelRank", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.trySetRank(this, data); self.channel.trySetRank(self, data);
} }
}.bind(this)); });
this.socket.on("banName", function(data) { self.socket.on("banName", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.banName(this, data.name || ""); self.channel.banName(self, data.name || "");
} }
}.bind(this)); });
this.socket.on("banIP", function(data) { self.socket.on("banIP", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryIPBan(this, data); self.channel.tryIPBan(self, data);
} }
}.bind(this)); });
this.socket.on("unban", function(data) { self.socket.on("unban", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryUnban(this, data); self.channel.tryUnban(self, data);
} }
}.bind(this)); });
this.socket.on("chatMsg", function(data) { self.socket.on("chatMsg", function(data) {
if(this.channel != null) { if(self.channel != null) {
if(data.msg.indexOf("/afk") != 0) { if(data.msg.indexOf("/afk") != 0) {
this.setAFK(false); self.setAFK(false);
this.autoAFK(); self.autoAFK();
} }
this.channel.tryChat(this, data); self.channel.tryChat(self, data);
} }
}.bind(this)); });
this.socket.on("newPoll", function(data) { self.socket.on("newPoll", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryOpenPoll(this, data); self.channel.tryOpenPoll(self, data);
} }
}.bind(this)); });
this.socket.on("playerReady", function() { self.socket.on("playerReady", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.sendMediaUpdate(this); self.channel.sendMediaUpdate(self);
} }
}.bind(this)); });
this.socket.on("requestPlaylist", function() { self.socket.on("requestPlaylist", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.sendPlaylist(this); self.channel.sendPlaylist(self);
} }
}.bind(this)); });
this.socket.on("queue", function(data) { self.socket.on("queue", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryQueue(this, data); self.channel.tryQueue(self, data);
} }
}.bind(this)); });
this.socket.on("setTemp", function(data) { self.socket.on("setTemp", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.trySetTemp(this, data); self.channel.trySetTemp(self, data);
} }
}.bind(this)); });
this.socket.on("delete", function(data) { self.socket.on("delete", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryDequeue(this, data); self.channel.tryDequeue(self, data);
} }
}.bind(this)); });
this.socket.on("uncache", function(data) { self.socket.on("uncache", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryUncache(this, data); self.channel.tryUncache(self, data);
} }
}.bind(this)); });
this.socket.on("moveMedia", function(data) { self.socket.on("moveMedia", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryMove(this, data); self.channel.tryMove(self, data);
} }
}.bind(this)); });
this.socket.on("jumpTo", function(data) { self.socket.on("jumpTo", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryJumpTo(this, data); self.channel.tryJumpTo(self, data);
} }
}.bind(this)); });
this.socket.on("playNext", function() { self.socket.on("playNext", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryPlayNext(this); self.channel.tryPlayNext(self);
} }
}.bind(this)); });
this.socket.on("clearPlaylist", function() { self.socket.on("clearPlaylist", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryClearqueue(this); self.channel.tryClearqueue(self);
} }
}.bind(this)); });
this.socket.on("shufflePlaylist", function() { self.socket.on("shufflePlaylist", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryShufflequeue(this); self.channel.tryShufflequeue(self);
} }
}.bind(this)); });
this.socket.on("togglePlaylistLock", function() { self.socket.on("togglePlaylistLock", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryToggleLock(this); self.channel.tryToggleLock(self);
} }
}.bind(this)); });
this.socket.on("mediaUpdate", function(data) { self.socket.on("mediaUpdate", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryUpdate(this, data); self.channel.tryUpdate(self, data);
} }
}.bind(this)); });
this.socket.on("searchMedia", function(data) { self.socket.on("searchMedia", function(data) {
var self = this; if(self.channel != null) {
if(this.channel != null) {
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) {
@ -315,148 +315,151 @@ User.prototype.initCallbacks = function() {
}); });
} }
} }
}.bind(this)); });
this.socket.on("closePoll", function() { self.socket.on("closePoll", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryClosePoll(this); self.channel.tryClosePoll(self);
} }
}.bind(this)); });
this.socket.on("vote", function(data) { self.socket.on("vote", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryVote(this, data); self.channel.tryVote(self, data);
} }
}.bind(this)); });
this.socket.on("registerChannel", function(data) { self.socket.on("registerChannel", function(data) {
if(this.channel == null) { if(self.channel == null) {
this.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 {
this.channel.tryRegister(this); self.channel.tryRegister(self);
} }
}.bind(this)); });
this.socket.on("unregisterChannel", function() { self.socket.on("unregisterChannel", function() {
if(this.channel == null) { if(self.channel == null) {
return; return;
} }
this.channel.unregister(this); self.channel.unregister(self);
}.bind(this)); });
this.socket.on("setOptions", function(data) { self.socket.on("setOptions", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryUpdateOptions(this, data); self.channel.tryUpdateOptions(self, data);
} }
}.bind(this)); });
this.socket.on("setPermissions", function(data) { self.socket.on("setPermissions", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryUpdatePermissions(this, data); self.channel.tryUpdatePermissions(self, data);
} }
}.bind(this)); });
this.socket.on("setChannelCSS", function(data) { self.socket.on("setChannelCSS", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.trySetCSS(this, data); self.channel.trySetCSS(self, data);
} }
}.bind(this)); });
this.socket.on("setChannelJS", function(data) { self.socket.on("setChannelJS", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.trySetJS(this, data); self.channel.trySetJS(self, data);
} }
}.bind(this)); });
this.socket.on("updateFilter", function(data) { self.socket.on("updateFilter", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryUpdateFilter(this, data); self.channel.tryUpdateFilter(self, data);
} }
}.bind(this)); });
this.socket.on("removeFilter", function(data) { self.socket.on("removeFilter", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryRemoveFilter(this, data); self.channel.tryRemoveFilter(self, data);
} }
}.bind(this)); });
this.socket.on("moveFilter", function(data) { self.socket.on("moveFilter", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryMoveFilter(this, data); self.channel.tryMoveFilter(self, data);
} }
}.bind(this)); });
this.socket.on("setMotd", function(data) { self.socket.on("setMotd", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryUpdateMotd(this, data); self.channel.tryUpdateMotd(self, data);
} }
}.bind(this)); });
this.socket.on("requestLoginHistory", function() { self.socket.on("requestLoginHistory", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.sendLoginHistory(this); self.channel.sendLoginHistory(self);
} }
}.bind(this)); });
this.socket.on("requestBanlist", function() { self.socket.on("requestBanlist", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.sendBanlist(this); self.channel.sendBanlist(self);
} }
}.bind(this)); });
this.socket.on("requestChatFilters", function() { self.socket.on("requestChatFilters", function() {
if(this.channel != null) { if(self.channel != null) {
this.channel.sendChatFilters(this); self.channel.sendChatFilters(self);
} }
}.bind(this)); });
this.socket.on("requestChannelRanks", function() { self.socket.on("requestChannelRanks", function() {
if(this.channel != null) { if(self.channel != null) {
if(this.noflood("requestChannelRanks", 0.25)) if(self.noflood("requestChannelRanks", 0.25))
return; return;
this.channel.sendChannelRanks(this); self.channel.sendChannelRanks(self);
} }
}.bind(this)); });
this.socket.on("voteskip", function(data) { self.socket.on("voteskip", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryVoteskip(this); self.channel.tryVoteskip(self);
} }
}.bind(this)); });
this.socket.on("listPlaylists", function(data) { self.socket.on("listPlaylists", function(data) {
if(this.name == "" || this.rank < 1) { if(self.name == "" || self.rank < 1) {
this.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"
}); });
return; return;
} }
var list = this.server.db.getUserPlaylists(this.name); self.server.db.listUserPlaylists(self.name, function (err, list) {
if(err)
list = [];
for(var i = 0; i < list.length; i++) { for(var i = 0; i < list.length; i++) {
list[i].time = formatTime(list[i].time); list[i].time = formatTime(list[i].time);
} }
this.socket.emit("listPlaylists", { self.socket.emit("listPlaylists", {
pllist: list, pllist: list,
}); });
}.bind(this)); });
});
this.socket.on("savePlaylist", function(data) { self.socket.on("savePlaylist", function(data) {
if(this.rank < 1) { if(self.rank < 1) {
this.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"
}); });
return; return;
} }
if(this.channel == null) { if(self.channel == null) {
this.socket.emit("savePlaylist", { self.socket.emit("savePlaylist", {
success: false, success: false,
error: "Not in a channel" error: "Not in a channel"
}); });
@ -467,65 +470,86 @@ User.prototype.initCallbacks = function() {
return; return;
} }
var pl = this.channel.playlist.items.toArray(); var pl = self.channel.playlist.items.toArray();
var result = this.server.db.saveUserPlaylist(pl, this.name, data.name); self.server.db.saveUserPlaylist(pl, self.name, data.name,
this.socket.emit("savePlaylist", { function (err, res) {
success: result, if(err) {
error: result ? false : "Unknown" console.log(typeof err);
self.socket.emit("savePlaylist", {
success: false,
error: err
}); });
var list = this.server.db.getUserPlaylists(this.name); return;
}
self.socket.emit("savePlaylist", {
success: true
});
self.server.db.listUserPlaylists(self.name,
function (err, list) {
if(err)
list = [];
for(var i = 0; i < list.length; i++) { for(var i = 0; i < list.length; i++) {
list[i].time = formatTime(list[i].time); list[i].time = formatTime(list[i].time);
} }
this.socket.emit("listPlaylists", { self.socket.emit("listPlaylists", {
pllist: list, pllist: list,
}); });
}.bind(this)); });
});
});
this.socket.on("queuePlaylist", function(data) { self.socket.on("queuePlaylist", function(data) {
if(this.channel != null) { if(self.channel != null) {
this.channel.tryQueuePlaylist(this, data); self.channel.tryQueuePlaylist(self, data);
} }
}.bind(this)); });
this.socket.on("deletePlaylist", function(data) { self.socket.on("deletePlaylist", function(data) {
if(typeof data.name != "string") { if(typeof data.name != "string") {
return; return;
} }
this.server.db.deleteUserPlaylist(this.name, data.name); self.server.db.deleteUserPlaylist(self.name, data.name,
var list = this.server.db.getUserPlaylists(this.name); function () {
self.server.db.listUserPlaylists(self.name,
function (err, list) {
if(err)
list = [];
for(var i = 0; i < list.length; i++) { for(var i = 0; i < list.length; i++) {
list[i].time = formatTime(list[i].time); list[i].time = formatTime(list[i].time);
} }
this.socket.emit("listPlaylists", { self.socket.emit("listPlaylists", {
pllist: list, pllist: list,
}); });
}.bind(this)); });
});
});
this.socket.on("readChanLog", function () { self.socket.on("readChanLog", function () {
if(this.channel !== null) { if(self.channel !== null) {
this.channel.tryReadLog(this); self.channel.tryReadLog(self);
} }
}.bind(this)); });
this.socket.on("acp-init", function() { self.socket.on("acp-init", function() {
if(this.global_rank >= Rank.Siteadmin) if(self.global_rank >= Rank.Siteadmin)
this.server.acp.init(this); self.server.acp.init(self);
}.bind(this)); });
this.socket.on("borrow-rank", function(rank) { self.socket.on("borrow-rank", function(rank) {
if(this.global_rank < 255) if(self.global_rank < 255)
return; return;
if(rank > this.global_rank) if(rank > self.global_rank)
return; return;
this.rank = rank; self.rank = rank;
this.socket.emit("rank", rank); self.socket.emit("rank", rank);
if(this.channel != null) if(self.channel != null)
this.channel.broadcastUserUpdate(this); self.channel.broadcastUserUpdate(self);
}.bind(this)); });
} }
var lastguestlogin = {}; var lastguestlogin = {};
@ -631,18 +655,28 @@ User.prototype.login = function(name, pw, session) {
image: row.profile_image, image: row.profile_image,
text: row.profile_text text: row.profile_text
}; };
var chanrank = (self.channel != null) ? self.channel.getRank(name)
: Rank.Guest;
var rank = (chanrank > row.global_rank) ? chanrank
: row.global_rank;
self.rank = (self.rank > rank) ? self.rank : rank;
self.global_rank = row.global_rank; self.global_rank = row.global_rank;
var afterRankLookup = function () {
self.socket.emit("rank", self.rank); self.socket.emit("rank", self.rank);
self.name = name; self.name = name;
if(self.channel != null) { if(self.channel != null) {
self.channel.logger.log(self.ip + " logged in as " + name); self.channel.logger.log(self.ip + " logged in as " +
name);
self.channel.broadcastNewUser(self); self.channel.broadcastNewUser(self);
} }
};
if(self.channel !== null) {
self.channel.getRank(self.name, function (err, rank) {
if(!err && rank > self.global_rank)
self.rank = rank;
else
self.rank = self.global_rank
afterRankLookup();
});
} else {
self.rank = self.global_rank;
afterRankLookup();
}
}); });
} }
} }