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=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BA=D0=B0=D0=BD=D0=B0=D0=BB=20=D0=BD=D0=B5=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B3=D1=83=D1=82.=20=D0=9F=D0=BB=D0=B0=D0=B3=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F/=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20minetest.conf?= =?UTF-8?q?=20eerchat.enable=5Fpriv=5Fcc=20=3D=20true/false=20=D0=98=D0=BC?= =?UTF-8?q?=D1=8F=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B8=D0=BB=D0=B5=D0=B3=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=B2=20minetest.conf=20(=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=83=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D1=81=20?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D0=BD=D0=B5=D0=BC=20chat=5Fcreator=20=D0=B1?= =?UTF-8?q?=D0=B5=D0=B7=20=D1=83=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=B5)=20beerc?= =?UTF-8?q?hat.name=5Fpriv=5Fcc=20=3D=20chat=5Fcreator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added priv_cc plugin The plugin creates a new privilege that allows players to create a new channel (cc/create_channel) Users without this privilege cannot create a channel. The plugin is enabled/disabled via minetest.conf eerchat.enable_priv_cc = true/false The privilege name can be set in minetest.conf (by default it is created with the name chart_creator without specifying it in the config) beer chat.name_priv_cc = chat_creator --- chatcommands.lua | 8 ++++++++ plugin/init.lua | 3 +++ plugin/priv_cc.lua | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 plugin/priv_cc.lua diff --git a/chatcommands.lua b/chatcommands.lua index 2731338..3e45bb6 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -21,6 +21,14 @@ local create_channel = { func = function(lname, param) local lowner = lname + --check player privileges if plugin priv_cc is enabled + local name_priv2cc = minetest.settings:get("beerchat.name_priv_cc") + if minetest.settings:get_bool("beerchat.enable_priv_cc") then + if not (minetest.check_player_privs(lowner, name_priv2cc) or minetest.check_player_privs(lowner, beerchat.admin_priv)) then + return false, "You don't have that privilege." + end + end --end check priv_cc + if not param or param == "" then return false, "ERROR: Invalid number of arguments. Please supply the channel name as a minimum." end diff --git a/plugin/init.lua b/plugin/init.lua index d25a401..720c9a9 100644 --- a/plugin/init.lua +++ b/plugin/init.lua @@ -58,3 +58,6 @@ load_plugin("event-logging", true) -- Allows linking channels through channel aliases load_plugin("alias", false) + +-- Add special priv to use create_channel command +load_plugin("priv_cc", false) diff --git a/plugin/priv_cc.lua b/plugin/priv_cc.lua new file mode 100644 index 0000000..5a0e8d1 --- /dev/null +++ b/plugin/priv_cc.lua @@ -0,0 +1,9 @@ +-- if you need to set a special name for privilege, use "beerchat.name_priv_cc = spec_name" in minetest.conf +local name_priv2cc = minetest.settings:get("beerchat.name_priv_cc") +if name_priv2cc == '' then name_priv2cc = chat_creator end +minetest.log("info", "to create channel add new priv: " .. name_priv2cc) +local S = minetest.get_translator("name_priv2cc") + minetest.register_privilege(name_priv2cc, { + description = S("Allows you to create a channel"), + give_to_singleplayer = false + }) From a1945417c76945dd95ebab091e663fbc2fbefc56 Mon Sep 17 00:00:00 2001 From: lord-papirus Date: Sat, 7 Dec 2024 01:30:54 +0300 Subject: [PATCH 2/5] fixed luacheck's remarks --- chatcommands.lua | 10 ++++++---- plugin/priv_cc.lua | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 3e45bb6..d075471 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -24,10 +24,12 @@ local create_channel = { --check player privileges if plugin priv_cc is enabled local name_priv2cc = minetest.settings:get("beerchat.name_priv_cc") if minetest.settings:get_bool("beerchat.enable_priv_cc") then - if not (minetest.check_player_privs(lowner, name_priv2cc) or minetest.check_player_privs(lowner, beerchat.admin_priv)) then - return false, "You don't have that privilege." - end - end --end check priv_cc + if not (minetest.check_player_privs(lowner, name_priv2cc) or + minetest.check_player_privs(lowner, beerchat.admin_priv)) then + return false, "You don't have that privilege." + end + end + --end check priv_cc if not param or param == "" then return false, "ERROR: Invalid number of arguments. Please supply the channel name as a minimum." diff --git a/plugin/priv_cc.lua b/plugin/priv_cc.lua index 5a0e8d1..80347a8 100644 --- a/plugin/priv_cc.lua +++ b/plugin/priv_cc.lua @@ -1,6 +1,6 @@ --- if you need to set a special name for privilege, use "beerchat.name_priv_cc = spec_name" in minetest.conf +-- if you need to set a special name for privilege, use "beerchat.name_priv_cc = spec_name" in minetest.conf local name_priv2cc = minetest.settings:get("beerchat.name_priv_cc") -if name_priv2cc == '' then name_priv2cc = chat_creator end +if name_priv2cc == '' then name_priv2cc = 'chat_creator' end minetest.log("info", "to create channel add new priv: " .. name_priv2cc) local S = minetest.get_translator("name_priv2cc") minetest.register_privilege(name_priv2cc, { From b6d4fb0976e786347f89a4f065d98a0bf745ea75 Mon Sep 17 00:00:00 2001 From: lord-papirus Date: Sat, 7 Dec 2024 23:15:23 +0300 Subject: [PATCH 3/5] Update chatcommands.lua Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> --- chatcommands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatcommands.lua b/chatcommands.lua index d075471..2bc52d9 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -22,8 +22,8 @@ local create_channel = { local lowner = lname --check player privileges if plugin priv_cc is enabled - local name_priv2cc = minetest.settings:get("beerchat.name_priv_cc") if minetest.settings:get_bool("beerchat.enable_priv_cc") then + local name_priv2cc = minetest.settings:get("beerchat.priv_cc.name") if not (minetest.check_player_privs(lowner, name_priv2cc) or minetest.check_player_privs(lowner, beerchat.admin_priv)) then return false, "You don't have that privilege." From dfc0e245e60b0cd51af10d63e14d1e988b81db28 Mon Sep 17 00:00:00 2001 From: lord-papirus Date: Sat, 7 Dec 2024 23:16:20 +0300 Subject: [PATCH 4/5] Update plugin/priv_cc.lua Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com> --- plugin/priv_cc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/priv_cc.lua b/plugin/priv_cc.lua index 80347a8..f296fb3 100644 --- a/plugin/priv_cc.lua +++ b/plugin/priv_cc.lua @@ -1,5 +1,5 @@ -- if you need to set a special name for privilege, use "beerchat.name_priv_cc = spec_name" in minetest.conf -local name_priv2cc = minetest.settings:get("beerchat.name_priv_cc") +local name_priv2cc = minetest.settings:get("beerchat.priv_cc.name") if name_priv2cc == '' then name_priv2cc = 'chat_creator' end minetest.log("info", "to create channel add new priv: " .. name_priv2cc) local S = minetest.get_translator("name_priv2cc") From e54bd547c7f8c53dfe6ed48382f6bbd9bc8d1591 Mon Sep 17 00:00:00 2001 From: lord-papirus Date: Sun, 8 Dec 2024 00:42:38 +0300 Subject: [PATCH 5/5] Update priv_cc.lua Remove get.translator. Add info about mod beerchat to the description. --- plugin/priv_cc.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin/priv_cc.lua b/plugin/priv_cc.lua index f296fb3..2ea04ed 100644 --- a/plugin/priv_cc.lua +++ b/plugin/priv_cc.lua @@ -2,8 +2,7 @@ local name_priv2cc = minetest.settings:get("beerchat.priv_cc.name") if name_priv2cc == '' then name_priv2cc = 'chat_creator' end minetest.log("info", "to create channel add new priv: " .. name_priv2cc) -local S = minetest.get_translator("name_priv2cc") - minetest.register_privilege(name_priv2cc, { - description = S("Allows you to create a channel"), - give_to_singleplayer = false - }) +minetest.register_privilege(name_priv2cc, { + description = "Allows you to create a channel (mod beerchat)", + give_to_singleplayer = false +})