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
+14 -10
View File
@@ -749,8 +749,10 @@ 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();
for (const auto& it : this->state->proxy_server->all_sessions()) { if (this->state->proxy_server) {
res.emplace_back(this->generate_proxy_client_json_st(it.second)); for (const auto& it : this->state->proxy_server->all_sessions()) {
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,13 +815,15 @@ JSON HTTPServer::generate_summary_json() const {
} }
auto proxy_clients_json = JSON::list(); auto proxy_clients_json = JSON::list();
for (const auto& it : this->state->proxy_server->all_sessions()) { if (this->state->proxy_server) {
proxy_clients_json.emplace_back(JSON::dict({ for (const auto& it : this->state->proxy_server->all_sessions()) {
{"AccountID", it.second->login ? it.second->login->account->account_id : JSON(nullptr)}, proxy_clients_json.emplace_back(JSON::dict({
{"Name", it.second->character_name}, {"AccountID", it.second->login ? it.second->login->account->account_id : JSON(nullptr)},
{"Version", name_for_enum(it.second->version())}, {"Name", it.second->character_name},
{"Language", name_for_language_code(it.second->language())}, {"Version", name_for_enum(it.second->version())},
})); {"Language", name_for_language_code(it.second->language())},
}));
}
} }
auto games_json = JSON::list(); auto games_json = JSON::list();