diff options
author | rubidium42 <rubidium@openttd.org> | 2021-05-24 09:44:20 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-29 10:07:30 +0200 |
commit | e2f5d9e561b70aec85d67b4eea822ba49f0c20bf (patch) | |
tree | 991721d92ede3f190db9fc3c0dac85d127e2c330 /src/network | |
parent | ea9715d970911300b17f8a55dd1047f3706d22f4 (diff) | |
download | openttd-e2f5d9e561b70aec85d67b4eea822ba49f0c20bf.tar.xz |
Codechange: use separate pre and post callbacks for string settings
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network_client.cpp | 17 | ||||
-rw-r--r-- | src/network/network_func.h | 2 |
2 files changed, 7 insertions, 12 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 08a35e980..1a729e34f 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -1344,27 +1344,22 @@ bool NetworkValidateClientName() } /** - * Send the server our name. + * Send the server our name as callback from the setting. + * @param newname The new client name. */ -void NetworkUpdateClientName() +void NetworkUpdateClientName(const std::string &client_name) { NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(_network_own_client_id); - if (ci == nullptr) return; - /* There is no validation on string settings, it is actually a post change callback. - * This method is called from that post change callback. So, when the client name is - * changed via the console there is no easy way to prevent an invalid name. Though, - * we can prevent it getting sent here. */ - if (!NetworkValidateClientName()) return; /* Don't change the name if it is the same as the old name */ - if (_settings_client.network.client_name.compare(ci->client_name) != 0) { + if (client_name.compare(ci->client_name) != 0) { if (!_network_server) { - MyClient::SendSetName(_settings_client.network.client_name.c_str()); + MyClient::SendSetName(client_name.c_str()); } else { /* Copy to a temporary buffer so no #n gets added after our name in the settings when there are duplicate names. */ char temporary_name[NETWORK_CLIENT_NAME_LENGTH]; - strecpy(temporary_name, _settings_client.network.client_name.c_str(), lastof(temporary_name)); + strecpy(temporary_name, client_name.c_str(), lastof(temporary_name)); if (NetworkFindName(temporary_name, lastof(temporary_name))) { NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, temporary_name); ci->client_name = temporary_name; diff --git a/src/network/network_func.h b/src/network/network_func.h index 1c5916eda..fbae8daf7 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -38,7 +38,7 @@ byte NetworkSpectatorCount(); bool NetworkIsValidClientName(const std::string_view client_name); bool NetworkValidateClientName(); bool NetworkValidateClientName(std::string &client_name); -void NetworkUpdateClientName(); +void NetworkUpdateClientName(const std::string &client_name); bool NetworkCompanyHasClients(CompanyID company); std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password); void NetworkReboot(); |