From fe989c3dc4e557d551407d802ae7de8602ef2ca5 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 13 Jun 2026 22:53:16 +0100 Subject: [PATCH] Codechange: make NetworkGameStatus a scoped enum --- src/network/network.cpp | 2 +- src/network/network_coordinator.cpp | 4 ++-- src/network/network_gamelist.h | 14 +++++++------- src/network/network_gui.cpp | 20 ++++++++++---------- src/network/network_query.cpp | 12 ++++++------ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/network/network.cpp b/src/network/network.cpp index c8b3d405a8..1c1cd864e5 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -668,7 +668,7 @@ public: Debug(net, 9, "Query::OnFailure(): connection_string={}", this->connection_string); NetworkGame *item = NetworkGameListAddItem(connection_string); - item->status = NGLS_OFFLINE; + item->status = NetworkGameStatus::Offline; item->refreshing = false; UpdateNetworkGameWindow(); diff --git a/src/network/network_coordinator.cpp b/src/network/network_coordinator.cpp index 5dfb08f05e..43bddce48b 100644 --- a/src/network/network_coordinator.cpp +++ b/src/network/network_coordinator.cpp @@ -153,7 +153,7 @@ bool ClientNetworkCoordinatorSocketHandler::ReceiveGameCoordinatorError(Packet & /* Mark the server as offline. */ NetworkGame *item = NetworkGameListAddItem(detail); - item->status = NGLS_OFFLINE; + item->status = NetworkGameStatus::Offline; UpdateNetworkGameWindow(); return true; @@ -259,7 +259,7 @@ bool ClientNetworkCoordinatorSocketHandler::ReceiveGameCoordinatorListing(Packet /* Check for compatibility with the client. */ CheckGameCompatibility(item->info); /* Mark server as online. */ - item->status = NGLS_ONLINE; + item->status = NetworkGameStatus::Online; /* Mark the item as up-to-date. */ item->version = _network_game_list_version; } diff --git a/src/network/network_gamelist.h b/src/network/network_gamelist.h index 61d973b0ed..88d179e4d0 100644 --- a/src/network/network_gamelist.h +++ b/src/network/network_gamelist.h @@ -15,12 +15,12 @@ #include "network_type.h" /** The status a server can be in. */ -enum NetworkGameStatus : uint8_t { - NGLS_OFFLINE, ///< Server is offline (or cannot be queried). - NGLS_ONLINE, ///< Server is online. - NGLS_FULL, ///< Server is full and cannot be queried. - NGLS_BANNED, ///< You are banned from this server. - NGLS_TOO_OLD, ///< Server is too old to query. +enum class NetworkGameStatus : uint8_t { + Offline, ///< Server is offline (or cannot be queried). + Online, ///< Server is online. + Full, ///< Server is full and cannot be queried. + Banned, ///< You are banned from this server. + TooOld, ///< Server is too old to query. }; /** Structure with information shown in the game list (GUI) */ @@ -33,7 +33,7 @@ struct NetworkGame { NetworkGameInfo info{}; ///< The game information of this server. std::string connection_string; ///< Address of the server. - NetworkGameStatus status = NGLS_OFFLINE; ///< Stats of the server. + NetworkGameStatus status = NetworkGameStatus::Offline; ///< Stats of the server. bool manually = false; ///< True if the server was added manually. bool refreshing = false; ///< Whether this server is being queried. int version = 0; ///< Used to see which servers are no longer available on the Game Coordinator and can be removed. diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 39dd75302e..6b41530ef6 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -378,7 +378,7 @@ protected: DrawString(name.left, name.right, y + text_y_offset, cur_item->info.server_name, TextColour::Black); /* only draw details if the server is online */ - if (cur_item->status == NGLS_ONLINE) { + if (cur_item->status == NetworkGameStatus::Online) { if (const NWidgetBase *nwid = this->GetWidget(WID_NG_CLIENTS); nwid->current_x != 0) { Rect clients = nwid->GetCurrentRect(); DrawString(clients.left, clients.right, y + text_y_offset, @@ -585,7 +585,7 @@ public: this->SetWidgetDisabledState(WID_NG_REFRESH, sel == nullptr); /* 'Join' button disabling conditions */ this->SetWidgetDisabledState(WID_NG_JOIN, sel == nullptr || // no Selected Server - sel->status != NGLS_ONLINE || // Server offline + sel->status != NetworkGameStatus::Online || // Server offline sel->info.clients_on >= sel->info.clients_max || // Server full !sel->info.compatible); // Revision mismatch @@ -593,8 +593,8 @@ public: /* 'NewGRF Settings' button invisible if no NewGRF is used */ bool changed = false; - changed |= this->GetWidget(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig.empty() ? SZSP_NONE : 0); - changed |= this->GetWidget(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig.empty() || !sel->info.version_compatible || sel->info.compatible ? SZSP_NONE : 0); + changed |= this->GetWidget(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NetworkGameStatus::Online || sel->info.grfconfig.empty() ? SZSP_NONE : 0); + changed |= this->GetWidget(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NetworkGameStatus::Online || sel->info.grfconfig.empty() || !sel->info.version_compatible || sel->info.compatible ? SZSP_NONE : 0); if (changed) { this->ReInit(); return; @@ -618,11 +618,11 @@ public: { if (this->server == nullptr) return STR_NETWORK_SERVER_LIST_GAME_INFO; switch (this->server->status) { - case NGLS_OFFLINE: return STR_NETWORK_SERVER_LIST_SERVER_OFFLINE; - case NGLS_ONLINE: return STR_NETWORK_SERVER_LIST_GAME_INFO; - case NGLS_FULL: return STR_NETWORK_SERVER_LIST_SERVER_FULL; - case NGLS_BANNED: return STR_NETWORK_SERVER_LIST_SERVER_BANNED; - case NGLS_TOO_OLD: return STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD; + case NetworkGameStatus::Offline: return STR_NETWORK_SERVER_LIST_SERVER_OFFLINE; + case NetworkGameStatus::Online: return STR_NETWORK_SERVER_LIST_GAME_INFO; + case NetworkGameStatus::Full: return STR_NETWORK_SERVER_LIST_SERVER_FULL; + case NetworkGameStatus::Banned: return STR_NETWORK_SERVER_LIST_SERVER_BANNED; + case NetworkGameStatus::TooOld: return STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD; default: NOT_REACHED(); } } @@ -652,7 +652,7 @@ public: if (sel == nullptr) return; hr.top = DrawStringMultiLine(hr, sel->info.server_name, TextColour::Orange, SA_HOR_CENTER); // game name - if (sel->status != NGLS_ONLINE) { + if (sel->status != NetworkGameStatus::Online) { tr.top = DrawStringMultiLine(tr, header_msg, TextColour::FromString, SA_HOR_CENTER); } else { // show game info tr.top = DrawStringMultiLine(tr, GetString(STR_NETWORK_SERVER_LIST_CLIENTS, sel->info.clients_on, sel->info.clients_max, sel->info.companies_on, sel->info.companies_max)); diff --git a/src/network/network_query.cpp b/src/network/network_query.cpp index 6b497d5451..4c7089e2b8 100644 --- a/src/network/network_query.cpp +++ b/src/network/network_query.cpp @@ -25,7 +25,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::CloseConnection(NetworkRecvStat /* Connection is closed, but we never received a packet. Must be offline. */ NetworkGame *item = NetworkGameListAddItem(this->connection_string); if (item->refreshing) { - item->status = NGLS_OFFLINE; + item->status = NetworkGameStatus::Offline; item->refreshing = false; UpdateNetworkGameWindow(); @@ -92,7 +92,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::ReceiveServerFull(Packet &) Debug(net, 9, "Query::ReceiveServerFull()"); NetworkGame *item = NetworkGameListAddItem(this->connection_string); - item->status = NGLS_FULL; + item->status = NetworkGameStatus::Full; item->refreshing = false; UpdateNetworkGameWindow(); @@ -105,7 +105,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::ReceiveServerBanned(Packet &) Debug(net, 9, "Query::ReceiveServerBanned()"); NetworkGame *item = NetworkGameListAddItem(this->connection_string); - item->status = NGLS_BANNED; + item->status = NetworkGameStatus::Banned; item->refreshing = false; UpdateNetworkGameWindow(); @@ -126,7 +126,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::ReceiveServerGameInfo(Packet &p /* Check for compatibility with the client. */ CheckGameCompatibility(item->info); /* Ensure we consider the server online. */ - item->status = NGLS_ONLINE; + item->status = NetworkGameStatus::Online; item->refreshing = false; UpdateNetworkGameWindow(); @@ -147,9 +147,9 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::ReceiveServerError(Packet &p) * NetworkErrorCode::NotExpected on requesting the game info. Show to the * user this server is too old to query. */ - item->status = NGLS_TOO_OLD; + item->status = NetworkGameStatus::TooOld; } else { - item->status = NGLS_OFFLINE; + item->status = NetworkGameStatus::Offline; } item->refreshing = false;