mirror of https://github.com/OpenTTD/OpenTTD
Codechange: move passwords in settings to std::string
parent
f219354f89
commit
c73d64adf9
|
@ -843,8 +843,8 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
if (client_id == _network_own_client_id) {
|
if (client_id == _network_own_client_id) {
|
||||||
assert(_local_company == COMPANY_SPECTATOR);
|
assert(_local_company == COMPANY_SPECTATOR);
|
||||||
SetLocalCompany(c->index);
|
SetLocalCompany(c->index);
|
||||||
if (!StrEmpty(_settings_client.network.default_company_pass)) {
|
if (!_settings_client.network.default_company_pass.empty()) {
|
||||||
NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass);
|
NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now that we have a new company, broadcast our company settings to
|
/* Now that we have a new company, broadcast our company settings to
|
||||||
|
|
|
@ -53,7 +53,7 @@ void LoadCheckData::Clear()
|
||||||
|
|
||||||
this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
|
this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
|
||||||
this->current_date = 0;
|
this->current_date = 0;
|
||||||
memset(&this->settings, 0, sizeof(this->settings));
|
this->settings = {};
|
||||||
|
|
||||||
for (auto &pair : this->companies) {
|
for (auto &pair : this->companies) {
|
||||||
delete pair.second;
|
delete pair.second;
|
||||||
|
|
|
@ -127,7 +127,7 @@ void CheckGameCompatibility(NetworkGameInfo &ngi)
|
||||||
*/
|
*/
|
||||||
void FillStaticNetworkServerGameInfo()
|
void FillStaticNetworkServerGameInfo()
|
||||||
{
|
{
|
||||||
_network_game_info.use_password = !StrEmpty(_settings_client.network.server_password);
|
_network_game_info.use_password = !_settings_client.network.server_password.empty();
|
||||||
_network_game_info.start_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
|
_network_game_info.start_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
|
||||||
_network_game_info.clients_max = _settings_client.network.max_clients;
|
_network_game_info.clients_max = _settings_client.network.max_clients;
|
||||||
_network_game_info.companies_max = _settings_client.network.max_companies;
|
_network_game_info.companies_max = _settings_client.network.max_companies;
|
||||||
|
|
|
@ -887,7 +887,7 @@ bool NetworkServerStart()
|
||||||
if (!ServerNetworkGameSocketHandler::Listen(_settings_client.network.server_port)) return false;
|
if (!ServerNetworkGameSocketHandler::Listen(_settings_client.network.server_port)) return false;
|
||||||
|
|
||||||
/* Only listen for admins when the password isn't empty. */
|
/* Only listen for admins when the password isn't empty. */
|
||||||
if (!StrEmpty(_settings_client.network.admin_password)) {
|
if (!_settings_client.network.admin_password.empty()) {
|
||||||
DEBUG(net, 5, "Starting listeners for admins");
|
DEBUG(net, 5, "Starting listeners for admins");
|
||||||
if (!ServerNetworkAdminSocketHandler::Listen(_settings_client.network.server_admin_port)) return false;
|
if (!ServerNetworkAdminSocketHandler::Listen(_settings_client.network.server_admin_port)) return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
|
||||||
*/
|
*/
|
||||||
/* static */ bool ServerNetworkAdminSocketHandler::AllowConnection()
|
/* static */ bool ServerNetworkAdminSocketHandler::AllowConnection()
|
||||||
{
|
{
|
||||||
bool accept = !StrEmpty(_settings_client.network.admin_password) && _network_admins_connected < MAX_ADMINS;
|
bool accept = !_settings_client.network.admin_password.empty() && _network_admins_connected < MAX_ADMINS;
|
||||||
/* We can't go over the MAX_ADMINS limit here. However, if we accept
|
/* We can't go over the MAX_ADMINS limit here. However, if we accept
|
||||||
* the connection, there has to be space in the pool. */
|
* the connection, there has to be space in the pool. */
|
||||||
static_assert(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS);
|
static_assert(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS);
|
||||||
|
@ -667,8 +667,8 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
|
||||||
char password[NETWORK_PASSWORD_LENGTH];
|
char password[NETWORK_PASSWORD_LENGTH];
|
||||||
p->Recv_string(password, sizeof(password));
|
p->Recv_string(password, sizeof(password));
|
||||||
|
|
||||||
if (StrEmpty(_settings_client.network.admin_password) ||
|
if (_settings_client.network.admin_password.empty() ||
|
||||||
strcmp(password, _settings_client.network.admin_password) != 0) {
|
_settings_client.network.admin_password.compare(password) != 0) {
|
||||||
/* Password is invalid */
|
/* Password is invalid */
|
||||||
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
|
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1032,7 +1032,7 @@ struct NetworkStartServerWindow : public Window {
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_NSS_SETPWD:
|
case WID_NSS_SETPWD:
|
||||||
/* If password is set, draw red '*' next to 'Set password' button. */
|
/* If password is set, draw red '*' next to 'Set password' button. */
|
||||||
if (!StrEmpty(_settings_client.network.server_password)) DrawString(r.right + WD_FRAMERECT_LEFT, this->width - WD_FRAMERECT_RIGHT, r.top, "*", TC_RED);
|
if (!_settings_client.network.server_password.empty()) DrawString(r.right + WD_FRAMERECT_LEFT, this->width - WD_FRAMERECT_RIGHT, r.top, "*", TC_RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1156,7 +1156,7 @@ struct NetworkStartServerWindow : public Window {
|
||||||
if (str == nullptr) return;
|
if (str == nullptr) return;
|
||||||
|
|
||||||
if (this->widget_id == WID_NSS_SETPWD) {
|
if (this->widget_id == WID_NSS_SETPWD) {
|
||||||
strecpy(_settings_client.network.server_password, str, lastof(_settings_client.network.server_password));
|
_settings_client.network.server_password = str;
|
||||||
} else {
|
} else {
|
||||||
int32 value = atoi(str);
|
int32 value = atoi(str);
|
||||||
this->SetWidgetDirty(this->widget_id);
|
this->SetWidgetDirty(this->widget_id);
|
||||||
|
@ -2583,7 +2583,7 @@ struct NetworkCompanyPasswordWindow : public Window {
|
||||||
void OnOk()
|
void OnOk()
|
||||||
{
|
{
|
||||||
if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) {
|
if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) {
|
||||||
strecpy(_settings_client.network.default_company_pass, this->password_editbox.text.buf, lastof(_settings_client.network.default_company_pass));
|
_settings_client.network.default_company_pass = this->password_editbox.text.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkChangeCompanyPassword(_local_company, this->password_editbox.text.buf);
|
NetworkChangeCompanyPassword(_local_company, this->password_editbox.text.buf);
|
||||||
|
|
|
@ -859,7 +859,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED
|
||||||
NetworkClientInfo *ci = this->GetInfo();
|
NetworkClientInfo *ci = this->GetInfo();
|
||||||
|
|
||||||
/* We now want a password from the client else we do not allow him in! */
|
/* We now want a password from the client else we do not allow him in! */
|
||||||
if (!StrEmpty(_settings_client.network.server_password)) {
|
if (!_settings_client.network.server_password.empty()) {
|
||||||
return this->SendNeedGamePassword();
|
return this->SendNeedGamePassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -957,8 +957,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(P
|
||||||
p->Recv_string(password, sizeof(password));
|
p->Recv_string(password, sizeof(password));
|
||||||
|
|
||||||
/* Check game password. Allow joining if we cleared the password meanwhile */
|
/* Check game password. Allow joining if we cleared the password meanwhile */
|
||||||
if (!StrEmpty(_settings_client.network.server_password) &&
|
if (!_settings_client.network.server_password.empty() &&
|
||||||
strcmp(password, _settings_client.network.server_password) != 0) {
|
_settings_client.network.server_password.compare(password) != 0) {
|
||||||
/* Password is invalid */
|
/* Password is invalid */
|
||||||
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
|
return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
|
||||||
}
|
}
|
||||||
|
@ -1439,12 +1439,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
|
||||||
char pass[NETWORK_PASSWORD_LENGTH];
|
char pass[NETWORK_PASSWORD_LENGTH];
|
||||||
char command[NETWORK_RCONCOMMAND_LENGTH];
|
char command[NETWORK_RCONCOMMAND_LENGTH];
|
||||||
|
|
||||||
if (StrEmpty(_settings_client.network.rcon_password)) return NETWORK_RECV_STATUS_OKAY;
|
if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY;
|
||||||
|
|
||||||
p->Recv_string(pass, sizeof(pass));
|
p->Recv_string(pass, sizeof(pass));
|
||||||
p->Recv_string(command, sizeof(command));
|
p->Recv_string(command, sizeof(command));
|
||||||
|
|
||||||
if (strcmp(pass, _settings_client.network.rcon_password) != 0) {
|
if (_settings_client.network.rcon_password.compare(pass) != 0) {
|
||||||
DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id);
|
DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id);
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -874,8 +874,8 @@ static void MakeNewGameDone()
|
||||||
|
|
||||||
/* We are the server, we start a new company (not dedicated),
|
/* We are the server, we start a new company (not dedicated),
|
||||||
* so set the default password *if* needed. */
|
* so set the default password *if* needed. */
|
||||||
if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
|
if (_network_server && !_settings_client.network.default_company_pass.empty()) {
|
||||||
NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass);
|
NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
|
if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
|
||||||
|
|
|
@ -1420,8 +1420,8 @@ static bool UpdateClientName(int32 p1)
|
||||||
|
|
||||||
static bool UpdateServerPassword(int32 p1)
|
static bool UpdateServerPassword(int32 p1)
|
||||||
{
|
{
|
||||||
if (strcmp(_settings_client.network.server_password, "*") == 0) {
|
if (_settings_client.network.server_password.compare("*") == 0) {
|
||||||
_settings_client.network.server_password[0] = '\0';
|
_settings_client.network.server_password.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkServerUpdateGameInfo();
|
NetworkServerUpdateGameInfo();
|
||||||
|
@ -1430,8 +1430,8 @@ static bool UpdateServerPassword(int32 p1)
|
||||||
|
|
||||||
static bool UpdateRconPassword(int32 p1)
|
static bool UpdateRconPassword(int32 p1)
|
||||||
{
|
{
|
||||||
if (strcmp(_settings_client.network.rcon_password, "*") == 0) {
|
if (_settings_client.network.rcon_password.compare("*") == 0) {
|
||||||
_settings_client.network.rcon_password[0] = '\0';
|
_settings_client.network.rcon_password.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -263,12 +263,12 @@ struct NetworkSettings {
|
||||||
uint16 server_admin_port; ///< port the server listens on for the admin network
|
uint16 server_admin_port; ///< port the server listens on for the admin network
|
||||||
bool server_admin_chat; ///< allow private chat for the server to be distributed to the admin network
|
bool server_admin_chat; ///< allow private chat for the server to be distributed to the admin network
|
||||||
char server_name[NETWORK_NAME_LENGTH]; ///< name of the server
|
char server_name[NETWORK_NAME_LENGTH]; ///< name of the server
|
||||||
char server_password[NETWORK_PASSWORD_LENGTH]; ///< password for joining this server
|
std::string server_password; ///< password for joining this server
|
||||||
char rcon_password[NETWORK_PASSWORD_LENGTH]; ///< password for rconsole (server side)
|
std::string rcon_password; ///< password for rconsole (server side)
|
||||||
char admin_password[NETWORK_PASSWORD_LENGTH]; ///< password for the admin network
|
std::string admin_password; ///< password for the admin network
|
||||||
bool server_advertise; ///< advertise the server to the masterserver
|
bool server_advertise; ///< advertise the server to the masterserver
|
||||||
char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< name of the player (as client)
|
char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< name of the player (as client)
|
||||||
char default_company_pass[NETWORK_PASSWORD_LENGTH]; ///< default password for new companies in encrypted form
|
std::string default_company_pass; ///< default password for new companies in encrypted form
|
||||||
char connect_to_ip[NETWORK_HOSTNAME_PORT_LENGTH]; ///< default for the "Add server" query
|
char connect_to_ip[NETWORK_HOSTNAME_PORT_LENGTH]; ///< default for the "Add server" query
|
||||||
char network_id[NETWORK_SERVER_ID_LENGTH]; ///< network ID for servers
|
char network_id[NETWORK_SERVER_ID_LENGTH]; ///< network ID for servers
|
||||||
bool autoclean_companies; ///< automatically remove companies that are not in use
|
bool autoclean_companies; ///< automatically remove companies that are not in use
|
||||||
|
|
|
@ -129,6 +129,9 @@ static size_t ConvertLandscape(const char *value);
|
||||||
#define SDTC_STR(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
#define SDTC_STR(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, sizeof(_settings_client.var), def, 0, 0, 0, nullptr, str, strhelp, strval, proc, from, to, cat, extra, startup)
|
SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, sizeof(_settings_client.var), def, 0, 0, 0, nullptr, str, strhelp, strval, proc, from, to, cat, extra, startup)
|
||||||
|
|
||||||
|
#define SDTC_SSTR(var, type, flags, guiflags, def, max_length, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
|
SDTG_GENERAL(#var, SDT_STDSTRING, SL_STDSTR, type, flags, guiflags, _settings_client.var, sizeof(_settings_client.var), def, 0, max_length, 0, nullptr, str, strhelp, strval, proc, from, to, cat, extra, startup)
|
||||||
|
|
||||||
#define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
#define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat, extra, startup)
|
SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat, extra, startup)
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ SDTC_BOOL = SDTC_BOOL( $var, $flags, $guiflags, $def,
|
||||||
SDTC_LIST = SDTC_LIST( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
SDTC_LIST = SDTC_LIST( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
||||||
SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
||||||
SDTC_STR = SDTC_STR( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
SDTC_STR = SDTC_STR( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
||||||
|
SDTC_SSTR = SDTC_SSTR( $var, $type, $flags, $guiflags, $def, $length, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
||||||
SDTC_VAR = SDTC_VAR( $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
SDTC_VAR = SDTC_VAR( $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
||||||
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
|
||||||
SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $load, $cat, $extra, $startup),
|
SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $load, $cat, $extra, $startup),
|
||||||
|
@ -3924,35 +3925,39 @@ def = nullptr
|
||||||
proc = UpdateClientName
|
proc = UpdateClientName
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
||||||
[SDTC_STR]
|
[SDTC_SSTR]
|
||||||
var = network.server_password
|
var = network.server_password
|
||||||
type = SLE_STRB
|
type = SLE_STR
|
||||||
|
length = NETWORK_PASSWORD_LENGTH
|
||||||
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
||||||
guiflags = SGF_NETWORK_ONLY
|
guiflags = SGF_NETWORK_ONLY
|
||||||
def = nullptr
|
def = nullptr
|
||||||
proc = UpdateServerPassword
|
proc = UpdateServerPassword
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
||||||
[SDTC_STR]
|
[SDTC_SSTR]
|
||||||
var = network.rcon_password
|
var = network.rcon_password
|
||||||
type = SLE_STRB
|
type = SLE_STR
|
||||||
|
length = NETWORK_PASSWORD_LENGTH
|
||||||
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
||||||
guiflags = SGF_NETWORK_ONLY
|
guiflags = SGF_NETWORK_ONLY
|
||||||
def = nullptr
|
def = nullptr
|
||||||
proc = UpdateRconPassword
|
proc = UpdateRconPassword
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
||||||
[SDTC_STR]
|
[SDTC_SSTR]
|
||||||
var = network.admin_password
|
var = network.admin_password
|
||||||
type = SLE_STRB
|
type = SLE_STR
|
||||||
|
length = NETWORK_PASSWORD_LENGTH
|
||||||
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
||||||
guiflags = SGF_NETWORK_ONLY
|
guiflags = SGF_NETWORK_ONLY
|
||||||
def = nullptr
|
def = nullptr
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
||||||
[SDTC_STR]
|
[SDTC_SSTR]
|
||||||
var = network.default_company_pass
|
var = network.default_company_pass
|
||||||
type = SLE_STRB
|
type = SLE_STR
|
||||||
|
length = NETWORK_PASSWORD_LENGTH
|
||||||
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
||||||
def = nullptr
|
def = nullptr
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue