mirror of https://github.com/calzoneman/sync.git
Fixes
- Add Channel.canonical_name to store lowercase - Hopefully prevent future dangling playlists - Disallow joining channels with names longer than 30 characters
This commit is contained in:
parent
6673e6c203
commit
9084a1aa8c
|
@ -30,6 +30,7 @@ var Channel = function(name, Server) {
|
||||||
this.server = Server;
|
this.server = Server;
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.canonical_name = name.toLowerCase();
|
||||||
// Initialize defaults
|
// Initialize defaults
|
||||||
this.registered = false;
|
this.registered = false;
|
||||||
this.users = [];
|
this.users = [];
|
||||||
|
@ -99,7 +100,7 @@ var Channel = function(name, Server) {
|
||||||
this.ip_alias = {};
|
this.ip_alias = {};
|
||||||
this.name_alias = {};
|
this.name_alias = {};
|
||||||
this.login_hist = [];
|
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.i = 0;
|
||||||
this.time = new Date().getTime();
|
this.time = new Date().getTime();
|
||||||
this.plmeta = {
|
this.plmeta = {
|
||||||
|
@ -773,6 +774,8 @@ Channel.prototype.sendRecentChat = function(user) {
|
||||||
/* REGION Broadcasts to all clients */
|
/* REGION Broadcasts to all clients */
|
||||||
|
|
||||||
Channel.prototype.sendAll = function(message, data) {
|
Channel.prototype.sendAll = function(message, data) {
|
||||||
|
if(this.name == "")
|
||||||
|
return;
|
||||||
this.server.io.sockets.in(this.name).emit(message, data);
|
this.server.io.sockets.in(this.name).emit(message, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
playlist.js
12
playlist.js
|
@ -33,8 +33,9 @@ PlaylistItem.prototype.pack = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Playlist(chan) {
|
function Playlist(chan) {
|
||||||
if(chan.name in AllPlaylists && AllPlaylists[chan.name]) {
|
var name = chan.canonical_name;
|
||||||
var pl = AllPlaylists[chan.name];
|
if(name in AllPlaylists && AllPlaylists[name]) {
|
||||||
|
var pl = AllPlaylists[name];
|
||||||
if(!pl.dead)
|
if(!pl.dead)
|
||||||
pl.die();
|
pl.die();
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,7 @@ function Playlist(chan) {
|
||||||
this.lock = false;
|
this.lock = false;
|
||||||
this.action_queue = [];
|
this.action_queue = [];
|
||||||
this._qaInterval = false;
|
this._qaInterval = false;
|
||||||
AllPlaylists[chan.name] = this;
|
AllPlaylists[name] = this;
|
||||||
|
|
||||||
if(chan) {
|
if(chan) {
|
||||||
this.channel = chan;
|
this.channel = chan;
|
||||||
|
@ -494,6 +495,11 @@ Playlist.prototype._leadLoop = function() {
|
||||||
if(this.current == null)
|
if(this.current == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(this.channel.name == "") {
|
||||||
|
this.die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.current.media.currentTime += (Date.now() - this._lastUpdate) / 1000.0;
|
this.current.media.currentTime += (Date.now() - this._lastUpdate) / 1000.0;
|
||||||
this._lastUpdate = Date.now();
|
this._lastUpdate = Date.now();
|
||||||
this._counter++;
|
this._counter++;
|
||||||
|
|
|
@ -35,14 +35,14 @@ var Server = {
|
||||||
channels: [],
|
channels: [],
|
||||||
channelLoaded: function (name) {
|
channelLoaded: function (name) {
|
||||||
for(var i in this.channels) {
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
getChannel: function (name) {
|
getChannel: function (name) {
|
||||||
for(var i in this.channels) {
|
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];
|
return this.channels[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,13 +55,12 @@ var Server = {
|
||||||
chan.saveDump();
|
chan.saveDump();
|
||||||
chan.playlist.die();
|
chan.playlist.die();
|
||||||
for(var i in this.channels) {
|
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);
|
this.channels.splice(i, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//for(var i in chan)
|
chan.name = "";
|
||||||
// delete chan[i];
|
|
||||||
},
|
},
|
||||||
stats: null,
|
stats: null,
|
||||||
app: null,
|
app: null,
|
||||||
|
|
13
user.js
13
user.js
|
@ -90,10 +90,17 @@ User.prototype.initCallbacks = function() {
|
||||||
return;
|
return;
|
||||||
if(typeof data.name != "string")
|
if(typeof data.name != "string")
|
||||||
return;
|
return;
|
||||||
if(!data.name.match(/^[\w-_]+$/))
|
if(!data.name.match(/^[\w-_]{1,30}$/)) {
|
||||||
return;
|
this.socket.emit("errorMsg", {
|
||||||
if(data.name.length > 100)
|
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;
|
return;
|
||||||
|
}
|
||||||
data.name = data.name.toLowerCase();
|
data.name = data.name.toLowerCase();
|
||||||
this.channel = this.server.getChannel(data.name);
|
this.channel = this.server.getChannel(data.name);
|
||||||
if(this.loggedIn) {
|
if(this.loggedIn) {
|
||||||
|
|
Loading…
Reference in New Issue