From f9c8afca11a637fe49229ee289eff78e401864b9 Mon Sep 17 00:00:00 2001 From: Killswitch Date: Sun, 21 Feb 2016 18:16:45 +0100 Subject: [PATCH] Add the ability to disable fnc_globalExecute Mission makers and/or server managers can disable the use of CBA_fnc_globalExecute either by using a mission setting or an optional addon. When disabled, calling fnc_globalExecute does nothing. Fixes #269 --- addons/network/XEH_preInit.sqf | 34 ++++++++++++++++++++++--- addons/network/config.cpp | 9 +++++-- optionals/disable_globalexec/config.cpp | 24 +++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 optionals/disable_globalexec/config.cpp diff --git a/addons/network/XEH_preInit.sqf b/addons/network/XEH_preInit.sqf index 86e6d4876..89d0bf205 100644 --- a/addons/network/XEH_preInit.sqf +++ b/addons/network/XEH_preInit.sqf @@ -46,8 +46,6 @@ ADDON = false; ISNIL(timeSync_Disabled,true); // deprecated ISNIL(weatherSync_Disabled,true); -PREP(exec); - DEPRECATE(fnc_remoteExecute,fnc_globalExecute); DEPRECATE(fnc_remoteSay,fnc_globalSay); @@ -95,8 +93,38 @@ if (SLX_XEH_MACHINE select 3) then { }; }; +// CBA_fnc_globalExecute is normally enabled +_disableGE = false; + +// Check the CfgSettings >> "CBA" >> "network" >> "disableGlobalExecute" value +_entry = (CFGSETTINGSS(CBA,COMPONENT) >> "disableGlobalExecute"); +if (isNumber _entry) then { + _disableGE = (getNumber _entry == 1); +} else { + if (isText _entry) then { + _disableGE = (getText _entry == "true"); + }; +}; + +// Check the mission configuration +_dGE = getMissionConfigValue ["CBA_disableGlobalExecute", -1]; +if (_dGE isEqualType 0) then { + if (_dGE in [0, 1]) then { + _disableGE = (_dGE == 1); + }; +} else { + if (_dGE isEqualType "") then { + _disableGE = (_dGE == "true"); + }; +}; -[QUOTE(GVAR(cmd)), { if (GVAR(init)) then { _this spawn FUNC(exec) } }] call (uiNamespace getVariable "CBA_fnc_addEventHandler"); +if (_disableGE) then { + uiNamespace setVariable [QGVAR(exec), compileFinal ""]; + missionNamespace setVariable [QGVAR(exec), compileFinal ""]; +} else { + PREP(exec); + [QUOTE(GVAR(cmd)), { if (GVAR(init)) then { _this spawn FUNC(exec) } }] call (uiNamespace getVariable "CBA_fnc_addEventHandler"); +}; [QUOTE(GVAR(say)), { private "_say"; _say = _this; _objects = _say select 0; if (typeName _objects != "ARRAY") then { _objects = [_objects] }; { _x say (_say select 1) } forEach _objects }] call (uiNamespace getVariable "CBA_fnc_addEventHandler"); [QUOTE(GVAR(say3d)), { private "_say"; _say = _this; if (count _this > 2) then { if ((positionCameraToWorld [0,0,0]) distance (_say select 0) <= (_say select 2)) then { (_say select 0) say3d (_say select 1) } } else { (_say select 0) say3d (_say select 1) } }] call (uiNamespace getVariable "CBA_fnc_addEventHandler"); [QUOTE(GVAR(date)), { private "_date"; _date = _this; setDate _date }] call (uiNamespace getVariable "CBA_fnc_addEventHandler"); diff --git a/addons/network/config.cpp b/addons/network/config.cpp index 8520fc09e..c3273e26a 100644 --- a/addons/network/config.cpp +++ b/addons/network/config.cpp @@ -11,7 +11,12 @@ class CfgPatches authorUrl = "https://github.com/CBATeam/CBA_A3"; }; }; +class CfgSettings { + class CBA { + class COMPONENT { + disableGlobalExecute = 0; + }; + }; +}; #include "CfgEventHandlers.hpp" #include "CfgFunctions.hpp" - - diff --git a/optionals/disable_globalexec/config.cpp b/optionals/disable_globalexec/config.cpp new file mode 100644 index 000000000..da3774daf --- /dev/null +++ b/optionals/disable_globalexec/config.cpp @@ -0,0 +1,24 @@ +/* + Disable network code execution + + This is an optional addon that can be used to disable the network + execution function "CBA_fnc_globalExecute" from running code on + other machines. +*/ + +class CfgPatches { + class CBA_Disable_GlobalExec { + units[] = {}; + weapons[] = {}; + requiredVersion = 0.1; + requiredAddons[] = {"cba_network"}; + }; +}; + +class CfgSettings { + class CBA { + class Network { + disableGlobalExecute = 1; + }; + }; +};