aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2022-03-15 06:51:53 +0300
committerRblSb <msrblsb@gmail.com>2022-03-15 06:51:53 +0300
commit79f3c34d24d6ae6aba17dd643726e20754140d80 (patch)
treed6b1d23bcfbdc023fc757f25b1b3fa085fd5e790
parent692e4690abc2083d151c011a2df2976ecf6886cc (diff)
Update locked playlist restrictions
And add "toggleItemType" permission. Closes #36
-rw-r--r--build/server.js72
-rw-r--r--default-config.json2
-rw-r--r--res/client.js59
-rw-r--r--res/langs/en.json1
-rw-r--r--res/langs/ru.json1
-rw-r--r--src/Client.hx13
-rw-r--r--src/ClientTools.hx9
-rw-r--r--src/Types.hx1
-rw-r--r--src/client/Buttons.hx8
-rw-r--r--src/client/Main.hx13
-rw-r--r--src/client/Player.hx5
-rw-r--r--src/server/Main.hx17
12 files changed, 126 insertions, 75 deletions
diff --git a/build/server.js b/build/server.js
index f1da10d..955c5cb 100644
--- a/build/server.js
+++ b/build/server.js
@@ -27,7 +27,22 @@ var Client = function(ws,req,id,name,group) {
};
Client.__name__ = true;
Client.prototype = {
- setGroupFlag: function(type,flag) {
+ hasPermission: function(permission,permissions) {
+ if((this.group & 1) != 0) {
+ return permissions.banned.indexOf(permission) != -1;
+ }
+ if((this.group & 8) != 0) {
+ return permissions.admin.indexOf(permission) != -1;
+ }
+ if((this.group & 4) != 0) {
+ return permissions.leader.indexOf(permission) != -1;
+ }
+ if((this.group & 2) != 0) {
+ return permissions.user.indexOf(permission) != -1;
+ }
+ return permissions.guest.indexOf(permission) != -1;
+ }
+ ,setGroupFlag: function(type,flag) {
if(flag) {
this.group |= 1 << type._hx_index;
} else {
@@ -72,21 +87,6 @@ ClientTools.getByName = function(clients,name,def) {
}
return def;
};
-ClientTools.hasPermission = function(client,permission,permissions) {
- if((client.group & 1) != 0) {
- return permissions.banned.indexOf(permission) != -1;
- }
- if((client.group & 8) != 0) {
- return permissions.admin.indexOf(permission) != -1;
- }
- if((client.group & 4) != 0) {
- return permissions.leader.indexOf(permission) != -1;
- }
- if((client.group & 2) != 0) {
- return permissions.user.indexOf(permission) != -1;
- }
- return permissions.guest.indexOf(permission) != -1;
-};
var DateTools = function() { };
DateTools.__name__ = true;
DateTools.__format_get = function(d,e) {
@@ -1857,7 +1857,7 @@ JsonParser_$67.prototype = $extend(json2object_reader_BaseParser.prototype,{
this.value = null;
}
,loadJsonString: function(s,pos,variable) {
- this.value = this.loadString(s,pos,variable,["guest","user","leader","admin","writeChat","addVideo","removeVideo","requestLeader","rewind","clearChat","setLeader","changeOrder","lockPlaylist","banClient"],"guest");
+ this.value = this.loadString(s,pos,variable,["guest","user","leader","admin","writeChat","addVideo","removeVideo","requestLeader","rewind","clearChat","setLeader","changeOrder","toggleItemType","lockPlaylist","banClient"],"guest");
}
,__class__: JsonParser_$67
});
@@ -4338,13 +4338,11 @@ server_Main.prototype = {
this.logger.log({ clientName : client.name, clientGroup : client.group, event : data, time : HxOverrides.dateStr(new Date())});
switch(data.type) {
case "AddVideo":
- if(!this.checkPermission(client,"addVideo")) {
+ if(this.isPlaylistLockedFor(client)) {
return;
}
- if(!this.videoList.isOpen) {
- if(!this.checkPermission(client,"lockPlaylist")) {
- return;
- }
+ if(!this.checkPermission(client,"addVideo")) {
+ return;
}
if(this.config.totalVideoLimit != 0 && this.videoList.items.length >= this.config.totalVideoLimit) {
this.serverMessage(client,"totalVideoLimitError");
@@ -4415,6 +4413,9 @@ server_Main.prototype = {
this.broadcast(data);
break;
case "ClearPlaylist":
+ if(this.isPlaylistLockedFor(client)) {
+ return;
+ }
if(!this.checkPermission(client,"removeVideo")) {
return;
}
@@ -4642,6 +4643,9 @@ server_Main.prototype = {
this.broadcast(data);
break;
case "RemoveVideo":
+ if(this.isPlaylistLockedFor(client)) {
+ return;
+ }
if(!this.checkPermission(client,"removeVideo")) {
return;
}
@@ -4707,6 +4711,9 @@ server_Main.prototype = {
}
break;
case "SetNextItem":
+ if(this.isPlaylistLockedFor(client)) {
+ return;
+ }
if(!this.checkPermission(client,"changeOrder")) {
return;
}
@@ -4741,6 +4748,9 @@ server_Main.prototype = {
this.broadcastExcept(client,{ type : data.type, setTime : data.setTime});
break;
case "ShufflePlaylist":
+ if(this.isPlaylistLockedFor(client)) {
+ return;
+ }
if(!this.checkPermission(client,"changeOrder")) {
return;
}
@@ -4757,6 +4767,12 @@ server_Main.prototype = {
this.skipVideo(data);
break;
case "ToggleItemType":
+ if(this.isPlaylistLockedFor(client)) {
+ return;
+ }
+ if(!this.checkPermission(client,"toggleItemType")) {
+ return;
+ }
this.videoList.toggleItemType(data.toggleItemType.pos);
this.broadcast(data);
break;
@@ -4834,7 +4850,7 @@ server_Main.prototype = {
if((client.group & 1) != 0) {
this.checkBan(client);
}
- var state = ClientTools.hasPermission(client,perm,this.config.permissions);
+ var state = client.hasPermission(perm,this.config.permissions);
if(!state) {
this.send(client,{ type : "ServerMessage", serverMessage : { textId : "accessError"}});
}
@@ -4859,7 +4875,7 @@ server_Main.prototype = {
client.setGroupFlag(ClientGroup.Banned,!isOutdated);
if(isOutdated) {
HxOverrides.remove(this.userList.bans,ban);
- haxe_Log.trace("" + client.name + " ban removed",{ fileName : "src/server/Main.hx", lineNumber : 923, className : "server.Main", methodName : "checkBan"});
+ haxe_Log.trace("" + client.name + " ban removed",{ fileName : "src/server/Main.hx", lineNumber : 927, className : "server.Main", methodName : "checkBan"});
this.sendClientList();
}
break;
@@ -4927,6 +4943,14 @@ server_Main.prototype = {
this.videoTimer.setTime(this.flashbackTime);
this.flashbackTime = time;
}
+ ,isPlaylistLockedFor: function(client) {
+ if(!this.videoList.isOpen) {
+ if(!this.checkPermission(client,"lockPlaylist")) {
+ return true;
+ }
+ }
+ return false;
+ }
,__class__: server_Main
};
var server_Utils = function() { };
diff --git a/default-config.json b/default-config.json
index c6e9083..36f4fee 100644
--- a/default-config.json
+++ b/default-config.json
@@ -14,7 +14,7 @@
"youtubePlaylistLimit": 50,
"permissions": {
"banned": [],
- "guest": ["writeChat", "addVideo", "removeVideo", "changeOrder", "requestLeader", "rewind"],
+ "guest": ["writeChat", "addVideo", "removeVideo", "changeOrder", "toggleItemType", "requestLeader", "rewind"],
"user": ["guest"],
"leader": ["user"],
"admin": ["user", "clearChat", "setLeader", "lockPlaylist", "banClient"]
diff --git a/res/client.js b/res/client.js
index 2f73059..d15aea4 100644
--- a/res/client.js
+++ b/res/client.js
@@ -1,4 +1,3 @@
-// Generated by Haxe 4.2.2
(function ($hx_exports, $global) { "use strict";
$hx_exports["client"] = $hx_exports["client"] || {};
$hx_exports["client"]["JsApi"] = $hx_exports["client"]["JsApi"] || {};
@@ -29,7 +28,22 @@ Client.fromData = function(data) {
return new Client(data.name,data.group);
};
Client.prototype = {
- setGroupFlag: function(type,flag) {
+ hasPermission: function(permission,permissions) {
+ if((this.group & 1) != 0) {
+ return permissions.banned.indexOf(permission) != -1;
+ }
+ if((this.group & 8) != 0) {
+ return permissions.admin.indexOf(permission) != -1;
+ }
+ if((this.group & 4) != 0) {
+ return permissions.leader.indexOf(permission) != -1;
+ }
+ if((this.group & 2) != 0) {
+ return permissions.user.indexOf(permission) != -1;
+ }
+ return permissions.guest.indexOf(permission) != -1;
+ }
+ ,setGroupFlag: function(type,flag) {
if(flag) {
this.group |= 1 << type._hx_index;
} else {
@@ -70,21 +84,6 @@ ClientTools.getByName = function(clients,name,def) {
}
return def;
};
-ClientTools.hasPermission = function(client,permission,permissions) {
- if((client.group & 1) != 0) {
- return permissions.banned.indexOf(permission) != -1;
- }
- if((client.group & 8) != 0) {
- return permissions.admin.indexOf(permission) != -1;
- }
- if((client.group & 4) != 0) {
- return permissions.leader.indexOf(permission) != -1;
- }
- if((client.group & 2) != 0) {
- return permissions.user.indexOf(permission) != -1;
- }
- return permissions.guest.indexOf(permission) != -1;
-};
var EReg = function(r,opt) {
this.r = new RegExp(r,opt.split("u").join(""));
};
@@ -639,9 +638,15 @@ client_Buttons.init = function(main) {
main.send({ type : "ShufflePlaylist"});
};
window.document.querySelector("#lockplaylist").onclick = function(e) {
- if((main.personal.group & 8) != 0) {
- main.send({ type : "TogglePlaylistLock"});
+ if(!main.hasPermission("lockPlaylist")) {
+ return;
+ }
+ if(main.isPlaylistOpen) {
+ if(!window.confirm(Lang.get("lockPlaylistConfirm"))) {
+ return;
+ }
}
+ main.send({ type : "TogglePlaylistLock"});
};
var showMediaUrl = window.document.querySelector("#showmediaurl");
showMediaUrl.onclick = function(e) {
@@ -1127,6 +1132,7 @@ var client_Main = function() {
this.filters = [];
this.pageTitle = window.document.title;
this.clients = [];
+ this.isPlaylistOpen = true;
this.globalIp = "";
this.forceSyncNextTick = false;
this.isSyncActive = true;
@@ -1294,6 +1300,9 @@ client_Main.prototype = {
};
window.document.querySelector("#customembed-content").onkeydown = window.document.querySelector("#customembed-title").onkeydown;
}
+ ,hasPermission: function(permission) {
+ return this.personal.hasPermission(permission,this.config.permissions);
+ }
,handleUrlMasks: function(links) {
var _g = 0;
while(_g < links.length) {
@@ -1463,7 +1472,7 @@ client_Main.prototype = {
var data = JSON.parse(e.data);
if(this.config != null && this.config.isVerbose) {
var t = data.type;
- haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 380, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]});
+ haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 384, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]});
}
client_JsApi.fireOnceEvent(data);
switch(data.type) {
@@ -1697,7 +1706,7 @@ client_Main.prototype = {
}
,onUserGroupChanged: function() {
var button = window.document.querySelector("#queue_next");
- if(ClientTools.hasPermission(this.personal,"changeOrder",this.config.permissions)) {
+ if(this.personal.hasPermission("changeOrder",this.config.permissions)) {
button.disabled = false;
} else {
button.disabled = true;
@@ -2036,6 +2045,7 @@ client_Main.prototype = {
}
}
,setPlaylistLock: function(isOpen) {
+ this.isPlaylistOpen = isOpen;
var lockPlaylist = window.document.querySelector("#lockplaylist");
var icon = lockPlaylist.firstElementChild;
if(isOpen) {
@@ -2059,9 +2069,6 @@ client_Main.prototype = {
this.settings.synchThreshold = s;
client_Settings.write(this.settings);
}
- ,hasPermission: function(group,permission) {
- return Reflect.field(this.config.permissions,$hxEnums[group.__enum__].__constructs__[group._hx_index]._hx_name.toLowerCase()).indexOf(permission) != -1;
- }
,toggleLeader: function() {
this.setLeaderButton((this.personal.group & 4) == 0);
this.send({ type : "SetLeader", setLeader : { clientName : (this.personal.group & 4) != 0 ? "" : this.personal.name}});
@@ -2132,7 +2139,7 @@ client_Player.prototype = {
}
,toggleItemType: function(pos) {
this.videoList.toggleItemType(pos);
- this.setItemElementType(this.videoItemsEl.children[pos],this.videoList.items[this.videoList.pos].isTemp);
+ this.setItemElementType(this.videoItemsEl.children[pos],this.videoList.items[pos].isTemp);
}
,setPlayer: function(newPlayer) {
if(this.player != newPlayer) {
@@ -2226,7 +2233,7 @@ client_Player.prototype = {
}
this.main.send({ type : "Play", play : { time : this.getTime()}});
if(this.main.hasLeaderOnPauseRequest() && this.videoList.items.length > 0) {
- if(this.main.hasPermission((this.main.personal.group & 8) != 0 ? ClientGroup.Admin : ClientGroup.User,"requestLeader")) {
+ if(this.main.hasPermission("requestLeader")) {
this.main.toggleLeader();
}
}
diff --git a/res/langs/en.json b/res/langs/en.json
index 692f816..e7ea8f4 100644
--- a/res/langs/en.json
+++ b/res/langs/en.json
@@ -81,6 +81,7 @@
"skipItemConfirm": "Are you sure you want to skip current video?",
"clearPlaylistConfirm": "Are you sure you want to clear the playlist?",
"shufflePlaylistConfirm": "Are you sure you want to shuffle the playlist?",
+ "lockPlaylistConfirm": "Are you sure you want to lock the playlist?",
"yes": "Yes",
"no": "No",
diff --git a/res/langs/ru.json b/res/langs/ru.json
index 77b1cb1..637e883 100644
--- a/res/langs/ru.json
+++ b/res/langs/ru.json
@@ -81,6 +81,7 @@
"skipItemConfirm": "Вы уверены что хотите пропустить текущее видео?",
"clearPlaylistConfirm": "Вы уверены что хотите очистить плейлист?",
"shufflePlaylistConfirm": "Вы уверены что хотите перемешать плейлист?",
+ "lockPlaylistConfirm": "Вы уверены что хотите заблокировать плейлист?",
"yes": "Да",
"no": "Нет",
diff --git a/src/Client.hx b/src/Client.hx
index ae35ef4..64d7e54 100644
--- a/src/Client.hx
+++ b/src/Client.hx
@@ -1,10 +1,12 @@
package;
+import Types.Permission;
+import Types.Permissions;
+import haxe.EnumFlags;
#if nodejs
import js.node.http.IncomingMessage;
import js.npm.ws.WebSocket;
#end
-import haxe.EnumFlags;
enum ClientGroup {
Banned;
@@ -47,6 +49,15 @@ class Client {
}
#end
+ public function hasPermission(permission:Permission, permissions:Permissions):Bool {
+ final p = permissions;
+ if (isBanned) return p.banned.contains(permission);
+ if (isAdmin) return p.admin.contains(permission);
+ if (isLeader) return p.leader.contains(permission);
+ if (isUser) return p.user.contains(permission);
+ return p.guest.contains(permission);
+ }
+
inline function get_isBanned():Bool {
return group.has(Banned);
}
diff --git a/src/ClientTools.hx b/src/ClientTools.hx
index c5053f1..46400f7 100644
--- a/src/ClientTools.hx
+++ b/src/ClientTools.hx
@@ -26,13 +26,4 @@ class ClientTools {
}
return def;
}
-
- public static function hasPermission(client:Client, permission:Permission, permissions:Permissions):Bool {
- final p = permissions;
- if (client.isBanned) return p.banned.contains(permission);
- if (client.isAdmin) return p.admin.contains(permission);
- if (client.isLeader) return p.leader.contains(permission);
- if (client.isUser) return p.user.contains(permission);
- return p.guest.contains(permission);
- }
}
diff --git a/src/Types.hx b/src/Types.hx
index d31196d..61a1ab1 100644
--- a/src/Types.hx
+++ b/src/Types.hx
@@ -57,6 +57,7 @@ enum abstract Permission(String) {
var ClearChatPerm = "clearChat";
var SetLeaderPerm = "setLeader";
var ChangeOrderPerm = "changeOrder";
+ var ToggleItemTypePerm = "toggleItemType";
var LockPlaylistPerm = "lockPlaylist";
var BanClientPerm = "banClient";
}
diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx
index 902da1b..aa7e1cc 100644
--- a/src/client/Buttons.hx
+++ b/src/client/Buttons.hx
@@ -144,7 +144,13 @@ class Buttons {
final lockPlaylist = ge("#lockplaylist");
lockPlaylist.onclick = e -> {
- if (main.isAdmin()) main.send({type: TogglePlaylistLock});
+ if (!main.hasPermission(LockPlaylistPerm)) return;
+ if (main.isPlaylistOpen) {
+ if (!window.confirm(Lang.get("lockPlaylistConfirm"))) return;
+ }
+ main.send({
+ type: TogglePlaylistLock
+ });
}
final showMediaUrl = ge("#showmediaurl");
diff --git a/src/client/Main.hx b/src/client/Main.hx
index b3eaea9..fad4e4f 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -1,7 +1,6 @@
package client;
import Client.ClientData;
-import Client.ClientGroup;
import Types.Config;
import Types.Permission;
import Types.VideoData;
@@ -33,6 +32,7 @@ class Main {
public var forceSyncNextTick = false;
public final host:String;
public var globalIp(default, null) = "";
+ public var isPlaylistOpen = true;
final clients:Array<Client> = [];
var pageTitle = document.title;
@@ -192,6 +192,10 @@ class Main {
return personal.name;
}
+ public function hasPermission(permission:Permission):Bool {
+ return personal.hasPermission(permission, config.permissions);
+ }
+
final mask = ~/\${([0-9]+)-([0-9]+)}/g;
function handleUrlMasks(links:Array<String>):Void {
@@ -959,6 +963,7 @@ class Main {
}
function setPlaylistLock(isOpen:Bool):Void {
+ isPlaylistOpen = isOpen;
final lockPlaylist = ge("#lockplaylist");
final icon = lockPlaylist.firstElementChild;
if (isOpen) {
@@ -984,12 +989,6 @@ class Main {
Settings.write(settings);
}
- public function hasPermission(group:ClientGroup, permission:Permission):Bool {
- final id = group.getName().toLowerCase();
- final arr:Array<Permission> = Reflect.field(config.permissions, id);
- return arr.contains(permission);
- }
-
public function toggleLeader():Void {
// change button style before answer
setLeaderButton(!personal.isLeader);
diff --git a/src/client/Player.hx b/src/client/Player.hx
index a147e6a..1979091 100644
--- a/src/client/Player.hx
+++ b/src/client/Player.hx
@@ -82,7 +82,7 @@ class Player {
public function toggleItemType(pos:Int):Void {
videoList.toggleItemType(pos);
final el = videoItemsEl.children[pos];
- setItemElementType(el, videoList.getItem(videoList.pos).isTemp);
+ setItemElementType(el, videoList.getItem(pos).isTemp);
}
function setPlayer(newPlayer:IPlayer):Void {
@@ -174,8 +174,7 @@ class Player {
final hasAutoPause = main.hasLeaderOnPauseRequest() && videoList.length > 0;
if (hasAutoPause) {
// do not remove leader if user cannot request it back
- final group:Client.ClientGroup = main.isAdmin() ? Admin : User;
- if (main.hasPermission(group, RequestLeaderPerm)) main.toggleLeader();
+ if (main.hasPermission(RequestLeaderPerm)) main.toggleLeader();
}
}
diff --git a/src/server/Main.hx b/src/server/Main.hx
index bef889a..e9f6e21 100644
--- a/src/server/Main.hx
+++ b/src/server/Main.hx
@@ -568,10 +568,8 @@ class Main {
case ServerMessage:
case AddVideo:
+ if (isPlaylistLockedFor(client)) return;
if (!checkPermission(client, AddVideoPerm)) return;
- if (!videoList.isOpen) {
- if (!checkPermission(client, LockPlaylistPerm)) return;
- }
if (config.totalVideoLimit != 0 && videoList.length >= config.totalVideoLimit) {
serverMessage(client, "totalVideoLimitError");
return;
@@ -604,6 +602,7 @@ class Main {
prepareVideoPlayback();
case RemoveVideo:
+ if (isPlaylistLockedFor(client)) return;
if (!checkPermission(client, RemoveVideoPerm)) return;
if (videoList.length == 0) return;
final url = data.removeVideo.url;
@@ -757,6 +756,7 @@ class Main {
broadcast(data);
case SetNextItem:
+ if (isPlaylistLockedFor(client)) return;
if (!checkPermission(client, ChangeOrderPerm)) return;
final pos = data.setNextItem.pos;
if (pos == videoList.pos || pos == videoList.pos + 1) return;
@@ -764,6 +764,8 @@ class Main {
broadcast(data);
case ToggleItemType:
+ if (isPlaylistLockedFor(client)) return;
+ if (!checkPermission(client, ToggleItemTypePerm)) return;
final pos = data.toggleItemType.pos;
videoList.toggleItemType(pos);
broadcast(data);
@@ -774,12 +776,14 @@ class Main {
broadcast(data);
case ClearPlaylist:
+ if (isPlaylistLockedFor(client)) return;
if (!checkPermission(client, RemoveVideoPerm)) return;
videoTimer.stop();
videoList.clear();
broadcast(data);
case ShufflePlaylist:
+ if (isPlaylistLockedFor(client)) return;
if (!checkPermission(client, ChangeOrderPerm)) return;
if (videoList.length == 0) return;
videoList.shuffle();
@@ -976,4 +980,11 @@ class Main {
videoTimer.setTime(flashbackTime);
flashbackTime = time;
}
+
+ function isPlaylistLockedFor(client:Client):Bool {
+ if (!videoList.isOpen) {
+ if (!checkPermission(client, LockPlaylistPerm)) return true;
+ }
+ return false;
+ }
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage