mirror of https://github.com/calzoneman/sync.git
Change the way unregistered channels work
This commit is contained in:
parent
b214c07fe0
commit
1864cc0b35
|
@ -168,6 +168,7 @@ Channel.prototype.tryLoadState = function () {
|
||||||
|
|
||||||
// Don't load state if the channel isn't registered
|
// Don't load state if the channel isn't registered
|
||||||
if (!self.registered) {
|
if (!self.registered) {
|
||||||
|
self.setUnregisteredPermissions();
|
||||||
self.emit("ready");
|
self.emit("ready");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -453,9 +454,6 @@ Channel.prototype.preJoin = function (user, password) {
|
||||||
if (err) {
|
if (err) {
|
||||||
user.rank = user.global_rank;
|
user.rank = user.global_rank;
|
||||||
} else {
|
} else {
|
||||||
if (!self.registered && user.rank > 2 && rank <= 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
user.rank = Math.max(rank, user.global_rank);
|
user.rank = Math.max(rank, user.global_rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,21 +517,6 @@ Channel.prototype.join = function (user) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self.registered) {
|
|
||||||
var hasAdmin = false;
|
|
||||||
for (var i = 0; i < self.users.length; i++) {
|
|
||||||
if (self.users[i].rank > 2) {
|
|
||||||
hasAdmin = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasAdmin) {
|
|
||||||
user.rank = 4;
|
|
||||||
user.socket.emit("rank", 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.sendUserJoin(self.users, user);
|
self.sendUserJoin(self.users, user);
|
||||||
self.sendUserlist([user]);
|
self.sendUserlist([user]);
|
||||||
};
|
};
|
||||||
|
@ -628,19 +611,6 @@ Channel.prototype.part = function (user) {
|
||||||
self.users.splice(idx, 1);
|
self.users.splice(idx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self.registered && user.rank === 4) {
|
|
||||||
if (self.users.length > 0) {
|
|
||||||
for (var i = 0; i < self.users.length; i++) {
|
|
||||||
self.users[i].rank = 4;
|
|
||||||
self.users[i].socket.emit("rank", 4);
|
|
||||||
self.sendAll("setUserRank", {
|
|
||||||
name: self.users[i].name,
|
|
||||||
rank: 4
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A change in usercount might cause a voteskip result to change
|
// A change in usercount might cause a voteskip result to change
|
||||||
self.checkVoteskipPass();
|
self.checkVoteskipPass();
|
||||||
self.sendUsercount(self.users);
|
self.sendUsercount(self.users);
|
||||||
|
@ -3014,4 +2984,40 @@ Channel.prototype.sendAll = function (msg, data) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a special set of permissions for unregistered channels
|
||||||
|
*/
|
||||||
|
Channel.prototype.setUnregisteredPermissions = function () {
|
||||||
|
this.permissions = {
|
||||||
|
playlistadd: -1, // Add video to the playlist
|
||||||
|
playlistnext: 0,
|
||||||
|
playlistmove: 0, // Move a video on the playlist
|
||||||
|
playlistdelete: 0, // Delete a video from the playlist
|
||||||
|
playlistjump: 0, // Start a different video on the playlist
|
||||||
|
playlistaddlist: 0, // Add a list of videos to the playlist
|
||||||
|
oplaylistadd: -1, // Same as above, but for open (unlocked) playlist
|
||||||
|
oplaylistnext: 0,
|
||||||
|
oplaylistmove: 0,
|
||||||
|
oplaylistdelete: 0,
|
||||||
|
oplaylistjump: 0,
|
||||||
|
oplaylistaddlist: 0,
|
||||||
|
playlistaddcustom: 0, // Add custom embed to the playlist
|
||||||
|
playlistaddlive: 0, // Add a livestream to the playlist
|
||||||
|
exceedmaxlength: 0, // Add a video longer than the maximum length set
|
||||||
|
addnontemp: 0, // Add a permanent video to the playlist
|
||||||
|
settemp: 0, // Toggle temporary status of a playlist item
|
||||||
|
playlistshuffle: 0, // Shuffle the playlist
|
||||||
|
playlistclear: 0, // Clear the playlist
|
||||||
|
pollctl: 0, // Open/close polls
|
||||||
|
pollvote: -1, // Vote in polls
|
||||||
|
viewhiddenpoll: 1.5, // View results of hidden polls
|
||||||
|
voteskip: -1, // Vote to skip the current video
|
||||||
|
playlistlock: 2, // Lock/unlock the playlist
|
||||||
|
leaderctl: 0, // Give/take leader
|
||||||
|
drink: 0, // Use the /d command
|
||||||
|
chat: 0 // Send chat messages
|
||||||
|
};
|
||||||
|
this.sendAll("setPermissions", this.permissions);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Channel;
|
module.exports = Channel;
|
||||||
|
|
|
@ -264,7 +264,6 @@ module.exports = {
|
||||||
err = e4;
|
err = e4;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(path.join(__dirname, "..", "..", "chandump", name));
|
|
||||||
fs.unlink(path.join(__dirname, "..", "..", "chandump", name),
|
fs.unlink(path.join(__dirname, "..", "..", "chandump", name),
|
||||||
function (err) {
|
function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -127,7 +127,7 @@ Server.prototype.getSocketIP = function (socket) {
|
||||||
Server.prototype.isChannelLoaded = function (name) {
|
Server.prototype.isChannelLoaded = function (name) {
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
for (var i = 0; i < this.channels.length; i++) {
|
for (var i = 0; i < this.channels.length; i++) {
|
||||||
if (this.channels[i].canonical_name == name)
|
if (this.channels[i].uniqueName == name)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -150,6 +150,10 @@ Server.prototype.getChannel = function (name) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype.unloadChannel = function (chan) {
|
Server.prototype.unloadChannel = function (chan) {
|
||||||
|
if (chan.dead) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (chan.registered) {
|
if (chan.registered) {
|
||||||
chan.saveState();
|
chan.saveState();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,14 @@ function deletePlaylist(user, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.init = function (user) {
|
module.exports.init = function (user) {
|
||||||
console.log('Initializing playlists for ' + user.name);
|
if (user.userPlInited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var s = user.socket;
|
var s = user.socket;
|
||||||
var wrap = function (cb) {
|
var wrap = function (cb) {
|
||||||
return function (data) {
|
return function (data) {
|
||||||
if (!user.loggedIn || user.rank < 1) {
|
if (!user.loggedIn || user.global_rank < 1) {
|
||||||
s.emit("errorMsg", {
|
s.emit("errorMsg", {
|
||||||
msg: "You must be logged in to manage playlists"
|
msg: "You must be logged in to manage playlists"
|
||||||
});
|
});
|
||||||
|
@ -74,4 +77,5 @@ module.exports.init = function (user) {
|
||||||
s.on("listPlaylists", wrap(listPlaylists));
|
s.on("listPlaylists", wrap(listPlaylists));
|
||||||
s.on("clonePlaylist", wrap(clonePlaylist));
|
s.on("clonePlaylist", wrap(clonePlaylist));
|
||||||
s.on("deletePlaylist", wrap(deletePlaylist));
|
s.on("deletePlaylist", wrap(deletePlaylist));
|
||||||
|
user.userPlInited = true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,7 @@ var Logger = require("../logger");
|
||||||
var db = require("../database");
|
var db = require("../database");
|
||||||
var $util = require("../utilities");
|
var $util = require("../utilities");
|
||||||
var Config = require("../config");
|
var Config = require("../config");
|
||||||
|
var Server = require("../server");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a GET request for /account/edit
|
* Handles a GET request for /account/edit
|
||||||
|
@ -255,7 +256,19 @@ function handleNewChannel(req, res) {
|
||||||
Logger.eventlog.log("[channel] " + user.name + "@" +
|
Logger.eventlog.log("[channel] " + user.name + "@" +
|
||||||
webserver.ipForRequest(req) + " registered channel " +
|
webserver.ipForRequest(req) + " registered channel " +
|
||||||
name);
|
name);
|
||||||
|
var sv = Server.getServer();
|
||||||
|
if (sv.isChannelLoaded(name)) {
|
||||||
|
var chan = sv.getChannel(name);
|
||||||
|
chan.users.forEach(function (u) {
|
||||||
|
u.kick("Channel reloading");
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!chan.dead) {
|
||||||
|
chan.emit("empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.channels.listUserChannels(loginName, function (err2, channels) {
|
db.channels.listUserChannels(loginName, function (err2, channels) {
|
||||||
sendJade(res, "account-channels", {
|
sendJade(res, "account-channels", {
|
||||||
loggedIn: true,
|
loggedIn: true,
|
||||||
|
|
|
@ -388,6 +388,9 @@ Callbacks = {
|
||||||
/* REGION Rank Stuff */
|
/* REGION Rank Stuff */
|
||||||
|
|
||||||
rank: function(r) {
|
rank: function(r) {
|
||||||
|
if (r >= 1) {
|
||||||
|
socket.emit("listPlaylists");
|
||||||
|
}
|
||||||
if(r >= 255)
|
if(r >= 255)
|
||||||
SUPERADMIN = true;
|
SUPERADMIN = true;
|
||||||
CLIENT.rank = r;
|
CLIENT.rank = r;
|
||||||
|
@ -438,7 +441,6 @@ Callbacks = {
|
||||||
|
|
||||||
if (!CLIENT.guest) {
|
if (!CLIENT.guest) {
|
||||||
socket.emit("initUserPLCallbacks");
|
socket.emit("initUserPLCallbacks");
|
||||||
socket.emit("listPlaylists");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue