diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-04-15 23:19:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-15 23:19:18 +0200 |
commit | 34d32ce55ae4f3f29d7b645075dc8efacb2c96d2 (patch) | |
tree | 6e21a37780352412b853fd242b6177eff2afd0fd /builtin/game | |
parent | 0f955bf7fa7a1376acdbc06a617c0f15f9fad467 (diff) | |
download | minetest-34d32ce55ae4f3f29d7b645075dc8efacb2c96d2.tar.gz minetest-34d32ce55ae4f3f29d7b645075dc8efacb2c96d2.tar.bz2 minetest-34d32ce55ae4f3f29d7b645075dc8efacb2c96d2.zip |
Implement delayed server shutdown with cancelation (#4664)
Diffstat (limited to 'builtin/game')
-rw-r--r-- | builtin/game/chatcommands.lua | 16 | ||||
-rw-r--r-- | builtin/game/misc.lua | 5 |
2 files changed, 16 insertions, 5 deletions
diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index 8df3903d2..25cc06178 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -763,14 +763,20 @@ core.register_chatcommand("days", { core.register_chatcommand("shutdown", { description = "Shutdown server", - params = "[reconnect] [message]", + params = "[delay_in_seconds(0..inf) or -1 for cancel] [reconnect] [message]", privs = {server=true}, func = function(name, param) - core.log("action", name .. " shuts down server") - core.chat_send_all("*** Server shutting down (operator request).") - local reconnect, message = param:match("([^ ]+)(.*)") + local delay, reconnect, message = param:match("([^ ][-]?[0-9]+)([^ ]+)(.*)") message = message or "" - core.request_shutdown(message:trim(), core.is_yes(reconnect)) + + if delay ~= "" then + delay = tonumber(param) or 0 + else + delay = 0 + core.log("action", name .. " shuts down server") + core.chat_send_all("*** Server shutting down (operator request).") + end + core.request_shutdown(message:trim(), core.is_yes(reconnect), delay) end, }) diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index 618d4d97f..a3eb26ac2 100644 --- a/builtin/game/misc.lua +++ b/builtin/game/misc.lua @@ -173,3 +173,8 @@ end function core.close_formspec(player_name, formname) return minetest.show_formspec(player_name, formname, "") end + +function core.cancel_shutdown_requests() + core.request_shutdown("", false, -1) +end + |