summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-06-10 19:00:34 +0000
committersmatz <smatz@openttd.org>2009-06-10 19:00:34 +0000
commit35635c62482bb7955d3f3633b5e22712a2039ce7 (patch)
treec2a0c8482b35b5a1326578bdbb8533e3d9d50e34 /src/network
parent3eb8f643fb17b34826370823cdc65d2aaf0958e4 (diff)
downloadopenttd-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/network')
-rw-r--r--src/network/network.cpp4
-rw-r--r--src/network/network_client.cpp16
-rw-r--r--src/network/network_client.h3
-rw-r--r--src/network/network_func.h2
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);