forked from Mirrorlandia_minetest/minetest
Fix misleading /shutdown command syntax
This commit is contained in:
parent
5bf72468f3
commit
d7a4479eb3
@ -1053,24 +1053,58 @@ core.register_chatcommand("days", {
|
|||||||
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", {
|
core.register_chatcommand("shutdown", {
|
||||||
params = S("[<delay_in_seconds> | -1] [reconnect] [<message>]"),
|
params = S("[<delay_in_seconds> | -1] [-r] [<message>]"),
|
||||||
description = S("Shutdown server (-1 cancels a delayed shutdown)"),
|
description = S("Shutdown server (-1 cancels a delayed shutdown, -r allows players to reconnect)"),
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local delay, reconnect, message
|
local delay, reconnect, message = parse_shutdown_param(param)
|
||||||
delay, param = param:match("^%s*(%S+)(.*)")
|
local bool_reconnect = reconnect == "-r"
|
||||||
if param then
|
if not message then
|
||||||
reconnect, param = param:match("^%s*(%S+)(.*)")
|
message = ""
|
||||||
end
|
end
|
||||||
message = param and param:match("^%s*(.+)") or ""
|
|
||||||
delay = tonumber(delay) or 0
|
delay = tonumber(delay) or 0
|
||||||
|
|
||||||
if delay == 0 then
|
if delay == 0 then
|
||||||
core.log("action", name .. " shuts down server")
|
core.log("action", name .. " shuts down server")
|
||||||
core.chat_send_all("*** "..S("Server shutting down (operator request)."))
|
core.chat_send_all("*** "..S("Server shutting down (operator request)."))
|
||||||
end
|
end
|
||||||
core.request_shutdown(message:trim(), core.is_yes(reconnect), delay)
|
core.request_shutdown(message:trim(), bool_reconnect, delay)
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -143,8 +143,8 @@ Invalid hour (must be between 0 and 23 inclusive).=
|
|||||||
Invalid minute (must be between 0 and 59 inclusive).=
|
Invalid minute (must be between 0 and 59 inclusive).=
|
||||||
Show day count since world creation=
|
Show day count since world creation=
|
||||||
Current day is @1.=
|
Current day is @1.=
|
||||||
[<delay_in_seconds> | -1] [reconnect] [<message>]=
|
[<delay_in_seconds> | -1] [-r] [<message>]=
|
||||||
Shutdown server (-1 cancels a delayed shutdown)=
|
Shutdown server (-1 cancels a delayed shutdown, -r allows players to reconnect)=
|
||||||
Server shutting down (operator request).=
|
Server shutting down (operator request).=
|
||||||
Ban the IP of a player or show the ban list=
|
Ban the IP of a player or show the ban list=
|
||||||
The ban list is empty.=
|
The ban list is empty.=
|
||||||
|
Loading…
Reference in New Issue
Block a user