Add hasprivs chat command (#7336)
Require 'basic_privs' priv Only the online players are listed.master
parent
142ce6a5d2
commit
da9e4b1f4a
|
@ -41,7 +41,7 @@ end)
|
||||||
|
|
||||||
if core.settings:get_bool("profiler.load") then
|
if core.settings:get_bool("profiler.load") then
|
||||||
-- Run after register_chatcommand and its register_on_chat_message
|
-- 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()
|
profiler.init_chatcommand()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -103,6 +103,31 @@ core.register_chatcommand("privs", {
|
||||||
end,
|
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 function handle_grant_command(caller, grantname, grantprivstr)
|
||||||
local caller_privs = core.get_player_privs(caller)
|
local caller_privs = core.get_player_privs(caller)
|
||||||
if not (caller_privs.privs or caller_privs.basic_privs) then
|
if not (caller_privs.privs or caller_privs.basic_privs) then
|
||||||
|
|
Loading…
Reference in New Issue