mirror of https://github.com/calzoneman/sync.git
Complete refactoring [untested]
This commit is contained in:
parent
6877b103f2
commit
f4019e8b83
|
@ -665,6 +665,11 @@ Channel.prototype.tryUpdate = function(user, data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.media != null && (this.media.type == "li" ||
|
||||||
|
this.media.type == "tw")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.media = new Media(data.id, data.title, data.seconds, data.type);
|
this.media = new Media(data.id, data.title, data.seconds, data.type);
|
||||||
this.sendAll("mediaUpdate", this.media.packupdate());
|
this.sendAll("mediaUpdate", this.media.packupdate());
|
||||||
}
|
}
|
||||||
|
@ -804,7 +809,12 @@ Channel.prototype.tryChangeFilter = function(user, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data.cmd == "update") {
|
if(data.cmd == "update") {
|
||||||
data.filter[0] = new RegExp(data.filter[0], "g");
|
try {
|
||||||
|
data.filter[0] = new RegExp(data.filter[0], "g");
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.updateFilter(data);
|
this.updateFilter(data);
|
||||||
}
|
}
|
||||||
else if(data.cmd == "remove") {
|
else if(data.cmd == "remove") {
|
||||||
|
@ -846,7 +856,17 @@ Channel.prototype.tryUpdateMotd = function(user, data) {
|
||||||
|
|
||||||
/* REGION Chat */
|
/* REGION Chat */
|
||||||
|
|
||||||
Channel.prototype.tryChat = function(user, msg) {
|
Channel.prototype.tryChat = function(user, data) {
|
||||||
|
if(user.name == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.msg == undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var msg = data.msg;
|
||||||
|
|
||||||
if(msg.indexOf("/") == 0)
|
if(msg.indexOf("/") == 0)
|
||||||
ChatCommand.handle(this, user, msg);
|
ChatCommand.handle(this, user, msg);
|
||||||
|
|
||||||
|
@ -951,3 +971,40 @@ Channel.prototype.tryDemoteUser = function(actor, data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Channel.prototype.changeLeader = function(name) {
|
||||||
|
if(this.leader != null) {
|
||||||
|
var old = this.leader;
|
||||||
|
this.leader = null;
|
||||||
|
this.broadcastRankUpdate(old);
|
||||||
|
}
|
||||||
|
if(name == "") {
|
||||||
|
this.logger.log("*** Resuming autolead");
|
||||||
|
if(this.media != null && this.media.type != "li"
|
||||||
|
&& this.media.type != "tw") {
|
||||||
|
this.time = new Date().getTime();
|
||||||
|
this.i = 0;
|
||||||
|
mediaUpdate(this, this.media.id);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(var i = 0; i < this.users.length; i++) {
|
||||||
|
if(this.users[i].name == name) {
|
||||||
|
this.logger.log("*** Assigned leader: " + name);
|
||||||
|
this.leader = this.users[i];
|
||||||
|
this.broadcastRankUpdate(this.leader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Channel.prototype.tryChangeLeader = function(user, data) {
|
||||||
|
if(!Rank.hasPermission(user, "assignLeader")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.name == undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.changeLeader(data.name);
|
||||||
|
}
|
||||||
|
|
137
user.js
137
user.js
|
@ -33,9 +33,7 @@ var User = function(socket, ip) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Set up socket callbacks
|
|
||||||
User.prototype.initCallbacks = function() {
|
User.prototype.initCallbacks = function() {
|
||||||
// What a shame
|
|
||||||
this.socket.on("disconnect", function() {
|
this.socket.on("disconnect", function() {
|
||||||
if(this.channel != null)
|
if(this.channel != null)
|
||||||
this.channel.userLeave(this);
|
this.channel.userLeave(this);
|
||||||
|
@ -79,37 +77,26 @@ User.prototype.initCallbacks = function() {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("assignLeader", function(data) {
|
this.socket.on("assignLeader", function(data) {
|
||||||
if(data.name == undefined)
|
if(this.channel != null) {
|
||||||
return;
|
this.channel.tryChangeLeader(this, data);
|
||||||
if(Rank.hasPermission(this, "assignLeader")) {
|
|
||||||
if(this.channel != null)
|
|
||||||
this.channel.changeLeader(data.name);
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("promote", function(data) {
|
this.socket.on("promote", function(data) {
|
||||||
if(data.name == undefined)
|
if(this.channel != null) {
|
||||||
return;
|
this.channel.tryPromote(this, data);
|
||||||
if(Rank.hasPermission(this, "promote")) {
|
|
||||||
if(this.channel != null) {
|
|
||||||
this.channel.promoteUser(this, data.name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("demote", function(data) {
|
this.socket.on("demote", function(data) {
|
||||||
if(Rank.hasPermission(this, "promote")) {
|
if(this.channel != null) {
|
||||||
if(this.channel != null) {
|
this.channel.tryDemote(this, data);
|
||||||
this.channel.demoteUser(this, data.name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("chatMsg", function(data) {
|
this.socket.on("chatMsg", function(data) {
|
||||||
if(this.name != "" && this.channel != null && data.msg != undefined) {
|
if(this.channel != null) {
|
||||||
if(data.msg.length > 500)
|
this.channel.tryChat(this, data);
|
||||||
data.msg = data.msg.substring(0, 500);
|
|
||||||
this.channel.chatMessage(this, data.msg);
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
@ -121,94 +108,64 @@ User.prototype.initCallbacks = function() {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("queue", function(data) {
|
this.socket.on("queue", function(data) {
|
||||||
if(this.channel == null)
|
if(this.channel != null) {
|
||||||
return;
|
this.channel.tryQueue(this, data);
|
||||||
if(Rank.hasPermission(this, "queue") ||
|
|
||||||
this.channel.leader == this ||
|
|
||||||
!this.channel.qlocked) {
|
|
||||||
if(data.pos == "next" &&
|
|
||||||
!this.channel.qopts_allow_qnext &&
|
|
||||||
this.channel.leader != this &&
|
|
||||||
!Rank.hasPermission(this, "queue"))
|
|
||||||
return;
|
|
||||||
this.channel.enqueue(data);
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("unqueue", function(data) {
|
this.socket.on("unqueue", function(data) {
|
||||||
if(this.channel == null)
|
if(this.channel != null) {
|
||||||
return;
|
this.channel.tryDequeue(this, data);
|
||||||
if(Rank.hasPermission(this, "queue") ||
|
|
||||||
this.channel.leader == this ||
|
|
||||||
this.channel.opts.qopen_allow_delete && !this.channel.qlocked) {
|
|
||||||
this.channel.unqueue(data);
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("moveMedia", function(data) {
|
this.socket.on("moveMedia", function(data) {
|
||||||
if(this.channel == null)
|
if(this.channel != null) {
|
||||||
return;
|
this.channel.tryMove(this, data);
|
||||||
if(Rank.hasPermission(this, "queue") ||
|
|
||||||
this.channel.leader == this ||
|
|
||||||
this.channel.opts.qopen_allow_move && !this.channel.qlocked ) {
|
|
||||||
this.channel.moveMedia(data);
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("jumpTo", function(data) {
|
this.socket.on("jumpTo", function(data) {
|
||||||
if(this.channel == null || data.pos == undefined)
|
if(this.channel != null) {
|
||||||
return;
|
this.channel.tryJumpTo(this, data);
|
||||||
if(Rank.hasPermission(this, "jump") ||
|
|
||||||
this.channel.leader == this) {
|
|
||||||
this.channel.jumpTo(data.pos);
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("playNext", function() {
|
this.socket.on("playNext", function() {
|
||||||
if(this.channel == null)
|
if(this.channel != null) {
|
||||||
return;
|
this.channel.tryPlayNext(this, data);
|
||||||
if(Rank.hasPermission(this, "queue") ||
|
|
||||||
this.channel.leader == this ||
|
|
||||||
this.channel.opts.qopen_allow_playnext && !this.channel.qlocked) {
|
|
||||||
this.channel.playNext();
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("queueLock", function(data) {
|
this.socket.on("queueLock", function(data) {
|
||||||
if(Rank.hasPermission(this, "qlock")) {
|
if(this.channel != null) {
|
||||||
if(this.channel != null) {
|
this.channel.trySetLock(this, data);
|
||||||
this.channel.setLock(data.locked);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("mediaUpdate", function(data) {
|
this.socket.on("mediaUpdate", function(data) {
|
||||||
if(this.channel != null && this.channel.leader == this) {
|
if(this.channel != null) {
|
||||||
this.channel.update(data);
|
this.channel.tryUpdate(this, data);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("searchLibrary", function(data) {
|
this.socket.on("searchLibrary", function(data) {
|
||||||
if(this.channel != null && Rank.hasPermission(this, "search")) {
|
if(this.channel != null) {
|
||||||
this.socket.emit("librarySearchResults", {
|
this.socket.emit("librarySearchResults", {
|
||||||
results: this.channel.searchLibrary(data.query)
|
results: this.channel.search(data.query)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("closePoll", function() {
|
this.socket.on("closePoll", function() {
|
||||||
if(Rank.hasPermission(this, "poll")) {
|
if(this.channel != null) {
|
||||||
if(this.channel != null && this.channel.poll) {
|
this.channel.tryClosePoll(this);
|
||||||
this.channel.poll = null;
|
|
||||||
this.channel.broadcastPollClose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("vote", function(data) {
|
this.socket.on("vote", function(data) {
|
||||||
if(this.channel != null && this.channel.poll) {
|
if(this.channel != null) {
|
||||||
this.channel.poll.vote(this.ip, data.option);
|
this.channel.tryVote(this, data);
|
||||||
this.channel.broadcastPollUpdate();
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
@ -243,46 +200,26 @@ User.prototype.initCallbacks = function() {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("channelOpts", function(data) {
|
this.socket.on("channelOpts", function(data) {
|
||||||
if(Rank.hasPermission(this, "channelOpts") && this.channel != null) {
|
if(this.channel != null) {
|
||||||
this.channel.opts = data;
|
this.channel.tryUpdateOptions(this, data);
|
||||||
this.channel.broadcastOpts();
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("chatFilter", function(data) {
|
this.socket.on("chatFilter", function(data) {
|
||||||
if(Rank.hasPermission(this, "chatFilter")) {
|
if(this.channel != null) {
|
||||||
if(data.cmd && data.cmd == "update" && this.channel != null) {
|
this.channel.tryChangeFilter(this, data);
|
||||||
try {
|
|
||||||
data.filter[0] = new RegExp(data.filter[0], "g");
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.channel.updateFilter(data.filter);
|
|
||||||
}
|
|
||||||
else if(data.cmd && data.cmd == "remove" && this.channel != null) {
|
|
||||||
this.channel.removeFilter(data.filter[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("updateMotd", function(data) {
|
this.socket.on("updateMotd", function(data) {
|
||||||
if(Rank.hasPermission(this, "updateMotd")) {
|
if(this.channel != null) {
|
||||||
if(data.motd != undefined && this.channel != null) {
|
this.channel.tryUpdateMotd(this, data);
|
||||||
var html = data.motd.replace(/\n/g, "<br>");
|
|
||||||
html = this.channel.filterMessage(html);
|
|
||||||
this.channel.motd = {
|
|
||||||
motd: data.motd,
|
|
||||||
html: html
|
|
||||||
};
|
|
||||||
this.channel.broadcastMotd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("voteskip", function(data) {
|
this.socket.on("voteskip", function(data) {
|
||||||
if(this.channel != null) {
|
if(this.channel != null) {
|
||||||
this.channel.handleVoteskip(this);
|
this.channel.voteskip(this);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
@ -348,7 +285,7 @@ User.prototype.login = function(name, pw) {
|
||||||
}
|
}
|
||||||
// No password => try guest login
|
// No password => try guest login
|
||||||
if(pw == "") {
|
if(pw == "") {
|
||||||
// Sorry bud, can"t take that name
|
// Sorry bud, can't take that name
|
||||||
if(Auth.isRegistered(name)) {
|
if(Auth.isRegistered(name)) {
|
||||||
this.socket.emit("login", {
|
this.socket.emit("login", {
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -363,7 +300,6 @@ User.prototype.login = function(name, pw) {
|
||||||
error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores"
|
error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Woah, success!
|
|
||||||
else {
|
else {
|
||||||
Logger.syslog.log(this.ip + " signed in as " + name);
|
Logger.syslog.log(this.ip + " signed in as " + name);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -388,7 +324,6 @@ User.prototype.login = function(name, pw) {
|
||||||
success: true
|
success: true
|
||||||
});
|
});
|
||||||
Logger.syslog.log(this.ip + " logged in as " + name);
|
Logger.syslog.log(this.ip + " logged in as " + name);
|
||||||
// Sweet, let"s look up our rank
|
|
||||||
var chanrank = (this.channel != null) ? this.channel.getRank(name)
|
var chanrank = (this.channel != null) ? this.channel.getRank(name)
|
||||||
: Rank.Guest;
|
: Rank.Guest;
|
||||||
var rank = (chanrank > row.global_rank) ? chanrank
|
var rank = (chanrank > row.global_rank) ? chanrank
|
||||||
|
|
Loading…
Reference in New Issue