Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings - Add "volatile" option to not persist server settings after restart #1617

Merged
merged 10 commits into from
Oct 21, 2023
1 change: 1 addition & 0 deletions .hemtt/project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name = "CBA_A3"
mainprefix = "x"
prefix = "cba"
author = "CBATeam"

Expand Down
2 changes: 1 addition & 1 deletion addons/settings/fnc_clear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions addons/settings/fnc_gui_sourceChanged.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion addons/settings/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
4 changes: 2 additions & 2 deletions addons/settings/fnc_set.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ 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;
} else {
[_settingsHash, toLower _setting, [_value, _priority]] call CBA_fnc_hashSet;
};

profileNamespace setVariable [QGVAR(hash), _settingsHash];
GET_LOCAL_SETTINGS_NAMESPACE setVariable [QGVAR(hash), _settingsHash];
saveProfileNamespace;
};

Expand Down
9 changes: 9 additions & 0 deletions addons/settings/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
};
};
};
Expand Down
3 changes: 3 additions & 0 deletions addons/settings/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions addons/settings/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,\
Expand Down
8 changes: 8 additions & 0 deletions addons/settings/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@
<Czech>Resetovat na původní hodnotu.</Czech>
<Korean>기본값으로 초기화합니다.</Korean>
</Key>
<Key ID="STR_cba_settings_volatile">
<English>Changes will not persist after server restart</English>
<Polish>Zmiany nie zostaną zachowane po restarcie serwera</Polish>
</Key>
<Key ID="STR_cba_settings_volatile_tooltip">
<English>The server is configured to not persist changes to settings between server restarts.\nChanges will persist between mission restarts.</English>
<Polish>Serwer jest skonfigurowany tak, aby odrzucać wszystkie zmiany w ustawieniach gdy zostanie zrestartowany.\nZmiany zostaną zachowane między restartami misji.</Polish>
</Key>
<Key ID="STR_cba_settings_overwrite_clients">
<English>Overwrite\nClients</English>
<German>Clients\nüberschreiben</German>
Expand Down
3 changes: 3 additions & 0 deletions template/cba_settings_userconfig/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;