mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-28 08:59:09 +00:00
(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.
This commit is contained in:
@@ -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(NetworkAddress address)
|
||||
|
||||
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 char *other)
|
||||
}
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
/* NOTE: this variable needs to be always available */
|
||||
CompanyID _network_playas;
|
||||
|
@@ -33,8 +33,4 @@ static inline void NetworkDrawChatMessage() {}
|
||||
#define _is_network_server 0
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
/** As which company do we play? */
|
||||
extern CompanyID _network_playas;
|
||||
|
||||
#endif /* NETWORK_H */
|
||||
|
@@ -44,6 +44,9 @@ static uint8 _network_server_max_companies;
|
||||
/** 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_JOIN)
|
||||
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_CLIENT_INFO)
|
||||
|
||||
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_MAP)
|
||||
|
||||
/* 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_MAP)
|
||||
}
|
||||
} else {
|
||||
/* take control over an existing company */
|
||||
SetLocalCompany(_network_playas);
|
||||
SetLocalCompany(_network_join_as);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -845,7 +845,6 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MOVE)
|
||||
if (!Company::IsValidID(company_id)) company_id = COMPANY_SPECTATOR;
|
||||
|
||||
if (client_id == _network_own_client_id) {
|
||||
_network_playas = company_id;
|
||||
SetLocalCompany(company_id);
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,8 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_MOVE)(CompanyID company, const char
|
||||
NetworkRecvStatus NetworkClient_ReadPackets(NetworkClientSocket *cs);
|
||||
void NetworkClient_Connected();
|
||||
|
||||
extern CompanyID _network_join_as;
|
||||
|
||||
#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);
|
||||
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);
|
||||
|
@@ -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 Window {
|
||||
|
||||
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 : Window {
|
||||
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user