diff options
author | smatz <smatz@openttd.org> | 2009-06-10 19:00:34 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-06-10 19:00:34 +0000 |
commit | 35635c62482bb7955d3f3633b5e22712a2039ce7 (patch) | |
tree | c2a0c8482b35b5a1326578bdbb8533e3d9d50e34 /src | |
parent | 3eb8f643fb17b34826370823cdc65d2aaf0958e4 (diff) | |
download | openttd-35635c62482bb7955d3f3633b5e22712a2039ce7.tar.xz |
(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)
Diffstat (limited to 'src')
-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 | ||||
-rw-r--r-- | src/openttd.cpp | 14 |
5 files changed, 33 insertions, 6 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); diff --git a/src/openttd.cpp b/src/openttd.cpp index 50efa4f8c..e60325c8d 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -160,6 +160,8 @@ static void ShowHelp() " -G seed = Set random seed\n" #if defined(ENABLE_NETWORK) " -n [ip:port#company]= Start networkgame\n" + " -p password = Password to join server\n" + " -P password = Password to join company\n" " -D [ip][:port] = Start dedicated server\n" " -l ip[:port] = Redirect DEBUG()\n" #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32) @@ -406,6 +408,8 @@ int ttd_main(int argc, char *argv[]) char *debuglog_conn = NULL; char *dedicated_host = NULL; uint16 dedicated_port = 0; + char *join_server_password = NULL; + char *join_company_password = NULL; #endif /* ENABLE_NETWORK */ _game_mode = GM_MENU; @@ -418,7 +422,7 @@ int ttd_main(int argc, char *argv[]) * a letter means: it accepts that param (e.g.: -h) * a ':' behind it means: it need a param (e.g.: -m<driver>) * a '::' behind it means: it can optional have a param (e.g.: -d<debug>) */ - optformat = "m:s:v:b:hD::n::ei::I:t:d::r:g::G:c:xl:" + optformat = "m:s:v:b:hD::n::ei::I:t:d::r:g::G:c:xl:p:P:" #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32) "f" #endif @@ -463,6 +467,12 @@ int ttd_main(int argc, char *argv[]) case 'l': debuglog_conn = mgo.opt; break; + case 'p': + join_server_password = mgo.opt; + break; + case 'P': + join_company_password = mgo.opt; + break; #endif /* ENABLE_NETWORK */ case 'r': ParseResolution(&resolution, mgo.opt); break; case 't': startyear = atoi(mgo.opt); break; @@ -694,7 +704,7 @@ int ttd_main(int argc, char *argv[]) LoadIntroGame(); _switch_mode = SM_NONE; - NetworkClientConnectGame(NetworkAddress(network_conn, rport), join_as); + NetworkClientConnectGame(NetworkAddress(network_conn, rport), join_as, join_server_password, join_company_password); } } #endif /* ENABLE_NETWORK */ |