This commit is contained in:
calzoneman 2013-06-19 17:54:27 -04:00
parent dc5c6801ed
commit 7b60d0948e
15 changed files with 139 additions and 113 deletions

View File

@ -20,7 +20,7 @@ var Logger = require("./logger.js");
exports.isRegistered = function(name) {
var db = Database.getConnection();
if(!db) {
return true;
throw "Database failure";
}
var query = Database.createQuery(
"SELECT * FROM `registrations` WHERE uname=?",
@ -90,7 +90,7 @@ exports.login = function(name, pw, session) {
exports.loginPassword = function(name, pw) {
var db = Database.getConnection();
if(!db) {
return false;
throw "Database failure";
}
var query = Database.createQuery(
"SELECT * FROM `registrations` WHERE uname=?",
@ -140,7 +140,7 @@ exports.createSession = function(name) {
var hash = hashlib.sha256(salt + name);
var db = Database.getConnection();
if(!db) {
return false;
throw "Database failure";
}
var query = Database.createQuery(
["UPDATE `registrations` SET ",
@ -156,7 +156,7 @@ exports.createSession = function(name) {
exports.loginSession = function(name, hash) {
var db = Database.getConnection();
if(!db) {
return false;
throw "Database failure";
}
var query = Database.createQuery(
"SELECT * FROM `registrations` WHERE `uname`=?",

View File

@ -138,8 +138,15 @@ Channel.prototype.hasPermission = function(user, key) {
Channel.prototype.loadDump = function() {
fs.readFile("chandump/" + this.name, function(err, data) {
if(err) {
Logger.errlog.log("Failed to open channel dump " + this.name);
Logger.errlog.log(err);
if(err.code == "ENOENT") {
Logger.errlog.log("WARN: missing dump for " + this.name);
this.initialized = true;
this.saveDump();
}
else {
Logger.errlog.log("Failed to open channel dump " + this.name);
Logger.errlog.log(err);
}
return;
}
try {

View File

@ -38,7 +38,7 @@ function getConnection() {
db = mysql.createConnectionSync();
db.connectSync(SERVER, USER, PASSWORD, DATABASE);
if(!db.connectedSync()) {
//Logger.errlog.log("DB connection failed");
Logger.errlog.log("DB connection failed");
return false;
}
if(CONFIG.DEBUG) {

View File

@ -141,6 +141,7 @@ function newConnection(req, res) {
exports.newConnection = newConnection;
function msgReceived(req, res) {
res.callback = req.query.callback;
var h = req.params.hash;
if(h in clients && clients[h] != null) {
var str = req.params.str;

132
user.js
View File

@ -541,73 +541,89 @@ User.prototype.login = function(name, pw, session) {
return false;
}
}
// Sorry bud, can't take that name
if(Auth.isRegistered(name)) {
this.socket.emit("login", {
success: false,
error: "That username is already taken"
});
return false;
}
// YOUR ARGUMENT IS INVALID
else if(!Auth.validateName(name)) {
this.socket.emit("login", {
success: false,
error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores"
});
}
else {
lastguestlogin[this.ip] = Date.now();
this.rank = Rank.Guest;
Logger.syslog.log(this.ip + " signed in as " + name);
Database.recordVisit(this.ip, name);
this.name = name;
this.loggedIn = false;
this.socket.emit("login", {
success: true,
name: name
});
this.socket.emit("rank", this.rank);
if(this.channel != null) {
this.channel.logger.log(this.ip + " signed in as " + name);
this.channel.broadcastNewUser(this);
try {
// Sorry bud, can't take that name
if(Auth.isRegistered(name)) {
this.socket.emit("login", {
success: false,
error: "That username is already taken"
});
return false;
}
// YOUR ARGUMENT IS INVALID
else if(!Auth.validateName(name)) {
this.socket.emit("login", {
success: false,
error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores"
});
}
else {
lastguestlogin[this.ip] = Date.now();
this.rank = Rank.Guest;
Logger.syslog.log(this.ip + " signed in as " + name);
Database.recordVisit(this.ip, name);
this.name = name;
this.loggedIn = false;
this.socket.emit("login", {
success: true,
name: name
});
this.socket.emit("rank", this.rank);
if(this.channel != null) {
this.channel.logger.log(this.ip + " signed in as " + name);
this.channel.broadcastNewUser(this);
}
}
}
catch(e) {
this.socket.emit("login", {
success: false,
error: e
});
}
}
else {
var row;
if((row = Auth.login(name, pw, session))) {
this.loggedIn = true;
this.socket.emit("login", {
success: true,
session: row.session_hash,
name: name
});
Logger.syslog.log(this.ip + " logged in as " + name);
Database.recordVisit(this.ip, name);
this.profile = {
image: row.profile_image,
text: row.profile_text
};
var chanrank = (this.channel != null) ? this.channel.getRank(name)
: Rank.Guest;
var rank = (chanrank > row.global_rank) ? chanrank
: row.global_rank;
this.rank = (this.rank > rank) ? this.rank : rank;
this.socket.emit("rank", this.rank);
this.name = name;
if(this.channel != null) {
this.channel.logger.log(this.ip + " logged in as " + name);
this.channel.broadcastNewUser(this);
try {
var row;
if((row = Auth.login(name, pw, session))) {
this.loggedIn = true;
this.socket.emit("login", {
success: true,
session: row.session_hash,
name: name
});
Logger.syslog.log(this.ip + " logged in as " + name);
Database.recordVisit(this.ip, name);
this.profile = {
image: row.profile_image,
text: row.profile_text
};
var chanrank = (this.channel != null) ? this.channel.getRank(name)
: Rank.Guest;
var rank = (chanrank > row.global_rank) ? chanrank
: row.global_rank;
this.rank = (this.rank > rank) ? this.rank : rank;
this.socket.emit("rank", this.rank);
this.name = name;
if(this.channel != null) {
this.channel.logger.log(this.ip + " logged in as " + name);
this.channel.broadcastNewUser(this);
}
}
// Wrong password
else {
this.socket.emit("login", {
success: false,
error: "Invalid session"
});
return false;
}
}
// Wrong password
else {
catch(e) {
this.socket.emit("login", {
success: false,
error: "Invalid session"
error: e
});
return false;
}
}
}

View File

@ -27,7 +27,7 @@
<div class="">
<ul class="nav">
<li><a href="index.html">Home</a></li>
<li><a href="help.html">Help</a></li>
<li><a href="https://github.com/calzoneman/sync/wiki/Beginner%27s-Guide-and-FAQ" target="_blank">Help</a></li>
<li class="active"><a href="account.html">Account</a></li>
</ul>
</div>

View File

@ -9,8 +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 uname = readCookie("sync_uname") || "";
var session = readCookie("sync_session") || "";
var uname = readCookie("cytube_uname") || "";
var session = readCookie("cytube_session") || "";
var api = WEB_URL + "/api/json/";
var loggedin = false;

View File

@ -356,9 +356,10 @@ Callbacks = {
banlist: function(entries) {
var tbl = $("#banlist table");
// dumb hack because of jquery UI
// sortable turns tables and lists into a mess of race conditions
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if(!tbl.hasClass("table")) {
console.log("thing");
setTimeout(function() {
Callbacks.banlist(entries);
}, 100);
@ -391,8 +392,8 @@ Callbacks = {
recentLogins: function(entries) {
var tbl = $("#loginhistory table");
// dumb hack because of jquery UI
// sortable turns tables and lists into a mess of race conditions
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if(!tbl.hasClass("table")) {
setTimeout(function() {
Callbacks.recentLogins(entries);
@ -415,8 +416,10 @@ Callbacks = {
channelRanks: function(entries) {
var tbl = $("#channelranks table");
// Dammit jQuery UI
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if(!tbl.hasClass("table")) {
console.log("thing");
setTimeout(function() {
Callbacks.channelRanks(entries);
}, 100);
@ -935,35 +938,8 @@ Callbacks = {
}
}
}
/*
pl = [];
for(var i = 0; i < 10; i++) {
var m = {
title: "Test " + i,
type: "yt",
id: "test" + i,
seconds: 0,
duration: "00:00"
};
pl.push(m);
}
setTimeout(function() {
Callbacks.playlist(pl);
}, 1000);
*/
$.getScript(IO_URL+"/socket.io/socket.io.js", function() {
try {
socket = io.connect(IO_URL);
setupCallbacks();
}
catch(e) {
Callbacks.disconnect();
}
});
setupCallbacks = function() {
console.log(socket);
for(var key in Callbacks) {
(function(key) {
socket.on(key, function(data) {
@ -973,3 +949,23 @@ setupCallbacks = function() {
}
}
if(USEROPTS.altsocket) {
socket = new NotWebsocket();
setupCallbacks();
}
else {
$.getScript(IO_URL+"/socket.io/socket.io.js", function() {
try {
if(NO_WEBSOCKETS) {
var i = io.transports.indexOf("websocket");
if(i >= 0)
io.transports.splice(i, 1);
}
socket = io.connect(IO_URL);
setupCallbacks();
}
catch(e) {
Callbacks.disconnect();
}
});
}

View File

@ -1,3 +1,5 @@
var CL_VERSION = "2.0.0";
var CLIENT = {
rank: -1,
leader: false,

View File

@ -11,3 +11,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var IO_URL = "http://localhost:1337";
var WEB_URL = "http://localhost:8080";
var NO_WEBSOCKETS = false;

View File

@ -12,7 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var NotWebsocket = function() {
this.connected = false;
this.polltmr = false;
$.getJSON(WEB_URL + "/nws/connect", function(data) {
$.getJSON(WEB_URL + "/nws/connect?callback=?", function(data) {
this.hash = data;
this.connected = true;
this.recv(["connect", undefined]);
@ -76,7 +76,7 @@ NotWebsocket.prototype.emit = function(msg, data) {
}
var pkt = [msg, data];
var str = escape(JSON.stringify(pkt)).replace(/\//g, "%2F");
$.getJSON(WEB_URL+"/nws/"+this.hash+"/"+str, function() {
$.getJSON(WEB_URL+"/nws/"+this.hash+"/"+str+"?callback=?", function() {
// Poll more quickly because sending a packet usually means
// expecting some data to come back
this.pollint = 100;

View File

@ -57,7 +57,7 @@ $("#chatline").keydown(function(ev) {
msg: msg
});
CHATHIST.push($("#chatline").val());
CHATLISTIDX = CHATHIST.length;
CHATHISTIDX = CHATHIST.length;
$("#chatline").val("");
}
return;
@ -326,3 +326,8 @@ else {
}
});
}
/* oh internet explorer, how I hate thee */
$(":input:not(textarea)").keypress(function(ev) {
return ev.keyCode != 13;
});

View File

@ -111,8 +111,6 @@ function addUserDropdown(entry, name) {
$("<strong/>").text(name).appendTo(menu);
$("<br/>").appendTo(menu);
if(CLIENT.rank >= 2)
$("<span/>").addClass("user-aliases").appendTo(menu);
if(hasPermission("kick")) {
$("<button/>").addClass("btn btn-mini btn-block")
.text("Kick")
@ -164,8 +162,6 @@ function addUserDropdown(entry, name) {
entry.contextmenu(function(ev) {
ev.preventDefault();
if(menu.css("display") == "none") {
menu.find(".user-aliases")
.text("Aliases: " + entry.data("aliases"));
menu.show();
}
else {
@ -476,7 +472,7 @@ function applyOpts() {
}
if(USEROPTS.altsocket) {
if(socket)
if(socket && socket.disconnect)
socket.disconnect();
socket = new NotWebsocket();
setupCallbacks();
@ -649,6 +645,8 @@ function hasPermission(key) {
function handlePermissionChange() {
function setVisible(selector, bool) {
// I originally added this check because of a race condition
// Now it seems to work without but I don't trust it
if($(selector) && $(selector).attr("id") != selector.substring(1)) {
setTimeout(function() {
setVisible(selector, bool);

View File

@ -26,8 +26,8 @@
<a class="brand" href="index.html">CyTube</a>
<ul class="nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="help.html">Help</a></li>
<li><a href="account.html">Account</a></li>
<li><a href="https://github.com/calzoneman/sync/wiki/Beginner%27s-Guide-and-FAQ" target="_blank">Help</a></li>
<li><a href="account.html" target="_blank">Account</a></li>
<li><a href="javascript:void(0)" id="optlink">Options</a></li>
<li><a href="javascript:void(0)" id="chatonly">Chat Only</a></li>
</ul>
@ -200,10 +200,10 @@
<script src="./assets/js/data.js"></script>
<script src="./assets/js/iourl.js"></script>
<script src="./assets/js/player.js"></script>
<script src="./assets/js/notwebsocket.js"></script>
<script src="./assets/js/util.js"></script>
<script src="./assets/js/ui.js"></script>
<script src="./assets/js/callbacks.js"></script>
<script src="./assets/js/notwebsocket.js"></script>
<!-- APIs -->
<script src="http://api.dmcdn.net/all.js"></script>
<script src="http://jwpsrv.com/library/QouFCLBMEeKC+CIACpYGxA.js"></script>

View File

@ -31,7 +31,7 @@
<div class="">
<ul class="nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="help.html">Help</a></li>
<li><a href="https://github.com/calzoneman/sync/wiki/Beginner%27s-Guide-and-FAQ" target="_blank">Help</a></li>
<li><a href="account.html">Account</a></li>
<li><a href="javascript:void(0)" id="optlink">Options</a></li>
</ul>