Changeset - r11951:a522cb996935
[Not reviewed]
master
0 11 0
rubidium - 16 years ago 2009-05-19 21:20:14
rubidium@openttd.org
(svn r16360) -Codechange: don't use _network_playas as a 'second' _local_company, but only as a storage location for the company you want to join in MP.
11 files changed with 38 insertions and 58 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -722,10 +722,10 @@ CommandCost CmdCompanyCtrl(TileIndex til
 

	
 
			/* Joining Client:
 
			 * _local_company: COMPANY_SPECTATOR
 
			 * _network_playas/cid = requested company/clientid
 
			 * cid = clientid
 
			 *
 
			 * Other client(s)/server:
 
			 * _local_company/_network_playas: what they play as
 
			 * _local_company: what they play as
 
			 * cid = requested company/company of joining client */
 
			ClientID cid = (ClientID)p2;
 

	
 
@@ -744,8 +744,6 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
				if (_network_server) {
 
					ci->client_playas = COMPANY_SPECTATOR;
 
					NetworkUpdateClientInfo(ci->client_id);
 
				} else if (_local_company == COMPANY_SPECTATOR) {
 
					_network_playas = COMPANY_SPECTATOR;
 
				}
 
				break;
 
			}
src/console_cmds.cpp
Show inline comments
 
@@ -769,11 +769,6 @@ DEF_CONSOLE_CMD(ConNetworkClients)
 

	
 
DEF_CONSOLE_CMD(ConNetworkConnect)
 
{
 
	char *ip;
 
	const char *port = NULL;
 
	const char *company = NULL;
 
	uint16 rport;
 

	
 
	if (argc == 0) {
 
		IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
 
		IConsoleHelp("IP can contain port and company: 'IP[[#Company]:Port]', eg: 'server.ottd.org#2:443'");
 
@@ -784,23 +779,25 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
 
	if (argc < 2) return false;
 
	if (_networking) NetworkDisconnect(); // we are in network-mode, first close it!
 

	
 
	ip = argv[1];
 
	const char *port = NULL;
 
	const char *company = NULL;
 
	char *ip = argv[1];
 
	/* Default settings: default port and new company */
 
	rport = NETWORK_DEFAULT_PORT;
 
	_network_playas = COMPANY_NEW_COMPANY;
 
	uint16 rport = NETWORK_DEFAULT_PORT;
 
	CompanyID join_as = COMPANY_NEW_COMPANY;
 

	
 
	ParseConnectionString(&company, &port, ip);
 

	
 
	IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
 
	if (company != NULL) {
 
		_network_playas = (CompanyID)atoi(company);
 
		IConsolePrintF(CC_DEFAULT, "    company-no: %d", _network_playas);
 
		join_as = (CompanyID)atoi(company);
 
		IConsolePrintF(CC_DEFAULT, "    company-no: %d", join_as);
 

	
 
		/* From a user pov 0 is a new company, internally it's different and all
 
		 * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
 
		if (_network_playas != COMPANY_SPECTATOR) {
 
			if (_network_playas > MAX_COMPANIES) return false;
 
			_network_playas--;
 
		if (join_as != COMPANY_SPECTATOR) {
 
			if (join_as > MAX_COMPANIES) return false;
 
			join_as--;
 
		}
 
	}
 
	if (port != NULL) {
 
@@ -808,7 +805,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
 
		IConsolePrintF(CC_DEFAULT, "    port: %s", port);
 
	}
 

	
 
	NetworkClientConnectGame(NetworkAddress(ip, rport));
 
	NetworkClientConnectGame(NetworkAddress(ip, rport), join_as);
 

	
 
	return true;
 
}
src/economy.cpp
Show inline comments
 
@@ -448,7 +448,6 @@ static void ChangeNetworkOwner(Owner cur
 
	if (!_networking) return;
 

	
 
	if (current_owner == _local_company) {
 
		_network_playas = new_owner;
 
		SetLocalCompany(new_owner);
 
	}
 

	
src/network/network.cpp
Show inline comments
 
@@ -714,7 +714,7 @@ public:
 

	
 

	
 
/* Used by clients, to connect to a server */
 
void NetworkClientConnectGame(NetworkAddress address)
 
void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as)
 
{
 
	if (!_network_available) return;
 

	
 
@@ -722,6 +722,7 @@ void NetworkClientConnectGame(NetworkAdd
 

	
 
	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;
 

	
 
	NetworkDisconnect();
 
	NetworkInitialize();
 
@@ -778,9 +779,6 @@ bool NetworkServerStart()
 
	_last_sync_frame = 0;
 
	_network_own_client_id = CLIENT_ID_SERVER;
 

	
 
	/* Non-dedicated server will always be company #1 */
 
	if (!_network_dedicated) _network_playas = COMPANY_FIRST;
 

	
 
	_network_clients_connected = 0;
 

	
 
	NetworkInitGameInfo();
 
@@ -1126,6 +1124,3 @@ bool IsNetworkCompatibleVersion(const ch
 
}
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
/* NOTE: this variable needs to be always available */
 
CompanyID _network_playas;
src/network/network.h
Show inline comments
 
@@ -33,8 +33,4 @@ static inline void NetworkDrawChatMessag
 
#define _is_network_server 0
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
/** As which company do we play? */
 
extern CompanyID _network_playas;
 

	
 
#endif /* NETWORK_H */
src/network/network_client.cpp
Show inline comments
 
@@ -44,6 +44,9 @@ static uint8 _network_server_max_compani
 
/** Maximum number of spectators of the currently joined server. */
 
static uint8 _network_server_max_spectators;
 

	
 
/** Who would we like to join as. */
 
CompanyID _network_join_as;
 

	
 
/** Make sure the unique ID length is the same as a md5 hash. */
 
assert_compile(NETWORK_UNIQUE_ID_LENGTH == 16 * 2 + 1);
 

	
 
@@ -135,7 +138,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JO
 
	p = NetworkSend_Init(PACKET_CLIENT_JOIN);
 
	p->Send_string(_openttd_revision);
 
	p->Send_string(_settings_client.network.client_name); // Client name
 
	p->Send_uint8 (_network_playas);      // PlayAs
 
	p->Send_uint8 (_network_join_as);     // PlayAs
 
	p->Send_uint8 (NETLANG_ANY);          // Language
 
	p->Send_string(_settings_client.network.network_id);
 
	MY_CLIENT->Send_Packet(p);
 
@@ -406,9 +409,6 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 

	
 
	if (MY_CLIENT->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
 

	
 
	/* Do we receive a change of data? Most likely we changed playas */
 
	if (client_id == _network_own_client_id) _network_playas = playas;
 

	
 
	ci = NetworkFindClientInfoFromClientID(client_id);
 
	if (ci != NULL) {
 
		if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
 
@@ -620,10 +620,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 

	
 
		/* New company/spectator (invalid company) or company we want to join is not active
 
		 * Switch local company to spectator and await the server's judgement */
 
		if (_network_playas == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_playas)) {
 
		if (_network_join_as == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_join_as)) {
 
			SetLocalCompany(COMPANY_SPECTATOR);
 

	
 
			if (_network_playas != COMPANY_SPECTATOR) {
 
			if (_network_join_as != COMPANY_SPECTATOR) {
 
				/* We have arrived and ready to start playing; send a command to make a new company;
 
				 * the server will give us a client-id and let us in */
 
				_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
 
@@ -632,7 +632,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
			}
 
		} else {
 
			/* take control over an existing company */
 
			SetLocalCompany(_network_playas);
 
			SetLocalCompany(_network_join_as);
 
		}
 
	}
 

	
 
@@ -845,7 +845,6 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
	if (!Company::IsValidID(company_id)) company_id = COMPANY_SPECTATOR;
 

	
 
	if (client_id == _network_own_client_id) {
 
		_network_playas = company_id;
 
		SetLocalCompany(company_id);
 
	}
 

	
src/network/network_client.h
Show inline comments
 
@@ -23,6 +23,8 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLI
 
NetworkRecvStatus NetworkClient_ReadPackets(NetworkClientSocket *cs);
 
void NetworkClient_Connected();
 

	
 
extern CompanyID _network_join_as;
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
#endif /* NETWORK_CLIENT_H */
src/network/network_func.h
Show inline comments
 
@@ -39,7 +39,7 @@ void NetworkStartDebugLog(NetworkAddress
 
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
 

	
 
void NetworkUpdateClientInfo(ClientID client_id);
 
void NetworkClientConnectGame(NetworkAddress address);
 
void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as);
 
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);
src/network/network_gui.cpp
Show inline comments
 
@@ -23,6 +23,7 @@
 
#include "../querystring_gui.h"
 
#include "../sortlist_type.h"
 
#include "../company_base.h"
 
#include "../company_func.h"
 

	
 
#include "table/strings.h"
 
#include "../table/sprites.h"
 
@@ -1534,18 +1535,15 @@ struct NetworkLobbyWindow : public Windo
 

	
 
			case NLWW_JOIN:     // Join company
 
				/* Button can be clicked only when it is enabled */
 
				_network_playas = this->company;
 
				NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
 
				NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port), this->company);
 
				break;
 

	
 
			case NLWW_NEW:      // New company
 
				_network_playas = COMPANY_NEW_COMPANY;
 
				NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
 
				NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port), COMPANY_NEW_COMPANY);
 
				break;
 

	
 
			case NLWW_SPECTATE: // Spectate game
 
				_network_playas = COMPANY_SPECTATOR;
 
				NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
 
				NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port), COMPANY_SPECTATOR);
 
				break;
 

	
 
			case NLWW_REFRESH:  // Refresh
 
@@ -1817,7 +1815,7 @@ struct NetworkClientListPopupWindow : Wi
 

	
 
		if (_network_own_client_id != ci->client_id) {
 
			/* We are no spectator and the company we want to give money to is no spectator and money gifts are allowed */
 
			if (Company::IsValidID(_network_playas) && Company::IsValidID(ci->client_playas) && _settings_game.economy.give_money) {
 
			if (Company::IsValidID(_local_company) && Company::IsValidID(ci->client_playas) && _settings_game.economy.give_money) {
 
				GetString(this->action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(this->action[i]));
 
				this->proc[i++] = &ClientList_GiveMoney;
 
			}
src/openttd.cpp
Show inline comments
 
@@ -675,26 +675,24 @@ int ttd_main(int argc, char *argv[])
 
		if (network_conn != NULL) {
 
			const char *port = NULL;
 
			const char *company = NULL;
 
			uint16 rport;
 

	
 
			rport = NETWORK_DEFAULT_PORT;
 
			_network_playas = COMPANY_NEW_COMPANY;
 
			uint16 rport = NETWORK_DEFAULT_PORT;
 
			CompanyID join_as = COMPANY_NEW_COMPANY;
 

	
 
			ParseConnectionString(&company, &port, network_conn);
 

	
 
			if (company != NULL) {
 
				_network_playas = (CompanyID)atoi(company);
 
				join_as = (CompanyID)atoi(company);
 

	
 
				if (_network_playas != COMPANY_SPECTATOR) {
 
					_network_playas--;
 
					if (_network_playas >= MAX_COMPANIES) return false;
 
				if (join_as != COMPANY_SPECTATOR) {
 
					join_as--;
 
					if (join_as >= MAX_COMPANIES) return false;
 
				}
 
			}
 
			if (port != NULL) rport = atoi(port);
 

	
 
			LoadIntroGame();
 
			_switch_mode = SM_NONE;
 
			NetworkClientConnectGame(NetworkAddress(network_conn, rport));
 
			NetworkClientConnectGame(NetworkAddress(network_conn, rport), join_as);
 
		}
 
	}
 
#endif /* ENABLE_NETWORK */
 
@@ -1197,8 +1195,7 @@ void GameLoop()
 
		if (_network_reconnect > 0 && --_network_reconnect == 0) {
 
			/* This means that we want to reconnect to the last host
 
			 * We do this here, because it means that the network is really closed */
 
			_network_playas = COMPANY_SPECTATOR;
 
			NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
 
			NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port), COMPANY_SPECTATOR);
 
		}
 
		/* Singleplayer */
 
		StateGameLoop();
src/video/dedicated_v.cpp
Show inline comments
 
@@ -255,7 +255,6 @@ void VideoDriver_Dedicated::MainLoop()
 
	/* Load the dedicated server stuff */
 
	_is_network_server = true;
 
	_network_dedicated = true;
 
	_network_playas = COMPANY_SPECTATOR;
 
	_local_company = COMPANY_SPECTATOR;
 

	
 
	/* If SwitchMode is SM_LOAD, it means that the user used the '-g' options */
0 comments (0 inline, 0 general)