fn_deleteUserMarker.sqf 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Name: cTab_fnc_deleteUserMarker
  3. Author(s):
  4. Gundy
  5. Description:
  6. Delete user placed marker at provided index and broadcast the result. This function is called on the server.
  7. Parameters:
  8. 0: STRING - Encryption Key for this marker
  9. 1: INTEGER - Index position of marker to delete
  10. Optional:
  11. 2: INTEGER - Transaction ID
  12. Returns:
  13. BOOLEAN - TRUE
  14. Example:
  15. // Client requesting marker deletion and server receiving request
  16. ["bluefor",5] call cTab_fnc_deleteUserMarker;
  17. // Client receiving request for marker deletion (from server)
  18. ["bluefor",5,158] call cTab_fnc_deleteUserMarker;
  19. */
  20. private ["_encryptionKey","_markerIndex","_transactionId","_userMarkerList","_removeIndex"];
  21. _encryptionKey = _this select 0;
  22. _markerIndex = _this select 1;
  23. _transactionId = _this select 2; // not set when initiated from client
  24. call {
  25. // If received on the server
  26. if (isServer) exitWith {
  27. if (isNil "_transactionId") then {
  28. // get the marker list that corresponds to the encryption key
  29. _userMarkerList = [cTab_userMarkerLists,_encryptionKey] call cTab_fnc_getFromPairs;
  30. // try to find the marker to be removed
  31. _removeIndex = -1;
  32. {
  33. if (_x select 0 == _markerIndex) exitWith {_removeIndex = _forEachIndex};
  34. } forEach _userMarkerList;
  35. // if the marker could be found, remove it
  36. if (_removeIndex != -1) then {
  37. 0 = _userMarkerList deleteAt _removeIndex;
  38. [cTab_userMarkerLists,_encryptionKey,_userMarkerList] call cTab_fnc_setToPairs;
  39. // Send deleteUserMarker command to all clients
  40. cTab_userMarkerTransactionId = cTab_userMarkerTransactionId + 1;
  41. [[_encryptionKey,_markerIndex,cTab_userMarkerTransactionId],"cTab_fnc_deleteUserMarker",true,false,true] call bis_fnc_MP;
  42. // If this was run on a client-server (i.e. in single player or locally hosted), update the marker list
  43. if (hasInterface && {_encryptionKey == call cTab_fnc_getPlayerEncryptionKey}) then {
  44. call cTab_fnc_updateUserMarkerList;
  45. };
  46. };
  47. };
  48. };
  49. // If received on a client, sent by the server
  50. if (hasInterface && !isNil "_transactionId") exitWith {
  51. call {
  52. if (cTab_userMarkerTransactionId == _transactionId) exitWith {};
  53. if (cTab_userMarkerTransactionId != (_transactionId -1)) exitWith {
  54. // get full list
  55. ["Transaction ID check failed! Had %1, received %2. Requesting user marker list.",cTab_userMarkerTransactionId,_transactionId] call bis_fnc_error;
  56. [] call cTab_fnc_getUserMarkerList;
  57. };
  58. cTab_userMarkerTransactionId = _transactionId;
  59. // get the marker list that corresponds to the encryption key
  60. _userMarkerList = [cTab_userMarkerLists,_encryptionKey] call cTab_fnc_getFromPairs;
  61. // try to find the marker to be removed
  62. _removeIndex = -1;
  63. {
  64. if (_x select 0 == _markerIndex) exitWith {_removeIndex = _forEachIndex};
  65. } forEach _userMarkerList;
  66. // if the marker could be found, remove it
  67. if (_removeIndex != -1) then {
  68. 0 = _userMarkerList deleteAt _removeIndex;
  69. [cTab_userMarkerLists,_encryptionKey,_userMarkerList] call cTab_fnc_setToPairs;
  70. // only update the user marker list if the marker was deleted from the player's side
  71. if (_encryptionKey == call cTab_fnc_getPlayerEncryptionKey) then {
  72. call cTab_fnc_updateUserMarkerList;
  73. };
  74. };
  75. };
  76. };
  77. // If received on a client, to be sent to the server
  78. if (hasInterface) then {
  79. [_this,"cTab_fnc_deleteUserMarker",false,false,true] call bis_fnc_MP;
  80. };
  81. };
  82. true