diff options
author | Patric Stout <truebrain@openttd.org> | 2021-04-29 12:09:03 +0200 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-04-29 20:12:11 +0200 |
commit | be37a2cab831cb645ef0f51dbcc944bd750f6926 (patch) | |
tree | 17efb6066721db8ce4974cee192cbd8a8193821a /src/network/core | |
parent | 99f998805ba835f48a8061762fa19761760c7451 (diff) | |
download | openttd-be37a2cab831cb645ef0f51dbcc944bd750f6926.tar.xz |
Codechange: use NetworkAddress instead of two host/port variables where possible
This also means we no longer need last_host/last_port, but can
just use a single last_joined setting.
Diffstat (limited to 'src/network/core')
-rw-r--r-- | src/network/core/address.cpp | 4 | ||||
-rw-r--r-- | src/network/core/config.h | 1 | ||||
-rw-r--r-- | src/network/core/tcp_http.cpp | 6 |
3 files changed, 4 insertions, 7 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp index 8b51e2c08..e91751c33 100644 --- a/src/network/core/address.cpp +++ b/src/network/core/address.cpp @@ -101,8 +101,8 @@ void NetworkAddress::GetAddressAsString(char *buffer, const char *last, bool wit */ std::string NetworkAddress::GetAddressAsString(bool with_family) { - /* 6 = for the : and 5 for the decimal port number */ - char buf[NETWORK_HOSTNAME_LENGTH + 6 + 7]; + /* 7 extra are for with_family, which adds " (IPvX)". */ + char buf[NETWORK_HOSTNAME_PORT_LENGTH + 7]; this->GetAddressAsString(buf, lastof(buf), with_family); return buf; } diff --git a/src/network/core/config.h b/src/network/core/config.h index 866d1791d..cacc907fa 100644 --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -56,6 +56,7 @@ static const byte NETWORK_MASTER_SERVER_VERSION = 2; ///< What vers static const uint NETWORK_NAME_LENGTH = 80; ///< The maximum length of the server name and map name, in bytes including '\0' static const uint NETWORK_COMPANY_NAME_LENGTH = 128; ///< The maximum length of the company name, in bytes including '\0' static const uint NETWORK_HOSTNAME_LENGTH = 80; ///< The maximum length of the host name, in bytes including '\0' +static const uint NETWORK_HOSTNAME_PORT_LENGTH = 80 + 6; ///< The maximum length of the host name + port, in bytes including '\0'. The extra six is ":" + port number (with a max of 65536) static const uint NETWORK_SERVER_ID_LENGTH = 33; ///< The maximum length of the network id of the servers, in bytes including '\0' static const uint NETWORK_REVISION_LENGTH = 33; ///< The maximum length of the revision, in bytes including '\0' static const uint NETWORK_PASSWORD_LENGTH = 33; ///< The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH) diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp index ee74c4507..99eca1cb7 100644 --- a/src/network/core/tcp_http.cpp +++ b/src/network/core/tcp_http.cpp @@ -203,11 +203,7 @@ int NetworkHTTPSocketHandler::HandleHeader() *url = '\0'; - /* Fetch the hostname, and possible port number. */ - const char *port = nullptr; - ParseConnectionString(&port, hname); - - NetworkAddress address(hname, port == nullptr ? 80 : atoi(port)); + NetworkAddress address = ParseConnectionString(hname, 80); /* Restore the URL. */ *url = '/'; |