diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/core/tcp_http.cpp | 2 | ||||
-rw-r--r-- | src/network/network.cpp | 26 | ||||
-rw-r--r-- | src/network/network_func.h | 7 | ||||
-rw-r--r-- | src/network/network_internal.h | 4 |
4 files changed, 28 insertions, 11 deletions
diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp index 99eca1cb7..e0c269faf 100644 --- a/src/network/core/tcp_http.cpp +++ b/src/network/core/tcp_http.cpp @@ -12,7 +12,7 @@ #include "../../stdafx.h" #include "../../debug.h" #include "../../rev.h" -#include "../network_func.h" +#include "../network_internal.h" #include "game_info.h" #include "tcp_http.h" diff --git a/src/network/network.cpp b/src/network/network.cpp index 0be46bbf3..d7cf9367a 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -490,10 +490,10 @@ void ParseFullConnectionString(const char **company, const char **port, char *co * @param default_port The default port to set port to if not in connection_string. * @return A valid NetworkAddress of the parsed information. */ -NetworkAddress ParseConnectionString(const char *connection_string, int default_port) +NetworkAddress ParseConnectionString(const std::string &connection_string, int default_port) { char internal_connection_string[NETWORK_HOSTNAME_PORT_LENGTH]; - strecpy(internal_connection_string, connection_string, lastof(internal_connection_string)); + strecpy(internal_connection_string, connection_string.c_str(), lastof(internal_connection_string)); const char *port = nullptr; ParseFullConnectionString(nullptr, &port, internal_connection_string); @@ -512,10 +512,10 @@ NetworkAddress ParseConnectionString(const char *connection_string, int default_ * @param default_port The default port to set port to if not in connection_string. * @return A valid NetworkAddress of the parsed information. */ -NetworkAddress ParseGameConnectionString(CompanyID *company, const char *connection_string, int default_port) +NetworkAddress ParseGameConnectionString(CompanyID *company, const std::string &connection_string, int default_port) { char internal_connection_string[NETWORK_HOSTNAME_PORT_LENGTH + 4]; // 4 extra for the "#" and company - strecpy(internal_connection_string, connection_string, lastof(internal_connection_string)); + strecpy(internal_connection_string, connection_string.c_str(), lastof(internal_connection_string)); const char *port_s = nullptr; const char *company_s = nullptr; @@ -693,6 +693,20 @@ public: } }; +void NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password, const char *join_company_password) +{ + CompanyID join_as = default_company; + NetworkAddress address = ParseGameConnectionString(&join_as, connection_string, NETWORK_DEFAULT_PORT); + + if (join_as != COMPANY_NEW_COMPANY && join_as != COMPANY_SPECTATOR) { + join_as--; + if (join_as >= MAX_COMPANIES) { + return; + } + } + + NetworkClientConnectGame(address, join_as, join_server_password, join_company_password); +} /* Used by clients, to connect to a server */ void NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const char *join_server_password, const char *join_company_password) @@ -1063,10 +1077,12 @@ static void NetworkGenerateServerId() seprintf(_settings_client.network.network_id, lastof(_settings_client.network.network_id), "%s", hex_output); } -void NetworkStartDebugLog(NetworkAddress &address) +void NetworkStartDebugLog(const std::string &connection_string) { extern SOCKET _debug_socket; // Comes from debug.c + NetworkAddress address = ParseConnectionString(connection_string, NETWORK_DEFAULT_DEBUGLOG_PORT); + DEBUG(net, 0, "Redirecting DEBUG() to %s", address.GetAddressAsString().c_str()); SOCKET s = address.Connect(); diff --git a/src/network/network_func.h b/src/network/network_func.h index 967bb6260..cd2b291bc 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -18,7 +18,6 @@ // #define DEBUG_FAILED_DUMP_COMMANDS #include "network_type.h" -#include "core/address.h" #include "../console_type.h" #include "../gfx_type.h" #include "../openttd.h" @@ -47,14 +46,12 @@ void NetworkDisconnect(bool blocking = false, bool close_admins = true); void NetworkGameLoop(); void NetworkBackgroundLoop(); void ParseFullConnectionString(const char **company, const char **port, char *connection_string); -NetworkAddress ParseConnectionString(const char *connection_string, int default_port); -NetworkAddress ParseGameConnectionString(CompanyID *company, const char *connection_string, int default_port); -void NetworkStartDebugLog(NetworkAddress &address); +void NetworkStartDebugLog(const std::string &connection_string); void NetworkPopulateCompanyStats(NetworkCompanyStats *stats); void NetworkUpdateClientInfo(ClientID client_id); void NetworkClientsToSpectators(CompanyID cid); -void NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const char *join_server_password = nullptr, const char *join_company_password = nullptr); +void NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password = nullptr, const char *join_company_password = nullptr); void NetworkClientRequestMove(CompanyID company, const char *pass = ""); void NetworkClientSendRcon(const char *password, const char *command); void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0); diff --git a/src/network/network_internal.h b/src/network/network_internal.h index c64eac795..ff3c8c22d 100644 --- a/src/network/network_internal.h +++ b/src/network/network_internal.h @@ -119,4 +119,8 @@ StringID GetNetworkErrorMsg(NetworkErrorCode err); bool NetworkFindName(char *new_name, const char *last); const char *GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed); +void NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const char *join_server_password = nullptr, const char *join_company_password = nullptr); +NetworkAddress ParseConnectionString(const std::string &connection_string, int default_port); +NetworkAddress ParseGameConnectionString(CompanyID *company, const std::string &connection_string, int default_port); + #endif /* NETWORK_INTERNAL_H */ |