summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-01 14:21:33 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-01 18:30:08 +0200
commit83985fe26f1ad87df709f122f74e5d50485095fa (patch)
tree9394e4f04a96f49b8d70dae117810e737cc1d323 /src
parent39c51c35f4566553ec3c6c273c2642d796070521 (diff)
downloadopenttd-83985fe26f1ad87df709f122f74e5d50485095fa.tar.xz
Codechange: Move join information into a single structure
Diffstat (limited to 'src')
-rw-r--r--src/network/network.cpp6
-rw-r--r--src/network/network_client.cpp21
-rw-r--r--src/network/network_client.h11
3 files changed, 19 insertions, 19 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 22ac5dc74..32fc4dec9 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -762,9 +762,9 @@ bool NetworkClientConnectGame(NetworkAddress &address, CompanyID join_as, const
strecpy(_settings_client.network.last_joined, address.GetAddressAsString(false).c_str(), lastof(_settings_client.network.last_joined));
- _network_join_as = join_as;
- _network_join_server_password = join_server_password;
- _network_join_company_password = join_company_password;
+ _network_join.company = 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 f73c8be52..ceb146333 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -326,13 +326,8 @@ 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;
-
-/** Login password from -p argument */
-const char *_network_join_server_password = nullptr;
-/** Company password from -P argument */
-const char *_network_join_company_password = nullptr;
+/** Information about the game to join to. */
+NetworkJoinInfo _network_join;
/** Make sure the server ID length is the same as a md5 hash. */
static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
@@ -372,7 +367,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin()
p->Send_string(GetNetworkRevisionString());
p->Send_uint32(_openttd_newgrf_version);
p->Send_string(_settings_client.network.client_name); // Client name
- p->Send_uint8 (_network_join_as); // PlayAs
+ p->Send_uint8 (_network_join.company); // PlayAs
p->Send_uint8 (0); // Used to be language
my_client->SendPacket(p);
return NETWORK_RECV_STATUS_OKAY;
@@ -804,7 +799,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSW
if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_GAME) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
this->status = STATUS_AUTH_GAME;
- const char *password = _network_join_server_password;
+ const char *password = _network_join.server_password;
if (!StrEmpty(password)) {
return SendGamePassword(password);
}
@@ -823,7 +818,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PA
p->Recv_string(_password_server_id, sizeof(_password_server_id));
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
- const char *password = _network_join_company_password;
+ const char *password = _network_join.company_password;
if (!StrEmpty(password)) {
return SendCompanyPassword(password);
}
@@ -945,10 +940,10 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
/* 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_join_as == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_join_as)) {
+ if (_network_join.company == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_join.company)) {
SetLocalCompany(COMPANY_SPECTATOR);
- if (_network_join_as != COMPANY_SPECTATOR) {
+ if (_network_join.company != 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;
@@ -957,7 +952,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
}
} else {
/* take control over an existing company */
- SetLocalCompany(_network_join_as);
+ SetLocalCompany(_network_join.company);
}
return NETWORK_RECV_STATUS_OKAY;
diff --git a/src/network/network_client.h b/src/network/network_client.h
index 40b8eedf9..28d2d0021 100644
--- a/src/network/network_client.h
+++ b/src/network/network_client.h
@@ -112,9 +112,14 @@ typedef ClientNetworkGameSocketHandler MyClient;
void NetworkClient_Connected();
void NetworkClientSetCompanyPassword(const char *password);
-extern CompanyID _network_join_as;
+/** Information required to join a server. */
+struct NetworkJoinInfo {
+ NetworkJoinInfo() : company(COMPANY_SPECTATOR), server_password(nullptr), company_password(nullptr) {}
+ CompanyID company; ///< The company to join.
+ const char *server_password; ///< The password of the server to join.
+ const char *company_password; ///< The password of the company to join.
+};
-extern const char *_network_join_server_password;
-extern const char *_network_join_company_password;
+extern NetworkJoinInfo _network_join;
#endif /* NETWORK_CLIENT_H */