From 9084a1aa8c405011eb1b0d9d14482a63b9183509 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 27 Jul 2013 10:40:49 -0400 Subject: [PATCH] Fixes - Add Channel.canonical_name to store lowercase - Hopefully prevent future dangling playlists - Disallow joining channels with names longer than 30 characters --- channel.js | 5 ++++- playlist.js | 12 +++++++++--- server.js | 9 ++++----- user.js | 13 ++++++++++--- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/channel.js b/channel.js index 68efd2bc..cca26a27 100644 --- a/channel.js +++ b/channel.js @@ -30,6 +30,7 @@ var Channel = function(name, Server) { this.server = Server; this.name = name; + this.canonical_name = name.toLowerCase(); // Initialize defaults this.registered = false; this.users = []; @@ -99,7 +100,7 @@ var Channel = function(name, Server) { this.ip_alias = {}; this.name_alias = {}; this.login_hist = []; - this.logger = new Logger.Logger("chanlogs/" + this.name + ".log"); + this.logger = new Logger.Logger("chanlogs/" + this.canonical_name + ".log"); this.i = 0; this.time = new Date().getTime(); this.plmeta = { @@ -773,6 +774,8 @@ Channel.prototype.sendRecentChat = function(user) { /* REGION Broadcasts to all clients */ Channel.prototype.sendAll = function(message, data) { + if(this.name == "") + return; this.server.io.sockets.in(this.name).emit(message, data); } diff --git a/playlist.js b/playlist.js index 917d23ae..e6bfd727 100644 --- a/playlist.js +++ b/playlist.js @@ -33,8 +33,9 @@ PlaylistItem.prototype.pack = function() { } function Playlist(chan) { - if(chan.name in AllPlaylists && AllPlaylists[chan.name]) { - var pl = AllPlaylists[chan.name]; + var name = chan.canonical_name; + if(name in AllPlaylists && AllPlaylists[name]) { + var pl = AllPlaylists[name]; if(!pl.dead) pl.die(); } @@ -53,7 +54,7 @@ function Playlist(chan) { this.lock = false; this.action_queue = []; this._qaInterval = false; - AllPlaylists[chan.name] = this; + AllPlaylists[name] = this; if(chan) { this.channel = chan; @@ -494,6 +495,11 @@ Playlist.prototype._leadLoop = function() { if(this.current == null) return; + if(this.channel.name == "") { + this.die(); + return; + } + this.current.media.currentTime += (Date.now() - this._lastUpdate) / 1000.0; this._lastUpdate = Date.now(); this._counter++; diff --git a/server.js b/server.js index 98e24d03..20ddd5ee 100644 --- a/server.js +++ b/server.js @@ -35,14 +35,14 @@ var Server = { channels: [], channelLoaded: function (name) { for(var i in this.channels) { - if(this.channels[i].name.toLowerCase() == name.toLowerCase()) + if(this.channels[i].canonical_name == name.toLowerCase()) return true; } return false; }, getChannel: function (name) { for(var i in this.channels) { - if(this.channels[i].name.toLowerCase() == name.toLowerCase()) + if(this.channels[i].canonical_name == name.toLowerCase()) return this.channels[i]; } @@ -55,13 +55,12 @@ var Server = { chan.saveDump(); chan.playlist.die(); for(var i in this.channels) { - if(this.channels[i].name.toLowerCase() == chan.name.toLowerCase()) { + if(this.channels[i].canonical_name == chan.canonical_name) { this.channels.splice(i, 1); break; } } - //for(var i in chan) - // delete chan[i]; + chan.name = ""; }, stats: null, app: null, diff --git a/user.js b/user.js index 2480de37..9207ebe6 100644 --- a/user.js +++ b/user.js @@ -90,10 +90,17 @@ User.prototype.initCallbacks = function() { return; if(typeof data.name != "string") return; - if(!data.name.match(/^[\w-_]+$/)) - return; - if(data.name.length > 100) + if(!data.name.match(/^[\w-_]{1,30}$/)) { + this.socket.emit("errorMsg", { + msg: "Invalid channel name. Channel names may consist of"+ + " 1-30 characters in the set a-z, A-Z, 0-9, -, and _" + }); + this.socket.emit("kick", { + reason: "Bad channel name" + }); + return; + } data.name = data.name.toLowerCase(); this.channel = this.server.getChannel(data.name); if(this.loggedIn) {