aboutsummaryrefslogtreecommitdiff
path: root/builtin/game/chatcommands.lua
diff options
context:
space:
mode:
authorAnand S <36130650+ClobberXD@users.noreply.github.com>2018-06-12 19:09:43 +0530
committerSmallJoker <SmallJoker@users.noreply.github.com>2018-06-12 15:39:43 +0200
commitda9e4b1f4a0ffd7ea0a2a04bbfb8068edcb73802 (patch)
treea6fdb882f574384997666482a2672e2b2a141136 /builtin/game/chatcommands.lua
parent142ce6a5d23f2aa35c887449ae7953df74502ca4 (diff)
downloadminetest-da9e4b1f4a0ffd7ea0a2a04bbfb8068edcb73802.tar.gz
minetest-da9e4b1f4a0ffd7ea0a2a04bbfb8068edcb73802.tar.bz2
minetest-da9e4b1f4a0ffd7ea0a2a04bbfb8068edcb73802.zip
Add hasprivs chat command (#7336)
Require 'basic_privs' priv Only the online players are listed.
Diffstat (limited to 'builtin/game/chatcommands.lua')
-rw-r--r--builtin/game/chatcommands.lua27
1 files changed, 26 insertions, 1 deletions
diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua
index 31ce4359f..a8aaba9c6 100644
--- a/builtin/game/chatcommands.lua
+++ b/builtin/game/chatcommands.lua
@@ -41,7 +41,7 @@ end)
if core.settings:get_bool("profiler.load") then
-- Run after register_chatcommand and its register_on_chat_message
- -- Before any chattcommands that should be profiled
+ -- Before any chatcommands that should be profiled
profiler.init_chatcommand()
end
@@ -103,6 +103,31 @@ core.register_chatcommand("privs", {
end,
})
+core.register_chatcommand("hasprivs", {
+ params = "<privilege>",
+ description = "Return list of all online players with privilege.",
+ privs = {basic_privs = true},
+ func = function(caller, param)
+ param = param:trim()
+ if param == "" then
+ return false, "Invalid parameters (see /help hasprivs)"
+ end
+ if not core.registered_privileges[param] then
+ return false, "Unknown privilege!"
+ end
+ local privs = core.string_to_privs(param)
+ local players_with_privs = {}
+ for _, player in pairs(core.get_connected_players()) do
+ local player_name = player:get_player_name()
+ if core.check_player_privs(player_name, privs) then
+ table.insert(players_with_privs, player_name)
+ end
+ end
+ return true, "Players online with the \"" .. param .. "\" priv: " ..
+ table.concat(players_with_privs, ", ")
+ end
+})
+
local function handle_grant_command(caller, grantname, grantprivstr)
local caller_privs = core.get_player_privs(caller)
if not (caller_privs.privs or caller_privs.basic_privs) then