Fix a few things

This commit is contained in:
calzoneman 2014-02-15 00:12:11 -06:00
parent 1cbb1c2a6a
commit 573e59680e
4 changed files with 75 additions and 49 deletions

View File

@ -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);

View File

@ -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");
}
};
})();

View File

@ -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
});
}

View File

@ -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+"");