Skip to content

Commit

Permalink
Get server hash namespace at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
veteran29 committed Oct 17, 2023
1 parent 1230453 commit 686fb17
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
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 {};

GVAR(serverHashNamespace) setVariable [QGVAR(hash), HASH_NULL];
GET_SERVER_NAMESPACE setVariable [QGVAR(hash), HASH_NULL];
saveProfileNamespace;
GVAR(client) call CBA_fnc_deleteNamespace;
GVAR(client) = [] call CBA_fnc_createNamespace;
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 = GVAR(serverHashNamespace) getVariable [QGVAR(hash), HASH_NULL];
private _settingsHash = GET_SERVER_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 = GVAR(serverHashNamespace) getVariable [QGVAR(hash), HASH_NULL];
private _settingsHash = GET_SERVER_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;
};

GVAR(serverHashNamespace) setVariable [QGVAR(hash), _settingsHash];
GET_SERVER_NAMESPACE setVariable [QGVAR(hash), _settingsHash];
saveProfileNamespace;
};

Expand Down
3 changes: 1 addition & 2 deletions addons/settings/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ if (isNil QGVAR(default)) then {

if (isNil QGVAR(server)) then {
GVAR(server) = NAMESPACE_NULL;
GVAR(serverHashNamespace) = [profileNamespace, uiNamespace] select _volatile;
if (_volatile) then { WARNING("Server settings changes will be lost upon game restart."); };
};

if (isServer) then {
missionNamespace setVariable [QGVAR(server), true call CBA_fnc_createNamespace, true];
missionNamespace setVariable [QGVAR(volatile), _volatile, true];
if (_volatile) then {WARNING("Server settings changes will be lost upon game restart.")};
};

// --- read userconfig file
Expand Down
2 changes: 2 additions & 0 deletions addons/settings/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,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_SERVER_NAMESPACE (with missionNamespace do {if (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

0 comments on commit 686fb17

Please sign in to comment.