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.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);
|
||||
}
|
||||
|
||||
|
|
12
playlist.js
12
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++;
|
||||
|
|
|
@ -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,
|
||||
|
|
13
user.js
13
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) {
|
||||
|
|
Loading…
Reference in New Issue