|
@@ -34,6 +34,7 @@
|
|
|
#include <mutex>
|
|
|
#include <condition_variable>
|
|
|
|
|
|
#include "../fileio_func.h"
|
|
|
#include "../safeguards.h"
|
|
|
|
|
|
|
|
@@ -1566,6 +1567,9 @@ static void NetworkAutoCleanCompanies()
|
|
|
IConsolePrint(CC_INFO, "Auto-removed protection from company #{}.", c->index + 1);
|
|
|
_network_company_states[c->index].months_empty = 0;
|
|
|
NetworkServerUpdateCompanyPassworded(c->index, false);
|
|
|
if (_settings_client.network.save_password) {
|
|
|
NetworkSavePassword();
|
|
|
}
|
|
|
}
|
|
|
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
|
|
|
if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) {
|
|
@@ -1659,6 +1663,10 @@ void NetworkServerSetCompanyPassword(Com
|
|
|
}
|
|
|
|
|
|
NetworkServerUpdateCompanyPassworded(company_id, !_network_company_states[company_id].password.empty());
|
|
|
|
|
|
if (_settings_client.network.save_password) {
|
|
|
NetworkSavePassword();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -2076,6 +2084,9 @@ void NetworkServerNewCompany(const Compa
|
|
|
_network_company_states[c->index].months_empty = 0;
|
|
|
_network_company_states[c->index].password.clear();
|
|
|
NetworkServerUpdateCompanyPassworded(c->index, false);
|
|
|
if (_settings_client.network.save_password) {
|
|
|
NetworkSavePassword();
|
|
|
}
|
|
|
|
|
|
if (ci != nullptr) {
|
|
|
/* ci is nullptr when replaying, or for AIs. In neither case there is a client. */
|
|
@@ -2094,3 +2105,41 @@ void NetworkServerNewCompany(const Compa
|
|
|
NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, c->index + 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void NetworkSavePassword()
|
|
|
{
|
|
|
std::string password_file_name = std::to_string(_settings_game.game_creation.generation_seed) + ".pwd";
|
|
|
Debug(net, 0, "Saving company passwords to %s", password_file_name);
|
|
|
FILE* file_pointer = FioFOpenFile(password_file_name, "wb", SAVE_DIR);
|
|
|
if (file_pointer != nullptr) {
|
|
|
for (CompanyID l_company = (CompanyID)0; l_company < MAX_COMPANIES; l_company++) {
|
|
|
if (NetworkCompanyIsPassworded(l_company)) {
|
|
|
const char* password = _network_company_states[l_company].password.c_str();
|
|
|
fwrite(password, strlen(password), 1, file_pointer);
|
|
|
}
|
|
|
fwrite("\n", 1, 1, file_pointer);
|
|
|
}
|
|
|
fclose(file_pointer);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void NetworkLoadPassword()
|
|
|
{
|
|
|
std::string password_file_name = std::to_string(_settings_game.game_creation.generation_seed) + ".pwd";
|
|
|
FILE* file_pointer = FioFOpenFile(password_file_name, "rb", SAVE_DIR);
|
|
|
if (file_pointer != nullptr) {
|
|
|
Debug(net, 0, "Loading company passwords from %s", password_file_name);
|
|
|
for (CompanyID l_company = (CompanyID)0; l_company < MAX_COMPANIES; l_company++) {
|
|
|
char password[NETWORK_PASSWORD_LENGTH] = { '\0' };
|
|
|
fgets(password, NETWORK_PASSWORD_LENGTH, file_pointer);
|
|
|
if (strlen(password) > 1) {
|
|
|
_network_company_states[l_company].password = password;
|
|
|
NetworkServerUpdateCompanyPassworded(l_company, !_network_company_states[l_company].password.empty());
|
|
|
fseek(file_pointer, 1L, SEEK_CUR);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
Debug(net, 0, "Password file %s not found", password_file_name);
|
|
|
}
|
|
|
}
|