Skip to content

Commit 409d043

Browse files
SmallJokernerzhul
authored andcommittedJun 11, 2018
Fix the /shutdown command (#7431)
1 parent fb4e4f0 commit 409d043

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed
 

‎builtin/game/chatcommands.lua

+8-6
Original file line numberDiff line numberDiff line change
@@ -827,13 +827,15 @@ core.register_chatcommand("shutdown", {
827827
description = "Shutdown server (-1 cancels a delayed shutdown)",
828828
privs = {server=true},
829829
func = function(name, param)
830-
local delay, reconnect, message = param:match("([^ ][-]?[0-9]+)([^ ]+)(.*)")
831-
message = message or ""
830+
local delay, reconnect, message
831+
delay, param = param:match("^%s*(%S+)(.*)")
832+
if param then
833+
reconnect, param = param:match("^%s*(%S+)(.*)")
834+
end
835+
message = param and param:match("^%s*(.+)") or ""
836+
delay = tonumber(delay) or 0
832837

833-
if delay ~= "" then
834-
delay = tonumber(delay) or 0
835-
else
836-
delay = 0
838+
if delay == 0 then
837839
core.log("action", name .. " shuts down server")
838840
core.chat_send_all("*** Server shutting down (operator request).")
839841
end

‎src/server.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -3396,10 +3396,6 @@ v3f Server::findSpawnPos()
33963396

33973397
void Server::requestShutdown(const std::string &msg, bool reconnect, float delay)
33983398
{
3399-
m_shutdown_timer = delay;
3400-
m_shutdown_msg = msg;
3401-
m_shutdown_ask_reconnect = reconnect;
3402-
34033399
if (delay == 0.0f) {
34043400
// No delay, shutdown immediately
34053401
m_shutdown_requested = true;
@@ -3418,17 +3414,23 @@ void Server::requestShutdown(const std::string &msg, bool reconnect, float delay
34183414

34193415
infostream << wide_to_utf8(ws.str()).c_str() << std::endl;
34203416
SendChatMessage(PEER_ID_INEXISTENT, ws.str());
3417+
// m_shutdown_* are already handled, skip.
3418+
return;
34213419
} else if (delay > 0.0f) {
34223420
// Positive delay, tell the clients when the server will shut down
34233421
std::wstringstream ws;
34243422

34253423
ws << L"*** Server shutting down in "
3426-
<< duration_to_string(myround(m_shutdown_timer)).c_str()
3424+
<< duration_to_string(myround(delay)).c_str()
34273425
<< ".";
34283426

34293427
infostream << wide_to_utf8(ws.str()).c_str() << std::endl;
34303428
SendChatMessage(PEER_ID_INEXISTENT, ws.str());
34313429
}
3430+
3431+
m_shutdown_timer = delay;
3432+
m_shutdown_msg = msg;
3433+
m_shutdown_ask_reconnect = reconnect;
34323434
}
34333435

34343436
PlayerSAO* Server::emergePlayer(const char *name, session_t peer_id, u16 proto_version)

0 commit comments

Comments
 (0)
Please sign in to comment.