mirror of https://github.com/calzoneman/sync.git
Improve logging
This commit is contained in:
parent
34f20f423f
commit
124ec0080f
9
auth.js
9
auth.js
|
@ -13,6 +13,7 @@ var mysql = require("mysql-libmysqlclient");
|
||||||
var Config = require("./config.js");
|
var Config = require("./config.js");
|
||||||
var bcrypt = require("bcrypt");
|
var bcrypt = require("bcrypt");
|
||||||
var hashlib = require("node_hash");
|
var hashlib = require("node_hash");
|
||||||
|
var Logger = require("./logger.js");
|
||||||
|
|
||||||
// Check if a name is taken
|
// Check if a name is taken
|
||||||
exports.isRegistered = function(name) {
|
exports.isRegistered = function(name) {
|
||||||
|
@ -20,7 +21,7 @@ exports.isRegistered = function(name) {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Auth.isRegistered: DB connection failed");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var query = "SELECT * FROM registrations WHERE uname='{}'"
|
var query = "SELECT * FROM registrations WHERE uname='{}'"
|
||||||
|
@ -50,7 +51,7 @@ exports.register = function(name, pw) {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Auth.register: DB connection failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var hash = bcrypt.hashSync(pw, 10);
|
var hash = bcrypt.hashSync(pw, 10);
|
||||||
|
@ -68,7 +69,7 @@ exports.login = function(name, pw) {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Auth.login: DB connection failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var query = "SELECT * FROM registrations WHERE uname='{1}'"
|
var query = "SELECT * FROM registrations WHERE uname='{1}'"
|
||||||
|
@ -92,7 +93,7 @@ exports.login = function(name, pw) {
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
db.closeSync();
|
db.closeSync();
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Failed to migrate password! user=", name);
|
Logger.errlog.log("Failed to migrate password! user=" + name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return rows[0];
|
return rows[0];
|
||||||
|
|
142
channel.js
142
channel.js
|
@ -18,9 +18,10 @@ var Media = require("./media.js").Media;
|
||||||
var ChatCommand = require("./chatcommand.js");
|
var ChatCommand = require("./chatcommand.js");
|
||||||
var Server = require("./server.js");
|
var Server = require("./server.js");
|
||||||
var io = Server.io;
|
var io = Server.io;
|
||||||
|
var Logger = require("./logger.js");
|
||||||
|
|
||||||
var Channel = function(name) {
|
var Channel = function(name) {
|
||||||
console.log("Opening channel " + name);
|
Logger.syslog.log("Opening channel " + name);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.registered = false;
|
this.registered = false;
|
||||||
this.users = [];
|
this.users = [];
|
||||||
|
@ -38,10 +39,11 @@ var Channel = function(name) {
|
||||||
qopen_allow_playnext: false,
|
qopen_allow_playnext: false,
|
||||||
qopen_allow_delete: false,
|
qopen_allow_delete: false,
|
||||||
pagetitle: "Sync",
|
pagetitle: "Sync",
|
||||||
bgimage: ""
|
customcss: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
this.ipbans = [];
|
this.ipbans = {};
|
||||||
|
this.logger = new Logger.Logger("chanlogs/" + this.name + ".log");
|
||||||
|
|
||||||
// Autolead stuff
|
// Autolead stuff
|
||||||
// Accumulator
|
// Accumulator
|
||||||
|
@ -59,7 +61,7 @@ Channel.prototype.loadMysql = function() {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Channel.loadMysql: MySQL Connection Failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check if channel exists
|
// Check if channel exists
|
||||||
|
@ -67,12 +69,12 @@ Channel.prototype.loadMysql = function() {
|
||||||
.replace(/\{\}/, this.name);
|
.replace(/\{\}/, this.name);
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("channel query failed");
|
Logger.errlog.log("Channel.loadMysql: Channel query failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var rows = results.fetchAllSync();
|
var rows = results.fetchAllSync();
|
||||||
if(rows.length == 0) {
|
if(rows.length == 0) {
|
||||||
console.log("Channel " + this.name + " is unregistered");
|
Logger.syslog.log("Channel " + this.name + " is unregistered.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.registered = true;
|
this.registered = true;
|
||||||
|
@ -82,7 +84,7 @@ Channel.prototype.loadMysql = function() {
|
||||||
.replace(/\{\}/, this.name);
|
.replace(/\{\}/, this.name);
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("channel library query failed");
|
Logger.errlog.log("Channel.loadMysql: failed to load library for " + this.name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var rows = results.fetchAllSync();
|
var rows = results.fetchAllSync();
|
||||||
|
@ -95,7 +97,7 @@ Channel.prototype.loadMysql = function() {
|
||||||
.replace(/\{\}/, this.name);
|
.replace(/\{\}/, this.name);
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Channel banlist query failed");
|
Logger.errlog.log("Channel.loadMysql: failed to load banlist for " + this.name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var rows = results.fetchAllSync();
|
var rows = results.fetchAllSync();
|
||||||
|
@ -103,7 +105,7 @@ Channel.prototype.loadMysql = function() {
|
||||||
this.ipbans[rows[i].ip] = [rows[i].name, rows[i].banner];
|
this.ipbans[rows[i].ip] = [rows[i].name, rows[i].banner];
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Loaded channel " + this.name + " from MySQL DB");
|
Logger.syslog.log("Loaded channel " + this.name + " from database");
|
||||||
db.closeSync();
|
db.closeSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +116,7 @@ Channel.prototype.createTables = function() {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Channel.createTables: DB connection failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Create library table
|
// Create library table
|
||||||
|
@ -187,6 +189,8 @@ Channel.prototype.tryRegister = function(user) {
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
success: true,
|
success: true,
|
||||||
});
|
});
|
||||||
|
this.logger.log("*** " + user.name + " registered the channel");
|
||||||
|
Logger.syslog.log("Channel " + this.name + " was registered by " + user.name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
|
@ -205,7 +209,7 @@ Channel.prototype.getRank = function(name) {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Channel.getRank: DB connection failed");
|
||||||
return Rank.Guest;
|
return Rank.Guest;
|
||||||
}
|
}
|
||||||
var query = "SELECT * FROM chan_{1}_ranks WHERE name='{2}'"
|
var query = "SELECT * FROM chan_{1}_ranks WHERE name='{2}'"
|
||||||
|
@ -231,7 +235,7 @@ Channel.prototype.saveRank = function(user) {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Channel.saveRank: DB connection failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var query = "UPDATE chan_{1}_ranks SET rank='{2}' WHERE name='{3}'"
|
var query = "UPDATE chan_{1}_ranks SET rank='{2}' WHERE name='{3}'"
|
||||||
|
@ -261,7 +265,7 @@ Channel.prototype.addToLibrary = function(media) {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Channel.addToLibrary: DB connection failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var query = "INSERT INTO chan_{1}_library VALUES ('{2}', '{3}', {4}, '{5}', '{6}')"
|
var query = "INSERT INTO chan_{1}_library VALUES ('{2}', '{3}', {4}, '{5}', '{6}')"
|
||||||
|
@ -287,7 +291,7 @@ Channel.prototype.banIP = function(banner, bannee) {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Channel.banIP: DB connection failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var query = "INSERT INTO chan_{1}_bans (`ip`, `name`, `banner`) VALUES ('{2}', '{3}', '{4}')"
|
var query = "INSERT INTO chan_{1}_bans (`ip`, `name`, `banner`) VALUES ('{2}', '{3}', '{4}')"
|
||||||
|
@ -297,7 +301,10 @@ Channel.prototype.banIP = function(banner, bannee) {
|
||||||
.replace(/\{4\}/, banner.name);
|
.replace(/\{4\}/, banner.name);
|
||||||
results = db.querySync(query);
|
results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Insert into ban table failed");
|
Logger.errlog.log("Channel.banIP: Insert failed");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.logger.log(bannee.ip + " (" + bannee.name + ") was banned by " + banner.name);
|
||||||
}
|
}
|
||||||
db.closeSync();
|
db.closeSync();
|
||||||
return results;
|
return results;
|
||||||
|
@ -313,7 +320,7 @@ Channel.prototype.unbanIP = function(ip) {
|
||||||
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
|
||||||
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
|
||||||
if(!db.connectedSync()) {
|
if(!db.connectedSync()) {
|
||||||
console.log("MySQL Connection Failed");
|
Logger.errlog.log("Channel.unbanIP: DB connection failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +330,7 @@ Channel.prototype.unbanIP = function(ip) {
|
||||||
|
|
||||||
results = db.querySync(query);
|
results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Delete from ban table failed");
|
Logger.errlog.log("Channel.unbanIP: Failed to delete entry");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
db.closeSync();
|
db.closeSync();
|
||||||
|
@ -351,7 +358,7 @@ Channel.prototype.searchLibrary = function(query) {
|
||||||
// Called when a new user enters the channel
|
// Called when a new user enters the channel
|
||||||
Channel.prototype.userJoin = function(user) {
|
Channel.prototype.userJoin = function(user) {
|
||||||
if(user.ip in this.ipbans && this.ipbans[user.ip] != null) {
|
if(user.ip in this.ipbans && this.ipbans[user.ip] != null) {
|
||||||
console.log("/" + user.ip + " was disconnected - banned");
|
this.logger.log("--- Kicking /" + user.ip + " - banned");
|
||||||
user.socket.disconnect();
|
user.socket.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -403,7 +410,8 @@ Channel.prototype.userJoin = function(user) {
|
||||||
user.socket.emit("banlist", {entries: ents});
|
user.socket.emit("banlist", {entries: ents});
|
||||||
if(user.playerReady)
|
if(user.playerReady)
|
||||||
this.sendMediaUpdate(user);
|
this.sendMediaUpdate(user);
|
||||||
console.log("/" + user.ip + " joined channel " + this.name);
|
this.logger.log("+++ /" + user.ip + " joined");
|
||||||
|
Logger.syslog.log("/" + user.ip + " joined channel " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when a user leaves the channel
|
// Called when a user leaves the channel
|
||||||
|
@ -428,6 +436,7 @@ Channel.prototype.userLeave = function(user) {
|
||||||
name: user.name
|
name: user.name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.logger.log("--- /" + user.ip + " (" + user.name + ") left");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queues a new media
|
// Queues a new media
|
||||||
|
@ -440,6 +449,7 @@ Channel.prototype.enqueue = function(data) {
|
||||||
media: this.library[data.id].pack(),
|
media: this.library[data.id].pack(),
|
||||||
pos: idx
|
pos: idx
|
||||||
});
|
});
|
||||||
|
this.logger.log("*** Queued from cache: id=" + data.id);
|
||||||
}
|
}
|
||||||
// Query metadata from YouTube
|
// Query metadata from YouTube
|
||||||
else if(data.type == "yt") {
|
else if(data.type == "yt") {
|
||||||
|
@ -460,9 +470,11 @@ Channel.prototype.enqueue = function(data) {
|
||||||
pos: idx
|
pos: idx
|
||||||
});
|
});
|
||||||
chan.addToLibrary(vid);
|
chan.addToLibrary(vid);
|
||||||
|
chan.logger.log("*** Queued new YT video: " + id);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
console.log("YTQueue Fail: id=" + id);
|
Logger.errlog.log("YTQueue Fail: id=" + id);
|
||||||
|
console.log(e);
|
||||||
}
|
}
|
||||||
}})(this, data.id);
|
}})(this, data.id);
|
||||||
InfoGetter.getYTInfo(data.id, callback);
|
InfoGetter.getYTInfo(data.id, callback);
|
||||||
|
@ -491,9 +503,10 @@ Channel.prototype.enqueue = function(data) {
|
||||||
chan.addToLibrary(vid);
|
chan.addToLibrary(vid);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
chan.logger.log("*** Queued YT Playlist: id=" + id);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
console.log("YTPlaylist Failed: id=", id);
|
Logger.errlog.log("YTPlaylist Failed: id=", id);
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
}})(this, data.id);
|
}})(this, data.id);
|
||||||
|
@ -507,6 +520,7 @@ Channel.prototype.enqueue = function(data) {
|
||||||
media: media.pack(),
|
media: media.pack(),
|
||||||
pos: idx
|
pos: idx
|
||||||
});
|
});
|
||||||
|
this.logger.log("*** Queued Twitch channel: " + data.id);
|
||||||
}
|
}
|
||||||
else if(data.type == "li") {
|
else if(data.type == "li") {
|
||||||
var media = new Media(data.id, "Livestream ~ " + data.id, 0, "li");
|
var media = new Media(data.id, "Livestream ~ " + data.id, 0, "li");
|
||||||
|
@ -515,6 +529,7 @@ Channel.prototype.enqueue = function(data) {
|
||||||
media: media.pack(),
|
media: media.pack(),
|
||||||
pos: idx
|
pos: idx
|
||||||
});
|
});
|
||||||
|
this.logger.log("*** Queued Livestream channel: " + data.id);
|
||||||
}
|
}
|
||||||
// Query metadata from Soundcloud
|
// Query metadata from Soundcloud
|
||||||
else if(data.type == "sc") {
|
else if(data.type == "sc") {
|
||||||
|
@ -523,15 +538,22 @@ Channel.prototype.enqueue = function(data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var seconds = data.duration / 1000;
|
try {
|
||||||
var title = data.title;
|
var seconds = data.duration / 1000;
|
||||||
var vid = new Media(id, title, seconds, "sc");
|
var title = data.title;
|
||||||
chan.queue.splice(idx, 0, vid);
|
var vid = new Media(id, title, seconds, "sc");
|
||||||
chan.sendAll("queue", {
|
chan.queue.splice(idx, 0, vid);
|
||||||
media: vid.pack(),
|
chan.sendAll("queue", {
|
||||||
pos: idx
|
media: vid.pack(),
|
||||||
});
|
pos: idx
|
||||||
chan.addToLibrary(vid);
|
});
|
||||||
|
chan.addToLibrary(vid);
|
||||||
|
chan.logger.log("*** Queued Soundcloud id=" + id);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
Logger.errlog.log("SCQueue fail: id=" + id);
|
||||||
|
Logger.errlog.log(e);
|
||||||
|
}
|
||||||
}})(this, data.id);
|
}})(this, data.id);
|
||||||
InfoGetter.getSCInfo(data.id, callback);
|
InfoGetter.getSCInfo(data.id, callback);
|
||||||
}
|
}
|
||||||
|
@ -542,16 +564,23 @@ Channel.prototype.enqueue = function(data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = data[0];
|
try {
|
||||||
var seconds = data.duration;
|
data = data[0];
|
||||||
var title = data.title;
|
var seconds = data.duration;
|
||||||
var vid = new Media(id, title, seconds, "vi");
|
var title = data.title;
|
||||||
chan.queue.splice(idx, 0, vid);
|
var vid = new Media(id, title, seconds, "vi");
|
||||||
chan.sendAll("queue", {
|
chan.queue.splice(idx, 0, vid);
|
||||||
media: vid.pack(),
|
chan.sendAll("queue", {
|
||||||
pos: idx
|
media: vid.pack(),
|
||||||
});
|
pos: idx
|
||||||
chan.addToLibrary(vid);
|
});
|
||||||
|
chan.addToLibrary(vid);
|
||||||
|
chan.logger.log("*** Queued Vimeo id=" + id);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
Logger.errlog.log("VIQueue fail: id=" + id);
|
||||||
|
Logger.errlog.log(e);
|
||||||
|
}
|
||||||
}})(this, data.id);
|
}})(this, data.id);
|
||||||
InfoGetter.getVIInfo(data.id, callback);
|
InfoGetter.getVIInfo(data.id, callback);
|
||||||
}
|
}
|
||||||
|
@ -563,15 +592,22 @@ Channel.prototype.enqueue = function(data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var seconds = data.duration;
|
try {
|
||||||
var title = data.title;
|
var seconds = data.duration;
|
||||||
var vid = new Media(id, title, seconds, "dm");
|
var title = data.title;
|
||||||
chan.queue.splice(idx, 0, vid);
|
var vid = new Media(id, title, seconds, "dm");
|
||||||
chan.sendAll("queue", {
|
chan.queue.splice(idx, 0, vid);
|
||||||
media: vid.pack(),
|
chan.sendAll("queue", {
|
||||||
pos: idx
|
media: vid.pack(),
|
||||||
});
|
pos: idx
|
||||||
chan.addToLibrary(vid);
|
});
|
||||||
|
chan.addToLibrary(vid);
|
||||||
|
chan.logger.log("*** Queued Dailymotion id=" + id);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
Logger.errlog.log("DMQueue fail: id=" + id);
|
||||||
|
Logger.errlog.log(e);
|
||||||
|
}
|
||||||
}})(this, data.id);
|
}})(this, data.id);
|
||||||
InfoGetter.getDMInfo(data.id, callback);
|
InfoGetter.getDMInfo(data.id, callback);
|
||||||
}
|
}
|
||||||
|
@ -693,6 +729,7 @@ Channel.prototype.sendMessage = function(username, msg, msgclass) {
|
||||||
});
|
});
|
||||||
if(this.recentChat.length > 15)
|
if(this.recentChat.length > 15)
|
||||||
this.recentChat.shift();
|
this.recentChat.shift();
|
||||||
|
this.logger.log("<" + username + "." + msgclass + "> " + msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Promotion! Actor is the client who initiated the promotion, name is the
|
// Promotion! Actor is the client who initiated the promotion, name is the
|
||||||
|
@ -715,6 +752,7 @@ Channel.prototype.promoteUser = function(actor, name) {
|
||||||
if(receiver.loggedIn) {
|
if(receiver.loggedIn) {
|
||||||
this.saveRank(receiver);
|
this.saveRank(receiver);
|
||||||
}
|
}
|
||||||
|
this.logger.log("*** " + actor.name + " promoted " + receiver.name + " from " + (receiver.rank - 1) + " to " + receiver.rank);
|
||||||
this.broadcastRankUpdate(receiver);
|
this.broadcastRankUpdate(receiver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -738,6 +776,7 @@ Channel.prototype.demoteUser = function(actor, name) {
|
||||||
if(receiver.loggedIn) {
|
if(receiver.loggedIn) {
|
||||||
this.saveRank(receiver);
|
this.saveRank(receiver);
|
||||||
}
|
}
|
||||||
|
this.logger.log("*** " + actor.name + " demoted " + receiver.name + " from " + (receiver.rank + 1) + " to " + receiver.rank);
|
||||||
this.broadcastRankUpdate(receiver);
|
this.broadcastRankUpdate(receiver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -752,6 +791,7 @@ Channel.prototype.changeLeader = function(name) {
|
||||||
this.broadcastRankUpdate(old);
|
this.broadcastRankUpdate(old);
|
||||||
}
|
}
|
||||||
if(name == "") {
|
if(name == "") {
|
||||||
|
this.logger.log("*** Resuming autolead");
|
||||||
if(this.currentMedia != null) {
|
if(this.currentMedia != null) {
|
||||||
this.time = new Date().getTime();
|
this.time = new Date().getTime();
|
||||||
this.i = 0;
|
this.i = 0;
|
||||||
|
@ -761,6 +801,7 @@ Channel.prototype.changeLeader = function(name) {
|
||||||
}
|
}
|
||||||
for(var i = 0; i < this.users.length; i++) {
|
for(var i = 0; i < this.users.length; i++) {
|
||||||
if(this.users[i].name == name) {
|
if(this.users[i].name == name) {
|
||||||
|
this.logger.log("*** Assigned leader: " + name);
|
||||||
this.leader = this.users[i];
|
this.leader = this.users[i];
|
||||||
this.broadcastRankUpdate(this.leader);
|
this.broadcastRankUpdate(this.leader);
|
||||||
}
|
}
|
||||||
|
@ -812,9 +853,6 @@ Channel.prototype.sendMediaUpdate = function(user) {
|
||||||
if(this.currentMedia != null) {
|
if(this.currentMedia != null) {
|
||||||
user.socket.emit("mediaUpdate", this.currentMedia.packupdate());
|
user.socket.emit("mediaUpdate", this.currentMedia.packupdate());
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
console.log("currentMedia is null");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sent when someone logs in, to add them to the user list
|
// Sent when someone logs in, to add them to the user list
|
||||||
|
|
|
@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||||
|
|
||||||
var Rank = require("./rank.js");
|
var Rank = require("./rank.js");
|
||||||
var Poll = require("./poll.js").Poll;
|
var Poll = require("./poll.js").Poll;
|
||||||
|
var Logger = require("./logger.js");
|
||||||
|
|
||||||
function handle(chan, user, msg) {
|
function handle(chan, user, msg) {
|
||||||
if(msg.indexOf("/me ") == 0)
|
if(msg.indexOf("/me ") == 0)
|
||||||
|
@ -46,6 +47,7 @@ function handleKick(chan, user, args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(kickee) {
|
if(kickee) {
|
||||||
|
chan.logger.log("*** " + user.name + " kicked " + args[0]);
|
||||||
kickee.socket.disconnect();
|
kickee.socket.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +63,7 @@ function handleBan(chan, user, args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(kickee && kickee.rank < user.rank) {
|
if(kickee && kickee.rank < user.rank) {
|
||||||
|
chan.logger.log("*** " + user.name + " banned " + args[0]);
|
||||||
chan.banIP(user, kickee);
|
chan.banIP(user, kickee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +71,7 @@ function handleBan(chan, user, args) {
|
||||||
|
|
||||||
function handleUnban(chan, user, args) {
|
function handleUnban(chan, user, args) {
|
||||||
if(Rank.hasPermission(user, "ipban") && args.length > 0) {
|
if(Rank.hasPermission(user, "ipban") && args.length > 0) {
|
||||||
|
chan.logger.log("*** " + user.name + " unbanned " + args[0]);
|
||||||
chan.unbanIP(args[0]);
|
chan.unbanIP(args[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +84,7 @@ function handlePoll(chan, user, msg) {
|
||||||
var poll = new Poll(user.name, title, args);
|
var poll = new Poll(user.name, title, args);
|
||||||
chan.poll = poll;
|
chan.poll = poll;
|
||||||
chan.broadcastPoll();
|
chan.broadcastPoll();
|
||||||
|
chan.logger.log("*** " + user.name + " Opened Poll: '" + poll.title + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
database.js
11
database.js
|
@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||||
|
|
||||||
var mysql = require("mysql-libmysqlclient");
|
var mysql = require("mysql-libmysqlclient");
|
||||||
var Config = require("./config.js");
|
var Config = require("./config.js");
|
||||||
|
var Logger = require("./logger.js");
|
||||||
|
|
||||||
var initialized = false;
|
var initialized = false;
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ exports.init = function() {
|
||||||
ENGINE = MyISAM;";
|
ENGINE = MyISAM;";
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Database initialization failed! Could not create channel table");
|
Logger.errlog.log("database.init: channel table init failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ exports.init = function() {
|
||||||
ENGINE = MyISAM;";
|
ENGINE = MyISAM;";
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Database initialization failed! Could not create registration table");
|
Logger.errlog.log("database.init: registration table init failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ exports.listChannels = function() {
|
||||||
var query = "SELECT * FROM `channels`";
|
var query = "SELECT * FROM `channels`";
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Database channel listing failed!");
|
Logger.errlog.log("database.listChannels: query failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@ exports.listUsers = function() {
|
||||||
var query = "SELECT * FROM `registrations`";
|
var query = "SELECT * FROM `registrations`";
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Database user listing failed!");
|
Logger.errlog.log("database.listUsers: query failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ exports.listChannelRanks = function(chan) {
|
||||||
console.log(query);
|
console.log(query);
|
||||||
var results = db.querySync(query);
|
var results = db.querySync(query);
|
||||||
if(!results) {
|
if(!results) {
|
||||||
console.log("Database channel listing failed!");
|
Logger.errlog.log("database.listChannelRanks: query failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||||
|
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var https = require("https");
|
var https = require("https");
|
||||||
|
var Logger = require("./logger.js");
|
||||||
|
|
||||||
// Helper function for making an HTTP request and getting the result
|
// Helper function for making an HTTP request and getting the result
|
||||||
// as JSON
|
// as JSON
|
||||||
|
@ -26,7 +27,7 @@ function getJSON(options, callback) {
|
||||||
var data = JSON.parse(buffer);
|
var data = JSON.parse(buffer);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
console.log("JSON fail: ", options);
|
Logger.errlog.log("JSON fail: " + options.path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
callback(res.statusCode, data);
|
callback(res.statusCode, data);
|
||||||
|
@ -49,7 +50,7 @@ function getJSONHTTPS(options, callback) {
|
||||||
var data = JSON.parse(buffer);
|
var data = JSON.parse(buffer);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
console.log("JSON fail: ", options);
|
Logger.errlog.log("JSON fail: " + options.path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
callback(res.statusCode, data);
|
callback(res.statusCode, data);
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
Copyright (c) 2013 Calvin Montgomery
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
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 fs = require("fs");
|
||||||
|
|
||||||
|
function getTimeString() {
|
||||||
|
return new Date().toTimeString().split(" ")[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
var Logger = function(filename) {
|
||||||
|
this.filename = filename;
|
||||||
|
this.buffer = [];
|
||||||
|
|
||||||
|
setInterval(function() {
|
||||||
|
this.flush();
|
||||||
|
}.bind(this), 15000);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.prototype.log = function(what) {
|
||||||
|
this.buffer.push("[" + getTimeString() + "] " + what);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.prototype.flush = function() {
|
||||||
|
if(this.buffer.length == 0)
|
||||||
|
return;
|
||||||
|
var text = this.buffer.join("\n") + "\n";
|
||||||
|
this.buffer = [];
|
||||||
|
fs.appendFile(this.filename, text, function(err) {
|
||||||
|
if(err) {
|
||||||
|
errlog.log("Append to " + this.filename + " failed: ");
|
||||||
|
errlog.log(err);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
var errlog = new Logger("error.log");
|
||||||
|
var syslog = new Logger("sys.log");
|
||||||
|
errlog.actualLog = errlog.log;
|
||||||
|
errlog.log = function(what) { console.log(what); this.actualLog(what); }
|
||||||
|
syslog.actualLog = syslog.log;
|
||||||
|
syslog.log = function(what) { console.log(what); this.actualLog(what); }
|
||||||
|
|
||||||
|
exports.Logger = Logger;
|
||||||
|
exports.errlog = errlog;
|
||||||
|
exports.syslog = syslog;
|
|
@ -9,6 +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.
|
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 Logger = require("./logger.js");
|
||||||
var Config = require("./config.js");
|
var Config = require("./config.js");
|
||||||
var connect = require("connect");
|
var connect = require("connect");
|
||||||
var app = connect.createServer(connect.static(__dirname+"/www")).listen(Config.IO_PORT);
|
var app = connect.createServer(connect.static(__dirname+"/www")).listen(Config.IO_PORT);
|
||||||
|
@ -22,5 +23,5 @@ exports.channels = {};
|
||||||
|
|
||||||
exports.io.sockets.on("connection", function(socket) {
|
exports.io.sockets.on("connection", function(socket) {
|
||||||
var user = new User(socket, socket.handshake.address.address);
|
var user = new User(socket, socket.handshake.address.address);
|
||||||
console.log("New connection from /" + user.ip);
|
Logger.syslog.log("Accepted connection from /" + user.ip);
|
||||||
});
|
});
|
||||||
|
|
7
user.js
7
user.js
|
@ -14,6 +14,7 @@ var Auth = require("./auth.js");
|
||||||
var Channel = require("./channel.js").Channel;
|
var Channel = require("./channel.js").Channel;
|
||||||
var Server = require("./server.js");
|
var Server = require("./server.js");
|
||||||
var Database = require("./database.js");
|
var Database = require("./database.js");
|
||||||
|
var Logger = require("./logger.js");
|
||||||
|
|
||||||
// Represents a client connected via socket.io
|
// Represents a client connected via socket.io
|
||||||
var User = function(socket, ip) {
|
var User = function(socket, ip) {
|
||||||
|
@ -303,7 +304,7 @@ User.prototype.login = function(name, pw) {
|
||||||
}
|
}
|
||||||
// Woah, success!
|
// Woah, success!
|
||||||
else {
|
else {
|
||||||
console.log(this.ip + " signed in as " + name);
|
Logger.syslog.log(this.ip + " signed in as " + name);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.loggedIn = false;
|
this.loggedIn = false;
|
||||||
this.socket.emit("login", {
|
this.socket.emit("login", {
|
||||||
|
@ -313,6 +314,7 @@ User.prototype.login = function(name, pw) {
|
||||||
rank: this.rank
|
rank: this.rank
|
||||||
});
|
});
|
||||||
if(this.channel != null) {
|
if(this.channel != null) {
|
||||||
|
this.channel.logger.log(this.ip + " signed in as " + name);
|
||||||
if(this.rank >= Rank.Moderator)
|
if(this.rank >= Rank.Moderator)
|
||||||
this.channel.sendPlaylist(this);
|
this.channel.sendPlaylist(this);
|
||||||
this.channel.broadcastNewUser(this);
|
this.channel.broadcastNewUser(this);
|
||||||
|
@ -326,7 +328,7 @@ User.prototype.login = function(name, pw) {
|
||||||
this.socket.emit("login", {
|
this.socket.emit("login", {
|
||||||
success: true
|
success: true
|
||||||
});
|
});
|
||||||
console.log(this.ip + " logged in as " + name);
|
Logger.syslog.log(this.ip + " logged in as " + name);
|
||||||
// Sweet, let"s look up our rank
|
// 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;
|
||||||
|
@ -338,6 +340,7 @@ User.prototype.login = function(name, pw) {
|
||||||
});
|
});
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if(this.channel != null) {
|
if(this.channel != null) {
|
||||||
|
this.channel.logger.log(this.ip + " logged in as " + name);
|
||||||
if(this.rank >= Rank.Moderator)
|
if(this.rank >= Rank.Moderator)
|
||||||
this.channel.sendPlaylist(this);
|
this.channel.sendPlaylist(this);
|
||||||
this.channel.broadcastNewUser(this);
|
this.channel.broadcastNewUser(this);
|
||||||
|
|
Loading…
Reference in New Issue