add checks for disabled proxy server; fixes #580

This commit is contained in:
Martin Michelsen
2024-10-29 06:32:12 -07:00
parent 996509531c
commit 6e808b8340
4 changed files with 43 additions and 27 deletions
+8
View File
@@ -107,12 +107,20 @@ static void check_is_leader(shared_ptr<Lobby> l, shared_ptr<Client> c) {
static void server_command_server_info(shared_ptr<Client> c, const std::string&) { static void server_command_server_info(shared_ptr<Client> c, const std::string&) {
auto s = c->require_server_state(); auto s = c->require_server_state();
string uptime_str = phosg::format_duration(phosg::now() - s->creation_time); string uptime_str = phosg::format_duration(phosg::now() - s->creation_time);
if (s->proxy_server) {
send_text_message_printf(c, send_text_message_printf(c,
"Uptime: $C6%s$C7\nLobbies: $C6%zu$C7\nClients: $C6%zu$C7(g) $C6%zu$C7(p)", "Uptime: $C6%s$C7\nLobbies: $C6%zu$C7\nClients: $C6%zu$C7(g) $C6%zu$C7(p)",
uptime_str.c_str(), uptime_str.c_str(),
s->id_to_lobby.size(), s->id_to_lobby.size(),
s->channel_to_client.size(), s->channel_to_client.size(),
s->proxy_server->num_sessions()); s->proxy_server->num_sessions());
} else {
send_text_message_printf(c,
"Uptime: $C6%s$C7\nLobbies: $C6%zu$C7\nClients: $C6%zu",
uptime_str.c_str(),
s->id_to_lobby.size(),
s->channel_to_client.size());
}
} }
static void server_command_lobby_info(shared_ptr<Client> c, const std::string&) { static void server_command_lobby_info(shared_ptr<Client> c, const std::string&) {
+1 -2
View File
@@ -2918,7 +2918,7 @@ Action a_run_server_replay_log(
config_log.info("Starting proxy server"); config_log.info("Starting proxy server");
state->proxy_server = make_shared<ProxyServer>(base, state); state->proxy_server = make_shared<ProxyServer>(base, state);
} }
if (state->proxy_server.get()) {
// For PC and GC, proxy sessions are dynamically created when a client // For PC and GC, proxy sessions are dynamically created when a client
// picks a destination from the menu. For patch and BB clients, there's // picks a destination from the menu. For patch and BB clients, there's
// no way to ask the client which destination they want, so only one // no way to ask the client which destination they want, so only one
@@ -2937,7 +2937,6 @@ Action a_run_server_replay_log(
} else { } else {
state->proxy_server->listen(pc->addr, pc->port, pc->version); state->proxy_server->listen(pc->addr, pc->port, pc->version);
} }
}
} else if (pc->behavior == ServerBehavior::PATCH_SERVER_PC) { } else if (pc->behavior == ServerBehavior::PATCH_SERVER_PC) {
if (!state->pc_patch_server.get()) { if (!state->pc_patch_server.get()) {
+5
View File
@@ -234,6 +234,11 @@ void send_client_to_lobby_server(shared_ptr<Client> c) {
} }
void send_client_to_proxy_server(shared_ptr<Client> c) { void send_client_to_proxy_server(shared_ptr<Client> c) {
auto s = c->require_server_state();
if (!s->proxy_server) {
throw logic_error("send_client_to_proxy_server called without proxy server present");
}
send_first_pre_lobby_commands(c, [wc = weak_ptr(c)]() { send_first_pre_lobby_commands(c, [wc = weak_ptr(c)]() {
auto c = wc.lock(); auto c = wc.lock();
if (!c) { if (!c) {
+4
View File
@@ -1191,6 +1191,10 @@ CommandDefinition c_close_idle_sessions(
"close-idle-sessions", "close-idle-sessions\n\ "close-idle-sessions", "close-idle-sessions\n\
Close all proxy sessions that don\'t have a client and server connected.", Close all proxy sessions that don\'t have a client and server connected.",
true, +[](CommandArgs& args) { true, +[](CommandArgs& args) {
if (args.s->proxy_server) {
size_t count = args.s->proxy_server->delete_disconnected_sessions(); size_t count = args.s->proxy_server->delete_disconnected_sessions();
fprintf(stderr, "%zu sessions closed\n", count); fprintf(stderr, "%zu sessions closed\n", count);
} else {
throw runtime_error("the proxy server is disabled");
}
}); });