Finish refactoring

This commit is contained in:
calzoneman 2013-04-03 12:47:41 -05:00
parent f4019e8b83
commit 7e9907ebdc
6 changed files with 646 additions and 1732 deletions

File diff suppressed because it is too large Load Diff

1301
channel.js

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@ var mysql = require("mysql-libmysqlclient");
var Config = require("./config.js");
var Logger = require("./logger.js");
var Rank = require("./rank.js");
var Media = require("./media.js").Media;
var initialized = false;
@ -84,6 +85,9 @@ exports.loadChannel = function(chan) {
Logger.syslog.log("Channel " + chan.name + " is unregistered.");
return;
}
else if(rows[0].name != chan.name) {
chan.name = rows[0].name;
}
chan.registered = true;
// Load library
@ -229,7 +233,7 @@ exports.cacheMedia = function(channame, media) {
return results;
}
exports.addChannelBan(channame, actor, receiver) {
exports.addChannelBan = function(channame, actor, receiver) {
var db = exports.getConnection();
if(!db) {
Logger.errlog.log("exports.addChannelBan: DB connection failed");
@ -245,7 +249,7 @@ exports.addChannelBan(channame, actor, receiver) {
return results;
}
exports.removeChannelBan(channame, ip) {
exports.removeChannelBan = function(channame, ip) {
var db = exports.getConnection();
if(!db) {
Logger.errlog.log("exports.removeChannelBan: DB connection failed");

View File

@ -25,16 +25,13 @@ Poll.prototype.vote = function(ip, option) {
this.votes[ip] = option;
this.counts[option]++;
}
console.log(this.votes);
}
Poll.prototype.unvote = function(ip) {
console.log('unvote ' + ip + this.votes[ip]);
if(ip in this.votes && this.votes[ip] != null) {
this.counts[this.votes[ip]]--;
this.votes[ip] = null;
}
console.log(this.votes);
}
Poll.prototype.packUpdate = function() {

View File

@ -9,6 +9,9 @@ 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.0.0";
console.log("Starting CyTube v" + VERSION);
var fs = require("fs");
var Logger = require("./logger.js");
var Config = require("./config.js");
@ -45,6 +48,7 @@ exports.io.sockets.on("connection", function(socket) {
Logger.syslog.log("Accepted connection from /" + user.ip);
});
process.on("uncaughtException", function(err) {
Logger.errlog.log("[SEVERE] Uncaught Exception: " + err);
});
@ -52,26 +56,12 @@ process.on("uncaughtException", function(err) {
process.on("exit", shutdown);
process.on("SIGINT", shutdown);
function shutdown() {
Logger.syslog.log("Unloading channels...");
for(var name in exports.channels) {
var chan = exports.channels[name];
var filts = new Array(chan.filters.length);
for(var i = 0; i < chan.filters.length; i++) {
filts[i] = [chan.filters[i][0].source,
chan.filters[i][1],
chan.filters[i][2]];
}
var dump = {
currentPosition: chan.currentPosition,
queue: chan.queue,
opts: chan.opts,
filters: filts,
motd: chan.motd
};
var text = JSON.stringify(dump);
fs.writeFileSync("chandump/" + name, text);
chan.logger.flush();
if(exports.channels[name].registered)
exports.channels[name].saveDump();
}
Logger.syslog.log("Shutting Down");
process.exit(0);

View File

@ -133,7 +133,7 @@ User.prototype.initCallbacks = function() {
this.socket.on("playNext", function() {
if(this.channel != null) {
this.channel.tryPlayNext(this, data);
this.channel.tryPlayNext(this);
}
}.bind(this));
@ -219,7 +219,7 @@ User.prototype.initCallbacks = function() {
this.socket.on("voteskip", function(data) {
if(this.channel != null) {
this.channel.voteskip(this);
this.channel.tryVoteskip(this);
}
}.bind(this));
}