diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network.cpp | 4 | ||||
-rw-r--r-- | src/network/network_client.cpp | 16 | ||||
-rw-r--r-- | src/network/network_client.h | 3 | ||||
-rw-r--r-- | src/network/network_func.h | 2 |
4 files changed, 21 insertions, 4 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index 90f048b2c..7646278ca 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -720,7 +720,7 @@ public: /* Used by clients, to connect to a server */ -void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as) +void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const char *join_server_password, const char *join_company_password) { if (!_network_available) return; @@ -729,6 +729,8 @@ void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as) strecpy(_settings_client.network.last_host, address.GetHostname(), lastof(_settings_client.network.last_host)); _settings_client.network.last_port = address.GetPort(); _network_join_as = join_as; + _network_join_server_password = join_server_password; + _network_join_company_password = join_company_password; NetworkDisconnect(); NetworkInitialize(); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index e31ecc6bc..ae1f59530 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -47,6 +47,11 @@ static uint8 _network_server_max_spectators; /** Who would we like to join as. */ CompanyID _network_join_as; +/** Login password from -p argument */ +const char *_network_join_server_password = NULL; +/** Company password from -P argument */ +const char *_network_join_company_password = NULL; + /** Make sure the unique ID length is the same as a md5 hash. */ assert_compile(NETWORK_UNIQUE_ID_LENGTH == 16 * 2 + 1); @@ -509,15 +514,22 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD) { NetworkPasswordType type = (NetworkPasswordType)p->Recv_uint8(); + const char *password = _network_join_server_password; + switch (type) { case NETWORK_COMPANY_PASSWORD: /* Initialize the password hash salting variables. */ _password_game_seed = p->Recv_uint32(); p->Recv_string(_password_server_unique_id, sizeof(_password_server_unique_id)); if (MY_CLIENT->HasClientQuit()) return NETWORK_RECV_STATUS_MALFORMED_PACKET; - + password = _network_join_company_password; + /* FALL THROUGH */ case NETWORK_GAME_PASSWORD: - ShowNetworkNeedPassword(type); + if (StrEmpty(password)) { + ShowNetworkNeedPassword(type); + } else { + SEND_COMMAND(PACKET_CLIENT_PASSWORD)(type, password); + } return NETWORK_RECV_STATUS_OKAY; default: return NETWORK_RECV_STATUS_MALFORMED_PACKET; diff --git a/src/network/network_client.h b/src/network/network_client.h index f40ccf518..7e4375684 100644 --- a/src/network/network_client.h +++ b/src/network/network_client.h @@ -25,6 +25,9 @@ void NetworkClient_Connected(); extern CompanyID _network_join_as; +extern const char *_network_join_server_password; +extern const char *_network_join_company_password; + #endif /* ENABLE_NETWORK */ #endif /* NETWORK_CLIENT_H */ diff --git a/src/network/network_func.h b/src/network/network_func.h index b8ca77abb..e59635fef 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -39,7 +39,7 @@ void NetworkStartDebugLog(NetworkAddress address); void NetworkPopulateCompanyStats(NetworkCompanyStats *stats); void NetworkUpdateClientInfo(ClientID client_id); -void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as); +void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const char *join_server_password = NULL, const char *join_company_password = NULL); 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); |