mirror of https://github.com/calzoneman/sync.git
Start fixing things
This commit is contained in:
parent
42e89dc557
commit
2f4621dab9
2
acp.js
2
acp.js
|
@ -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.
|
||||
*/
|
||||
|
||||
var Logger = require("./logger");
|
||||
|
||||
module.exports = function (Server) {
|
||||
var db = Server.db;
|
||||
var ActionLog = Server.actionlog;
|
||||
|
|
3
api.js
3
api.js
|
@ -141,6 +141,7 @@ module.exports = function (Server) {
|
|||
/* login */
|
||||
app.post("/api/login", function (req, res) {
|
||||
res.type("application/jsonp");
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
var name = req.body.name;
|
||||
var pw = req.body.pw;
|
||||
var session = req.body.session;
|
||||
|
@ -567,8 +568,6 @@ module.exports = function (Server) {
|
|||
|
||||
res.jsonp(actions);
|
||||
});
|
||||
var actions = ActionLog.readLog(types);
|
||||
res.jsonp(actions);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
10
channel.js
10
channel.js
|
@ -25,6 +25,7 @@ var Channel = function(name, Server) {
|
|||
var self = this;
|
||||
Logger.syslog.log("Opening channel " + name);
|
||||
self.initialized = false;
|
||||
self.dbloaded = false;
|
||||
self.server = Server;
|
||||
|
||||
self.name = name;
|
||||
|
@ -117,6 +118,7 @@ var Channel = function(name, Server) {
|
|||
}
|
||||
|
||||
Server.db.loadChannelData(self, function () {
|
||||
self.dbloaded = true;
|
||||
if(self.registered) {
|
||||
self.loadDump();
|
||||
}
|
||||
|
@ -658,13 +660,13 @@ Channel.prototype.search = function(query, callback) {
|
|||
res = [];
|
||||
}
|
||||
|
||||
results.sort(function(a, b) {
|
||||
res.sort(function(a, b) {
|
||||
var x = a.title.toLowerCase();
|
||||
var y = b.title.toLowerCase();
|
||||
|
||||
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
|
||||
// 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.socket.emit("channelNotRegistered");
|
||||
}
|
||||
|
@ -948,7 +950,7 @@ Channel.prototype.broadcastNewUser = function(user) {
|
|||
|
||||
self.ip_alias[user.ip] = aliases;
|
||||
aliases.forEach(function (alias) {
|
||||
chan.name_alias[alias] = aliases;
|
||||
self.name_alias[alias] = aliases;
|
||||
});
|
||||
|
||||
self.login_hist.unshift({
|
||||
|
|
28
database.js
28
database.js
|
@ -10,7 +10,8 @@ var Database = function (cfg) {
|
|||
host: cfg["mysql-server"],
|
||||
user: cfg["mysql-user"],
|
||||
password: cfg["mysql-pw"],
|
||||
database: cfg["mysql-db"]
|
||||
database: cfg["mysql-db"],
|
||||
multipleStatements: true
|
||||
});
|
||||
|
||||
// Test the connection
|
||||
|
@ -43,6 +44,7 @@ Database.prototype.query = function (query, sub, callback) {
|
|||
function cback(err, res) {
|
||||
if(err) {
|
||||
if(self.cfg["debug"]) {
|
||||
console.log(query);
|
||||
console.log(err);
|
||||
}
|
||||
callback("Database failure", null);
|
||||
|
@ -52,9 +54,9 @@ Database.prototype.query = function (query, sub, callback) {
|
|||
conn.end();
|
||||
}
|
||||
|
||||
if(sub)
|
||||
if(sub) {
|
||||
conn.query(query, sub, cback);
|
||||
else {
|
||||
} else {
|
||||
conn.query(query, cback);
|
||||
}
|
||||
}
|
||||
|
@ -296,11 +298,11 @@ Database.prototype.searchChannel = function (field, value, callback) {
|
|||
|
||||
var query = "SELECT * FROM channels WHERE ";
|
||||
if(field === "owner")
|
||||
query += "owner LIKE %?%";
|
||||
query += "owner LIKE ?";
|
||||
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) {
|
||||
|
@ -611,9 +613,9 @@ Database.prototype.searchLibrary = function (channame, term, callback) {
|
|||
}
|
||||
|
||||
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,
|
||||
|
@ -889,7 +891,7 @@ Database.prototype.getGlobalRank = function (name, callback) {
|
|||
return;
|
||||
|
||||
var query = "SELECT global_rank FROM registrations WHERE uname=?";
|
||||
self.query(query, function (err, res) {
|
||||
self.query(query, [name], function (err, res) {
|
||||
if(err) {
|
||||
callback(err, null);
|
||||
return;
|
||||
|
@ -917,9 +919,9 @@ Database.prototype.searchUser = function (name, callback) {
|
|||
// the user's password hash
|
||||
var query = "SELECT id, uname, global_rank, profile_image, " +
|
||||
"profile_text, email FROM registrations WHERE " +
|
||||
"uname LIKE %?%";
|
||||
"uname LIKE ?";
|
||||
|
||||
self.query(query, [name], callback);
|
||||
self.query(query, ["%" + name + "%"], callback);
|
||||
};
|
||||
|
||||
/* rank */
|
||||
|
@ -1221,7 +1223,7 @@ Database.prototype.listAliases = function (ip, callback) {
|
|||
if(!err) {
|
||||
names = [];
|
||||
res.forEach(function (row) {
|
||||
names.append(row.name);
|
||||
names.push(row.name);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1338,7 +1340,7 @@ Database.prototype.listActions = function (types, callback) {
|
|||
list.push("?");
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
542
user.js
542
user.js
|
@ -116,188 +116,188 @@ User.prototype.autoAFK = function () {
|
|||
}
|
||||
|
||||
User.prototype.initCallbacks = function() {
|
||||
this.socket.on("disconnect", function() {
|
||||
this.awaytimer && clearTimeout(this.awaytimer);
|
||||
if(this.channel != null)
|
||||
this.channel.userLeave(this);
|
||||
}.bind(this));
|
||||
var self = this;
|
||||
self.socket.on("disconnect", function() {
|
||||
self.awaytimer && clearTimeout(self.awaytimer);
|
||||
if(self.channel != null)
|
||||
self.channel.userLeave(self);
|
||||
});
|
||||
|
||||
this.socket.on("joinChannel", function(data) {
|
||||
if(this.channel != null)
|
||||
self.socket.on("joinChannel", function(data) {
|
||||
if(self.channel != null)
|
||||
return;
|
||||
if(typeof data.name != "string")
|
||||
return;
|
||||
if(!data.name.match(/^[\w-_]{1,30}$/)) {
|
||||
this.socket.emit("errorMsg", {
|
||||
self.socket.emit("errorMsg", {
|
||||
msg: "Invalid channel name. Channel names may consist of"+
|
||||
" 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"
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
data.name = data.name.toLowerCase();
|
||||
this.channel = this.server.getChannel(data.name);
|
||||
if(this.loggedIn) {
|
||||
var chanrank = this.channel.getRank(this.name);
|
||||
if(chanrank > this.rank) {
|
||||
this.rank = chanrank;
|
||||
}
|
||||
self.channel = self.server.getChannel(data.name);
|
||||
if(self.loggedIn) {
|
||||
self.channel.getRank(self.name, function (err, rank) {
|
||||
if(!err && rank > self.rank)
|
||||
self.rank = rank;
|
||||
});
|
||||
}
|
||||
this.channel.userJoin(this);
|
||||
}.bind(this));
|
||||
self.channel.userJoin(self);
|
||||
});
|
||||
|
||||
this.socket.on("login", function(data) {
|
||||
self.socket.on("login", function(data) {
|
||||
var name = data.name || "";
|
||||
var pw = data.pw || "";
|
||||
var session = data.session || "";
|
||||
if(pw.length > 100)
|
||||
pw = pw.substring(0, 100);
|
||||
if(this.name == "")
|
||||
this.login(name, pw, session);
|
||||
}.bind(this));
|
||||
if(self.name == "")
|
||||
self.login(name, pw, session);
|
||||
});
|
||||
|
||||
this.socket.on("assignLeader", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryChangeLeader(this, data);
|
||||
self.socket.on("assignLeader", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryChangeLeader(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("promote", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryPromoteUser(this, data);
|
||||
self.socket.on("promote", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryPromoteUser(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("demote", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryDemoteUser(this, data);
|
||||
self.socket.on("demote", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryDemoteUser(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("setChannelRank", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.trySetRank(this, data);
|
||||
self.socket.on("setChannelRank", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.trySetRank(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("banName", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.banName(this, data.name || "");
|
||||
self.socket.on("banName", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.banName(self, data.name || "");
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("banIP", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryIPBan(this, data);
|
||||
self.socket.on("banIP", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryIPBan(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("unban", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryUnban(this, data);
|
||||
self.socket.on("unban", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryUnban(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("chatMsg", function(data) {
|
||||
if(this.channel != null) {
|
||||
self.socket.on("chatMsg", function(data) {
|
||||
if(self.channel != null) {
|
||||
if(data.msg.indexOf("/afk") != 0) {
|
||||
this.setAFK(false);
|
||||
this.autoAFK();
|
||||
self.setAFK(false);
|
||||
self.autoAFK();
|
||||
}
|
||||
this.channel.tryChat(this, data);
|
||||
self.channel.tryChat(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("newPoll", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryOpenPoll(this, data);
|
||||
self.socket.on("newPoll", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryOpenPoll(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("playerReady", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.sendMediaUpdate(this);
|
||||
self.socket.on("playerReady", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.sendMediaUpdate(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("requestPlaylist", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.sendPlaylist(this);
|
||||
self.socket.on("requestPlaylist", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.sendPlaylist(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("queue", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryQueue(this, data);
|
||||
self.socket.on("queue", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryQueue(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("setTemp", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.trySetTemp(this, data);
|
||||
self.socket.on("setTemp", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.trySetTemp(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("delete", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryDequeue(this, data);
|
||||
self.socket.on("delete", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryDequeue(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("uncache", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryUncache(this, data);
|
||||
self.socket.on("uncache", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryUncache(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("moveMedia", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryMove(this, data);
|
||||
self.socket.on("moveMedia", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryMove(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("jumpTo", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryJumpTo(this, data);
|
||||
self.socket.on("jumpTo", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryJumpTo(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("playNext", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryPlayNext(this);
|
||||
self.socket.on("playNext", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryPlayNext(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("clearPlaylist", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryClearqueue(this);
|
||||
self.socket.on("clearPlaylist", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryClearqueue(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("shufflePlaylist", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryShufflequeue(this);
|
||||
self.socket.on("shufflePlaylist", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryShufflequeue(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("togglePlaylistLock", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryToggleLock(this);
|
||||
self.socket.on("togglePlaylistLock", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryToggleLock(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("mediaUpdate", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryUpdate(this, data);
|
||||
self.socket.on("mediaUpdate", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryUpdate(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("searchMedia", function(data) {
|
||||
var self = this;
|
||||
if(this.channel != null) {
|
||||
self.socket.on("searchMedia", function(data) {
|
||||
if(self.channel != null) {
|
||||
if(data.source == "yt") {
|
||||
var searchfn = self.server.infogetter.Getters["ytSearch"];
|
||||
searchfn(data.query.split(" "), function (e, vids) {
|
||||
|
@ -315,148 +315,151 @@ User.prototype.initCallbacks = function() {
|
|||
});
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("closePoll", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryClosePoll(this);
|
||||
self.socket.on("closePoll", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryClosePoll(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("vote", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryVote(this, data);
|
||||
self.socket.on("vote", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryVote(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("registerChannel", function(data) {
|
||||
if(this.channel == null) {
|
||||
this.socket.emit("channelRegistration", {
|
||||
self.socket.on("registerChannel", function(data) {
|
||||
if(self.channel == null) {
|
||||
self.socket.emit("channelRegistration", {
|
||||
success: false,
|
||||
error: "You're not in any channel!"
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.channel.tryRegister(this);
|
||||
self.channel.tryRegister(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("unregisterChannel", function() {
|
||||
if(this.channel == null) {
|
||||
self.socket.on("unregisterChannel", function() {
|
||||
if(self.channel == null) {
|
||||
return;
|
||||
}
|
||||
this.channel.unregister(this);
|
||||
}.bind(this));
|
||||
self.channel.unregister(self);
|
||||
});
|
||||
|
||||
this.socket.on("setOptions", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryUpdateOptions(this, data);
|
||||
self.socket.on("setOptions", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryUpdateOptions(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("setPermissions", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryUpdatePermissions(this, data);
|
||||
self.socket.on("setPermissions", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryUpdatePermissions(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("setChannelCSS", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.trySetCSS(this, data);
|
||||
self.socket.on("setChannelCSS", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.trySetCSS(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("setChannelJS", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.trySetJS(this, data);
|
||||
self.socket.on("setChannelJS", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.trySetJS(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("updateFilter", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryUpdateFilter(this, data);
|
||||
self.socket.on("updateFilter", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryUpdateFilter(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("removeFilter", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryRemoveFilter(this, data);
|
||||
self.socket.on("removeFilter", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryRemoveFilter(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("moveFilter", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryMoveFilter(this, data);
|
||||
self.socket.on("moveFilter", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryMoveFilter(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("setMotd", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryUpdateMotd(this, data);
|
||||
self.socket.on("setMotd", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryUpdateMotd(self, data);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("requestLoginHistory", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.sendLoginHistory(this);
|
||||
self.socket.on("requestLoginHistory", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.sendLoginHistory(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("requestBanlist", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.sendBanlist(this);
|
||||
self.socket.on("requestBanlist", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.sendBanlist(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("requestChatFilters", function() {
|
||||
if(this.channel != null) {
|
||||
this.channel.sendChatFilters(this);
|
||||
self.socket.on("requestChatFilters", function() {
|
||||
if(self.channel != null) {
|
||||
self.channel.sendChatFilters(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("requestChannelRanks", function() {
|
||||
if(this.channel != null) {
|
||||
if(this.noflood("requestChannelRanks", 0.25))
|
||||
self.socket.on("requestChannelRanks", function() {
|
||||
if(self.channel != null) {
|
||||
if(self.noflood("requestChannelRanks", 0.25))
|
||||
return;
|
||||
this.channel.sendChannelRanks(this);
|
||||
self.channel.sendChannelRanks(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("voteskip", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryVoteskip(this);
|
||||
self.socket.on("voteskip", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryVoteskip(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("listPlaylists", function(data) {
|
||||
if(this.name == "" || this.rank < 1) {
|
||||
this.socket.emit("listPlaylists", {
|
||||
self.socket.on("listPlaylists", function(data) {
|
||||
if(self.name == "" || self.rank < 1) {
|
||||
self.socket.emit("listPlaylists", {
|
||||
pllist: [],
|
||||
error: "You must be logged in to manage playlists"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var list = this.server.db.getUserPlaylists(this.name);
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
this.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
self.server.db.listUserPlaylists(self.name, function (err, list) {
|
||||
if(err)
|
||||
list = [];
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
self.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
});
|
||||
});
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("savePlaylist", function(data) {
|
||||
if(this.rank < 1) {
|
||||
this.socket.emit("savePlaylist", {
|
||||
self.socket.on("savePlaylist", function(data) {
|
||||
if(self.rank < 1) {
|
||||
self.socket.emit("savePlaylist", {
|
||||
success: false,
|
||||
error: "You must be logged in to manage playlists"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.channel == null) {
|
||||
this.socket.emit("savePlaylist", {
|
||||
if(self.channel == null) {
|
||||
self.socket.emit("savePlaylist", {
|
||||
success: false,
|
||||
error: "Not in a channel"
|
||||
});
|
||||
|
@ -467,65 +470,86 @@ User.prototype.initCallbacks = function() {
|
|||
return;
|
||||
}
|
||||
|
||||
var pl = this.channel.playlist.items.toArray();
|
||||
var result = this.server.db.saveUserPlaylist(pl, this.name, data.name);
|
||||
this.socket.emit("savePlaylist", {
|
||||
success: result,
|
||||
error: result ? false : "Unknown"
|
||||
});
|
||||
var list = this.server.db.getUserPlaylists(this.name);
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
this.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
});
|
||||
}.bind(this));
|
||||
var pl = self.channel.playlist.items.toArray();
|
||||
self.server.db.saveUserPlaylist(pl, self.name, data.name,
|
||||
function (err, res) {
|
||||
if(err) {
|
||||
console.log(typeof err);
|
||||
self.socket.emit("savePlaylist", {
|
||||
success: false,
|
||||
error: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
self.socket.emit("savePlaylist", {
|
||||
success: true
|
||||
});
|
||||
|
||||
this.socket.on("queuePlaylist", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.tryQueuePlaylist(this, data);
|
||||
}
|
||||
}.bind(this));
|
||||
self.server.db.listUserPlaylists(self.name,
|
||||
function (err, list) {
|
||||
if(err)
|
||||
list = [];
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
self.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
this.socket.on("deletePlaylist", function(data) {
|
||||
self.socket.on("queuePlaylist", function(data) {
|
||||
if(self.channel != null) {
|
||||
self.channel.tryQueuePlaylist(self, data);
|
||||
}
|
||||
});
|
||||
|
||||
self.socket.on("deletePlaylist", function(data) {
|
||||
if(typeof data.name != "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
this.server.db.deleteUserPlaylist(this.name, data.name);
|
||||
var list = this.server.db.getUserPlaylists(this.name);
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
this.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
self.server.db.deleteUserPlaylist(self.name, data.name,
|
||||
function () {
|
||||
self.server.db.listUserPlaylists(self.name,
|
||||
function (err, list) {
|
||||
if(err)
|
||||
list = [];
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
list[i].time = formatTime(list[i].time);
|
||||
}
|
||||
self.socket.emit("listPlaylists", {
|
||||
pllist: list,
|
||||
});
|
||||
});
|
||||
});
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("readChanLog", function () {
|
||||
if(this.channel !== null) {
|
||||
this.channel.tryReadLog(this);
|
||||
self.socket.on("readChanLog", function () {
|
||||
if(self.channel !== null) {
|
||||
self.channel.tryReadLog(self);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this.socket.on("acp-init", function() {
|
||||
if(this.global_rank >= Rank.Siteadmin)
|
||||
this.server.acp.init(this);
|
||||
}.bind(this));
|
||||
self.socket.on("acp-init", function() {
|
||||
if(self.global_rank >= Rank.Siteadmin)
|
||||
self.server.acp.init(self);
|
||||
});
|
||||
|
||||
this.socket.on("borrow-rank", function(rank) {
|
||||
if(this.global_rank < 255)
|
||||
self.socket.on("borrow-rank", function(rank) {
|
||||
if(self.global_rank < 255)
|
||||
return;
|
||||
if(rank > this.global_rank)
|
||||
if(rank > self.global_rank)
|
||||
return;
|
||||
|
||||
this.rank = rank;
|
||||
this.socket.emit("rank", rank);
|
||||
if(this.channel != null)
|
||||
this.channel.broadcastUserUpdate(this);
|
||||
self.rank = rank;
|
||||
self.socket.emit("rank", rank);
|
||||
if(self.channel != null)
|
||||
self.channel.broadcastUserUpdate(self);
|
||||
|
||||
}.bind(this));
|
||||
});
|
||||
}
|
||||
|
||||
var lastguestlogin = {};
|
||||
|
@ -631,17 +655,27 @@ User.prototype.login = function(name, pw, session) {
|
|||
image: row.profile_image,
|
||||
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.socket.emit("rank", self.rank);
|
||||
self.name = name;
|
||||
if(self.channel != null) {
|
||||
self.channel.logger.log(self.ip + " logged in as " + name);
|
||||
self.channel.broadcastNewUser(self);
|
||||
var afterRankLookup = function () {
|
||||
self.socket.emit("rank", self.rank);
|
||||
self.name = name;
|
||||
if(self.channel != null) {
|
||||
self.channel.logger.log(self.ip + " logged in as " +
|
||||
name);
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue