diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 1a267c3cb3..437423d744 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -380,6 +380,7 @@ namespace Config model->known_keys_only = reader->GetBoolean("known_keys_only", false); model->log_chat = reader->GetBoolean("log_chat", false); model->log_server_actions = reader->GetBoolean("log_server_actions", false); + model->pause_server_if_no_clients = reader->GetBoolean("pause_server_if_no_clients", false); } } @@ -404,6 +405,7 @@ namespace Config writer->WriteBoolean("known_keys_only", model->known_keys_only); writer->WriteBoolean("log_chat", model->log_chat); writer->WriteBoolean("log_server_actions", model->log_server_actions); + writer->WriteBoolean("pause_server_if_no_clients", model->pause_server_if_no_clients); } static void ReadNotifications(IIniReader * reader) diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index 23ed4adeaf..f6b1f66b38 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -152,6 +152,7 @@ typedef struct NetworkConfiguration bool known_keys_only; bool log_chat; bool log_server_actions; + bool pause_server_if_no_clients; } NetworkConfiguration; typedef struct NotificationConfiguration diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 26bf788d89..4eed927c3a 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -351,6 +351,11 @@ bool Network::BeginServer(uint16 port, const char* address) _advertiser = CreateServerAdvertiser(listening_port); } + if (gConfigNetwork.pause_server_if_no_clients) + { + game_do_command(0, 1, 0, 0, GAME_COMMAND_TOGGLE_PAUSE, 0, 0); + } + return true; } @@ -1502,6 +1507,10 @@ void Network::EnqueueGameAction(const GameAction *action) void Network::AddClient(ITcpSocket * socket) { + if (gConfigNetwork.pause_server_if_no_clients && game_is_paused()) + { + game_do_command(0, 1, 0, 0, GAME_COMMAND_TOGGLE_PAUSE, 0, 0); + } auto connection = std::make_unique(); connection->Socket = socket; char addr[128]; @@ -1540,6 +1549,10 @@ void Network::RemoveClient(std::unique_ptr& connection) return player.get() == connection_player; }), player_list.end()); client_connection_list.remove(connection); + if (gConfigNetwork.pause_server_if_no_clients && game_is_not_paused() && client_connection_list.size() == 0) + { + game_do_command(0, 1, 0, 0, GAME_COMMAND_TOGGLE_PAUSE, 0, 0); + } Server_Send_PLAYERLIST(); }