# HG changeset patch # User Rubidium # Date 2024-02-03 19:27:25 # Node ID 54f1f97dad9a4d34299bbbedd1ef65dee33ecb93 # Parent e44cabba94f2f26505aca05308cbb9d45563a770 Codechange: cascade through SendNeedGame/CompanyPassword functions, instead of duplicating logic for determining whether to call these functions diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -423,6 +423,11 @@ NetworkRecvStatus ServerNetworkGameSocke /** Request the game password. */ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword() { + if (_settings_client.network.server_password.empty()) { + /* Do not actually need a game password, continue with the company password. */ + return this->SendNeedCompanyPassword(); + } + Debug(net, 9, "client[{}] SendNeedGamePassword()", this->client_id); /* Invalid packet when status is STATUS_AUTH_GAME or higher */ @@ -441,6 +446,11 @@ NetworkRecvStatus ServerNetworkGameSocke /** Request the company password. */ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword() { + NetworkClientInfo *ci = this->GetInfo(); + if (!Company::IsValidID(ci->client_playas) || _network_company_states[ci->client_playas].password.empty()) { + return this->SendWelcome(); + } + Debug(net, 9, "client[{}] SendNeedCompanyPassword()", this->client_id); /* Invalid packet when status is STATUS_AUTH_COMPANY or higher */ @@ -845,18 +855,7 @@ NetworkRecvStatus ServerNetworkGameSocke Debug(net, 9, "client[{}] Receive_CLIENT_NEWGRFS_CHECKED()", this->client_id); - NetworkClientInfo *ci = this->GetInfo(); - - /* We now want a password from the client else we do not allow them in! */ - if (!_settings_client.network.server_password.empty()) { - return this->SendNeedGamePassword(); - } - - if (Company::IsValidID(ci->client_playas) && !_network_company_states[ci->client_playas].password.empty()) { - return this->SendNeedCompanyPassword(); - } - - return this->SendWelcome(); + return this->SendNeedGamePassword(); } NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p) @@ -930,8 +929,8 @@ NetworkRecvStatus ServerNetworkGameSocke this->status = STATUS_NEWGRFS_CHECK; if (_grfconfig == nullptr) { - /* Behave as if we received PACKET_CLIENT_NEWGRFS_CHECKED */ - return this->Receive_CLIENT_NEWGRFS_CHECKED(nullptr); + /* Continue asking for the game password. */ + return this->SendNeedGamePassword(); } return this->SendNewGRFCheck(); @@ -954,13 +953,7 @@ NetworkRecvStatus ServerNetworkGameSocke return this->SendError(NETWORK_ERROR_WRONG_PASSWORD); } - const NetworkClientInfo *ci = this->GetInfo(); - if (Company::IsValidID(ci->client_playas) && !_network_company_states[ci->client_playas].password.empty()) { - return this->SendNeedCompanyPassword(); - } - - /* Valid password, allow user */ - return this->SendWelcome(); + return this->SendNeedCompanyPassword(); } NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet *p)