table.insert(players_with_priv, player_name)
end
end
- return true, S("Players online with the \"@1\" privilege: @2",
- param,
- table.concat(players_with_priv, ", "))
+ if #players_with_priv == 0 then
+ return true, S("No online player has the \"@1\" privilege.",
+ param)
+ else
+ return true, S("Players online with the \"@1\" privilege: @2",
+ param,
+ table.concat(players_with_priv, ", "))
+ end
end
})
if privs_unknown ~= "" then
return false, privs_unknown
end
+ core.set_player_privs(grantname, privs)
for priv, _ in pairs(grantprivs) do
-- call the on_grant callbacks
core.run_priv_callbacks(grantname, priv, caller, "grant")
end
- core.set_player_privs(grantname, privs)
core.log("action", caller..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
if grantname ~= caller then
core.chat_send_player(grantname,
end
local revokecount = 0
+
+ core.set_player_privs(revokename, privs)
for priv, _ in pairs(revokeprivs) do
-- call the on_revoke callbacks
core.run_priv_callbacks(revokename, priv, caller, "revoke")
revokecount = revokecount + 1
end
-
- core.set_player_privs(revokename, privs)
local new_privs = core.get_player_privs(revokename)
if revokecount == 0 then
-- pos may be a non-integer position
local function find_free_position_near(pos)
local tries = {
- {x=1, y=0, z=0},
- {x=-1, y=0, z=0},
- {x=0, y=0, z=1},
- {x=0, y=0, z=-1},
+ vector.new( 1, 0, 0),
+ vector.new(-1, 0, 0),
+ vector.new( 0, 0, 1),
+ vector.new( 0, 0, -1),
}
for _, d in ipairs(tries) do
local p = vector.add(pos, d)
-- Teleports player <name> to <p> if possible
local function teleport_to_pos(name, p)
- local lm = 31000
+ local lm = 31007 -- equals MAX_MAP_GENERATION_LIMIT in C++
if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm
or p.z < -lm or p.z > lm then
return false, S("Cannot teleport out of map bounds!")
description = S("List mods installed on the server"),
privs = {},
func = function(name, param)
- return true, table.concat(core.get_modnames(), ", ")
+ local mods = core.get_modnames()
+ if #mods == 0 then
+ return true, S("No mods installed.")
+ else
+ return true, table.concat(core.get_modnames(), ", ")
+ end
end,
})
end
local hour, minute = param:match("^(%d+):(%d+)$")
if not hour then
- local new_time = tonumber(param)
- if not new_time then
- return false, S("Invalid time.")
+ local new_time = tonumber(param) or -1
+ if new_time ~= new_time or new_time < 0 or new_time > 24000 then
+ return false, S("Invalid time (must be between 0 and 24000).")
end
- -- Backward compatibility.
- core.set_timeofday((new_time % 24000) / 24000)
+ core.set_timeofday(new_time / 24000)
core.log("action", name .. " sets time to " .. new_time)
return true, S("Time of day changed.")
end
end
})
+local function parse_shutdown_param(param)
+ local delay, reconnect, message
+ local one, two, three
+ one, two, three = param:match("^(%S+) +(%-r) +(.*)")
+ if one and two and three then
+ -- 3 arguments: delay, reconnect and message
+ return one, two, three
+ end
+ -- 2 arguments
+ one, two = param:match("^(%S+) +(.*)")
+ if one and two then
+ if tonumber(one) then
+ delay = one
+ if two == "-r" then
+ reconnect = two
+ else
+ message = two
+ end
+ elseif one == "-r" then
+ reconnect, message = one, two
+ end
+ return delay, reconnect, message
+ end
+ -- 1 argument
+ one = param:match("(.*)")
+ if tonumber(one) then
+ delay = one
+ elseif one == "-r" then
+ reconnect = one
+ else
+ message = one
+ end
+ return delay, reconnect, message
+end
+
core.register_chatcommand("shutdown", {
- params = S("[<delay_in_seconds> | -1] [reconnect] [<message>]"),
- description = S("Shutdown server (-1 cancels a delayed shutdown)"),
+ params = S("[<delay_in_seconds> | -1] [-r] [<message>]"),
+ description = S("Shutdown server (-1 cancels a delayed shutdown, -r allows players to reconnect)"),
privs = {server=true},
func = function(name, param)
- local delay, reconnect, message
- delay, param = param:match("^%s*(%S+)(.*)")
- if param then
- reconnect, param = param:match("^%s*(%S+)(.*)")
+ local delay, reconnect, message = parse_shutdown_param(param)
+ local bool_reconnect = reconnect == "-r"
+ if not message then
+ message = ""
end
- message = param and param:match("^%s*(.+)") or ""
delay = tonumber(delay) or 0
if delay == 0 then
core.log("action", name .. " shuts down server")
core.chat_send_all("*** "..S("Server shutting down (operator request)."))
end
- core.request_shutdown(message:trim(), core.is_yes(reconnect), delay)
+ core.request_shutdown(message:trim(), bool_reconnect, delay)
return true
end,
})