multiplayer: Adds option to pause server

OpenRCT2 does not provide a simple function to pause a server
while no client is connected. This patch adds a so called
"pause_server_if_no_clients" flag within network section of
config.ini. By default this flag is set to false to be backward
compatible with running servers. After setting this flag to
true the game is paused on launch and gets unpaused on first
connection.

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
This commit is contained in:
Tobias Kohlbau 2017-12-17 13:30:24 +01:00 committed by Michael Steenbeek
parent 92fc010b9a
commit 7a8c5c2842
3 changed files with 16 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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<NetworkConnection>();
connection->Socket = socket;
char addr[128];
@ -1540,6 +1549,10 @@ void Network::RemoveClient(std::unique_ptr<NetworkConnection>& 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();
}