Changeset - r25461:f4423b696b95
[Not reviewed]
master
0 12 0
rubidium42 - 4 years ago 2021-04-27 18:26:56
rubidium@openttd.org
Codechange: move passwords in settings to std::string
12 files changed with 42 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -843,8 +843,8 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
			if (client_id == _network_own_client_id) {
 
				assert(_local_company == COMPANY_SPECTATOR);
 
				SetLocalCompany(c->index);
 
				if (!StrEmpty(_settings_client.network.default_company_pass)) {
 
					NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass);
 
				if (!_settings_client.network.default_company_pass.empty()) {
 
					NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass.c_str());
 
				}
 

	
 
				/* Now that we have a new company, broadcast our company settings to
src/fios_gui.cpp
Show inline comments
 
@@ -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->current_date = 0;
 
	memset(&this->settings, 0, sizeof(this->settings));
 
	this->settings = {};
 

	
 
	for (auto &pair : this->companies) {
 
		delete pair.second;
src/network/core/game_info.cpp
Show inline comments
 
@@ -127,7 +127,7 @@ void CheckGameCompatibility(NetworkGameI
 
 */
 
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.clients_max    = _settings_client.network.max_clients;
 
	_network_game_info.companies_max  = _settings_client.network.max_companies;
src/network/network.cpp
Show inline comments
 
@@ -887,7 +887,7 @@ bool NetworkServerStart()
 
	if (!ServerNetworkGameSocketHandler::Listen(_settings_client.network.server_port)) return false;
 

	
 
	/* 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");
 
		if (!ServerNetworkAdminSocketHandler::Listen(_settings_client.network.server_admin_port)) return false;
 
	}
src/network/network_admin.cpp
Show inline comments
 
@@ -84,7 +84,7 @@ ServerNetworkAdminSocketHandler::~Server
 
 */
 
/* 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
 
	 * the connection, there has to be space in the pool. */
 
	static_assert(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS);
 
@@ -667,8 +667,8 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	char password[NETWORK_PASSWORD_LENGTH];
 
	p->Recv_string(password, sizeof(password));
 

	
 
	if (StrEmpty(_settings_client.network.admin_password) ||
 
			strcmp(password, _settings_client.network.admin_password) != 0) {
 
	if (_settings_client.network.admin_password.empty() ||
 
			_settings_client.network.admin_password.compare(password) != 0) {
 
		/* Password is invalid */
 
		return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
 
	}
src/network/network_gui.cpp
Show inline comments
 
@@ -1032,7 +1032,7 @@ struct NetworkStartServerWindow : public
 
		switch (widget) {
 
			case WID_NSS_SETPWD:
 
				/* 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
 
		if (str == nullptr) return;
 

	
 
		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 {
 
			int32 value = atoi(str);
 
			this->SetWidgetDirty(this->widget_id);
 
@@ -2583,7 +2583,7 @@ struct NetworkCompanyPasswordWindow : pu
 
	void OnOk()
 
	{
 
		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);
src/network/network_server.cpp
Show inline comments
 
@@ -859,7 +859,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	NetworkClientInfo *ci = this->GetInfo();
 

	
 
	/* 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();
 
	}
 

	
 
@@ -957,8 +957,8 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	p->Recv_string(password, sizeof(password));
 

	
 
	/* Check game password. Allow joining if we cleared the password meanwhile */
 
	if (!StrEmpty(_settings_client.network.server_password) &&
 
			strcmp(password, _settings_client.network.server_password) != 0) {
 
	if (!_settings_client.network.server_password.empty() &&
 
			_settings_client.network.server_password.compare(password) != 0) {
 
		/* Password is invalid */
 
		return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
 
	}
 
@@ -1439,12 +1439,12 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	char pass[NETWORK_PASSWORD_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(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);
 
		return NETWORK_RECV_STATUS_OKAY;
 
	}
src/openttd.cpp
Show inline comments
 
@@ -874,8 +874,8 @@ static void MakeNewGameDone()
 

	
 
	/* We are the server, we start a new company (not dedicated),
 
	 * so set the default password *if* needed. */
 
	if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
 
		NetworkChangeCompanyPassword(_local_company, _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.c_str());
 
	}
 

	
 
	if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
src/settings.cpp
Show inline comments
 
@@ -1420,8 +1420,8 @@ static bool UpdateClientName(int32 p1)
 

	
 
static bool UpdateServerPassword(int32 p1)
 
{
 
	if (strcmp(_settings_client.network.server_password, "*") == 0) {
 
		_settings_client.network.server_password[0] = '\0';
 
	if (_settings_client.network.server_password.compare("*") == 0) {
 
		_settings_client.network.server_password.clear();
 
	}
 

	
 
	NetworkServerUpdateGameInfo();
 
@@ -1430,8 +1430,8 @@ static bool UpdateServerPassword(int32 p
 

	
 
static bool UpdateRconPassword(int32 p1)
 
{
 
	if (strcmp(_settings_client.network.rcon_password, "*") == 0) {
 
		_settings_client.network.rcon_password[0] = '\0';
 
	if (_settings_client.network.rcon_password.compare("*") == 0) {
 
		_settings_client.network.rcon_password.clear();
 
	}
 

	
 
	return true;
src/settings_type.h
Show inline comments
 
@@ -263,12 +263,12 @@ struct NetworkSettings {
 
	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
 
	char   server_name[NETWORK_NAME_LENGTH];              ///< name of the server
 
	char   server_password[NETWORK_PASSWORD_LENGTH];      ///< password for joining this server
 
	char   rcon_password[NETWORK_PASSWORD_LENGTH];        ///< password for rconsole (server side)
 
	char   admin_password[NETWORK_PASSWORD_LENGTH];       ///< password for the admin network
 
	std::string server_password;                          ///< password for joining this server
 
	std::string rcon_password;                            ///< password for rconsole (server side)
 
	std::string admin_password;                           ///< password for the admin network
 
	bool   server_advertise;                              ///< advertise the server to the masterserver
 
	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   network_id[NETWORK_SERVER_ID_LENGTH];          ///< network ID for servers
 
	bool   autoclean_companies;                           ///< automatically remove companies that are not in use
src/table/settings.h.preamble
Show inline comments
 
@@ -129,6 +129,9 @@ static size_t ConvertLandscape(const cha
 
#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)
 

	
 
#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)\
 
	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)
 

	
src/table/settings.ini
Show inline comments
 
@@ -70,6 +70,7 @@ SDTC_BOOL  =  SDTC_BOOL(       $var,    
 
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_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),
 
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),
 
@@ -3924,35 +3925,39 @@ def      = nullptr
 
proc     = UpdateClientName
 
cat      = SC_BASIC
 

	
 
[SDTC_STR]
 
[SDTC_SSTR]
 
var      = network.server_password
 
type     = SLE_STRB
 
type     = SLE_STR
 
length   = NETWORK_PASSWORD_LENGTH
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
guiflags = SGF_NETWORK_ONLY
 
def      = nullptr
 
proc     = UpdateServerPassword
 
cat      = SC_BASIC
 

	
 
[SDTC_STR]
 
[SDTC_SSTR]
 
var      = network.rcon_password
 
type     = SLE_STRB
 
type     = SLE_STR
 
length   = NETWORK_PASSWORD_LENGTH
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
guiflags = SGF_NETWORK_ONLY
 
def      = nullptr
 
proc     = UpdateRconPassword
 
cat      = SC_BASIC
 

	
 
[SDTC_STR]
 
[SDTC_SSTR]
 
var      = network.admin_password
 
type     = SLE_STRB
 
type     = SLE_STR
 
length   = NETWORK_PASSWORD_LENGTH
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
guiflags = SGF_NETWORK_ONLY
 
def      = nullptr
 
cat      = SC_BASIC
 

	
 
[SDTC_STR]
 
[SDTC_SSTR]
 
var      = network.default_company_pass
 
type     = SLE_STRB
 
type     = SLE_STR
 
length   = NETWORK_PASSWORD_LENGTH
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = nullptr
 

	
0 comments (0 inline, 0 general)