From 573e59680e5d20b6342ba7f1a79e75866ce14ce5 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 15 Feb 2014 00:12:11 -0600 Subject: [PATCH] Fix a few things --- lib/channel.js | 4 +- lib/utilities.js | 103 +++++++++++++++++++++++------------------- lib/web/webserver.js | 15 ++++++ www/assets/js/util.js | 2 + 4 files changed, 75 insertions(+), 49 deletions(-) diff --git a/lib/channel.js b/lib/channel.js index 171adf58..43f396ac 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -547,7 +547,7 @@ Channel.prototype.join = function (user) { self.sendVoteskipUpdate(self.users); self.sendUsercount(self.users); - user.whenLoggedIn(function () { + user.once("channelRank", function () { if (!self.registered) { afterLogin(); return; @@ -1341,7 +1341,7 @@ Channel.prototype.sendPoll = function (users) { var unobscured = self.poll.packUpdate(true); users.forEach(function (u) { - if (self.hasPermission(u, "viewpollresults")) { + if (self.hasPermission(u, "viewhiddenpoll")) { u.socket.emit("newPoll", unobscured); } else { u.socket.emit("newPoll", obscured); diff --git a/lib/utilities.js b/lib/utilities.js index f59f4352..afdafe03 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -1,49 +1,57 @@ -var crypto = require("crypto"); +(function () { + var root, crypto = false; -/* - Set prototype- simple wrapper around JS objects to - manipulate them like a set -*/ -var Set = function (items) { - this._items = {}; - var self = this; - if (items instanceof Array) - items.forEach(function (it) { self.add(it); }); -}; - -Set.prototype.contains = function (what) { - return (what in this._items); -}; - -Set.prototype.add = function (what) { - this._items[what] = true; -}; - -Set.prototype.remove = function (what) { - if (what in this._items) - delete this._items[what]; -}; - -Set.prototype.clear = function () { - this._items = {}; -}; - -Set.prototype.forEach = function (fn) { - for (var k in this._items) { - fn(k); + if (typeof window === "undefined") { + root = module.exports; + } else { + root = window.utils = {}; } -}; -module.exports = { - isValidChannelName: function (name) { + if (typeof require === "function") { + crypto = require("crypto"); + } + + var Set = function (items) { + this._items = {}; + var self = this; + if (items instanceof Array) + items.forEach(function (it) { self.add(it); }); + }; + + Set.prototype.contains = function (what) { + return (what in this._items); + }; + + Set.prototype.add = function (what) { + this._items[what] = true; + }; + + Set.prototype.remove = function (what) { + if (what in this._items) + delete this._items[what]; + }; + + Set.prototype.clear = function () { + this._items = {}; + }; + + Set.prototype.forEach = function (fn) { + for (var k in this._items) { + fn(k); + } + }; + + root.Set = Set; + + root.isValidChannelName = function (name) { return name.match(/^[\w-]{1,30}$/); }, - isValidUserName: function (name) { + root.isValidUserName = function (name) { return name.match(/^[\w-]{1,20}$/); }, - isValidEmail: function (email) { + root.isValidEmail = function (email) { if (email.length > 255) { return false; } @@ -59,7 +67,7 @@ module.exports = { return true; }, - randomSalt: function (length) { + root.randomSalt = function (length) { var chars = "abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789!@#$%^&*_+=~"; var salt = []; @@ -69,7 +77,7 @@ module.exports = { return salt.join(''); }, - maskIP: function (ip) { + root.maskIP = function (ip) { if(ip.match(/^\d+\.\d+\.\d+\.\d+$/)) { // standard 32 bit IP return ip.replace(/\d+\.\d+\.(\d+\.\d+)/, "x.x.$1"); @@ -79,7 +87,7 @@ module.exports = { } }, - formatTime: function (sec) { + root.formatTime = function (sec) { if(sec === "--:--") return sec; @@ -107,7 +115,7 @@ module.exports = { return [h, m, s].join(":"); }, - newRateLimiter: function () { + root.newRateLimiter = function () { return { count: 0, lastTime: 0, @@ -152,7 +160,7 @@ module.exports = { }; }, - formatLink: function (id, type) { + root.formatLink = function (id, type) { switch (type) { case "yt": return "http://youtu.be/" + id; @@ -181,7 +189,7 @@ module.exports = { } }, - isLive: function (type) { + root.isLive = function (type) { switch (type) { case "li": case "tw": @@ -197,11 +205,12 @@ module.exports = { } }, - Set: Set, - - sha1: function (data) { + root.sha1 = function (data) { + if (!crypto) { + return ""; + } var shasum = crypto.createHash("sha1"); shasum.update(data); return shasum.digest("hex"); } -}; +})(); diff --git a/lib/web/webserver.js b/lib/web/webserver.js index 2507d5b3..3f3e3658 100644 --- a/lib/web/webserver.js +++ b/lib/web/webserver.js @@ -179,7 +179,15 @@ function handleSocketConfig(req, res) { function handleUserAgreement(req, res) { logRequest(req); + + var loginName = false; + if (req.cookies.auth) { + loginName = req.cookies.auth.split(":")[0]; + } + sendJade(res, "tos", { + loggedIn: loginName !== false, + loginName: loginName, domain: Config.get("http.domain") }); } @@ -187,6 +195,11 @@ function handleUserAgreement(req, res) { function handleContactPage(req, res) { logRequest(req); + var loginName = false; + if (req.cookies.auth) { + loginName = req.cookies.auth.split(":")[0]; + } + // Make a copy to prevent messing with the original var contacts = Config.get("contacts").map(function (c) { return { @@ -210,6 +223,8 @@ function handleContactPage(req, res) { }); sendJade(res, "contact", { + loggedIn: loginName !== false, + loginName: loginName, contacts: contacts }); } diff --git a/www/assets/js/util.js b/www/assets/js/util.js index 46f49ca3..4b592c18 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -1596,6 +1596,8 @@ function genPermissionsEditor() { makeOption("Edit MOTD", "motdedit", modplus, CHANNEL.perms.motdedit+""); makeOption("Edit chat filters", "filteredit", modplus, CHANNEL.perms.filteredit+""); makeOption("Import chat filters", "filterimport", modplus, CHANNEL.perms.filterimport+""); + makeOption("Edit chat emotes", "emoteedit", modplus, CHANNEL.perms.emoteedit+""); + makeOption("Import chat emotes", "emoteimport", modplus, CHANNEL.perms.emoteimport+""); addDivider("Misc"); makeOption("Drink calls", "drink", modleader, CHANNEL.perms.drink+"");