mirror of https://github.com/calzoneman/sync.git
Limit dump size to 1MB
This commit is contained in:
parent
9c22fbc462
commit
817d5b85e0
86
channel.js
86
channel.js
|
@ -142,21 +142,36 @@ Channel.prototype.hasPermission = function(user, key) {
|
||||||
|
|
||||||
/* REGION Channel data */
|
/* REGION Channel data */
|
||||||
Channel.prototype.loadDump = function() {
|
Channel.prototype.loadDump = function() {
|
||||||
fs.readFile("chandump/" + this.name, function(err, data) {
|
var self = this;
|
||||||
|
fs.stat("chandump/" + this.name, function (err, stats) {
|
||||||
|
if(!err) {
|
||||||
|
var mb = stats.size / 1048576;
|
||||||
|
mb = parseInt(mb * 100) / 100;
|
||||||
|
if(mb > 1) {
|
||||||
|
Logger.errlog.log("Large chandump detected: " + self.name +
|
||||||
|
" (" + mb + " MB)");
|
||||||
|
self.updateMotd("Your channel file has exceeded the " +
|
||||||
|
"maximum size of 1MB and cannot be " +
|
||||||
|
"loaded. Please ask an administrator " +
|
||||||
|
"for assistance in restoring it.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs.readFile("chandump/" + self.name, function(err, data) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(err.code == "ENOENT") {
|
if(err.code == "ENOENT") {
|
||||||
Logger.errlog.log("WARN: missing dump for " + this.name);
|
Logger.errlog.log("WARN: missing dump for " + self.name);
|
||||||
this.initialized = true;
|
self.initialized = true;
|
||||||
this.saveDump();
|
self.saveDump();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logger.errlog.log("Failed to open channel dump " + this.name);
|
Logger.errlog.log("Failed to open channel dump " + self.name);
|
||||||
Logger.errlog.log(err);
|
Logger.errlog.log(err);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.logger.log("*** Loading channel dump from disk");
|
self.logger.log("*** Loading channel dump from disk");
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
/* Load the playlist */
|
/* Load the playlist */
|
||||||
|
|
||||||
|
@ -167,22 +182,22 @@ Channel.prototype.loadDump = function() {
|
||||||
for(var i = 0; i < data.queue.length; i++) {
|
for(var i = 0; i < data.queue.length; i++) {
|
||||||
var e = data.queue[i];
|
var e = data.queue[i];
|
||||||
var m = new Media(e.id, e.title, e.seconds, e.type);
|
var m = new Media(e.id, e.title, e.seconds, e.type);
|
||||||
var p = this.playlist.makeItem(m);
|
var p = self.playlist.makeItem(m);
|
||||||
p.queueby = data.queue[i].queueby ? data.queue[i].queueby
|
p.queueby = data.queue[i].queueby ? data.queue[i].queueby
|
||||||
: "";
|
: "";
|
||||||
p.temp = e.temp;
|
p.temp = e.temp;
|
||||||
this.playlist.items.append(p);
|
self.playlist.items.append(p);
|
||||||
if(i == data.position)
|
if(i == data.position)
|
||||||
this.playlist.current = p;
|
self.playlist.current = p;
|
||||||
}
|
}
|
||||||
this.sendAll("playlist", this.playlist.items.toArray());
|
self.sendAll("playlist", self.playlist.items.toArray());
|
||||||
this.broadcastPlaylistMeta();
|
self.broadcastPlaylistMeta();
|
||||||
this.playlist.startPlayback();
|
self.playlist.startPlayback();
|
||||||
}
|
}
|
||||||
// Current
|
// Current
|
||||||
else if(data.playlist) {
|
else if(data.playlist) {
|
||||||
var chan = this;
|
var chan = self;
|
||||||
this.playlist.load(data.playlist, function() {
|
self.playlist.load(data.playlist, function() {
|
||||||
chan.sendAll("playlist", chan.playlist.items.toArray());
|
chan.sendAll("playlist", chan.playlist.items.toArray());
|
||||||
chan.broadcastPlaylistMeta();
|
chan.broadcastPlaylistMeta();
|
||||||
chan.playlist.startPlayback(data.playlist.time);
|
chan.playlist.startPlayback(data.playlist.time);
|
||||||
|
@ -192,18 +207,18 @@ Channel.prototype.loadDump = function() {
|
||||||
// Gotta love backwards compatibility
|
// Gotta love backwards compatibility
|
||||||
if(key == "customcss" || key == "customjs") {
|
if(key == "customcss" || key == "customjs") {
|
||||||
var k = key.substring(6);
|
var k = key.substring(6);
|
||||||
this.opts[k] = data.opts[key];
|
self.opts[k] = data.opts[key];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.opts[key] = data.opts[key];
|
self.opts[key] = data.opts[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(var key in data.permissions) {
|
for(var key in data.permissions) {
|
||||||
this.permissions[key] = data.permissions[key];
|
self.permissions[key] = data.permissions[key];
|
||||||
}
|
}
|
||||||
this.sendAll("setPermissions", this.permissions);
|
self.sendAll("setPermissions", self.permissions);
|
||||||
this.broadcastOpts();
|
self.broadcastOpts();
|
||||||
this.users.forEach(function (u) {
|
self.users.forEach(function (u) {
|
||||||
u.autoAFK();
|
u.autoAFK();
|
||||||
});
|
});
|
||||||
if(data.filters) {
|
if(data.filters) {
|
||||||
|
@ -213,37 +228,38 @@ Channel.prototype.loadDump = function() {
|
||||||
if(f[0] != undefined) {
|
if(f[0] != undefined) {
|
||||||
var filt = new Filter("", f[0], "g", f[1]);
|
var filt = new Filter("", f[0], "g", f[1]);
|
||||||
filt.active = f[2];
|
filt.active = f[2];
|
||||||
this.updateFilter(filt, false);
|
self.updateFilter(filt, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var filt = new Filter(f.name, f.source, f.flags, f.replace);
|
var filt = new Filter(f.name, f.source, f.flags, f.replace);
|
||||||
filt.active = f.active;
|
filt.active = f.active;
|
||||||
filt.filterlinks = f.filterlinks;
|
filt.filterlinks = f.filterlinks;
|
||||||
this.updateFilter(filt, false);
|
self.updateFilter(filt, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.broadcastChatFilters();
|
self.broadcastChatFilters();
|
||||||
}
|
}
|
||||||
if(data.motd) {
|
if(data.motd) {
|
||||||
this.motd = data.motd;
|
self.motd = data.motd;
|
||||||
this.broadcastMotd();
|
self.broadcastMotd();
|
||||||
}
|
}
|
||||||
this.setLock(!(data.openqueue || false));
|
self.setLock(!(data.openqueue || false));
|
||||||
this.chatbuffer = data.chatbuffer || [];
|
self.chatbuffer = data.chatbuffer || [];
|
||||||
for(var i = 0; i < this.chatbuffer.length; i++) {
|
for(var i = 0; i < self.chatbuffer.length; i++) {
|
||||||
this.sendAll("chatMsg", this.chatbuffer[i]);
|
self.sendAll("chatMsg", self.chatbuffer[i]);
|
||||||
}
|
}
|
||||||
this.css = data.css || "";
|
self.css = data.css || "";
|
||||||
this.js = data.js || "";
|
self.js = data.js || "";
|
||||||
this.sendAll("channelCSSJS", {css: this.css, js: this.js});
|
self.sendAll("channelCSSJS", {css: self.css, js: self.js});
|
||||||
this.initialized = true;
|
self.initialized = true;
|
||||||
setTimeout(function() { incrementalDump(this); }.bind(this), 300000);
|
setTimeout(function() { incrementalDump(self); }.bind(self), 300000);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
Logger.errlog.log("Channel dump load failed: ");
|
Logger.errlog.log("Channel dump load failed: ");
|
||||||
Logger.errlog.log(e.stack);
|
Logger.errlog.log(e.stack);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.saveDump = function() {
|
Channel.prototype.saveDump = function() {
|
||||||
|
|
Loading…
Reference in New Issue