(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:
		@@ -1,6 +1,6 @@
 | 
			
		||||
.\"                                      Hey, EMACS: -*- nroff -*-
 | 
			
		||||
.\" Please adjust this date whenever revising the manpage.
 | 
			
		||||
.Dd Feb 05, 2009
 | 
			
		||||
.Dd Jun 10, 2009
 | 
			
		||||
.Dt OPENTTD 6
 | 
			
		||||
.Sh NAME
 | 
			
		||||
.Nm openttd
 | 
			
		||||
@@ -20,6 +20,8 @@
 | 
			
		||||
.Op Fl l Ar host[:port]
 | 
			
		||||
.Op Fl m Ar driver
 | 
			
		||||
.Op Fl n Ar host[:port][#player]
 | 
			
		||||
.Op Fl p Ar password
 | 
			
		||||
.Op Fl P Ar password
 | 
			
		||||
.Op Fl r Ar widthxheight
 | 
			
		||||
.Op Fl s Ar driver
 | 
			
		||||
.Op Fl t Ar year
 | 
			
		||||
@@ -72,6 +74,12 @@ Set the music driver, see
 | 
			
		||||
.Fl h
 | 
			
		||||
.It Fl n Ar host[:port][#player]
 | 
			
		||||
Join a network game, optionally specify player to play as and port to connect to
 | 
			
		||||
.It Fl p Ar password
 | 
			
		||||
Password used to join server. Only useful with
 | 
			
		||||
.Fl n
 | 
			
		||||
.It Fl P Ar password
 | 
			
		||||
Password used to join company. Only useful with
 | 
			
		||||
.Fl n
 | 
			
		||||
.It Fl r Ar widthxheight
 | 
			
		||||
Set the resolution
 | 
			
		||||
.It Fl s Ar driver
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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 */
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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 */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user