Skip to content

Commit da9e4b1

Browse files
ClobberXDSmallJoker
authored andcommittedJun 12, 2018
Add hasprivs chat command (#7336)
Require 'basic_privs' priv Only the online players are listed.
1 parent 142ce6a commit da9e4b1

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed
 

Diff for: ‎builtin/game/chatcommands.lua

+26-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end)
4141

4242
if core.settings:get_bool("profiler.load") then
4343
-- Run after register_chatcommand and its register_on_chat_message
44-
-- Before any chattcommands that should be profiled
44+
-- Before any chatcommands that should be profiled
4545
profiler.init_chatcommand()
4646
end
4747

@@ -103,6 +103,31 @@ core.register_chatcommand("privs", {
103103
end,
104104
})
105105

106+
core.register_chatcommand("hasprivs", {
107+
params = "<privilege>",
108+
description = "Return list of all online players with privilege.",
109+
privs = {basic_privs = true},
110+
func = function(caller, param)
111+
param = param:trim()
112+
if param == "" then
113+
return false, "Invalid parameters (see /help hasprivs)"
114+
end
115+
if not core.registered_privileges[param] then
116+
return false, "Unknown privilege!"
117+
end
118+
local privs = core.string_to_privs(param)
119+
local players_with_privs = {}
120+
for _, player in pairs(core.get_connected_players()) do
121+
local player_name = player:get_player_name()
122+
if core.check_player_privs(player_name, privs) then
123+
table.insert(players_with_privs, player_name)
124+
end
125+
end
126+
return true, "Players online with the \"" .. param .. "\" priv: " ..
127+
table.concat(players_with_privs, ", ")
128+
end
129+
})
130+
106131
local function handle_grant_command(caller, grantname, grantprivstr)
107132
local caller_privs = core.get_player_privs(caller)
108133
if not (caller_privs.privs or caller_privs.basic_privs) then

0 commit comments

Comments
 (0)