mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: [Network] Make company state password std::string
This commit is contained in:
parent
1da0ba95b2
commit
98283116fa
|
@ -1635,7 +1635,7 @@ DEF_CONSOLE_CMD(ConCompanies)
|
||||||
if (c->is_ai) {
|
if (c->is_ai) {
|
||||||
password_state = "AI";
|
password_state = "AI";
|
||||||
} else if (_network_server) {
|
} else if (_network_server) {
|
||||||
password_state = StrEmpty(_network_company_states[c->index].password) ? "unprotected" : "protected";
|
password_state = _network_company_states[c->index].password.empty() ? "unprotected" : "protected";
|
||||||
}
|
}
|
||||||
|
|
||||||
char colour[512];
|
char colour[512];
|
||||||
|
|
|
@ -601,7 +601,7 @@ void NetworkClose(bool close_admins)
|
||||||
|
|
||||||
NetworkFreeLocalCommandQueue();
|
NetworkFreeLocalCommandQueue();
|
||||||
|
|
||||||
free(_network_company_states);
|
delete[] _network_company_states;
|
||||||
_network_company_states = nullptr;
|
_network_company_states = nullptr;
|
||||||
|
|
||||||
InitializeNetworkPools(close_admins);
|
InitializeNetworkPools(close_admins);
|
||||||
|
@ -896,7 +896,7 @@ bool NetworkServerStart()
|
||||||
DEBUG(net, 5, "Starting listeners for incoming server queries");
|
DEBUG(net, 5, "Starting listeners for incoming server queries");
|
||||||
NetworkUDPServerListen();
|
NetworkUDPServerListen();
|
||||||
|
|
||||||
_network_company_states = CallocT<NetworkCompanyState>(MAX_COMPANIES);
|
_network_company_states = new NetworkCompanyState[MAX_COMPANIES];
|
||||||
_network_server = true;
|
_network_server = true;
|
||||||
_networking = true;
|
_networking = true;
|
||||||
_frame_counter = 0;
|
_frame_counter = 0;
|
||||||
|
|
|
@ -863,7 +863,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED
|
||||||
return this->SendNeedGamePassword();
|
return this->SendNeedGamePassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Company::IsValidID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
|
if (Company::IsValidID(ci->client_playas) && !_network_company_states[ci->client_playas].password.empty()) {
|
||||||
return this->SendNeedCompanyPassword();
|
return this->SendNeedCompanyPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -964,7 +964,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(P
|
||||||
}
|
}
|
||||||
|
|
||||||
const NetworkClientInfo *ci = this->GetInfo();
|
const NetworkClientInfo *ci = this->GetInfo();
|
||||||
if (Company::IsValidID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
|
if (Company::IsValidID(ci->client_playas) && !_network_company_states[ci->client_playas].password.empty()) {
|
||||||
return this->SendNeedCompanyPassword();
|
return this->SendNeedCompanyPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -985,8 +985,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWOR
|
||||||
* Also, check the company is still valid - client could be moved to spectators
|
* Also, check the company is still valid - client could be moved to spectators
|
||||||
* in the middle of the authorization process */
|
* in the middle of the authorization process */
|
||||||
CompanyID playas = this->GetInfo()->client_playas;
|
CompanyID playas = this->GetInfo()->client_playas;
|
||||||
if (Company::IsValidID(playas) && !StrEmpty(_network_company_states[playas].password) &&
|
if (Company::IsValidID(playas) && !_network_company_states[playas].password.empty() &&
|
||||||
strcmp(password, _network_company_states[playas].password) != 0) {
|
_network_company_states[playas].password.compare(password) != 0) {
|
||||||
/* Password is invalid */
|
/* Password is invalid */
|
||||||
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
|
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
|
||||||
}
|
}
|
||||||
|
@ -1467,13 +1467,13 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p)
|
||||||
if (company_id != COMPANY_SPECTATOR && !Company::IsValidHumanID(company_id)) return NETWORK_RECV_STATUS_OKAY;
|
if (company_id != COMPANY_SPECTATOR && !Company::IsValidHumanID(company_id)) return NETWORK_RECV_STATUS_OKAY;
|
||||||
|
|
||||||
/* Check if we require a password for this company */
|
/* Check if we require a password for this company */
|
||||||
if (company_id != COMPANY_SPECTATOR && !StrEmpty(_network_company_states[company_id].password)) {
|
if (company_id != COMPANY_SPECTATOR && !_network_company_states[company_id].password.empty()) {
|
||||||
/* we need a password from the client - should be in this packet */
|
/* we need a password from the client - should be in this packet */
|
||||||
char password[NETWORK_PASSWORD_LENGTH];
|
char password[NETWORK_PASSWORD_LENGTH];
|
||||||
p->Recv_string(password, sizeof(password));
|
p->Recv_string(password, sizeof(password));
|
||||||
|
|
||||||
/* Incorrect password sent, return! */
|
/* Incorrect password sent, return! */
|
||||||
if (strcmp(password, _network_company_states[company_id].password) != 0) {
|
if (_network_company_states[company_id].password.compare(password) != 0) {
|
||||||
DEBUG(net, 2, "Wrong password from client-id #%d for company #%d", this->client_id, company_id + 1);
|
DEBUG(net, 2, "Wrong password from client-id #%d for company #%d", this->client_id, company_id + 1);
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
@ -1523,7 +1523,7 @@ void NetworkSocketHandler::SendCompanyInformation(Packet *p, const Company *c, c
|
||||||
p->Send_uint16(c->old_economy[0].performance_history);
|
p->Send_uint16(c->old_economy[0].performance_history);
|
||||||
|
|
||||||
/* Send 1 if there is a password for the company else send 0 */
|
/* Send 1 if there is a password for the company else send 0 */
|
||||||
p->Send_bool (!StrEmpty(_network_company_states[c->index].password));
|
p->Send_bool (!_network_company_states[c->index].password.empty());
|
||||||
|
|
||||||
for (uint i = 0; i < NETWORK_VEH_END; i++) {
|
for (uint i = 0; i < NETWORK_VEH_END; i++) {
|
||||||
p->Send_uint16(stats->num_vehicle[i]);
|
p->Send_uint16(stats->num_vehicle[i]);
|
||||||
|
@ -1660,15 +1660,15 @@ static void NetworkAutoCleanCompanies()
|
||||||
_network_company_states[c->index].months_empty++;
|
_network_company_states[c->index].months_empty++;
|
||||||
|
|
||||||
/* Is the company empty for autoclean_unprotected-months, and is there no protection? */
|
/* Is the company empty for autoclean_unprotected-months, and is there no protection? */
|
||||||
if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) {
|
if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && _network_company_states[c->index].password.empty()) {
|
||||||
/* Shut the company down */
|
/* Shut the company down */
|
||||||
DoCommandP(0, CCA_DELETE | c->index << 16 | CRR_AUTOCLEAN << 24, 0, CMD_COMPANY_CTRL);
|
DoCommandP(0, CCA_DELETE | c->index << 16 | CRR_AUTOCLEAN << 24, 0, CMD_COMPANY_CTRL);
|
||||||
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1);
|
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1);
|
||||||
}
|
}
|
||||||
/* Is the company empty for autoclean_protected-months, and there is a protection? */
|
/* Is the company empty for autoclean_protected-months, and there is a protection? */
|
||||||
if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !StrEmpty(_network_company_states[c->index].password)) {
|
if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !_network_company_states[c->index].password.empty()) {
|
||||||
/* Unprotect the company */
|
/* Unprotect the company */
|
||||||
_network_company_states[c->index].password[0] = '\0';
|
_network_company_states[c->index].password.clear();
|
||||||
IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", c->index + 1);
|
IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", c->index + 1);
|
||||||
_network_company_states[c->index].months_empty = 0;
|
_network_company_states[c->index].months_empty = 0;
|
||||||
NetworkServerUpdateCompanyPassworded(c->index, false);
|
NetworkServerUpdateCompanyPassworded(c->index, false);
|
||||||
|
@ -1765,8 +1765,8 @@ void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password,
|
||||||
password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id.c_str(), _settings_game.game_creation.generation_seed);
|
password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id.c_str(), _settings_game.game_creation.generation_seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
strecpy(_network_company_states[company_id].password, password, lastof(_network_company_states[company_id].password));
|
_network_company_states[company_id].password = password;
|
||||||
NetworkServerUpdateCompanyPassworded(company_id, !StrEmpty(_network_company_states[company_id].password));
|
NetworkServerUpdateCompanyPassworded(company_id, !_network_company_states[company_id].password.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2188,7 +2188,7 @@ void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci)
|
||||||
if (!_network_server) return;
|
if (!_network_server) return;
|
||||||
|
|
||||||
_network_company_states[c->index].months_empty = 0;
|
_network_company_states[c->index].months_empty = 0;
|
||||||
_network_company_states[c->index].password[0] = '\0';
|
_network_company_states[c->index].password.clear();
|
||||||
NetworkServerUpdateCompanyPassworded(c->index, false);
|
NetworkServerUpdateCompanyPassworded(c->index, false);
|
||||||
|
|
||||||
if (ci != nullptr) {
|
if (ci != nullptr) {
|
||||||
|
|
|
@ -62,8 +62,8 @@ struct NetworkCompanyStats {
|
||||||
|
|
||||||
/** Some state information of a company, especially for servers */
|
/** Some state information of a company, especially for servers */
|
||||||
struct NetworkCompanyState {
|
struct NetworkCompanyState {
|
||||||
char password[NETWORK_PASSWORD_LENGTH]; ///< The password for the company
|
std::string password; ///< The password for the company
|
||||||
uint16 months_empty; ///< How many months the company is empty
|
uint16 months_empty; ///< How many months the company is empty
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NetworkClientInfo;
|
struct NetworkClientInfo;
|
||||||
|
|
Loading…
Reference in New Issue