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
func = function(name)
local admin = core.settings:get("name")
if admin then
- return true, "The administrator of this server is "..admin.."."
+ return true, "The administrator of this server is " .. admin .. "."
else
return false, "There's no administrator named in the config file."
end
func = function(caller, param)
param = param:trim()
local name = (param ~= "" and param or caller)
+ if not core.player_exists(name) then
+ return false, "Player " .. name .. " does not exist."
+ end
return true, "Privileges of " .. name .. ": "
.. core.privs_to_string(
core.get_player_privs(name), ' ')
end,
})
+core.register_chatcommand("haspriv", {
+ 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 haspriv)"
+ end
+ if not core.registered_privileges[param] then
+ return false, "Unknown privilege!"
+ end
+ local privs = core.string_to_privs(param)
+ local players_with_priv = {}
+ 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_priv, player_name)
+ end
+ end
+ return true, "Players online with the \"" .. param .. "\" privilege: " ..
+ table.concat(players_with_priv, ", ")
+ 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
end
teleportee = core.get_player_by_name(name)
if teleportee then
- teleportee:setpos(p)
+ teleportee:set_pos(p)
return true, "Teleporting to "..core.pos_to_string(p)
end
end
if target_name then
local target = core.get_player_by_name(target_name)
if target then
- p = target:getpos()
+ p = target:get_pos()
end
end
if teleportee and p then
p = find_free_position_near(p)
- teleportee:setpos(p)
+ teleportee:set_pos(p)
return true, "Teleporting to " .. target_name
.. " at "..core.pos_to_string(p)
end
teleportee = core.get_player_by_name(teleportee_name)
end
if teleportee and p.x and p.y and p.z then
- teleportee:setpos(p)
+ teleportee:set_pos(p)
return true, "Teleporting " .. teleportee_name
.. " to " .. core.pos_to_string(p)
end
if target_name then
local target = core.get_player_by_name(target_name)
if target then
- p = target:getpos()
+ p = target:get_pos()
end
end
if teleportee and p then
p = find_free_position_near(p)
- teleportee:setpos(p)
+ teleportee:set_pos(p)
return true, "Teleporting " .. teleportee_name
.. " to " .. target_name
.. " at " .. core.pos_to_string(p)
return false, "Cannot spawn an unknown entity"
end
if p == "" then
- p = player:getpos()
+ p = player:get_pos()
else
p = core.string_to_pos(p)
if p == nil then
core.log("error", "Unable to pulverize, no player.")
return false, "Unable to pulverize, no player."
end
- if player:get_wielded_item():is_empty() then
+ local wielded_item = player:get_wielded_item()
+ if wielded_item:is_empty() then
return false, "Unable to pulverize, no item in hand."
end
- player:set_wielded_item(nil)
+ core.log("action", name .. " pulverized \"" ..
+ wielded_item:get_name() .. " " .. wielded_item:get_count() .. "\"")
+ player:set_wielded_item(nil)
return true, "An item was pulverized."
end,
})
core.register_chatcommand("status", {
description = "Show server status",
func = function(name, param)
- return true, core.get_server_status()
+ local status = core.get_server_status(name, false)
+ if status and status ~= "" then
+ return true, status
+ end
+ return false, "This command was disabled by a mod or game"
end,
})
description = "Shutdown server (-1 cancels a delayed shutdown)",
privs = {server=true},
func = function(name, param)
- local delay, reconnect, message = param:match("([^ ][-]?[0-9]+)([^ ]+)(.*)")
- message = message or ""
+ local delay, reconnect, message
+ delay, param = param:match("^%s*(%S+)(.*)")
+ if param then
+ reconnect, param = param:match("^%s*(%S+)(.*)")
+ end
+ message = param and param:match("^%s*(.+)") or ""
+ delay = tonumber(delay) or 0
- if delay ~= "" then
- delay = tonumber(delay) or 0
- else
- delay = 0
+ if delay == 0 then
core.log("action", name .. " shuts down server")
core.chat_send_all("*** Server shutting down (operator request).")
end