summaryrefslogtreecommitdiff
path: root/src/network/core/address.cpp
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-07-11 12:08:03 +0200
committerPatric Stout <github@truebrain.nl>2021-07-11 20:38:42 +0200
commit1baec41542780cf4fc898df7d2fc9925d823fb44 (patch)
tree57aa8bc38997fc9d39a4ae66af7b912712e1830e /src/network/core/address.cpp
parentcee8174d02e38542548fc74de93450cfebefaa91 (diff)
downloadopenttd-1baec41542780cf4fc898df7d2fc9925d823fb44.tar.xz
Change: groundwork to allow ServerAddress to use invite codes
Normally TCPConnecter will do a DNS resolving of the connection_string and connect to it. But for SERVER_ADDRESS_INVITE_CODE this is different: the Game Coordinator does the "resolving". This means we need to allow TCPConnecter to not setup a connection and allow it to be told when a connection has been setup by an external (to TCPConnecter) part of the code. We do this by telling the (active) socket for the connection. This means the rest of the code doesn't need to know the TCPConnecter is not doing a simple resolve+connect. The rest of the code only cares the connection is established; not how it was established.
Diffstat (limited to 'src/network/core/address.cpp')
-rw-r--r--src/network/core/address.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp
index 113dae686..4c090c14a 100644
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -414,17 +414,22 @@ void NetworkAddress::Listen(int socktype, SocketList *sockets)
}
/**
- * Convert a string containing either "hostname" or "hostname:ip" to a
- * ServerAddress, where the string can be postfixed with "#company" to
+ * Convert a string containing either "hostname", "hostname:port" or invite code
+ * to a ServerAddress, where the string can be postfixed with "#company" to
* indicate the requested company.
*
* @param connection_string The string to parse.
* @param default_port The default port to set port to if not in connection_string.
- * @param company Pointer to the company variable to set iff indicted.
+ * @param company Pointer to the company variable to set iff indicated.
* @return A valid ServerAddress of the parsed information.
*/
/* static */ ServerAddress ServerAddress::Parse(const std::string &connection_string, uint16 default_port, CompanyID *company_id)
{
+ if (StrStartsWith(connection_string, "+")) {
+ std::string_view invite_code = ParseCompanyFromConnectionString(connection_string, company_id);
+ return ServerAddress(SERVER_ADDRESS_INVITE_CODE, std::string(invite_code));
+ }
+
uint16 port = default_port;
std::string_view ip = ParseFullConnectionString(connection_string, port, company_id);
return ServerAddress(SERVER_ADDRESS_DIRECT, std::string(ip) + ":" + std::to_string(port));