diff options
author | Patric Stout <truebrain@openttd.org> | 2021-05-05 23:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-05 23:21:14 +0200 |
commit | f94fb9377910c63fc8e1ea0ede1d96603e4d8862 (patch) | |
tree | 9b8041b53749744b4df075520181294806332e07 /src/network/network_gui.cpp | |
parent | ead30dc725c60cac8bc13c86d18b179dac684bec (diff) | |
download | openttd-f94fb9377910c63fc8e1ea0ede1d96603e4d8862.tar.xz |
Codechange: use connection_string in favour of NetworkAddress (#9197)
We now resolve the connection_string to a NetworkAddress in a much
later state. This means there are fewer places constructing a NetworkAddress.
The main benefit of this is in later PRs that introduce different types
of NetworkAddresses. Storing this in things like NetworkGameList is
rather complex, especially as NetworkAddress has to be mutable at all
times.
Additionally, the NetworkAddress is a complex object to store simple
information: how to connect to this server.
Diffstat (limited to 'src/network/network_gui.cpp')
-rw-r--r-- | src/network/network_gui.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index ac86b868c..526f141cd 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -272,7 +272,9 @@ protected: static bool NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b) { int r = strnatcmp(a->info.server_name, b->info.server_name, true); // Sort by name (natural sorting). - return r == 0 ? a->address.CompareTo(b->address) < 0: r < 0; + if (r == 0) r = a->connection_string.compare(b->connection_string); + + return r < 0; } /** @@ -646,8 +648,7 @@ public: DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_SERVER_VERSION); // server version y += FONT_HEIGHT_NORMAL; - std::string address = sel->address.GetAddressAsString(); - SetDParamStr(0, address.c_str()); + SetDParamStr(0, sel->connection_string.c_str()); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_SERVER_ADDRESS); // server address y += FONT_HEIGHT_NORMAL; @@ -751,7 +752,7 @@ public: break; case WID_NG_REFRESH: // Refresh - if (this->server != nullptr) NetworkTCPQueryServer(this->server->address); + if (this->server != nullptr) NetworkTCPQueryServer(this->server->connection_string); break; case WID_NG_NEWGRF: // NewGRF Settings @@ -1471,22 +1472,22 @@ struct NetworkLobbyWindow : public Window { case WID_NL_JOIN: // Join company /* Button can be clicked only when it is enabled. */ - NetworkClientConnectGame(this->server->address, this->company); + NetworkClientConnectGame(this->server->connection_string, this->company); break; case WID_NL_NEW: // New company - NetworkClientConnectGame(this->server->address, COMPANY_NEW_COMPANY); + NetworkClientConnectGame(this->server->connection_string, COMPANY_NEW_COMPANY); break; case WID_NL_SPECTATE: // Spectate game - NetworkClientConnectGame(this->server->address, COMPANY_SPECTATOR); + NetworkClientConnectGame(this->server->connection_string, COMPANY_SPECTATOR); break; case WID_NL_REFRESH: // Refresh /* Clear the information so removed companies don't remain */ for (auto &company : this->company_info) company = {}; - NetworkTCPQueryServer(this->server->address, true); + NetworkTCPQueryServer(this->server->connection_string, true); break; } } @@ -1554,9 +1555,9 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl) DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_START); DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME); - strecpy(_settings_client.network.last_joined, ngl->address.GetAddressAsString(false).c_str(), lastof(_settings_client.network.last_joined)); + strecpy(_settings_client.network.last_joined, ngl->connection_string.c_str(), lastof(_settings_client.network.last_joined)); - NetworkTCPQueryServer(ngl->address, true); + NetworkTCPQueryServer(ngl->connection_string, true); new NetworkLobbyWindow(&_network_lobby_window_desc, ngl); } |