From 843ab67390f41492b15f17586eecf52618bd1051 Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Sat, 21 Oct 2023 19:40:01 +0200 Subject: [PATCH] Settings - Add "volatile" option to not persist server settings after restart (#1617) Co-authored-by: BrettMayson Co-authored-by: PabstMirror --- .hemtt/project.toml | 1 + addons/settings/fnc_clear.sqf | 2 +- addons/settings/fnc_gui_sourceChanged.sqf | 1 + addons/settings/fnc_init.sqf | 2 +- addons/settings/fnc_set.sqf | 4 ++-- addons/settings/gui.hpp | 9 +++++++++ addons/settings/initSettings.sqf | 3 +++ addons/settings/script_component.hpp | 3 +++ addons/settings/stringtable.xml | 8 ++++++++ template/cba_settings_userconfig/config.cpp | 3 +++ 10 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.hemtt/project.toml b/.hemtt/project.toml index ed381d0e1c..39060b6e91 100644 --- a/.hemtt/project.toml +++ b/.hemtt/project.toml @@ -1,4 +1,5 @@ name = "CBA_A3" +mainprefix = "x" prefix = "cba" author = "CBATeam" diff --git a/addons/settings/fnc_clear.sqf b/addons/settings/fnc_clear.sqf index 00811a2137..c3c34ff7b2 100644 --- a/addons/settings/fnc_clear.sqf +++ b/addons/settings/fnc_clear.sqf @@ -77,7 +77,7 @@ switch (toLower _source) do { case "server": { if (!isServer) exitWith {}; - profileNamespace setVariable [QGVAR(hash), HASH_NULL]; + GET_LOCAL_SETTINGS_NAMESPACE setVariable [QGVAR(hash), HASH_NULL]; saveProfileNamespace; GVAR(client) call CBA_fnc_deleteNamespace; GVAR(client) = [] call CBA_fnc_createNamespace; diff --git a/addons/settings/fnc_gui_sourceChanged.sqf b/addons/settings/fnc_gui_sourceChanged.sqf index c9bd5e2a27..56f35bfe12 100644 --- a/addons/settings/fnc_gui_sourceChanged.sqf +++ b/addons/settings/fnc_gui_sourceChanged.sqf @@ -32,6 +32,7 @@ private _selectedAddon = uiNamespace getVariable QGVAR(addon); (_display displayCtrl IDC_TXT_OVERWRITE_CLIENT) ctrlShow (_selectedSource isNotEqualTo "client"); (_display displayCtrl IDC_TXT_OVERWRITE_MISSION) ctrlShow (_selectedSource isEqualTo "server"); +(_display displayCtrl IDC_TXT_VOLATILE_WARNING) ctrlShow (_selectedSource isEqualTo "server" && GVAR(volatile)); // enable / disable IMPORT and LOAD buttons private _ctrlButtonImport = _display displayCtrl IDC_BTN_IMPORT; diff --git a/addons/settings/fnc_init.sqf b/addons/settings/fnc_init.sqf index 173b9aeb6c..3b35a49812 100644 --- a/addons/settings/fnc_init.sqf +++ b/addons/settings/fnc_init.sqf @@ -166,7 +166,7 @@ GVAR(default) setVariable [_setting, [_defaultValue, _setting, _settingType, _se private _settingInfo = GVAR(userconfig) getVariable _setting; if (isNil "_settingInfo") then { - private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL]; + private _settingsHash = GET_LOCAL_SETTINGS_NAMESPACE getVariable [QGVAR(hash), HASH_NULL]; _settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet; }; diff --git a/addons/settings/fnc_set.sqf b/addons/settings/fnc_set.sqf index f7cbb1ba2b..1ace681f5a 100644 --- a/addons/settings/fnc_set.sqf +++ b/addons/settings/fnc_set.sqf @@ -118,7 +118,7 @@ switch (toLower _source) do { private _defaultValue = [_setting, "default"] call FUNC(get); private _defaultPriority = SANITIZE_PRIORITY(_setting,0,_source); - private _settingsHash = profileNamespace getVariable [QGVAR(hash), HASH_NULL]; + private _settingsHash = GET_LOCAL_SETTINGS_NAMESPACE getVariable [QGVAR(hash), HASH_NULL]; if ([_value, _priority] isEqualTo [_defaultValue, _defaultPriority]) then { [_settingsHash, toLower _setting] call CBA_fnc_hashRem; @@ -126,7 +126,7 @@ switch (toLower _source) do { [_settingsHash, toLower _setting, [_value, _priority]] call CBA_fnc_hashSet; }; - profileNamespace setVariable [QGVAR(hash), _settingsHash]; + GET_LOCAL_SETTINGS_NAMESPACE setVariable [QGVAR(hash), _settingsHash]; saveProfileNamespace; }; diff --git a/addons/settings/gui.hpp b/addons/settings/gui.hpp index a5c5e30311..a5eb4aef7c 100644 --- a/addons/settings/gui.hpp +++ b/addons/settings/gui.hpp @@ -85,6 +85,15 @@ class RscDisplayGameOptions { idc = IDC_TXT_OVERWRITE_MISSION; x = QUOTE(POS_W(33)); }; + class VolatileWarningText: OverwriteClientText { + onLoad = QUOTE((_this select 0) ctrlEnable true;); + idc = IDC_TXT_VOLATILE_WARNING; + style = ST_LEFT; + text = CSTRING(volatile); + tooltip = CSTRING(volatile_tooltip); + x = QUOTE(POS_W(1)); + w = QUOTE(POS_W(24)); + }; }; }; }; diff --git a/addons/settings/initSettings.sqf b/addons/settings/initSettings.sqf index 71d75f8673..ad6c8c1226 100644 --- a/addons/settings/initSettings.sqf +++ b/addons/settings/initSettings.sqf @@ -14,6 +14,9 @@ if (isNil QGVAR(default)) then { if (isServer) then { missionNamespace setVariable [QGVAR(server), true call CBA_fnc_createNamespace, true]; + private _volatile = isDedicated && {(getNumber (configFile >> QGVAR(volatile))) == 1}; + missionNamespace setVariable [QGVAR(volatile), _volatile, true]; + if (_volatile) then {WARNING("Server settings changes will be lost upon game restart.")}; }; // --- read userconfig file diff --git a/addons/settings/script_component.hpp b/addons/settings/script_component.hpp index 131fdb723d..9d7cb42a5c 100644 --- a/addons/settings/script_component.hpp +++ b/addons/settings/script_component.hpp @@ -32,6 +32,7 @@ #define IDC_BTN_CONFIGURE 9030 #define IDC_TXT_OVERWRITE_CLIENT 9040 #define IDC_TXT_OVERWRITE_MISSION 9041 +#define IDC_TXT_VOLATILE_WARNING 9042 #define IDC_SETTING_CONTROLS_GROUP 5000 #define IDC_SETTING_BACKGROUND 5001 @@ -127,6 +128,8 @@ #define SET_TEMP_NAMESPACE_VALUE(setting,value,source) GET_TEMP_NAMESPACE(source) setVariable [setting, [value, GET_TEMP_NAMESPACE_PRIORITY(setting,source)]]; SET_TEMP_NAMESPACE_AWAITING_RESTART(setting) #define SET_TEMP_NAMESPACE_PRIORITY(setting,priority,source) GET_TEMP_NAMESPACE(source) setVariable [setting, [GET_TEMP_NAMESPACE_VALUE(setting,source), priority]]; SET_TEMP_NAMESPACE_AWAITING_RESTART(setting) +#define GET_LOCAL_SETTINGS_NAMESPACE (with missionNamespace do {if (isDedicated && {GVAR(volatile)}) then {uiNamespace} else {profileNamespace}}) + #define TEMP_PRIORITY(setting) (call {private _arr = [\ (uiNamespace getVariable QGVAR(clientTemp)) getVariable [setting, [nil, [setting, "client"] call FUNC(priority)]] select 1,\ (uiNamespace getVariable QGVAR(missionTemp)) getVariable [setting, [nil, [setting, "mission"] call FUNC(priority)]] select 1,\ diff --git a/addons/settings/stringtable.xml b/addons/settings/stringtable.xml index d42661da15..09d716b087 100644 --- a/addons/settings/stringtable.xml +++ b/addons/settings/stringtable.xml @@ -315,6 +315,14 @@ Resetovat na původní hodnotu. 기본값으로 초기화합니다. + + Changes will not persist after server restart + Zmiany nie zostaną zachowane po restarcie serwera + + + The server is configured to not persist changes to settings between server restarts.\nChanges will persist between mission restarts. + Serwer jest skonfigurowany tak, aby odrzucać wszystkie zmiany w ustawieniach gdy zostanie zrestartowany.\nZmiany zostaną zachowane między restartami misji. + Overwrite\nClients Clients\nüberschreiben diff --git a/template/cba_settings_userconfig/config.cpp b/template/cba_settings_userconfig/config.cpp index fbd45cbb22..50d772df4b 100644 --- a/template/cba_settings_userconfig/config.cpp +++ b/template/cba_settings_userconfig/config.cpp @@ -12,3 +12,6 @@ class CfgPatches { authors[] = {"commy2"}; }; }; + +// Uncommenting this will make any changes to "Server" settings be lost upon game restart, applies only to dedicated servers +// cba_settings_volatile = 1;