add checks for disabled proxy server; fixes #580
This commit is contained in:
+14
-6
@@ -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&) {
|
||||
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<Client> c, const std::string&) {
|
||||
|
||||
+18
-19
@@ -2918,25 +2918,24 @@ Action a_run_server_replay_log(
|
||||
config_log.info("Starting proxy server");
|
||||
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
|
||||
// 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) {
|
||||
|
||||
@@ -234,6 +234,11 @@ void send_client_to_lobby_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)]() {
|
||||
auto c = wc.lock();
|
||||
if (!c) {
|
||||
|
||||
+6
-2
@@ -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");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user