summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-24 09:44:20 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-29 10:07:30 +0200
commite2f5d9e561b70aec85d67b4eea822ba49f0c20bf (patch)
tree991721d92ede3f190db9fc3c0dac85d127e2c330 /src/settings.cpp
parentea9715d970911300b17f8a55dd1047f3706d22f4 (diff)
downloadopenttd-e2f5d9e561b70aec85d67b4eea822ba49f0c20bf.tar.xz
Codechange: use separate pre and post callbacks for string settings
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index bf3360319..f2980a363 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1343,37 +1343,28 @@ static bool InvalidateShipPathCache(int32 p1)
return true;
}
-static bool UpdateClientName(int32 p1)
+/**
+ * Replace a passwords that are a literal asterisk with an empty string.
+ * @param newval The new string value for this password field.
+ * @return Always true.
+ */
+static bool ReplaceAsteriskWithEmptyPassword(std::string &newval)
{
- NetworkUpdateClientName();
+ if (newval.compare("*") == 0) newval.clear();
return true;
}
-static bool UpdateServerPassword(int32 p1)
-{
- if (_settings_client.network.server_password.compare("*") == 0) {
- _settings_client.network.server_password.clear();
- }
-
- NetworkServerUpdateGameInfo();
- return true;
-}
-
-static bool UpdateRconPassword(int32 p1)
+static bool UpdateClientConfigValues(int32 p1)
{
- if (_settings_client.network.rcon_password.compare("*") == 0) {
- _settings_client.network.rcon_password.clear();
- }
-
+ UpdateClientConfigValues();
return true;
}
-static bool UpdateClientConfigValues(int32 p1)
+/** Update the game info, and send it to the clients when we are running as a server. */
+static void UpdateClientConfigValues()
{
NetworkServerUpdateGameInfo();
if (_network_server) NetworkServerSendConfigUpdate();
-
- return true;
}
/* End - Callback Functions */
@@ -2069,8 +2060,10 @@ bool SetSettingValue(const StringSettingDesc *sd, std::string value, bool force_
void StringSettingDesc::ChangeValue(const void *object, std::string &newval) const
{
this->MakeValueValid(newval);
+ if (this->pre_check != nullptr && !this->pre_check(newval)) return;
+
this->Write(object, newval);
- if (this->proc != nullptr) this->proc(0);
+ if (this->post_callback != nullptr) this->post_callback(newval);
if (_save_config) SaveToConfig();
}