Changeset - r25463:a9b079004e01
[Not reviewed]
master
0 5 0
rubidium42 - 3 years ago 2021-04-27 19:25:52
rubidium@openttd.org
Codechange: move server name/id in settings to std::string
5 files changed with 19 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/network/network.cpp
Show inline comments
 
@@ -830,14 +830,14 @@ void NetworkClientJoinGame()
 

	
 
	new TCPClientConnecter(_network_join.connection_string);
 
}
 

	
 
static void NetworkInitGameInfo()
 
{
 
	if (StrEmpty(_settings_client.network.server_name)) {
 
		strecpy(_settings_client.network.server_name, "Unnamed Server", lastof(_settings_client.network.server_name));
 
	if (_settings_client.network.server_name.empty()) {
 
		_settings_client.network.server_name = "Unnamed Server";
 
	}
 

	
 
	FillStaticNetworkServerGameInfo();
 
	/* The server is a client too */
 
	_network_game_info.clients_on = _network_dedicated ? 0 : 1;
 

	
 
@@ -860,16 +860,16 @@ static void CheckClientAndServerName()
 
	static const char *fallback_client_name = "Unnamed Client";
 
	if (StrEmpty(_settings_client.network.client_name) || strcmp(_settings_client.network.client_name, fallback_client_name) == 0) {
 
		DEBUG(net, 1, "No \"client_name\" has been set, using \"%s\" instead. Please set this now using the \"name <new name>\" command", fallback_client_name);
 
		strecpy(_settings_client.network.client_name, fallback_client_name, lastof(_settings_client.network.client_name));
 
	}
 

	
 
	static const char *fallback_server_name = "Unnamed Server";
 
	if (StrEmpty(_settings_client.network.server_name) || strcmp(_settings_client.network.server_name, fallback_server_name) == 0) {
 
		DEBUG(net, 1, "No \"server_name\" has been set, using \"%s\" instead. Please set this now using the \"server_name <new name>\" command", fallback_server_name);
 
		strecpy(_settings_client.network.server_name, fallback_server_name, lastof(_settings_client.network.server_name));
 
	static const std::string fallback_server_name = "Unnamed Server";
 
	if (_settings_client.network.server_name.empty() || _settings_client.network.server_name.compare(fallback_server_name) == 0) {
 
		DEBUG(net, 1, "No \"server_name\" has been set, using \"%s\" instead. Please set this now using the \"server_name <new name>\" command", fallback_server_name.c_str());
 
		_settings_client.network.server_name = fallback_server_name;
 
	}
 
}
 

	
 
bool NetworkServerStart()
 
{
 
	if (!_network_available) return false;
 
@@ -1198,13 +1198,13 @@ static void NetworkGenerateServerId()
 

	
 
	for (di = 0; di < 16; ++di) {
 
		seprintf(hex_output + di * 2, lastof(hex_output), "%02x", digest[di]);
 
	}
 

	
 
	/* _settings_client.network.network_id is our id */
 
	seprintf(_settings_client.network.network_id, lastof(_settings_client.network.network_id), "%s", hex_output);
 
	_settings_client.network.network_id = hex_output;
 
}
 

	
 
class TCPNetworkDebugConnecter : TCPConnecter {
 
private:
 
	std::string connection_string;
 

	
 
@@ -1238,13 +1238,13 @@ void NetworkStartUp()
 
	/* Network is available */
 
	_network_available = NetworkCoreInitialize();
 
	_network_dedicated = false;
 
	_network_need_advertise = true;
 

	
 
	/* Generate an server id when there is none yet */
 
	if (StrEmpty(_settings_client.network.network_id)) NetworkGenerateServerId();
 
	if (_settings_client.network.network_id.empty()) NetworkGenerateServerId();
 

	
 
	_network_game_info = {};
 

	
 
	NetworkInitialize();
 
	DEBUG(net, 3, "Network online, multiplayer available");
 
	NetworkFindBroadcastIPs(&_broadcast_list);
src/network/network_gui.cpp
Show inline comments
 
@@ -987,13 +987,13 @@ struct NetworkStartServerWindow : public
 

	
 
	NetworkStartServerWindow(WindowDesc *desc) : Window(desc), name_editbox(NETWORK_NAME_LENGTH)
 
	{
 
		this->InitNested(WN_NETWORK_WINDOW_START);
 

	
 
		this->querystrings[WID_NSS_GAMENAME] = &this->name_editbox;
 
		this->name_editbox.text.Assign(_settings_client.network.server_name);
 
		this->name_editbox.text.Assign(_settings_client.network.server_name.c_str());
 

	
 
		this->SetFocusedWidget(WID_NSS_GAMENAME);
 
	}
 

	
 
	void SetStringParameters(int widget) const override
 
	{
 
@@ -1133,13 +1133,13 @@ struct NetworkStartServerWindow : public
 
		this->SetDirty();
 
	}
 

	
 
	void OnEditboxChanged(int wid) override
 
	{
 
		if (wid == WID_NSS_GAMENAME) {
 
			strecpy(_settings_client.network.server_name, this->name_editbox.text.buf, lastof(_settings_client.network.server_name));
 
			_settings_client.network.server_name = this->name_editbox.text.buf;
 
		}
 
	}
 

	
 
	void OnTimeout() override
 
	{
 
		static const int raise_widgets[] = {WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU, WID_NSS_SPECTATORS_BTND, WID_NSS_SPECTATORS_BTNU, WIDGET_LIST_END};
src/network/network_server.cpp
Show inline comments
 
@@ -1759,13 +1759,13 @@ bool NetworkServerChangeClientName(Clien
 
 */
 
void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password, bool already_hashed)
 
{
 
	if (!Company::IsValidHumanID(company_id)) return;
 

	
 
	if (!already_hashed) {
 
		password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id, _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));
 
	NetworkServerUpdateCompanyPassworded(company_id, !StrEmpty(_network_company_states[company_id].password));
 
}
 

	
src/settings_type.h
Show inline comments
 
@@ -259,21 +259,21 @@ struct NetworkSettings {
 
	uint16 max_password_time;                             ///< maximum amount of time, in game ticks, a client may take to enter the password
 
	uint16 max_lag_time;                                  ///< maximum amount of time, in game ticks, a client may be lagging behind the server
 
	bool   pause_on_join;                                 ///< pause the game when people join
 
	uint16 server_port;                                   ///< port the server listens on
 
	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
 
	std::string server_name;                              ///< name of the server
 
	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)
 
	std::string default_company_pass;                     ///< default password for new companies in encrypted form
 
	std::string connect_to_ip;                            ///< default for the "Add server" query
 
	char   network_id[NETWORK_SERVER_ID_LENGTH];          ///< network ID for servers
 
	std::string network_id;                               ///< network ID for servers
 
	bool   autoclean_companies;                           ///< automatically remove companies that are not in use
 
	uint8  autoclean_unprotected;                         ///< remove passwordless companies after this many months
 
	uint8  autoclean_protected;                           ///< remove the password from passworded companies after this many months
 
	uint8  autoclean_novehicles;                          ///< remove companies with no vehicles after this many months
 
	uint8  max_companies;                                 ///< maximum amount of companies
 
	uint8  max_clients;                                   ///< maximum amount of clients
src/table/settings.ini
Show inline comments
 
@@ -3958,15 +3958,16 @@ cat      = SC_BASIC
 
var      = network.default_company_pass
 
type     = SLE_STR
 
length   = NETWORK_PASSWORD_LENGTH
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = nullptr
 

	
 
[SDTC_STR]
 
[SDTC_SSTR]
 
var      = network.server_name
 
type     = SLE_STRB
 
type     = SLE_STR
 
length   = NETWORK_NAME_LENGTH
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
guiflags = SGF_NETWORK_ONLY
 
def      = nullptr
 
proc     = UpdateClientConfigValues
 
cat      = SC_BASIC
 

	
 
@@ -3974,15 +3975,16 @@ cat      = SC_BASIC
 
var      = network.connect_to_ip
 
type     = SLE_STR
 
length   = 0
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
def      = nullptr
 

	
 
[SDTC_STR]
 
[SDTC_SSTR]
 
var      = network.network_id
 
type     = SLE_STRB
 
type     = SLE_STR
 
length   = NETWORK_SERVER_ID_LENGTH
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
guiflags = SGF_NETWORK_ONLY
 
def      = nullptr
 

	
 
[SDTC_BOOL]
 
var      = network.autoclean_companies
0 comments (0 inline, 0 general)