From 0e49f06fbf190aa4633f2fd9c9ab1ea1e71c51ab Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 4 Apr 2013 14:56:43 -0500 Subject: [PATCH] Fixes and stuff --- channel.js | 19 +++++++++++++++---- chatcommand.js | 28 ++++++++++++++++++++++++++++ rank.js | 1 + server.js | 2 +- www/assets/css/ytsync.css | 12 ++++++++++++ www/assets/js/callbacks.js | 11 +++++++++++ www/assets/js/functions.js | 8 ++++++++ www/index.html | 3 +++ 8 files changed, 79 insertions(+), 5 deletions(-) diff --git a/channel.js b/channel.js index d799bfa3..924e39e7 100644 --- a/channel.js +++ b/channel.js @@ -18,6 +18,7 @@ var Logger = require("./logger.js"); var InfoGetter = require("./get-info.js"); var io = require("./server.js").io; var Rank = require("./rank.js"); +var ChatCommand = require("./chatcommand.js"); var Channel = function(name) { Logger.syslog.log("Opening channel " + name); @@ -30,6 +31,7 @@ var Channel = function(name) { this.library = {}; this.position = -1; this.media = null; + this.drinks = 0; this.leader = null; this.chatbuffer = []; this.openqueue = false; @@ -297,6 +299,7 @@ Channel.prototype.userJoin = function(user) { } user.socket.emit("channelOpts", this.opts); user.socket.emit("updateMotd", this.motd); + user.socket.emit("drinkCount", {count: this.drinks}); // Send things that require special permission this.sendRankStuff(user); @@ -479,6 +482,10 @@ Channel.prototype.broadcastMotd = function() { this.sendAll("updateMotd", this.motd); } +Channel.prototype.broadcastDrinks = function() { + this.sendAll("drinkCount", {count: this.drinks}); +} + /* REGION Playlist Stuff */ // The server autolead function @@ -709,12 +716,16 @@ Channel.prototype.tryUpdate = function(user, data) { return; } - if(data.id == undefined || data.currentTime == undefined) { + if(data == null || + data.id == undefined || data.currentTime == undefined) { return; } - if(this.media != null && (this.media.type == "li" || - this.media.type == "tw")) { + if(this.media == null) { + return; + } + + if(this.media.type == "li" || this.media.type == "tw") { return; } @@ -956,7 +967,7 @@ Channel.prototype.sendMessage = function(username, msg, msgclass) { msg: msg, msgclass: msgclass }); - this.recentChat.push({ + this.chatbuffer.push({ username: username, msg: msg, msgclass: msgclass diff --git a/chatcommand.js b/chatcommand.js index ddeb925f..01843956 100644 --- a/chatcommand.js +++ b/chatcommand.js @@ -35,6 +35,10 @@ function handle(chan, user, msg) { else if(msg.indexOf("/poll ") == 0) { handlePoll(chan, user, msg.substring(6)); } + else if(msg.indexOf("/d") == 0 && msg.length > 2 && + msg[2].match(/[-0-9 ]/)) { + handleDrink(chan, user, msg.substring(2)); + } } function handleKick(chan, user, args) { @@ -88,5 +92,29 @@ function handlePoll(chan, user, msg) { } } +function handleDrink(chan, user, msg) { + if(!Rank.hasPermission(user, "drink") && chan.leader != user) { + return; + } + + var count = msg.split(" ")[0]; + msg = msg.substring(count.length + 1); + if(count == "") + count = 1; + else + count = parseInt(count); + + chan.drinks += count; + chan.broadcastDrinks(); + if(count < 0) { + return; + } + + msg = msg + " drink!"; + if(count > 1) + msg += " (x" + count + ")"; + chan.sendMessage(user.name, msg, "drink"); +} + exports.handle = handle; diff --git a/rank.js b/rank.js index 51e9c460..3bddcaeb 100644 --- a/rank.js +++ b/rank.js @@ -31,6 +31,7 @@ var permissions = { jump : exports.Moderator, chatFilter : exports.Moderator, updateMotd : exports.Moderator, + drink : exports.Moderator, search : exports.Guest, chat : exports.Guest, }; diff --git a/server.js b/server.js index 02f8f39f..8a8d2efc 100644 --- a/server.js +++ b/server.js @@ -9,7 +9,7 @@ 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. */ -const VERSION = "1.1.0"; +const VERSION = "1.1.1"; var fs = require("fs"); var Logger = require("./logger.js"); diff --git a/www/assets/css/ytsync.css b/www/assets/css/ytsync.css index e19f8cba..5ca9f3da 100644 --- a/www/assets/css/ytsync.css +++ b/www/assets/css/ytsync.css @@ -125,6 +125,18 @@ background-color: #ddffdd; } +.drink { + margin: 10px 10px; + padding: 10px 0px; + border: 2px solid #0000cc; +} + +.drinkbar { + background-color: #000000; + color: #ffffff; + text-align: center; +} + #motdtext { width: 100%; } diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 49ec106d..c005088c 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -189,6 +189,17 @@ function initCallbacks() { } }); + socket.on("drinkCount", function(data) { + var count = data.count; + if(count != 0) { + $("#drinkcount").text(count + " drinks"); + $(".drinkbar").show(); + } + else { + $(".drinkbar").hide(); + } + }); + /* REGION Playlist Stuff */ socket.on("playlist", function(data) { diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index 2198a4c1..8aff6dfd 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -140,6 +140,14 @@ function formatChatMessage(data) { .addClass("action") .appendTo(div); } + else if(data.msgclass == "drink") { + div.addClass("drink"); + var name = $(""); + $("").text("<" + data.username + ">").appendTo(name); + var message = $("").text(data.msg); + name.appendTo(div); + message.appendTo(div); + } else { var name = $(""); $("").text("<" + data.username + ">").appendTo(name); diff --git a/www/index.html b/www/index.html index 26ed0a73..e2de7607 100644 --- a/www/index.html +++ b/www/index.html @@ -52,6 +52,9 @@

+
+

+