diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index a3f0b79f..91d193e4 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -107,12 +107,20 @@ static void check_is_leader(shared_ptr l, shared_ptr c) { static void server_command_server_info(shared_ptr c, const std::string&) { auto s = c->require_server_state(); string uptime_str = phosg::format_duration(phosg::now() - s->creation_time); - send_text_message_printf(c, - "Uptime: $C6%s$C7\nLobbies: $C6%zu$C7\nClients: $C6%zu$C7(g) $C6%zu$C7(p)", - uptime_str.c_str(), - s->id_to_lobby.size(), - s->channel_to_client.size(), - s->proxy_server->num_sessions()); + if (s->proxy_server) { + send_text_message_printf(c, + "Uptime: $C6%s$C7\nLobbies: $C6%zu$C7\nClients: $C6%zu$C7(g) $C6%zu$C7(p)", + uptime_str.c_str(), + s->id_to_lobby.size(), + s->channel_to_client.size(), + 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 c, const std::string&) { diff --git a/src/Main.cc b/src/Main.cc index dc9f8733..ad277444 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -2918,25 +2918,24 @@ Action a_run_server_replay_log( config_log.info("Starting proxy server"); state->proxy_server = make_shared(base, state); } - if (state->proxy_server.get()) { - // 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 - // no way to ask the client which destination they want, so only one - // destination is supported, and we have to manually specify the - // destination netloc here. - if (is_patch(pc->version)) { - auto [ss, size] = phosg::make_sockaddr_storage( - state->proxy_destination_patch.first, - state->proxy_destination_patch.second); - state->proxy_server->listen(pc->addr, pc->port, pc->version, &ss); - } else if (is_v4(pc->version)) { - auto [ss, size] = phosg::make_sockaddr_storage( - state->proxy_destination_bb.first, - state->proxy_destination_bb.second); - state->proxy_server->listen(pc->addr, pc->port, pc->version, &ss); - } else { - state->proxy_server->listen(pc->addr, pc->port, pc->version); - } + + // 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 + // no way to ask the client which destination they want, so only one + // destination is supported, and we have to manually specify the + // destination netloc here. + if (is_patch(pc->version)) { + auto [ss, size] = phosg::make_sockaddr_storage( + state->proxy_destination_patch.first, + state->proxy_destination_patch.second); + state->proxy_server->listen(pc->addr, pc->port, pc->version, &ss); + } else if (is_v4(pc->version)) { + auto [ss, size] = phosg::make_sockaddr_storage( + state->proxy_destination_bb.first, + state->proxy_destination_bb.second); + state->proxy_server->listen(pc->addr, pc->port, pc->version, &ss); + } else { + state->proxy_server->listen(pc->addr, pc->port, pc->version); } } else if (pc->behavior == ServerBehavior::PATCH_SERVER_PC) { diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 593855b8..aae3198b 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -234,6 +234,11 @@ void send_client_to_lobby_server(shared_ptr c) { } void send_client_to_proxy_server(shared_ptr 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)]() { auto c = wc.lock(); if (!c) { diff --git a/src/ServerShell.cc b/src/ServerShell.cc index 91bb2bad..4a92cf71 100644 --- a/src/ServerShell.cc +++ b/src/ServerShell.cc @@ -1191,6 +1191,10 @@ CommandDefinition c_close_idle_sessions( "close-idle-sessions", "close-idle-sessions\n\ Close all proxy sessions that don\'t have a client and server connected.", true, +[](CommandArgs& args) { - size_t count = args.s->proxy_server->delete_disconnected_sessions(); - fprintf(stderr, "%zu sessions closed\n", count); + if (args.s->proxy_server) { + size_t count = args.s->proxy_server->delete_disconnected_sessions(); + fprintf(stderr, "%zu sessions closed\n", count); + } else { + throw runtime_error("the proxy server is disabled"); + } });