(svn r16555) -Feature [FS#570]: ability to enter server and company password via command line when joining a server (based on patch by Progman, Ammler and planetmaker)

This commit is contained in:
smatz
2009-06-10 19:00:34 +00:00
parent 2d841c66e5
commit 7d4d3850cb
6 changed files with 42 additions and 7 deletions

View File

@@ -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();

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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);