diff --git a/addons/dogtags/XEH_PREP.hpp b/addons/dogtags/XEH_PREP.hpp index 59176001399..a34a04a982a 100644 --- a/addons/dogtags/XEH_PREP.hpp +++ b/addons/dogtags/XEH_PREP.hpp @@ -5,10 +5,8 @@ PREP(bloodType); PREP(canCheckDogtag); PREP(canTakeDogtag); PREP(checkDogtag); -PREP(checkDogtagItem); PREP(getDogtagData); PREP(getDogtagItem); -PREP(sendDogtagData); PREP(showDogtag); PREP(ssn); PREP(takeDogtag); diff --git a/addons/dogtags/XEH_postInit.sqf b/addons/dogtags/XEH_postInit.sqf index 1633aace3cd..9f9fad0f818 100644 --- a/addons/dogtags/XEH_postInit.sqf +++ b/addons/dogtags/XEH_postInit.sqf @@ -1,10 +1,29 @@ #include "script_component.hpp" [QGVAR(showDogtag), LINKFUNC(showDogtag)] call CBA_fnc_addEventHandler; -[QGVAR(sendDogtagData), LINKFUNC(sendDogtagData)] call CBA_fnc_addEventHandler; [QGVAR(getDogtagItem), LINKFUNC(getDogtagItem)] call CBA_fnc_addEventHandler; [QGVAR(addDogtagItem), LINKFUNC(addDogtagItem)] call CBA_fnc_addEventHandler; +if (hasInterface || isServer) then { + [QGVAR(broadcastDogtagInfo), { + GVAR(dogtagsData) set _this; + }] call CBA_fnc_addEventHandler; + + if (isServer) then { + // Sync dogtag data from server to client + [QGVAR(requestSyncDogtagDataJIP), { + params ["_clientOwner"]; + + { + [QGVAR(broadcastDogtagInfo), [_x, _y], _clientOwner] call CBA_fnc_ownerEvent; + } forEach GVAR(dogtagsData); + }] call CBA_fnc_addEventHandler; + } else { + // To be here, hasInterface must be true + [QGVAR(requestSyncDogtagDataJIP), clientOwner] call CBA_fnc_serverEvent; + }; +}; + // Add actions and event handlers only if ace_medical is enabled // - Adding actions via config would create a dependency ["CBA_settingsInitialized", { @@ -56,8 +75,6 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then { if (_leftPanelIDC in [2010, 2012, 2014] && {_rightPanelIDC == 38}) then { LOG("passed"); private _rightPanel = _display displayCtrl 15; - private _allDogtags = missionNamespace getVariable [QGVAR(allDogtags), []]; - private _allDogtagsData = missionNamespace getVariable [QGVAR(allDogtagDatas), []]; private _cfgWeapons = configFile >> "CfgWeapons"; private _item = ""; private _dogtagData = []; @@ -66,7 +83,7 @@ if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then { _item = _rightPanel lnbData [_i, 0]; if (_item isKindOf ["ACE_dogtag", _cfgWeapons]) then { - private _name = (_allDogtagsData param [_allDogtags find _item, []]) param [0, ""]; + private _name = (GVAR(dogtagsData) getOrDefault [_item, []]) param [0, ""]; // If data doesn't exist or body has no name, set name as "unknown" if (_name == "") then { diff --git a/addons/dogtags/XEH_preInit.sqf b/addons/dogtags/XEH_preInit.sqf index f5fcb406b1d..482551de0ad 100644 --- a/addons/dogtags/XEH_preInit.sqf +++ b/addons/dogtags/XEH_preInit.sqf @@ -8,4 +8,12 @@ PREP_RECOMPILE_END; GVAR(disabledFactions) = createHashMap; +if (hasInterface || isServer) then { + GVAR(dogtagsData) = createHashMap; + + if (!isServer) exitWith {}; + + GVAR(idCounter) = 0; +}; + ADDON = true; diff --git a/addons/dogtags/functions/fnc_addDogtagActions.sqf b/addons/dogtags/functions/fnc_addDogtagActions.sqf index 7c7a2e5e8f9..b41cce1be84 100644 --- a/addons/dogtags/functions/fnc_addDogtagActions.sqf +++ b/addons/dogtags/functions/fnc_addDogtagActions.sqf @@ -27,7 +27,9 @@ private _fnc_getActions = { private _displayName = getText (_config >> "displayName"); private _picture = getText (_config >> "picture"); - private _action = [_x, _displayName, _picture, FUNC(checkDogtagItem), {true}, {}, _x] call EFUNC(interact_menu,createAction); + private _action = [_x, _displayName, _picture, { + [GVAR(dogtagsData) getOrDefault [_this select 2, []]] call FUNC(showDogtag); + }, {true}, {}, _x] call EFUNC(interact_menu,createAction); _actions pushBack [_action, [], _player]; }; } forEach (_player call EFUNC(common,uniqueItems)); diff --git a/addons/dogtags/functions/fnc_checkDogtagItem.sqf b/addons/dogtags/functions/fnc_checkDogtagItem.sqf deleted file mode 100644 index 09526d83ed8..00000000000 --- a/addons/dogtags/functions/fnc_checkDogtagItem.sqf +++ /dev/null @@ -1,22 +0,0 @@ -#include "..\script_component.hpp" -/* - * Author: SzwedzikPL - * Check dogtag self menu action. - * - * Arguments: - * 0: Player - * 1: Target - * 2: Item class - * - * Return Value: - * None - * - * Example: - * [player, unit, "itemClass"] call ace_dogtags_fnc_checkDogtagItem - * - * Public: No - */ - -params ["_player", "_target", "_item"]; - -[QGVAR(sendDogtagData), [_player, _item]] call CBA_fnc_serverEvent; diff --git a/addons/dogtags/functions/fnc_getDogtagItem.sqf b/addons/dogtags/functions/fnc_getDogtagItem.sqf index 04112bcc940..41cfc4deb78 100644 --- a/addons/dogtags/functions/fnc_getDogtagItem.sqf +++ b/addons/dogtags/functions/fnc_getDogtagItem.sqf @@ -21,19 +21,15 @@ if(!isServer) exitWith {}; params ["_player", "_target"]; TRACE_2("getDogtagItem",_player,_target); -private _allDogtags = missionNamespace getVariable [QGVAR(allDogtags), []]; -private _allDogtagDatas = missionNamespace getVariable [QGVAR(allDogtagDatas), []]; +GVAR(idCounter) = GVAR(idCounter) + 1; -private _nextID = count _allDogtags + 1; - -if (_nextID > 999) exitWith {ERROR("Ran out of IDs");}; +if (GVAR(idCounter) > 999) exitWith {ERROR("Ran out of IDs");}; private _dogTagData = [_target] call FUNC(getDogTagData); -private _item = format ["ACE_dogtag_%1", _nextID]; -_allDogtags pushBack _item; -_allDogtagDatas pushBack _dogTagData; +private _item = format ["ACE_dogtag_%1", GVAR(idCounter)]; -missionNamespace setVariable [QGVAR(allDogtags), _allDogtags]; -missionNamespace setVariable [QGVAR(allDogtagDatas), _allDogtagDatas]; [QGVAR(addDogtagItem), [_item, _dogTagData], [_player]] call CBA_fnc_targetEvent; + +// Broadcast data globally, so that clients can use it where needed +[QGVAR(broadcastDogtagInfo), [_item, _dogTagData]] call CBA_fnc_globalEvent; diff --git a/addons/dogtags/functions/fnc_sendDogtagData.sqf b/addons/dogtags/functions/fnc_sendDogtagData.sqf deleted file mode 100644 index 2351e611665..00000000000 --- a/addons/dogtags/functions/fnc_sendDogtagData.sqf +++ /dev/null @@ -1,33 +0,0 @@ -#include "..\script_component.hpp" -/* - * Author: SzwedzikPL - * Server: returns to client data on given dogtag. - * - * Arguments: - * 0: Player - * 1: Target - * - * Return Value: - * None - * - * Example: - * [player, unit] call ace_dogtags_fnc_sendDogtagData - * - * Public: No - */ - -if (!isServer) exitWith {}; - -params ["_target", "_item"]; -TRACE_2("sendDogtagData",_target,_item); - -private _allDogtags = missionNameSpace getVariable [QGVAR(allDogtags), []]; -private _allDogtagDatas = missionNameSpace getVariable [QGVAR(allDogtagDatas), []]; - -private _dogtagData = []; -private _index = _allDogtags find _item; -if (_index >= 0) then { - _dogtagData = _allDogtagDatas select _index; -}; - -[QGVAR(showDogtag), [_dogtagData], [_target]] call CBA_fnc_targetEvent;