fn_addUserMarker.sqf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Name: cTab_fnc_addUserMarker
  3. Author(s):
  4. Gundy
  5. Description:
  6. Add a new user marker to the list and broadcast it. This function is called on the server.
  7. Parameters:
  8. 0: STRING - Encryption Key for this marker
  9. 1: ARRAY - markerData
  10. Optional:
  11. 2: INTEGER - Transaction ID
  12. Returns:
  13. BOOLEAN - Always TRUE
  14. Example:
  15. // Client requesting marker addition and server receiving request
  16. ["bluefor",[[1714.35,5716.82],0,0,0,"12:00",player]]call cTab_fnc_addUserMarker;
  17. // Client receiving marker addition (from server)
  18. ["bluefor",[21,[[1714.35,5716.82],0,0,0,"12:00",player]],157]call cTab_fnc_addUserMarker;
  19. */
  20. private ["_encryptionKey","_markerData","_transactionId"];
  21. _encryptionKey = _this select 0;
  22. _markerData = _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. // Increase transaction ID
  29. cTab_userMarkerTransactionId = cTab_userMarkerTransactionId + 1;
  30. _transactionId = cTab_userMarkerTransactionId;
  31. // Add marker data to list
  32. [cTab_userMarkerLists,_encryptionKey,[[_transactionId,_markerData]]] call cTab_fnc_addToPairs;
  33. // Send addUserMarker command to all clients
  34. [[_encryptionKey,[_transactionId,_markerData],_transactionId],"cTab_fnc_addUserMarker",true,false,true] call bis_fnc_MP;
  35. // If this was run on a client-server (i.e. in single player or locally hosted), update the marker list
  36. if (hasInterface && {_encryptionKey == call cTab_fnc_getPlayerEncryptionKey}) then {
  37. call cTab_fnc_updateUserMarkerList;
  38. if ((_markerData select 5) != cTab_player) then {
  39. ["BFT",format ["New marker at #%1",mapGridPosition (_markerData select 0)],20] call cTab_fnc_addNotification;
  40. } else {
  41. ["BFT","Marker added succesfully",3] call cTab_fnc_addNotification;
  42. };
  43. };
  44. };
  45. };
  46. // If received on a client, sent by the server
  47. if (hasInterface && !isNil "_transactionId") exitWith {
  48. call {
  49. if (cTab_userMarkerTransactionId == _transactionId) exitWith {};
  50. if (cTab_userMarkerTransactionId != (_transactionId -1)) exitWith {
  51. // get full list
  52. ["Transaction ID check failed! Had %1, received %2. Requesting user marker list.",cTab_userMarkerTransactionId,_transactionId] call bis_fnc_error;
  53. [] call cTab_fnc_getUserMarkerList;
  54. };
  55. cTab_userMarkerTransactionId = _transactionId;
  56. [cTab_userMarkerLists,_encryptionKey,[_markerData]] call cTab_fnc_addToPairs;
  57. // only update the user marker list if the marker was added to the player's side
  58. if (_encryptionKey == call cTab_fnc_getPlayerEncryptionKey) then {
  59. call cTab_fnc_updateUserMarkerList;
  60. // add notification if marker was issued by someone else
  61. if ((_markerData select 1 select 5) != cTab_player) then {
  62. ["BFT",format ["New marker at #%1",mapGridPosition (_markerData select 1 select 0)],20] call cTab_fnc_addNotification;
  63. } else {
  64. ["BFT","Marker added succesfully",3] call cTab_fnc_addNotification;
  65. };
  66. };
  67. };
  68. };
  69. // If received on a client, to be sent to the server
  70. if (hasInterface) then {
  71. [_this,"cTab_fnc_addUserMarker",false,false,true] call bis_fnc_MP;
  72. };
  73. };
  74. true