Change quotes to be consistent

Fixes Issue#11
This commit is contained in:
calzoneman 2013-03-24 12:23:48 -05:00
parent a5ca7d227e
commit 5f5049db12
12 changed files with 527 additions and 527 deletions

10
auth.js
View File

@ -9,8 +9,8 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var mysql = require('mysql-libmysqlclient');
var Config = require('./config.js');
var mysql = require("mysql-libmysqlclient");
var Config = require("./config.js");
// Check if a name is taken
exports.isRegistered = function(name) {
@ -21,7 +21,7 @@ exports.isRegistered = function(name) {
console.log("MySQL Connection Failed");
return true;
}
var query = 'SELECT * FROM registrations WHERE uname="{}"'
var query = "SELECT * FROM registrations WHERE uname='{}'"
.replace(/\{\}/, name);
var results = db.querySync(query);
var rows = results.fetchAllSync();
@ -51,7 +51,7 @@ exports.register = function(name, sha256) {
console.log("MySQL Connection Failed");
return false;
}
var query = 'INSERT INTO registrations VALUES (NULL, "{1}", "{2}", 0)'
var query = "INSERT INTO registrations VALUES (NULL, '{1}', '{2}', 0)"
.replace(/\{1\}/, name)
.replace(/\{2\}/, sha256);
var results = db.querySync(query);
@ -68,7 +68,7 @@ exports.login = function(name, sha256) {
console.log("MySQL Connection Failed");
return false;
}
var query = 'SELECT * FROM registrations WHERE uname="{1}" AND pw="{2}"'
var query = "SELECT * FROM registrations WHERE uname='{1}' AND pw='{2}'"
.replace(/\{1\}/, name)
.replace(/\{2\}/, sha256);
var results = db.querySync(query);

View File

@ -9,14 +9,14 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var mysql = require('mysql-libmysqlclient');
var Config = require('./config.js');
var Rank = require('./rank.js');
var mysql = require("mysql-libmysqlclient");
var Config = require("./config.js");
var Rank = require("./rank.js");
// I should use the <noun><verb>er naming scheme more often
var InfoGetter = require('./get-info.js');
var Media = require('./media.js').Media;
var ChatCommand = require('./chatcommand.js');
var Server = require('./server.js');
var InfoGetter = require("./get-info.js");
var Media = require("./media.js").Media;
var ChatCommand = require("./chatcommand.js");
var Server = require("./server.js");
var io = Server.io;
var Channel = function(name) {
@ -63,7 +63,7 @@ Channel.prototype.loadMysql = function() {
return false;
}
// Check if channel exists
var query = 'SELECT * FROM channels WHERE name="{}"'
var query = "SELECT * FROM channels WHERE name='{}'"
.replace(/\{\}/, this.name);
var results = db.querySync(query);
if(!results) {
@ -78,7 +78,7 @@ Channel.prototype.loadMysql = function() {
this.registered = true;
// Load library
var query = 'SELECT * FROM chan_{}_library'
var query = "SELECT * FROM chan_{}_library"
.replace(/\{\}/, this.name);
var results = db.querySync(query);
if(!results) {
@ -91,7 +91,7 @@ Channel.prototype.loadMysql = function() {
}
// Load bans
var query = 'SELECT * FROM chan_{}_bans'
var query = "SELECT * FROM chan_{}_bans"
.replace(/\{\}/, this.name);
var results = db.querySync(query);
if(!results) {
@ -153,7 +153,7 @@ Channel.prototype.createTables = function() {
results = db.querySync(query) || results;
// Insert into global channel table
var query = 'INSERT INTO channels (`id`, `name`) VALUES (NULL, "{}")'
var query = "INSERT INTO channels (`id`, `name`) VALUES (NULL, '{}')"
.replace(/\{\}/, this.name);
results = db.querySync(query) || results;
db.closeSync();
@ -162,20 +162,20 @@ Channel.prototype.createTables = function() {
Channel.prototype.tryRegister = function(user) {
if(this.registered) {
user.socket.emit('registerChannel', {
user.socket.emit("registerChannel", {
success: false,
error: "This channel is already registered"
});
}
else if(!user.loggedIn) {
user.socket.emit('registerChannel', {
user.socket.emit("registerChannel", {
success: false,
error: "You must log in to register a channel"
});
}
else if(!Rank.hasPermission(user, "registerChannel")) {
user.socket.emit('registerChannel', {
user.socket.emit("registerChannel", {
success: false,
error: "You don't have permission to register this channel"
});
@ -184,12 +184,12 @@ Channel.prototype.tryRegister = function(user) {
if(this.createTables()) {
this.registered = true;
this.saveRank(user);
user.socket.emit('registerChannel', {
user.socket.emit("registerChannel", {
success: true,
});
}
else {
user.socket.emit('registerChannel', {
user.socket.emit("registerChannel", {
success: false,
error: "Unable to register channel, see an admin"
});
@ -197,7 +197,7 @@ Channel.prototype.tryRegister = function(user) {
}
}
// Retrieves a user's rank from the database
// Retrieves a user"s rank from the database
Channel.prototype.getRank = function(name) {
if(!this.registered)
return Rank.Guest;
@ -208,7 +208,7 @@ Channel.prototype.getRank = function(name) {
console.log("MySQL Connection Failed");
return Rank.Guest;
}
var query = 'SELECT * FROM chan_{1}_ranks WHERE name="{2}"'
var query = "SELECT * FROM chan_{1}_ranks WHERE name='{2}'"
.replace(/\{1\}/, this.name)
.replace(/\{2\}/, name);
var results = db.querySync(query);
@ -223,7 +223,7 @@ Channel.prototype.getRank = function(name) {
return rows[0].rank;
}
// Saves a user's rank to the database
// Saves a user"s rank to the database
Channel.prototype.saveRank = function(user) {
if(!this.registered)
return false;
@ -234,14 +234,14 @@ Channel.prototype.saveRank = function(user) {
console.log("MySQL Connection Failed");
return false;
}
var query = 'UPDATE chan_{1}_ranks SET rank="{2}" WHERE name="{3}"'
var query = "UPDATE chan_{1}_ranks SET rank='{2}' WHERE name='{3}'"
.replace(/\{1\}/, this.name)
.replace(/\{2\}/, user.rank)
.replace(/\{3\}/, user.name);
var results = db.querySync(query);
// Gonna have to insert a new one, bugger
if(!results.fetchAllSync) {
var query = 'INSERT INTO chan_{1}_ranks (`name`, `rank`) VALUES ("{2}", "{3}")'
var query = "INSERT INTO chan_{1}_ranks (`name`, `rank`) VALUES ('{2}', '{3}')"
.replace(/\{1\}/, this.name)
.replace(/\{2\}/, user.name)
.replace(/\{3\}/, user.rank);
@ -264,7 +264,7 @@ Channel.prototype.addToLibrary = function(media) {
console.log("MySQL Connection Failed");
return false;
}
var query = 'INSERT INTO chan_{1}_library VALUES ("{2}", "{3}", {4}, "{5}", "{6}")'
var query = "INSERT INTO chan_{1}_library VALUES ('{2}', '{3}', {4}, '{5}', '{6}')"
.replace(/\{1\}/, this.name)
.replace(/\{2\}/, media.id)
.replace(/\{3\}/, media.title)
@ -290,7 +290,7 @@ Channel.prototype.banIP = function(banner, bannee) {
console.log("MySQL Connection Failed");
return false;
}
var query = 'INSERT INTO chan_{1}_bans (`ip`, `name`, `banner`) VALUES ("{2}", "{3}", "{4}")'
var query = "INSERT INTO chan_{1}_bans (`ip`, `name`, `banner`) VALUES ('{2}', '{3}', '{4}')"
.replace(/\{1\}/, this.name)
.replace(/\{2\}/, bannee.ip)
.replace(/\{3\}/, bannee.name)
@ -317,7 +317,7 @@ Channel.prototype.unbanIP = function(ip) {
return false;
}
var query = 'DELETE FROM chan_{1}_bans WHERE `ip` = "{2}"'
var query = "DELETE FROM chan_{1}_bans WHERE `ip` = '{2}'"
.replace(/\{1\}/, this.name)
.replace(/\{2\}/, ip);
@ -363,18 +363,18 @@ Channel.prototype.userJoin = function(user) {
if(this.users[i].name == user.name) {
user.name = "";
user.loggedIn = false;
user.socket.emit('login', {
user.socket.emit("login", {
success: false,
error: "The username " + user.name + " is already in use on this channel"
});
}
}
}
// If the channel is empty and isn't registered, the first person
// If the channel is empty and isn"t registered, the first person
// gets ownership of the channel (temporarily)
if(this.users.length == 0 && !this.registered) {
user.rank = (user.rank < Rank.Owner) ? Rank.Owner + 7 : user.rank;
user.socket.emit('channelNotRegistered');
user.socket.emit("channelNotRegistered");
}
this.users.push(user);
if(user.name != "") {
@ -383,13 +383,13 @@ Channel.prototype.userJoin = function(user) {
this.updateUsercount();
// Set the new guy up
this.sendPlaylist(user);
user.socket.emit('queueLock', {locked: this.qlocked});
user.socket.emit("queueLock", {locked: this.qlocked});
this.sendUserlist(user);
this.sendRecentChat(user);
if(this.poll) {
user.socket.emit('newPoll', this.poll.packUpdate());
user.socket.emit("newPoll", this.poll.packUpdate());
}
user.socket.emit('channelOpts', this.opts);
user.socket.emit("channelOpts", this.opts);
var ents = [];
for(var ip in this.ipbans) {
if(this.ipbans[ip] != null) {
@ -400,7 +400,7 @@ Channel.prototype.userJoin = function(user) {
});
}
}
user.socket.emit('banlist', {entries: ents});
user.socket.emit("banlist", {entries: ents});
if(user.playerReady)
this.sendMediaUpdate(user);
console.log("/" + user.ip + " joined channel " + this.name);
@ -424,7 +424,7 @@ Channel.prototype.userLeave = function(user) {
this.users.splice(idx, 1);
this.updateUsercount();
if(user.name != "") {
this.sendAll('userLeave', {
this.sendAll("userLeave", {
name: user.name
});
}
@ -436,7 +436,7 @@ Channel.prototype.enqueue = function(data) {
// Try to look up cached metadata first
if(data.id in this.library) {
this.queue.splice(idx, 0, this.library[data.id]);
this.sendAll('queue', {
this.sendAll("queue", {
media: this.library[data.id].pack(),
pos: idx
});
@ -451,11 +451,11 @@ Channel.prototype.enqueue = function(data) {
try {
// Whoever decided on this variable name should be fired
var seconds = data.entry.media$group.yt$duration.seconds;
// This one's slightly better
// This one"s slightly better
var title = data.entry.title.$t;
var vid = new Media(id, title, seconds, "yt");
chan.queue.splice(idx, 0, vid);
chan.sendAll('queue', {
chan.sendAll("queue", {
media: vid.pack(),
pos: idx
});
@ -471,7 +471,7 @@ Channel.prototype.enqueue = function(data) {
else if(data.type == "tw") {
var media = new Media(data.id, "Twitch ~ " + data.id, 0, "tw");
this.queue.splice(idx, 0, media);
this.sendAll('queue', {
this.sendAll("queue", {
media: media.pack(),
pos: idx
});
@ -479,7 +479,7 @@ Channel.prototype.enqueue = function(data) {
else if(data.type == "li") {
var media = new Media(data.id, "Livestream ~ " + data.id, 0, "li");
this.queue.splice(idx, 0, media);
this.sendAll('queue', {
this.sendAll("queue", {
media: media.pack(),
pos: idx
});
@ -495,7 +495,7 @@ Channel.prototype.enqueue = function(data) {
var title = data.title;
var vid = new Media(id, title, seconds, "sc");
chan.queue.splice(idx, 0, vid);
chan.sendAll('queue', {
chan.sendAll("queue", {
media: vid.pack(),
pos: idx
});
@ -515,7 +515,7 @@ Channel.prototype.enqueue = function(data) {
var title = data.title;
var vid = new Media(id, title, seconds, "vi");
chan.queue.splice(idx, 0, vid);
chan.sendAll('queue', {
chan.sendAll("queue", {
media: vid.pack(),
pos: idx
});
@ -535,7 +535,7 @@ Channel.prototype.enqueue = function(data) {
var title = data.title;
var vid = new Media(id, title, seconds, "dm");
chan.queue.splice(idx, 0, vid);
chan.sendAll('queue', {
chan.sendAll("queue", {
media: vid.pack(),
pos: idx
});
@ -552,13 +552,13 @@ Channel.prototype.unqueue = function(data) {
return;
this.queue.splice(data.pos, 1);
this.sendAll('unqueue', {
this.sendAll("unqueue", {
pos: data.pos
});
if(data.pos < this.currentPosition) {
this.currentPosition--;
this.sendAll('updatePlaylistIdx', {
this.sendAll("updatePlaylistIdx", {
idx: this.currentPosition
});
}
@ -579,8 +579,8 @@ Channel.prototype.playNext = function() {
this.currentMedia = this.queue[this.currentPosition];
this.currentMedia.currentTime = 0;
this.sendAll('mediaUpdate', this.currentMedia.packupdate());
this.sendAll('updatePlaylistIdx', {
this.sendAll("mediaUpdate", this.currentMedia.packupdate());
this.sendAll("updatePlaylistIdx", {
idx: this.currentPosition
});
// Enable autolead for non-twitch
@ -592,7 +592,7 @@ Channel.prototype.playNext = function() {
Channel.prototype.setLock = function(locked) {
this.qlocked = locked;
this.sendAll('queueLock', {locked: locked});
this.sendAll("queueLock", {locked: locked});
for(var i = 0; i < this.users.length; i++) {
this.sendPlaylist(this.users[i]);
}
@ -606,7 +606,7 @@ Channel.prototype.update = function(data) {
}
else
this.currentMedia.currentTime = data.seconds;
this.sendAll('mediaUpdate', this.currentMedia.packupdate());
this.sendAll("mediaUpdate", this.currentMedia.packupdate());
}
// Move something around in the queue
@ -619,7 +619,7 @@ Channel.prototype.moveMedia = function(data) {
var media = this.queue[data.src];
this.queue.splice(data.src, 1);
this.queue.splice(data.dest, 0, media);
this.sendAll('moveVideo', {
this.sendAll("moveVideo", {
src: data.src,
dest: data.dest
});
@ -645,11 +645,11 @@ Channel.prototype.chatMessage = function(user, msg) {
}
Channel.prototype.sendMessage = function(username, msg, msgclass) {
// I don't want HTML from strangers
// I don"t want HTML from strangers
msg = msg.replace(/</g, "&lt;").replace(/>/g, "&gt;");
// Match URLs
msg = msg.replace(/(((https?)|(ftp))(:\/\/[0-9a-zA-Z\.]+(:[0-9]+)?[^\s$]+))/, "<a href=\"$1\" target=\"_blank\">$1</a>");
this.sendAll('chatMsg', {
this.sendAll("chatMsg", {
username: username,
msg: msg,
msgclass: msgclass
@ -676,8 +676,8 @@ Channel.prototype.promoteUser = function(actor, name) {
if(receiver) {
// You can only promote someone if you are 2 ranks or higher above
// them. This way you can't promote them to your rank and end
// up in a situation where you can't demote them
// them. This way you can"t promote them to your rank and end
// up in a situation where you can"t demote them
if(actor.rank > receiver.rank + 1) {
receiver.rank++;
if(receiver.loggedIn) {
@ -688,7 +688,7 @@ Channel.prototype.promoteUser = function(actor, name) {
}
}
// You're fired
// You"re fired
Channel.prototype.demoteUser = function(actor, name) {
var receiver;
for(var i = 0; i < this.users.length; i++) {
@ -699,8 +699,8 @@ Channel.prototype.demoteUser = function(actor, name) {
}
if(receiver) {
// Wouldn't it be funny if you could demote people who rank higher
// than you? No, it wouldn't.
// Wouldn"t it be funny if you could demote people who rank higher
// than you? No, it wouldn"t.
if(actor.rank > receiver.rank) {
receiver.rank--;
if(receiver.loggedIn) {
@ -711,7 +711,7 @@ Channel.prototype.demoteUser = function(actor, name) {
}
}
// Manual leader. This shouldn't be necessary since the server autoleads,
// Manual leader. This shouldn"t be necessary since the server autoleads,
// but you never know
Channel.prototype.changeLeader = function(name) {
if(this.leader != null) {
@ -736,11 +736,11 @@ Channel.prototype.changeLeader = function(name) {
}
// Send the userlist to a client
// Do you know you're all my very best friends?
// Do you know you"re all my very best friends?
Channel.prototype.sendUserlist = function(user) {
var users = [];
for(var i = 0; i < this.users.length; i++) {
// Skip people who haven't logged in
// Skip people who haven"t logged in
if(this.users[i].name != "") {
users.push({
name: this.users[i].name,
@ -749,21 +749,21 @@ Channel.prototype.sendUserlist = function(user) {
});
}
}
user.socket.emit('userlist', users)
user.socket.emit("userlist", users)
}
Channel.prototype.updateUsercount = function() {
this.sendAll('usercount', {
this.sendAll("usercount", {
count: this.users.length
});
}
// Send the play queue
Channel.prototype.sendPlaylist = function(user) {
user.socket.emit('playlist', {
user.socket.emit("playlist", {
pl: this.queue
});
user.socket.emit('updatePlaylistIdx', {
user.socket.emit("updatePlaylistIdx", {
idx: this.currentPosition
});
}
@ -771,32 +771,32 @@ Channel.prototype.sendPlaylist = function(user) {
// Send the last 15 messages for context
Channel.prototype.sendRecentChat = function(user) {
for(var i = 0; i < this.recentChat.length; i++) {
user.socket.emit('chatMsg', this.recentChat[i]);
user.socket.emit("chatMsg", this.recentChat[i]);
}
}
// Send a sync packet
Channel.prototype.sendMediaUpdate = function(user) {
if(this.currentMedia != null) {
user.socket.emit('mediaUpdate', this.currentMedia.packupdate());
user.socket.emit("mediaUpdate", this.currentMedia.packupdate());
}
else {
console.log('currentMedia is null');
console.log("currentMedia is null");
}
}
// Sent when someone logs in, to add them to the user list
Channel.prototype.broadcastNewUser = function(user) {
this.sendAll('addUser', {
this.sendAll("addUser", {
name: user.name,
rank: user.rank,
leader: this.leader == user
});
}
// Someone's rank changed, or their leadership status changed
// Someone"s rank changed, or their leadership status changed
Channel.prototype.broadcastRankUpdate = function(user) {
this.sendAll('updateUser', {
this.sendAll("updateUser", {
name: user.name,
rank: user.rank,
leader: this.leader == user
@ -804,19 +804,19 @@ Channel.prototype.broadcastRankUpdate = function(user) {
}
Channel.prototype.broadcastPoll = function() {
this.sendAll('newPoll', this.poll.packUpdate());
this.sendAll("newPoll", this.poll.packUpdate());
}
Channel.prototype.broadcastPollUpdate = function() {
this.sendAll('updatePoll', this.poll.packUpdate());
this.sendAll("updatePoll", this.poll.packUpdate());
}
Channel.prototype.broadcastPollClose = function() {
this.sendAll('closePoll');
this.sendAll("closePoll");
}
Channel.prototype.broadcastOpts = function() {
this.sendAll('channelOpts', this.opts);
this.sendAll("channelOpts", this.opts);
}
Channel.prototype.broadcastIpbans = function() {
@ -830,7 +830,7 @@ Channel.prototype.broadcastIpbans = function() {
});
}
}
this.sendAll('banlist', {entries: ents});
this.sendAll("banlist", {entries: ents});
}
// Send to ALL the clients!
@ -840,7 +840,7 @@ Channel.prototype.sendAll = function(message, data) {
// Autolead yay
function channelVideoUpdate(chan, id) {
// Someone changed the video or there's a manual leader, so your
// Someone changed the video or there"s a manual leader, so your
// argument is invalid
if(chan.currentMedia == null || id != chan.currentMedia.id || chan.leader != null)
return;
@ -853,7 +853,7 @@ function channelVideoUpdate(chan, id) {
}
// Every ~5 seconds send a sync packet to everyone
else if(chan.i % 5 == 0)
chan.sendAll('mediaUpdate', chan.currentMedia.packupdate());
chan.sendAll("mediaUpdate", chan.currentMedia.packupdate());
chan.i++;
// Do it all over again in about a second
setTimeout(function() { channelVideoUpdate(chan, id); }, 1000);

View File

@ -9,8 +9,8 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var Rank = require('./rank.js');
var Poll = require('./poll.js').Poll;
var Rank = require("./rank.js");
var Poll = require("./poll.js").Poll;
function handle(chan, user, msg) {
if(msg.indexOf("/me ") == 0)
@ -23,13 +23,13 @@ function handle(chan, user, msg) {
}
}
else if(msg.indexOf("/kick ") == 0) {
handleKick(chan, user, msg.substring(6).split(' '));
handleKick(chan, user, msg.substring(6).split(" "));
}
else if(msg.indexOf("/ban ") == 0) {
handleBan(chan, user, msg.substring(5).split(' '));
handleBan(chan, user, msg.substring(5).split(" "));
}
else if(msg.indexOf("/unban ") == 0) {
handleUnban(chan, user, msg.substring(7).split(' '));
handleUnban(chan, user, msg.substring(7).split(" "));
}
else if(msg.indexOf("/poll ") == 0) {
handlePoll(chan, user, msg.substring(6));
@ -74,7 +74,7 @@ function handleUnban(chan, user, args) {
function handlePoll(chan, user, msg) {
if(Rank.hasPermission(user, "poll")) {
var args = msg.split(',');
var args = msg.split(",");
var title = args[0];
args.splice(0, 1);
var poll = new Poll(user.name, title, args);

View File

@ -9,8 +9,8 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
exports.MYSQL_SERVER = '';
exports.MYSQL_DB = '';
exports.MYSQL_USER = '';
exports.MYSQL_PASSWORD = '';
exports.MYSQL_SERVER = "";
exports.MYSQL_DB = "";
exports.MYSQL_USER = "";
exports.MYSQL_PASSWORD = "";
exports.IO_PORT = 1337;

View File

@ -9,8 +9,8 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var mysql = require('mysql-libmysqlclient');
var Config = require('./config.js');
var mysql = require("mysql-libmysqlclient");
var Config = require("./config.js");
var initialized = false;

View File

@ -9,19 +9,19 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var http = require('http');
var https = require('https');
var http = require("http");
var https = require("https");
// Helper function for making an HTTP request and getting the result
// as JSON
function getJSON(options, callback) {
var req = http.request(options, function(res){
var buffer = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
var buffer = "";
res.setEncoding("utf8");
res.on("data", function (chunk) {
buffer += chunk;
});
res.on('end', function() {
res.on("end", function() {
try {
var data = JSON.parse(buffer);
}
@ -39,12 +39,12 @@ function getJSON(options, callback) {
// Dailymotion uses HTTPS for anonymous requests... [](/picard)
function getJSONHTTPS(options, callback) {
var req = https.request(options, function(res){
var buffer = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
var buffer = "";
res.setEncoding("utf8");
res.on("data", function (chunk) {
buffer += chunk;
});
res.on('end', function() {
res.on("end", function() {
try {
var data = JSON.parse(buffer);
}
@ -72,13 +72,13 @@ exports.getYTInfo = function(id, callback) {
}
// Look up Soundcloud metadata
// Whoever designed this should rethink it. I'll submit a feedback
// Whoever designed this should rethink it. I"ll submit a feedback
// form on their website.
exports.getSCInfo = function(url, callback) {
const SC_CLIENT = '2e0c82ab5a020f3a7509318146128abd';
const SC_CLIENT = "2e0c82ab5a020f3a7509318146128abd";
// SoundCloud is dumb
// I have to request the API URL for the given input URL
// Because the sound ID isn't in the URL
// Because the sound ID isn"t in the URL
getJSON({
host: "api.soundcloud.com",
port: 80,

View File

@ -9,17 +9,17 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var Config = require('./config.js');
var connect = require('connect');
var app = connect.createServer(connect.static(__dirname+'/www')).listen(Config.IO_PORT);
exports.io = require('socket.io').listen(app);
var User = require('./user.js').User;
var Database = require('./database.js');
var Config = require("./config.js");
var connect = require("connect");
var app = connect.createServer(connect.static(__dirname+"/www")).listen(Config.IO_PORT);
exports.io = require("socket.io").listen(app);
var User = require("./user.js").User;
var Database = require("./database.js");
Database.init();
exports.channels = {};
exports.io.sockets.on('connection', function(socket) {
exports.io.sockets.on("connection", function(socket) {
var user = new User(socket, socket.handshake.address.address);
console.log('New connection from /' + user.ip);
console.log("New connection from /" + user.ip);
});

98
user.js
View File

@ -9,11 +9,11 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var Rank = require('./rank.js');
var Auth = require('./auth.js');
var Channel = require('./channel.js').Channel;
var Server = require('./server.js');
var Database = require('./database.js');
var Rank = require("./rank.js");
var Auth = require("./auth.js");
var Channel = require("./channel.js").Channel;
var Server = require("./server.js");
var Database = require("./database.js");
// Represents a client connected via socket.io
var User = function(socket, ip) {
@ -27,7 +27,7 @@ var User = function(socket, ip) {
this.initCallbacks();
if(Server.announcement != null) {
this.socket.emit('announcement', Server.announcement);
this.socket.emit("announcement", Server.announcement);
}
};
@ -35,12 +35,12 @@ var User = function(socket, ip) {
// Set up socket callbacks
User.prototype.initCallbacks = function() {
// What a shame
this.socket.on('disconnect', function() {
this.socket.on("disconnect", function() {
if(this.channel != null)
this.channel.userLeave(this);
}.bind(this));
this.socket.on('joinChannel', function(data) {
this.socket.on("joinChannel", function(data) {
if(!data.name.match(/^[a-zA-Z0-9]+$/))
return;
// Channel already loaded
@ -56,23 +56,23 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('login', function(data) {
this.socket.on("login", function(data) {
if(this.name == "")
this.login(data.name, data.sha256);
}.bind(this));
this.socket.on('register', function(data) {
this.socket.on("register", function(data) {
this.register(data.name, data.sha256);
}.bind(this));
this.socket.on('assignLeader', function(data) {
this.socket.on("assignLeader", function(data) {
if(Rank.hasPermission(this, "assignLeader")) {
if(this.channel != null)
this.channel.changeLeader(data.name);
}
}.bind(this));
this.socket.on('promote', function(data) {
this.socket.on("promote", function(data) {
if(Rank.hasPermission(this, "promote")) {
if(this.channel != null) {
this.channel.promoteUser(this, data.name);
@ -80,7 +80,7 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('demote', function(data) {
this.socket.on("demote", function(data) {
if(Rank.hasPermission(this, "promote")) {
if(this.channel != null) {
this.channel.demoteUser(this, data.name);
@ -88,20 +88,20 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('chatMsg', function(data) {
this.socket.on("chatMsg", function(data) {
if(this.name != "" && this.channel != null) {
this.channel.chatMessage(this, data.msg);
}
}.bind(this));
this.socket.on('playerReady', function() {
this.socket.on("playerReady", function() {
if(this.channel != null) {
this.channel.sendMediaUpdate(this);
}
this.playerReady = true;
}.bind(this));
this.socket.on('queue', function(data) {
this.socket.on("queue", function(data) {
if(this.channel == null)
return;
if(Rank.hasPermission(this, "queue") ||
@ -116,7 +116,7 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('unqueue', function(data) {
this.socket.on("unqueue", function(data) {
if(this.channel == null)
return;
if(Rank.hasPermission(this, "queue") ||
@ -126,7 +126,7 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('moveMedia', function(data) {
this.socket.on("moveMedia", function(data) {
if(this.channel == null)
return;
if(Rank.hasPermission(this, "queue") ||
@ -136,7 +136,7 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('playNext', function() {
this.socket.on("playNext", function() {
if(this.channel == null)
return;
if(Rank.hasPermission(this, "queue") ||
@ -149,7 +149,7 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('queueLock', function(data) {
this.socket.on("queueLock", function(data) {
if(Rank.hasPermission(this, "qlock")) {
if(this.channel != null) {
this.channel.setLock(data.locked);
@ -157,21 +157,21 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('mediaUpdate', function(data) {
this.socket.on("mediaUpdate", function(data) {
if(this.channel != null && this.channel.leader == this) {
this.channel.update(data);
}
}.bind(this));
this.socket.on('searchLibrary', function(data) {
this.socket.on("searchLibrary", function(data) {
if(this.channel != null && Rank.hasPermission(this, "search")) {
this.socket.emit('librarySearchResults', {
this.socket.emit("librarySearchResults", {
results: this.channel.searchLibrary(data.query)
});
}
}.bind(this));
this.socket.on('closePoll', function() {
this.socket.on("closePoll", function() {
if(Rank.hasPermission(this, "poll")) {
if(this.channel != null && this.channel.poll) {
this.channel.poll = null;
@ -180,16 +180,16 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('vote', function(data) {
this.socket.on("vote", function(data) {
if(this.channel != null && this.channel.poll) {
this.channel.poll.vote(this.ip, data.option);
this.channel.broadcastPollUpdate();
}
}.bind(this));
this.socket.on('registerChannel', function(data) {
this.socket.on("registerChannel", function(data) {
if(this.channel == null) {
this.socket.emit('channelRegistration', {
this.socket.emit("channelRegistration", {
success: false,
error: "You're not in any channel!"
});
@ -199,25 +199,25 @@ User.prototype.initCallbacks = function() {
}
}.bind(this));
this.socket.on('adm', function(data) {
this.socket.on("adm", function(data) {
if(Rank.hasPermission(this, "acp")) {
this.handleAdm(data);
}
}.bind(this));
this.socket.on('announce', function(data) {
this.socket.on("announce", function(data) {
if(Rank.hasPermission(this, "announce")) {
if(data.clear) {
Server.announcement = null;
}
else {
Server.io.sockets.emit('announcement', data);
Server.io.sockets.emit("announcement", data);
Server.announcement = data;
}
}
}.bind(this));
this.socket.on('channelOpts', function(data) {
this.socket.on("channelOpts", function(data) {
if(Rank.hasPermission(this, "channelOpts") && this.channel != null) {
this.channel.opts = data;
this.channel.broadcastOpts();
@ -239,7 +239,7 @@ User.prototype.handleAdm = function(data) {
nowplaying: nowplaying
});
}
this.socket.emit('adm', {
this.socket.emit("adm", {
cmd: "listchannels",
chans: chans
});
@ -255,7 +255,7 @@ User.prototype.handleAdm = function(data) {
rank: dbusers[i].global_rank
};
}
this.socket.emit('adm', {
this.socket.emit("adm", {
cmd: "listusers",
users: users
});
@ -263,7 +263,7 @@ User.prototype.handleAdm = function(data) {
else if(data.cmd == "listchannelranks") {
if(data.chan == undefined)
return;
this.socket.emit('adm', {
this.socket.emit("adm", {
cmd: "listchannelranks",
ranks: Database.listChannelRanks(data.chan)
});
@ -276,7 +276,7 @@ User.prototype.login = function(name, sha256) {
if(this.channel != null && name != "") {
for(var i = 0; i < this.channel.users.length; i++) {
if(this.channel.users[i].name == name) {
this.socket.emit('login', {
this.socket.emit("login", {
success: false,
error: "The username " + name + " is already in use on this channel"
});
@ -286,9 +286,9 @@ User.prototype.login = function(name, sha256) {
}
// No password => try guest login
if(sha256 == "") {
// Sorry bud, can't take that name
// Sorry bud, can"t take that name
if(Auth.isRegistered(name)) {
this.socket.emit('login', {
this.socket.emit("login", {
success: false,
error: "That username is already taken"
});
@ -296,7 +296,7 @@ User.prototype.login = function(name, sha256) {
}
// YOUR ARGUMENT IS INVALID
else if(!Auth.validateName(name)) {
this.socket.emit('login', {
this.socket.emit("login", {
success: false,
error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores"
});
@ -306,10 +306,10 @@ User.prototype.login = function(name, sha256) {
console.log(this.ip + " signed in as " + name);
this.name = name;
this.loggedIn = false;
this.socket.emit('login', {
this.socket.emit("login", {
success: true
});
this.socket.emit('rank', {
this.socket.emit("rank", {
rank: this.rank
});
if(this.channel != null) {
@ -323,17 +323,17 @@ User.prototype.login = function(name, sha256) {
var row;
if((row = Auth.login(name, sha256))) {
this.loggedIn = true;
this.socket.emit('login', {
this.socket.emit("login", {
success: true
});
console.log(this.ip + " logged in as " + name);
// Sweet, let's look up our rank
// Sweet, let"s look up our rank
var chanrank = (this.channel != null) ? this.channel.getRank(name)
: Rank.Guest;
var rank = (chanrank > row.global_rank) ? chanrank
: row.global_rank;
this.rank = (this.rank > rank) ? this.rank : rank;
this.socket.emit('rank', {
this.socket.emit("rank", {
rank: this.rank
});
this.name = name;
@ -345,7 +345,7 @@ User.prototype.login = function(name, sha256) {
}
// Wrong password
else {
this.socket.emit('login', {
this.socket.emit("login", {
success: false,
error: "Invalid username/password pair"
});
@ -358,34 +358,34 @@ User.prototype.login = function(name, sha256) {
User.prototype.register = function(name, sha256) {
if(sha256 == "") {
// Sorry bud, password required
this.socket.emit('register', {
this.socket.emit("register", {
success: false,
error: "You must provide a password"
});
return false;
}
else if(Auth.isRegistered(name)) {
this.socket.emit('register', {
this.socket.emit("register", {
success: false,
error: "That username is already taken"
});
return false;
}
else if(!Auth.validateName(name)) {
this.socket.emit('register', {
this.socket.emit("register", {
success: false,
error: "Invalid username. Usernames must be 1-20 characters long and consist only of alphanumeric characters and underscores"
});
}
else if(Auth.register(name, sha256)) {
console.log(this.ip + " registered " + name);
this.socket.emit('register', {
this.socket.emit("register", {
success: true
});
this.login(name, sha256);
}
else {
this.socket.emit('register', {
this.socket.emit("register", {
success: false,
error: "[](/ppshrug) Registration Failed."
});

View File

@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
*/
var RANK = 0;
var uname = readCookie('sync_uname');
var pw = readCookie('sync_pw');
var uname = readCookie("sync_uname");
var pw = readCookie("sync_pw");
var manageChannel = false;
var Rank = {
@ -27,44 +27,44 @@ initCallbacks();
function initCallbacks() {
socket.on('adm', function(data) {
socket.on("adm", function(data) {
console.log(data);
if(data.cmd == "listchannels")
handleChannelList(data);
});
socket.on('login', function(data) {
if(data.success && $('#password').val()) {
createCookie('sync_uname', uname, 1);
createCookie('sync_pw', pw, 1);
socket.on("login", function(data) {
if(data.success && $("#password").val()) {
createCookie("sync_uname", uname, 1);
createCookie("sync_pw", pw, 1);
}
if(data.success) {
$('#loggedin').css('display', '');
$('#logoutform').css('display', '');
$('#loginform').css('display', 'none');
$("#loggedin").css("display", "");
$("#logoutform").css("display", "");
$("#loginform").css("display", "none");
}
socket.emit('adm', {
socket.emit("adm", {
cmd: "listchannels"
});
});
}
function handleChannelList(data) {
if($('#chanlist').children.length > 1)
$($('#chanlist').children()[1]).remove();
if($("#chanlist").children.length > 1)
$($("#chanlist").children()[1]).remove();
for(var i = 0; i < data.chans.length; i++) {
var row = $('<tr/>').appendTo($('#chanlist'));
var name = $('<td/>').appendTo(row).text(data.chans[i].name);
var usercount = $('<td/>').appendTo(row).text(data.chans[i].usercount);
var nowplaying = $('<td/>').appendTo(row).text(data.chans[i].nowplaying);
var row = $("<tr/>").appendTo($("#chanlist"));
var name = $("<td/>").appendTo(row).text(data.chans[i].name);
var usercount = $("<td/>").appendTo(row).text(data.chans[i].usercount);
var nowplaying = $("<td/>").appendTo(row).text(data.chans[i].nowplaying);
}
}
var params = {};
if(window.location.search) {
var parameters = window.location.search.substring(1).split('&');
var parameters = window.location.search.substring(1).split("&");
for(var i = 0; i < parameters.length; i++) {
var s = parameters[i].split('=');
var s = parameters[i].split("=");
if(s.length != 2)
continue;
params[s[0]] = s[1];
@ -72,37 +72,37 @@ if(window.location.search) {
}
if(uname != null && pw != null && pw != "false") {
socket.emit('login', {
socket.emit("login", {
name: uname,
sha256: pw
});
}
function loginClick() {
uname = $('#username').val();
if($('#password').val() == "")
uname = $("#username").val();
if($("#password").val() == "")
pw = "";
else
pw = SHA256($('#password').val());
socket.emit('login', {
pw = SHA256($("#password").val());
socket.emit("login", {
name: uname,
sha256: pw
});
};
$('#login').click(loginClick);
$('#username').keydown(function(ev) {
$("#login").click(loginClick);
$("#username").keydown(function(ev) {
if(ev.key == 13)
loginClick();
});
$('#password').keydown(function(ev) {
$("#password").keydown(function(ev) {
if(ev.key == 13)
loginClick();
});
$('#logout').click(function() {
eraseCookie('sync_uname');
eraseCookie('sync_pw');
$("#logout").click(function() {
eraseCookie("sync_uname");
eraseCookie("sync_pw");
document.location.reload(true);
});
@ -119,10 +119,10 @@ function createCookie(name,value,days) {
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
while (c.charAt(0)==" ") c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;

View File

@ -12,120 +12,120 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// Wrapped in a function so I can ensure that the socket
// is defined before these statements are run
function initCallbacks() {
socket.on('disconnect', function() {
$('<div/>').addClass('alert').addClass('alert-error')
.insertAfter($('.row')[0])[0]
socket.on("disconnect", function() {
$("<div/>").addClass("alert").addClass("alert-error")
.insertAfter($(".row")[0])[0]
.innerHTML = "<h3>Disconnected from server</h3>";
});
socket.on('channelNotRegistered', function() {
socket.on("channelNotRegistered", function() {
showChannelRegistration();
});
socket.on('announcement', function(data) {
socket.on("announcement", function(data) {
showAnnouncement(data.title, data.text);
});
socket.on('registerChannel', function(data) {
socket.on("registerChannel", function(data) {
if(data.success) {
$('#chregnotice').remove();
$("#chregnotice").remove();
}
else {
alert(data.error);
}
});
socket.on('rank', function(data) {
socket.on("rank", function(data) {
if(data.rank >= Rank.Moderator) {
$('#playlist_controls').css("display", "block");
$('#playlist_controls button').each(function() {
$(this).attr('disabled', false);
$("#playlist_controls").css("display", "block");
$("#playlist_controls button").each(function() {
$(this).attr("disabled", false);
});
$('#qlockbtn').css("display", "block");
var poll = $('#pollcontainer .active');
$("#qlockbtn").css("display", "block");
var poll = $("#pollcontainer .active");
if(poll.length > 0) {
$('<button/>').addClass('btn btn-danger pull-right').text('Close Poll')
.insertAfter(poll.find('.close'))
$("<button/>").addClass("btn btn-danger pull-right").text("Close Poll")
.insertAfter(poll.find(".close"))
.click(function() {
socket.emit('closePoll')
socket.emit("closePoll")
});
}
var users = $('#userlist').children();
var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) {
addUserDropdown(users[i], users[i].children[1].innerHTML);
}
$('#modnav').show();
$('#chancontrols').show();
$("#modnav").show();
$("#chancontrols").show();
}
RANK = data.rank;
});
socket.on('login', function(data) {
socket.on("login", function(data) {
if(!data.success)
alert(data.error);
else {
$('#welcome')[0].innerHTML = "Welcome, " + uname;
$('#loginform').css("display", "none");
$('#logoutform').css("display", "");
$('#loggedin').css("display", "");
$("#welcome")[0].innerHTML = "Welcome, " + uname;
$("#loginform").css("display", "none");
$("#logoutform").css("display", "");
$("#loggedin").css("display", "");
if(pw != "") {
createCookie('sync_uname', uname, 1);
createCookie('sync_pw', pw, 1);
createCookie("sync_uname", uname, 1);
createCookie("sync_pw", pw, 1);
}
}
});
socket.on('register', function(data) {
socket.on("register", function(data) {
if(data.error) {
alert(data.error);
}
});
socket.on('channelOpts', function(opts) {
$('#opt_qopen_allow_qnext').prop('checked', opts.qopen_allow_qnext);
$('#opt_qopen_allow_move').prop('checked', opts.qopen_allow_move);
$('#opt_qopen_allow_delete').prop('checked', opts.qopen_allow_delete);
$('#opt_qopen_allow_playnext').prop('checked', opts.qopen_allow_playnext);
$('#opt_pagetitle').attr('placeholder', opts.pagetitle);
socket.on("channelOpts", function(opts) {
$("#opt_qopen_allow_qnext").prop("checked", opts.qopen_allow_qnext);
$("#opt_qopen_allow_move").prop("checked", opts.qopen_allow_move);
$("#opt_qopen_allow_delete").prop("checked", opts.qopen_allow_delete);
$("#opt_qopen_allow_playnext").prop("checked", opts.qopen_allow_playnext);
$("#opt_pagetitle").attr("placeholder", opts.pagetitle);
document.title = opts.pagetitle;
$('opt_customcss').val(opts.customcss);
$('#customCss').remove();
$("opt_customcss").val(opts.customcss);
$("#customCss").remove();
if(opts.customcss != "") {
$('<link/>').attr("rel", "stylesheet")
$("<link/>").attr("rel", "stylesheet")
.attr("href", opts.customcss)
.attr("id", "customCss")
.insertAfter($('link[href="./assets/css/ytsync.css"]'));
.insertAfter($("link[href='./assets/css/ytsync.css']"));
}
CHANNELOPTS = opts;
if(opts.qopen_allow_qnext)
$('#queue_next').attr('disabled', false);
$("#queue_next").attr("disabled", false);
if(opts.qopen_allow_playnext)
$('#play_next').attr('disabled', false);
$("#play_next").attr("disabled", false);
rebuildPlaylist();
});
socket.on('banlist', function(data) {
socket.on("banlist", function(data) {
updateBanlist(data.entries);
});
socket.on('usercount', function(data) {
$('#usercount').text(data.count + " connected users");
socket.on("usercount", function(data) {
$("#usercount").text(data.count + " connected users");
});
socket.on('chatMsg', function(data) {
socket.on("chatMsg", function(data) {
var div = formatChatMessage(data);
$('#messagebuffer')[0].appendChild(div);
$("#messagebuffer")[0].appendChild(div);
// Cap chatbox at most recent 100 messages
if($('#messagebuffer').children().length > 100) {
$($('#messagebufer').children()[0]).remove();
if($("#messagebuffer").children().length > 100) {
$($("#messagebufer").children()[0]).remove();
}
$('#messagebuffer').scrollTop($('#messagebuffer').prop("scrollHeight"));
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
});
socket.on('playlist', function(data) {
var ul = $('#queue')[0];
socket.on("playlist", function(data) {
var ul = $("#queue")[0];
var n = ul.children.length;
for(var i = 0; i < n; i++) {
ul.removeChild(ul.children[0]);
@ -138,71 +138,71 @@ function initCallbacks() {
}
});
socket.on('queue', function(data) {
socket.on("queue", function(data) {
var li = makeQueueEntry(data.media);
if(RANK >= Rank.Moderator || OPENQUEUE)
addQueueButtons(li);
$(li).css('display', 'none');
$(li).css("display", "none");
var idx = data.pos;
var ul = $('#queue')[0];
var ul = $("#queue")[0];
$(li).appendTo(ul);
if(idx < ul.children.length - 1)
moveVideo(ul.children.length - 1, idx);
$(li).show('blind');
$(li).show("blind");
});
socket.on('unqueue', function(data) {
if(data.pos == POSITION && $('#queue').children().length > POSITION + 1) {
$($('#queue').children()[POSITION+1]).addClass("alert alert-info");
socket.on("unqueue", function(data) {
if(data.pos == POSITION && $("#queue").children().length > POSITION + 1) {
$($("#queue").children()[POSITION+1]).addClass("alert alert-info");
}
var li = $('#queue').children()[data.pos];
//$(li).hide('blind', function() {
var li = $("#queue").children()[data.pos];
//$(li).hide("blind", function() {
$(li).remove();
//});
});
socket.on('moveVideo', function(data) {
socket.on("moveVideo", function(data) {
moveVideo(data.src, data.dest);
});
socket.on('queueLock', function(data) {
socket.on("queueLock", function(data) {
OPENQUEUE = !data.locked;
if(OPENQUEUE) {
$('#playlist_controls').css('display', '');
$("#playlist_controls").css("display", "");
if(RANK < Rank.Moderator) {
$('#qlockbtn').css('display', 'none');
$("#qlockbtn").css("display", "none");
rebuildPlaylist();
if(!CHANNELOPTS.qopen_allow_qnext)
$('#queue_next').attr('disabled', true);
$("#queue_next").attr("disabled", true);
if(!CHANNELOPTS.qopen_allow_playnext)
$('#play_next').attr('disabled', true);
$("#play_next").attr("disabled", true);
}
}
else if(RANK < Rank.Moderator) {
$('#playlist_controls').css('display', 'none');
$("#playlist_controls").css("display", "none");
}
if(OPENQUEUE) {
$('#qlockbtn').removeClass('btn-danger')
.addClass('btn-success')
.text('Lock Queue');
$("#qlockbtn").removeClass("btn-danger")
.addClass("btn-success")
.text("Lock Queue");
}
else {
$('#qlockbtn').removeClass('btn-success')
.addClass('btn-danger')
.text('Unlock Queue');
$("#qlockbtn").removeClass("btn-success")
.addClass("btn-danger")
.text("Unlock Queue");
}
});
socket.on('updatePlaylistIdx', function(data) {
var liold = $('#queue').children()[POSITION];
socket.on("updatePlaylistIdx", function(data) {
var liold = $("#queue").children()[POSITION];
$(liold).removeClass("alert alert-info");
var linew = $('#queue').children()[data.idx];
var linew = $("#queue").children()[data.idx];
$(linew).addClass("alert alert-info");
POSITION= data.idx;
});
socket.on('mediaUpdate', function(data) {
$('#currenttitle').text("Currently Playing: " + data.title);
socket.on("mediaUpdate", function(data) {
$("#currenttitle").text("Currently Playing: " + data.title);
if(data.type == "yt")
updateYT(data);
else if(data.type == "tw")
@ -217,24 +217,24 @@ function initCallbacks() {
updateDM(data);
});
socket.on('userlist', function(data) {
socket.on("userlist", function(data) {
for(var i = 0; i < data.length; i++) {
addUser(data[i].name, data[i].rank, data[i].leader);
}
});
socket.on('addUser', function(data) {
socket.on("addUser", function(data) {
addUser(data.name, data.rank, data.leader);
});
socket.on('updateUser', function(data) {
socket.on("updateUser", function(data) {
if(data.name == uname) {
LEADER = data.leader;
if(LEADER) {
// I'm a leader! Set up sync function
// I"m a leader! Set up sync function
sendVideoUpdate = function() {
if(MEDIATYPE == "yt") {
socket.emit('mediaUpdate', {
socket.emit("mediaUpdate", {
id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(),
paused: PLAYER.getPlayerState() == YT.PlayerState.PAUSED,
@ -243,7 +243,7 @@ function initCallbacks() {
}
else if(MEDIATYPE == "sc") {
PLAYER.getPosition(function(pos) {
socket.emit('mediaUpdate', {
socket.emit("mediaUpdate", {
id: PLAYER.mediaId,
seconds: pos / 1000,
paused: false,
@ -252,8 +252,8 @@ function initCallbacks() {
});
}
else if(MEDIATYPE == "vi") {
PLAYER.api('getCurrentTime', function(data) {
socket.emit('mediaUpdate', {
PLAYER.api("getCurrentTime", function(data) {
socket.emit("mediaUpdate", {
id: PLAYER.videoid,
seconds: data,
paused: false,
@ -262,7 +262,7 @@ function initCallbacks() {
});
}
else if(MEDIATYPE == "dm") {
socket.emit('mediaUpdate', {
socket.emit("mediaUpdate", {
id: PLAYER.mediaId,
seconds: PLAYER.currentTime,
paused: PLAYER.paused,
@ -271,16 +271,16 @@ function initCallbacks() {
}
};
}
// I'm not a leader. Don't send syncs to the server
// I"m not a leader. Don"t send syncs to the server
else {
sendVideoUpdate = function() { }
}
RANK = data.rank;
if(data.rank >= Rank.Moderator)
$('#playlist_controls').css("display", "block");
$("#playlist_controls").css("display", "block");
}
var users = $('#userlist').children();
var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML;
// Reformat user
@ -290,22 +290,22 @@ function initCallbacks() {
}
});
socket.on('userLeave', function(data) {
var users = $('#userlist').children();
socket.on("userLeave", function(data) {
var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML;
if(name == data.name) {
$('#userlist')[0].removeChild(users[i]);
$("#userlist")[0].removeChild(users[i]);
}
}
});
socket.on('librarySearchResults', function(data) {
var n = $('#library').children().length;
socket.on("librarySearchResults", function(data) {
var n = $("#library").children().length;
for(var i = 0; i < n; i++) {
$('#library')[0].removeChild($('#library').children()[0]);
$("#library")[0].removeChild($("#library").children()[0]);
}
var ul = $('#library')[0];
var ul = $("#library")[0];
for(var i = 0; i < data.results.length; i++) {
var li = makeQueueEntry(data.results[i]);
if(RANK >= Rank.Moderator || OPENQUEUE)
@ -314,15 +314,15 @@ function initCallbacks() {
}
});
socket.on('newPoll', function(data) {
socket.on("newPoll", function(data) {
addPoll(data);
});
socket.on('updatePoll', function(data) {
socket.on("updatePoll", function(data) {
updatePoll(data);
});
socket.on('closePoll', function() {
socket.on("closePoll", function() {
closePoll();
});
}

View File

@ -17,8 +17,8 @@ var POSITION = -1;
var RANK = 0;
var OPENQUEUE = false;
var CHANNELOPTS = {};
var uname = readCookie('sync_uname');
var pw = readCookie('sync_pw');
var uname = readCookie("sync_uname");
var pw = readCookie("sync_pw");
var Rank = {
Guest: 0,
@ -33,31 +33,31 @@ initCallbacks();
var params = {};
if(window.location.search) {
var parameters = window.location.search.substring(1).split('&');
var parameters = window.location.search.substring(1).split("&");
for(var i = 0; i < parameters.length; i++) {
var s = parameters[i].split('=');
var s = parameters[i].split("=");
if(s.length != 2)
continue;
params[s[0]] = s[1];
}
}
if(params['novideo'] != undefined) {
$('.span7').remove();
if(params["novideo"] != undefined) {
$(".span7").remove();
}
if(params['channel'] == undefined) {
var main = $($('.container')[1]);
var container = $('<div/>').addClass('container').insertBefore(main);
var row = $('<div/>').addClass('row').appendTo(container);
var div = $('<div/>').addClass('span6').appendTo(row);
if(params["channel"] == undefined) {
var main = $($(".container")[1]);
var container = $("<div/>").addClass("container").insertBefore(main);
var row = $("<div/>").addClass("row").appendTo(container);
var div = $("<div/>").addClass("span6").appendTo(row);
main.css("display", "none");
var label = $('<label/>').text('Enter Channel:').appendTo(div);
var entry = $('<input/>').attr('type', 'text').appendTo(div);
var label = $("<label/>").text("Enter Channel:").appendTo(div);
var entry = $("<input/>").attr("type", "text").appendTo(div);
entry.keydown(function(ev) {
if(ev.keyCode == 13) {
document.location = document.location + "?channel=" + entry.val();
socket.emit('joinChannel', {
socket.emit("joinChannel", {
name: entry.val()
});
container.remove();
@ -65,38 +65,38 @@ if(params['channel'] == undefined) {
}
});
}
else if(!params['channel'].match(/^[a-zA-Z0-9]+$/)) {
$('<div/>').addClass('alert alert-error')
.insertAfter($('.row')[0])[0]
else if(!params["channel"].match(/^[a-zA-Z0-9]+$/)) {
$("<div/>").addClass("alert alert-error")
.insertAfter($(".row")[0])[0]
.innerHTML = "<h3>Invalid Channel Name</h3><p>Channel names must conain only numbers and letters</p>";
}
else {
socket.emit('joinChannel', {
name: params['channel']
socket.emit("joinChannel", {
name: params["channel"]
});
}
// Load the youtube iframe API
var tag = document.createElement('script');
var tag = document.createElement("script");
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Load the Dailymotion iframe API
/*
var tag = document.createElement('script');
var tag = document.createElement("script");
tag.src = "http://api.dmcdn.net/all.js";
var firstScriptTag = document.getElementsByTagName('script')[0];
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
*/
if(uname != null && pw != null && pw != "false") {
socket.emit('login', {
socket.emit("login", {
name: uname,
sha256: pw
});
@ -107,95 +107,95 @@ setInterval(function() {
sendVideoUpdate();
}, 5000);
$('#queue_end').click(function() {
var parsed = parseVideoURL($('#mediaurl').val());
$("#queue_end").click(function() {
var parsed = parseVideoURL($("#mediaurl").val());
var id = parsed[0];
var type = parsed[1];
if(id) {
$('#mediaurl').val("");
$("#mediaurl").val("");
}
socket.emit('queue', {
socket.emit("queue", {
id: id,
pos: "end",
type: type
});
});
$('#queue_next').click(function() {
var parsed = parseVideoURL($('#mediaurl').val());
$("#queue_next").click(function() {
var parsed = parseVideoURL($("#mediaurl").val());
var id = parsed[0];
var type = parsed[1];
if(id) {
$('#mediaurl').val("");
$("#mediaurl").val("");
}
socket.emit('queue', {
socket.emit("queue", {
id: id,
pos: "next",
type: type
});
});
$('#play_next').click(function() {
socket.emit('playNext');
$("#play_next").click(function() {
socket.emit("playNext");
});
$('#qlockbtn').click(function() {
socket.emit('queueLock', {
$("#qlockbtn").click(function() {
socket.emit("queueLock", {
locked: OPENQUEUE
});
});
function loginClick() {
uname = $('#username').val();
if($('#password').val() == "")
uname = $("#username").val();
if($("#password").val() == "")
pw = "";
else
pw = SHA256($('#password').val());
socket.emit('login', {
pw = SHA256($("#password").val());
socket.emit("login", {
name: uname,
sha256: pw
});
};
$('#login').click(loginClick);
$('#username').keydown(function(ev) {
$("#login").click(loginClick);
$("#username").keydown(function(ev) {
if(ev.key == 13)
loginClick();
});
$('#password').keydown(function(ev) {
$("#password").keydown(function(ev) {
if(ev.key == 13)
loginClick();
});
$('#logout').click(function() {
eraseCookie('sync_uname');
eraseCookie('sync_pw');
$("#logout").click(function() {
eraseCookie("sync_uname");
eraseCookie("sync_pw");
document.location.reload(true);
});
$('#register').click(function() {
uname = $('#username').val();
if($('#password').val() == "")
$("#register").click(function() {
uname = $("#username").val();
if($("#password").val() == "")
pw = "";
else
pw = SHA256($('#password').val());
socket.emit('register', {
pw = SHA256($("#password").val());
socket.emit("register", {
name: uname,
sha256: pw
});
});
$('#chatline').keydown(function(ev) {
if(ev.keyCode == 13 && $('#chatline').val() != '') {
socket.emit('chatMsg', {
msg: $('#chatline').val()
$("#chatline").keydown(function(ev) {
if(ev.keyCode == 13 && $("#chatline").val() != "") {
socket.emit("chatMsg", {
msg: $("#chatline").val()
});
$('#chatline').val('');
$("#chatline").val("");
}
else if(ev.keyCode == 9) { // Tab completion
var words = $('#chatline').val().split(' ');
var words = $("#chatline").val().split(" ");
var current = words[words.length - 1].toLowerCase();
var users = $('#userlist').children();
var users = $("#userlist").children();
var match = null;
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML.toLowerCase();
@ -213,79 +213,79 @@ $('#chatline').keydown(function(ev) {
words[0] += ": ";
else
words[words.length - 1] += " ";
$('#chatline').val(words.join(' '));
$("#chatline").val(words.join(" "));
}
ev.preventDefault();
return false;
}
});
$('#opt_submit').click(function() {
var ptitle = $('#opt_pagetitle').val();
if(ptitle == '')
ptitle = $('#opt_pagetitle').attr('placeholder')
$("#opt_submit").click(function() {
var ptitle = $("#opt_pagetitle").val();
if(ptitle == "")
ptitle = $("#opt_pagetitle").attr("placeholder")
opts = {
qopen_allow_qnext: $('#opt_qopen_allow_qnext').prop('checked'),
qopen_allow_move: $('#opt_qopen_allow_move').prop('checked'),
qopen_allow_delete: $('#opt_qopen_allow_delete').prop('checked'),
qopen_allow_playnext: $('#opt_qopen_allow_playnext').prop('checked'),
qopen_allow_qnext: $("#opt_qopen_allow_qnext").prop("checked"),
qopen_allow_move: $("#opt_qopen_allow_move").prop("checked"),
qopen_allow_delete: $("#opt_qopen_allow_delete").prop("checked"),
qopen_allow_playnext: $("#opt_qopen_allow_playnext").prop("checked"),
pagetitle: ptitle,
customcss: $('#opt_customcss').val()
customcss: $("#opt_customcss").val()
};
socket.emit('channelOpts', opts);
socket.emit("channelOpts", opts);
});
$('#show_chancontrols').click(function() {
$('#show_chancontrols').parent().addClass("active");
$('#show_banlist').parent().removeClass("active");
$('#banlist').hide();
$('#chancontrols').show();
$("#show_chancontrols").click(function() {
$("#show_chancontrols").parent().addClass("active");
$("#show_banlist").parent().removeClass("active");
$("#banlist").hide();
$("#chancontrols").show();
});
$('#show_banlist').click(function() {
$('#show_chancontrols').parent().removeClass("active");
$('#show_banlist').parent().addClass("active");
$('#banlist').show();
$('#chancontrols').hide();
$("#show_banlist").click(function() {
$("#show_chancontrols").parent().removeClass("active");
$("#show_banlist").parent().addClass("active");
$("#banlist").show();
$("#chancontrols").hide();
});
function searchLibrary() {
socket.emit('searchLibrary', {
query: $('#library_query').val()
socket.emit("searchLibrary", {
query: $("#library_query").val()
});
}
$('#library_search').click(searchLibrary);
$('#library_query').keydown(function(ev) {
$("#library_search").click(searchLibrary);
$("#library_query").keydown(function(ev) {
if(ev.key == 13)
searchLibrary();
});
function onYouTubeIframeAPIReady() {
PLAYER = new YT.Player('ytapiplayer', {
height: '390',
width: '640',
videoId: '',
PLAYER = new YT.Player("ytapiplayer", {
height: "390",
width: "640",
videoId: "",
playerVars: {
'autoplay': 0,
'controls': 1,
"autoplay": 0,
"controls": 1,
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
"onReady": onPlayerReady,
"onStateChange": onPlayerStateChange
}
});
}
function onPlayerReady() {
socket.emit('playerReady');
socket.emit("playerReady");
}
function onPlayerStateChange(state) {
if(LEADER && state.data == YT.PlayerState.ENDED) {
socket.emit('playNext');
socket.emit("playNext");
}
else if(LEADER && state.data == YT.PlayerState.PAUSED) {
socket.emit('mediaUpdate', {
socket.emit("mediaUpdate", {
id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(),
type: "yt",
@ -293,7 +293,7 @@ function onPlayerStateChange(state) {
});
}
if(LEADER && state.data == YT.PlayerState.PLAYING) {
socket.emit('mediaUpdate', {
socket.emit("mediaUpdate", {
id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(),
type: "yt",
@ -314,10 +314,10 @@ function createCookie(name,value,days) {
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
while (c.charAt(0)==" ") c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;

View File

@ -11,17 +11,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// Adds a user to the chatbox userlist
function addUser(name, rank, leader) {
var div = document.createElement('div');
var div = document.createElement("div");
$(div).attr("class", "userlist_item");
var span = document.createElement('span');
var flair = document.createElement('span');
var span = document.createElement("span");
var flair = document.createElement("span");
span.innerHTML = name;
div.appendChild(flair);
div.appendChild(span);
fmtUserlistItem(div, rank, leader);
if(RANK >= Rank.Moderator)
addUserDropdown(div, name);
var users = $('#userlist').children();
var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) {
var othername = users[i].children[1].innerHTML;
if(othername.toLowerCase() > name.toLowerCase()) {
@ -29,10 +29,10 @@ function addUser(name, rank, leader) {
return;
}
}
$('#userlist')[0].appendChild(div);
$("#userlist")[0].appendChild(div);
}
// Format a userlist entry based on a person's rank
// Format a userlist entry based on a person"s rank
function fmtUserlistItem(div, rank, leader) {
var span = div.children[1];
if(rank >= Rank.Siteadmin)
@ -54,63 +54,63 @@ function fmtUserlistItem(div, rank, leader) {
// Adds a dropdown with user actions (promote/demote/leader)
function addUserDropdown(entry, name) {
var div = $('<div />').addClass("dropdown").appendTo(entry);
var ul = $('<ul />').addClass("dropdown-menu").appendTo(div);
var div = $("<div />").addClass("dropdown").appendTo(entry);
var ul = $("<ul />").addClass("dropdown-menu").appendTo(div);
ul.attr("role", "menu");
ul.attr("aria-labelledby", "dropdownMenu");
var makeLeader = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(makeLeader);
var makeLeader = $("<li />").appendTo(ul);
var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(makeLeader);
a.text("Make Leader");
a.click(function() {
socket.emit('assignLeader', {
socket.emit("assignLeader", {
name: name
});
});
var takeLeader = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(takeLeader);
var takeLeader = $("<li />").appendTo(ul);
var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(takeLeader);
a.text("Take Leader");
a.click(function() {
socket.emit('assignLeader', {
socket.emit("assignLeader", {
name: ""
});
});
var kick = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(kick);
var kick = $("<li />").appendTo(ul);
var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(kick);
a.text("Kick");
a.click(function() {
socket.emit('chatMsg', {
socket.emit("chatMsg", {
msg: "/kick " + name
});
});
var ban = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(ban);
var ban = $("<li />").appendTo(ul);
var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(ban);
a.text("IP Ban");
a.click(function() {
socket.emit('chatMsg', {
socket.emit("chatMsg", {
msg: "/ban " + name
});
});
$('<li />').addClass("divider").appendTo(ul);
$("<li />").addClass("divider").appendTo(ul);
var promote = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(promote);
var promote = $("<li />").appendTo(ul);
var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(promote);
a.text("Promote");
a.click(function() {
socket.emit('promote', {
socket.emit("promote", {
name: name
});
});
var demote = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(demote);
var demote = $("<li />").appendTo(ul);
var a = $("<a />").attr("tabindex", "-1").attr("href", "#").appendTo(demote);
a.text("Demote");
a.click(function() {
socket.emit('demote', {
socket.emit("demote", {
name: name
});
});
@ -127,18 +127,18 @@ function addUserDropdown(entry, name) {
}
function formatChatMessage(data) {
var div = document.createElement('div');
var div = document.createElement("div");
if(data.msg.indexOf(uname) != -1)
$(div).addClass('nick-highlight');
$(div).addClass("nick-highlight");
if(data.msgclass == "action") {
var message = document.createElement('span');
$(message).addClass('action');
var message = document.createElement("span");
$(message).addClass("action");
message.innerHTML = data.username + " " + data.msg;
div.appendChild(message);
}
else {
var name = document.createElement('span');
var message = document.createElement('span');
var name = document.createElement("span");
var message = document.createElement("span");
name.innerHTML = "<strong>&lt;" + data.username + "&gt;</strong> ";
if(data.msgclass == "shout")
$(name).addClass("shout");
@ -152,60 +152,60 @@ function formatChatMessage(data) {
// Creates and formats a queue entry
function makeQueueEntry(video) {
var li = $('<li />');
var li = $("<li />");
li.attr("class", "well");
var title = $('<span />').attr("class", "qe_title").appendTo(li);
var title = $("<span />").attr("class", "qe_title").appendTo(li);
title.text(video.title);
var time = $('<span />').attr("class", "qe_time").appendTo(li);
var time = $("<span />").attr("class", "qe_time").appendTo(li);
time.text(video.duration);
var clear = $('<div />').attr("class", "qe_clear").appendTo(li);
var clear = $("<div />").attr("class", "qe_clear").appendTo(li);
return li;
}
// Add buttons to a queue list entry
function addQueueButtons(li) {
var btnstrip = $('<div />').attr("class", "btn-group qe_buttons").prependTo(li);
var btnstrip = $("<div />").attr("class", "btn-group qe_buttons").prependTo(li);
var btnRemove = $('<button />').attr("class", "btn btn-danger qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-remove").appendTo(btnRemove);
var btnRemove = $("<button />").attr("class", "btn btn-danger qe_btn").appendTo(btnstrip);
$("<i />").attr("class", "icon-remove").appendTo(btnRemove);
var btnUp = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-arrow-up").appendTo(btnUp);
var btnUp = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
$("<i />").attr("class", "icon-arrow-up").appendTo(btnUp);
var btnDown = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-arrow-down").appendTo(btnDown);
var btnDown = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
$("<i />").attr("class", "icon-arrow-down").appendTo(btnDown);
var btnNext = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
//$('<i />').attr("class", "icon-play").appendTo(btnNext);
btnNext.text('Next');
var btnNext = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
//$("<i />").attr("class", "icon-play").appendTo(btnNext);
btnNext.text("Next");
// Callback time
$(btnRemove).click(function() {
btnstrip.remove();
var idx = $('#queue').children().index(li);
socket.emit('unqueue', { pos: idx });
var idx = $("#queue").children().index(li);
socket.emit("unqueue", { pos: idx });
});
$(btnUp).click(function() {
var idx = $('#queue').children().index(li);
socket.emit('moveMedia', {
var idx = $("#queue").children().index(li);
socket.emit("moveMedia", {
src: idx,
dest: idx-1
});
});
$(btnDown).click(function() {
var idx = $('#queue').children().index(li);
socket.emit('moveMedia', {
var idx = $("#queue").children().index(li);
socket.emit("moveMedia", {
src: idx,
dest: idx+1
});
});
$(btnNext).click(function() {
var idx = $('#queue').children().index(li);
var idx = $("#queue").children().index(li);
var dest = idx < POSITION ? POSITION : POSITION + 1;
socket.emit('moveMedia', {
socket.emit("moveMedia", {
src: idx,
dest: dest
});
@ -213,19 +213,19 @@ function addQueueButtons(li) {
if(RANK < Rank.Moderator && !LEADER) {
if(!CHANNELOPTS.qopen_allow_delete)
$(btnRemove).attr('disabled', true);
$(btnRemove).attr("disabled", true);
if(!CHANNELOPTS.qopen_allow_move) {
$(btnUp).attr('disabled', true);
$(btnDown).attr('disabled', true);
$(btnUp).attr("disabled", true);
$(btnDown).attr("disabled", true);
}
if(!CHANNELOPTS.qopen_allow_qnext)
$(btnNext).attr('disabled', true);
$(btnNext).attr("disabled", true);
}
}
function rebuildPlaylist() {
$('#queue li').each(function() {
$(this).find('.btn-group').remove();
$("#queue li").each(function() {
$(this).find(".btn-group").remove();
if(RANK >= Rank.Moderator || LEADER || OPENQUEUE)
addQueueButtons(this);
});
@ -233,27 +233,27 @@ function rebuildPlaylist() {
// Add buttons to a list entry for the library search results
function addLibraryButtons(li, id) {
var btnstrip = $('<div />').attr("class", "btn-group qe_buttons").prependTo(li);
var btnstrip = $("<div />").attr("class", "btn-group qe_buttons").prependTo(li);
var btnNext = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
//$('<i />').attr("class", "icon-play").appendTo(btnNext);
btnNext.text('Next');
var btnNext = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
//$("<i />").attr("class", "icon-play").appendTo(btnNext);
btnNext.text("Next");
var btnEnd = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
//$('<i />').attr("class", "icon-fast-forward").appendTo(btnEnd);
btnEnd.text('End');
var btnEnd = $("<button />").attr("class", "btn qe_btn").appendTo(btnstrip);
//$("<i />").attr("class", "icon-fast-forward").appendTo(btnEnd);
btnEnd.text("End");
// Callback time
$(btnNext).click(function() {
socket.emit('queue', {
socket.emit("queue", {
id: id,
pos: "next"
});
});
$(btnEnd).click(function() {
socket.emit('queue', {
socket.emit("queue", {
id: id,
pos: "end"
});
@ -262,17 +262,17 @@ function addLibraryButtons(li, id) {
// Rearranges the queue
function moveVideo(src, dest) {
var li = $('#queue').children()[src];
var ul = $('#queue')[0];
$(li).hide('blind', function() {
var li = $("#queue").children()[src];
var ul = $("#queue")[0];
$(li).hide("blind", function() {
ul.removeChild(li);
if(dest == ul.children.length) {
ul.appendChild(li);
}
else {
ul.insertBefore(li, ul.getElementsByTagName('li')[dest]);
ul.insertBefore(li, ul.getElementsByTagName("li")[dest]);
}
$(li).show('blind');
$(li).show("blind");
});
if(src < POSITION && dest >= POSITION)
POSITION--;
@ -286,24 +286,24 @@ function updateYT(data) {
removeCurrentPlayer();
MEDIATYPE = "yt";
// Note to Soundcloud/Vimeo API designers:
// YouTube's API is actually nice to use
PLAYER = new YT.Player('ytapiplayer', {
height: '390',
width: '640',
videoId: '',
// YouTube"s API is actually nice to use
PLAYER = new YT.Player("ytapiplayer", {
height: "390",
width: "640",
videoId: "",
playerVars: {
'autoplay': 0,
'controls': 1,
"autoplay": 0,
"controls": 1,
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
"onReady": onPlayerReady,
"onStateChange": onPlayerStateChange
}
});
}
// Load new video
if(PLAYER.getVideoUrl && data.id != parseYTURL(PLAYER.getVideoUrl())) {
PLAYER.loadVideoById(data.id, data.currentTime, $('#quality').val());
PLAYER.loadVideoById(data.id, data.currentTime, $("#quality").val());
if(data.paused)
PLAYER.pauseVideo();
}
@ -327,7 +327,7 @@ function updateSC(data) {
iframe.css("width", "100%").attr("height", "166")
.attr("frameborder", "no");
PLAYER = SC.Widget('ytapiplayer');
PLAYER = SC.Widget("ytapiplayer");
MEDIATYPE = "sc";
}
// Server is on a different soundcloud track than client
@ -338,7 +338,7 @@ function updateSC(data) {
// Keep track of current ID
PLAYER.mediaId = data.id;
}
// Soundcloud's API is async
// Soundcloud"s API is async
// Query the playback position and compare that with the sync packet
PLAYER.getPosition(function(pos) {
if(Math.abs(pos / 1000 - data.currentTime) > SYNC_THRESHOLD) {
@ -380,15 +380,15 @@ function updateVI(data) {
if(MEDIATYPE != "vi") {
initVI(data);
}
// Either vimeo's API doesn't support loading a new video
// or their terrible documentation doesn't document it
// Either vimeo"s API doesn"t support loading a new video
// or their terrible documentation doesn"t document it
else if(data.id != PLAYER.videoid) {
initVI(data);
}
PLAYER.api('getCurrentTime', function(time) {
PLAYER.api("getCurrentTime", function(time) {
if(Math.abs(time - data.currentTime) > SYNC_THRESHOLD) {
PLAYER.api('seekTo', data.currentTime);
PLAYER.api("seekTo", data.currentTime);
}
});
}
@ -398,16 +398,16 @@ function initVI(data) {
var currentEmbed = $("#ytapiplayer");
var div = currentEmbed.parent();
currentEmbed.remove();
// Ugly but it's the only way I managed to get the API calls to work
div[0].innerHTML += '<iframe id="ytapiplayer" src="http://player.vimeo.com/video/' + data.id + '?api=1&player_id=ytapiplayer" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
// $f() is defined by froogaloop, Vimeo's API wrapper
PLAYER = $f($('iframe')[0]);
// Ugly but it"s the only way I managed to get the API calls to work
div[0].innerHTML += "<iframe id=\"ytapiplayer\" src=\"http://player.vimeo.com/video/" + data.id + "?api=1&player_id=ytapiplayer\" width=\"640\" height=\"390\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";
// $f() is defined by froogaloop, Vimeo"s API wrapper
PLAYER = $f($("iframe")[0]);
// So we can retrieve the ID synchronously instead of waiting for
// getVideoId with a callback
PLAYER.videoid = data.id;
PLAYER.addEvent('ready', function() {
PLAYER.addEvent("ready", function() {
// Autoplay
PLAYER.api('play');
PLAYER.api("play");
});
MEDIATYPE = "vi";
}
@ -425,14 +425,14 @@ function loadTwitch(channel) {
id: "live_embed_player_flash",
flashvars:"hostname=www.twitch.tv&channel="+channel+"&auto_play=true&start_volume=100"
};
swfobject.embedSWF( url, "ytapiplayer", '640', '390', "8", null, null, params, {} );
swfobject.embedSWF( url, "ytapiplayer", "640", "390", "8", null, null, params, {} );
}
function loadLivestream(channel) {
MEDIATYPE = "li";
removeCurrentPlayer();
flashvars = { channel: channel };
params = { AllowScriptAccess: 'always' };
params = { AllowScriptAccess: "always" };
swfobject.embedSWF("http://cdn.livestream.com/chromelessPlayer/v20/playerapi.swf", "ytapiplayer", "640", "390", "9.0.0", "expressInstall.swf", flashvars, params);
}
@ -519,13 +519,13 @@ function parseDailymotion(url) {
}
function closePoll() {
if($('#pollcontainer .active').length != 0) {
var poll = $('#pollcontainer .active');
if($("#pollcontainer .active").length != 0) {
var poll = $("#pollcontainer .active");
poll.removeClass("active").addClass("muted");
poll.find('.option button').each(function() {
$(this).attr('disabled', 'disabled');
poll.find(".option button").each(function() {
$(this).attr("disabled", "disabled");
});
poll.find('.btn-danger').each(function() {
poll.find(".btn-danger").each(function() {
$(this).remove()
});
}
@ -533,34 +533,34 @@ function closePoll() {
function addPoll(data) {
closePoll();
var pollMsg = $('<div/>').addClass('poll-notify')
.text(data.initiator + ' opened a poll: "' + data.title + '"')
.appendTo($('#messagebuffer'));
var poll = $('<div/>').addClass('well active').prependTo($('#pollcontainer'));
$('<button/>').addClass('close pull-right').text('×')
var pollMsg = $("<div/>").addClass("poll-notify")
.text(data.initiator + " opened a poll: \"" + data.title + "\"")
.appendTo($("#messagebuffer"));
var poll = $("<div/>").addClass("well active").prependTo($("#pollcontainer"));
$("<button/>").addClass("close pull-right").text("×")
.appendTo(poll)
.click(function() { poll.remove(); });
if(RANK >= Rank.Moderator) {
$('<button/>').addClass('btn btn-danger pull-right').text('Close Poll')
$("<button/>").addClass("btn btn-danger pull-right").text("Close Poll")
.appendTo(poll)
.click(function() {
socket.emit('closePoll')
socket.emit("closePoll")
});
}
$('<h3/>').text(data.title).appendTo(poll);
$("<h3/>").text(data.title).appendTo(poll);
for(var i = 0; i < data.options.length; i++) {
var callback = (function(i) { return function() {
console.log(i);
socket.emit('vote', {
socket.emit("vote", {
option: i
});
poll.find('.option button').each(function() {
$(this).attr('disabled', 'disabled');
poll.find(".option button").each(function() {
$(this).attr("disabled", "disabled");
});
} })(i);
$('<button/>').addClass('btn').text(data.counts[i])
.prependTo($('<div/>').addClass('option').text(data.options[i])
$("<button/>").addClass("btn").text(data.counts[i])
.prependTo($("<div/>").addClass("option").text(data.options[i])
.appendTo(poll))
.click(callback);
@ -568,54 +568,54 @@ function addPoll(data) {
}
function updatePoll(data) {
var poll = $('#pollcontainer .active');
var poll = $("#pollcontainer .active");
var i = 0;
poll.find('.option button').each(function() {
poll.find(".option button").each(function() {
$(this).text(data.counts[i]);
i++;
});
}
function showChannelRegistration() {
var div = $('<div/>').addClass('alert alert-info').attr('id', 'chregnotice')
.insertAfter($('.row')[0]);
$('<button/>').addClass('close pull-right').text('×')
var div = $("<div/>").addClass("alert alert-info").attr("id", "chregnotice")
.insertAfter($(".row")[0]);
$("<button/>").addClass("close pull-right").text("×")
.appendTo(div)
.click(function() { div.remove(); });
$('<h3/>').text("This channel isn't registered").appendTo(div);
$('<button/>').addClass('btn btn-primary').text('Register it')
$("<h3/>").text("This channel isn"t registered").appendTo(div);
$("<button/>").addClass("btn btn-primary").text("Register it")
.appendTo(div)
.click(function() {
socket.emit('registerChannel');
socket.emit("registerChannel");
});
}
function showAnnouncement(title, text) {
var div = $('<div/>').addClass('alert')
.insertAfter($('.row')[0]);
$('<button/>').addClass('close pull-right').text('×')
var div = $("<div/>").addClass("alert")
.insertAfter($(".row")[0]);
$("<button/>").addClass("close pull-right").text("×")
.appendTo(div)
.click(function() { div.remove(); });
$('<h3/>').text(title).appendTo(div);
$('<p/>').html(text).appendTo(div);
$("<h3/>").text(title).appendTo(div);
$("<p/>").html(text).appendTo(div);
}
function updateBanlist(entries) {
var tbl = $('#banlist table');
var tbl = $("#banlist table");
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
for(var i = 0; i < entries.length; i++) {
var tr = $('<tr/>').appendTo(tbl);
var remove = $('<button/>').addClass("btn btn-mini btn-danger")
.appendTo($('<td/>').appendTo(tr));
$('<i/>').addClass("icon-remove-circle").appendTo(remove);
var ip = $('<td/>').text(entries[i].ip).appendTo(tr);
var name = $('<td/>').text(entries[i].name).appendTo(tr);
var banner = $('<td/>').text(entries[i].banner).appendTo(tr);
var tr = $("<tr/>").appendTo(tbl);
var remove = $("<button/>").addClass("btn btn-mini btn-danger")
.appendTo($("<td/>").appendTo(tr));
$("<i/>").addClass("icon-remove-circle").appendTo(remove);
var ip = $("<td/>").text(entries[i].ip).appendTo(tr);
var name = $("<td/>").text(entries[i].name).appendTo(tr);
var banner = $("<td/>").text(entries[i].banner).appendTo(tr);
var callback = (function(ip) { return function() {
socket.emit('chatMsg', {
socket.emit("chatMsg", {
msg: "/unban " + ip
});
} })(entries[i].ip);