fix HTTP server segfault if proxy server is disabled

This commit is contained in:
Martin Michelsen
2024-04-30 09:11:02 -07:00
parent 83b8c199b9
commit 9b6a6e4412
+5 -1
View File
@@ -749,9 +749,11 @@ JSON HTTPServer::generate_game_server_clients_json() const {
JSON HTTPServer::generate_proxy_server_clients_json() const { JSON HTTPServer::generate_proxy_server_clients_json() const {
return call_on_event_thread<JSON>(this->state->base, [&]() { return call_on_event_thread<JSON>(this->state->base, [&]() {
JSON res = JSON::list(); JSON res = JSON::list();
if (this->state->proxy_server) {
for (const auto& it : this->state->proxy_server->all_sessions()) { for (const auto& it : this->state->proxy_server->all_sessions()) {
res.emplace_back(this->generate_proxy_client_json_st(it.second)); res.emplace_back(this->generate_proxy_client_json_st(it.second));
} }
}
return res; return res;
}); });
} }
@@ -776,7 +778,7 @@ JSON HTTPServer::generate_server_info_json() const {
{"LobbyCount", lobby_count}, {"LobbyCount", lobby_count},
{"GameCount", game_count}, {"GameCount", game_count},
{"ClientCount", this->state->channel_to_client.size()}, {"ClientCount", this->state->channel_to_client.size()},
{"ProxySessionCount", this->state->proxy_server->num_sessions()}, {"ProxySessionCount", this->state->proxy_server ? this->state->proxy_server->num_sessions() : 0},
{"ServerName", this->state->name}, {"ServerName", this->state->name},
}); });
}); });
@@ -813,6 +815,7 @@ JSON HTTPServer::generate_summary_json() const {
} }
auto proxy_clients_json = JSON::list(); auto proxy_clients_json = JSON::list();
if (this->state->proxy_server) {
for (const auto& it : this->state->proxy_server->all_sessions()) { for (const auto& it : this->state->proxy_server->all_sessions()) {
proxy_clients_json.emplace_back(JSON::dict({ proxy_clients_json.emplace_back(JSON::dict({
{"AccountID", it.second->login ? it.second->login->account->account_id : JSON(nullptr)}, {"AccountID", it.second->login ? it.second->login->account->account_id : JSON(nullptr)},
@@ -821,6 +824,7 @@ JSON HTTPServer::generate_summary_json() const {
{"Language", name_for_language_code(it.second->language())}, {"Language", name_for_language_code(it.second->language())},
})); }));
} }
}
auto games_json = JSON::list(); auto games_json = JSON::list();
for (const auto& it : this->state->id_to_lobby) { for (const auto& it : this->state->id_to_lobby) {