diff --git a/lib/channel-new.js b/lib/channel-new.js index d2fb2e32..cc48a41e 100644 --- a/lib/channel-new.js +++ b/lib/channel-new.js @@ -1926,6 +1926,7 @@ Channel.prototype.handleJumpTo = function (user, data) { Channel.prototype.clear = function () { this.playlist.clear(); this.plqueue.reset(); + this.updatePlaylistMeta(); this.sendPlaylist(this.users); }; @@ -2103,11 +2104,15 @@ Channel.prototype.checkVoteskipPass = function () { return false; } + if (this.playlist.length === 0) { + return false; + } + var max = this.calcVoteskipMax(); var need = Math.ceil(max * this.opts.voteskip_ratio); if (this.voteskip.counts[0] >= need) { this.logger.log("### Voteskip passed, skipping to next video"); - this.playNext(); + this.playlist.next(); } this.sendVoteskipUpdate(this.users); diff --git a/lib/server.js b/lib/server.js index 6d6ff253..ae5aea9f 100644 --- a/lib/server.js +++ b/lib/server.js @@ -146,25 +146,30 @@ Server.prototype.isChannelLoaded = function (name) { }; Server.prototype.getChannel = function (name) { + var self = this; var cname = name.toLowerCase(); - for (var i = 0; i < this.channels.length; i++) { - if (this.channels[i].uniqueName === cname) - return this.channels[i]; + for (var i = 0; i < self.channels.length; i++) { + if (self.channels[i].uniqueName === cname) + return self.channels[i]; } var c = new Channel(name); - this.channels.push(c); + c.on("empty", function () { + self.unloadChannel(c); + }); + self.channels.push(c); return c; }; Server.prototype.unloadChannel = function (chan) { - if (chan.registered) + if (chan.registered) { chan.saveState(); + } chan.playlist.die(); chan.logger.close(); for (var i = 0; i < this.channels.length; i++) { - if (this.channels[i].canonical_name === chan.canonical_name) { + if (this.channels[i].uniqueName === chan.uniqueName) { this.channels.splice(i, 1); i--; } diff --git a/lib/utilities.js b/lib/utilities.js index ed4f078b..ada297c8 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -32,26 +32,13 @@ Set.prototype.forEach = function (fn) { } }; -var USERNAME_REGEX = new RegExp( - "^[-\\w" + // Hyphen and a-zA-Z0-9_ - "\\u00c0-\\u00c5" + // Uppercase A - "\\u00c7-\\u00cf" + // Uppercase C, E and I - "\\u00d1-\\u00d6" + // Uppercase N and O - "\\u00d9-\\u00dd" + // Uppercase U and Y - "\\u00e0-\\u00e5" + // Lowercase A - "\\u00e7-\\u00ef" + // Lowercase C, E anf I - "\\u00f1-\\u00f6" + // Lowercase N anf O - "\\u00f9-\\u00ff" + // Lowercase U anf Y - "]{1,20}$" -); - module.exports = { isValidChannelName: function (name) { - return name.match(/^[\w-_]{1,30}$/); + return name.match(/^[\w-]{1,30}$/); }, isValidUserName: function (name) { - return name.match(USERNAME_REGEX); + return name.match(/^[\w-]{1,20}$/); }, isValidEmail: function (email) { diff --git a/lib/web/webserver.js b/lib/web/webserver.js index a72d96d6..8ff0cebd 100644 --- a/lib/web/webserver.js +++ b/lib/web/webserver.js @@ -142,6 +142,15 @@ function handleIndex(req, res) { loginName = req.cookies.auth.split(":")[0]; } + var channels = Server.getServer().packChannelList(true); + channels.sort(function (a, b) { + if (a.usercount === b.usercount) { + return a.uniqueName > b.uniqueName ? 1 : -1; + } + + return a.usercount - b.usercount; + }); + sendJade(res, "index", { loggedIn: loginName !== false, loginName: loginName, diff --git a/templates/index.jade b/templates/index.jade index 56f0ef7c..3fe38da3 100644 --- a/templates/index.jade +++ b/templates/index.jade @@ -24,7 +24,7 @@ html(lang="en") tbody each chan in channels tr - td #{chan.pagetitle} (#{chan.name}) + td: a(href="/r/#{chan.name}") #{chan.pagetitle} (#{chan.name}) td= chan.usercount td= chan.mediatitle .col-lg-3.col-md-3