Added whole websocket handling to the client addon

This commit is contained in:
Valmo Trindade
2025-05-15 23:48:14 -03:00
parent ffcd4feb4e
commit 6de6a29a09
15 changed files with 81 additions and 61 deletions

View File

@@ -0,0 +1 @@
armatak\armatak\armatak_client

View File

@@ -0,0 +1,11 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};

View File

@@ -0,0 +1,3 @@
PREP(convertLocation);
PREP(extractClientPosition);
PREP(socketRouter);

View File

@@ -0,0 +1,9 @@
#include "script_component.hpp"
ADDON = false;
PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;
ADDON = true;

View File

@@ -0,0 +1,3 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"

View File

@@ -21,3 +21,5 @@ class Extended_PostInit_EventHandlers {
init = "call compileScript ['\armatak\armatak\armatak_client\initPlayerLocal.sqf']";
};
};
#include "CfgEventHandlers.hpp"

View File

@@ -0,0 +1,61 @@
params["_latitude", "_longitude", "_altitude"];
_position = [_latitude, _longitude, _altitude];
_realLocation = null;
switch (toLower worldName) do {
case "altis": {
_realLocation = _position call armatak_fnc_convert_to_altis;
};
case "stratis": {
_realLocation = _position call armatak_fnc_convert_to_stratis;
};
case "malden": {
_realLocation = _position call armatak_fnc_convert_to_malden;
};
case "vr": {
_realLocation = _position call armatak_fnc_convert_to_vr;
};
case "cucui": {
_realLocation = _position call armatak_fnc_convert_to_cucui;
};
case "chernarus": {
_realLocation = _position call armatak_fnc_convert_to_chernarus;
};
case "chernarus_summer": {
_realLocation = _position call armatak_fnc_convert_to_chernarus;
};
case "chernarus_winter": {
_realLocation = _position call armatak_fnc_convert_to_chernarus;
};
case "bootcamp_acr": {
_realLocation = _position call armatak_fnc_convert_to_bukovina;
};
case "woodland_acr": {
_realLocation = _position call armatak_fnc_convert_to_bystrika;
};
case "mountains_acr": {
_realLocation = _position call armatak_fnc_convert_to_takistan_montains;
};
case "sara_dbe1": {
_realLocation = _position call armatak_fnc_convert_to_united_sahrani;
};
case "saralite": {
_realLocation = _position call armatak_fnc_convert_to_southen_sahrani;
};
case "enoch": {
_realLocation = _position call armatak_fnc_convert_to_livonia;
};
case "kunduz": {
_realLocation = _position call armatak_fnc_convert_to_kunduz;
};
default {
_warning = format ["<t color='#FF8021'>ARMATAK</t><br/> %1", "Unsupported Map"];
[[_warning, 1.5]] call CBA_fnc_notify;
_realLocation = [0, 0, 0];
};
};
_realLocation

View File

@@ -0,0 +1,30 @@
#include "..\script_component.hpp"
/*
* Author: Valmo Trindade
* This function is used to extract the position of a unit and convert it to a format suitable for SIMTAK.
*
* Argument:
* 0: The first argument <OBJECT> is the unit whose position you want to extract.
*
* Return Value:
* ARRAY -> [latitude, longitude, altitude, bearing]
*
* Example:
* [player] call armatak_client_fnc_extractClientPosition;
*
* Public: Yes
*/
params["_unit"];
private _location = (getPos _unit) call armatak_client_fnc_convertClientLocation;
private _atak_latitude = _location select 0;
private _atak_longitude = _location select 1;
private _atak_altitude = _location select 2;
private _atak_bearing = parseNumber ((getDir _unit) toFixed 0);
_unit_info = [_atak_latitude,_atak_longitude,_atak_altitude,_atak_bearing];
_unit_info

View File

@@ -0,0 +1,11 @@
#include "..\script_component.hpp"
if (!hasInterface) exitWith {};
_local_address = "armatak" callExtension ["local_ip", []] select 0;
SETVAR(player, localAddress, _local_address);
[{
"armatak" callExtension ["websocket:location", [player call FUNC(extractClientPosition)]];
}, 1, []] call CBA_fnc_addPerFrameHandler;

View File

@@ -1,18 +0,0 @@
if (!hasInterface) exitWith {};
_local_address = "armatak" callExtension ["local_ip", []] select 0;
player setVariable ["localAddress", _local_address];
player addEventHandler ["Respawn", {
params["_unit", "_corpse"];
[{
if (alive _this) then {
"armatak" callExtension ["websocket:location", [player call armatak_fnc_extract_position]];
};
}, 1, []] call CBA_fnc_addPerFrameHandler;
}];
[{
"armatak" callExtension ["websocket:location", [player call armatak_fnc_extract_position]];
}, 1, []] call CBA_fnc_addPerFrameHandler;

View File

@@ -1,17 +1,17 @@
#define COMPONENT client
#define COMPONENT_BEAUTIFIED WebSocket
#define COMPONENT_BEAUTIFIED WebSocket Client
#include "\armatak\armatak\armatak_main\script_mod.hpp"
// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS
#ifdef DEBUG_ENABLED_MAIN
#ifdef DEBUG_ENABLED_CLIENT
#define DEBUG_MODE_FULL
#endif
#ifdef DEBUG_SETTINGS_MAIN
#define DEBUG_SETTINGS DEBUG_SETTINGS_MAIN
#ifdef DEBUG_SETTINGS_CLIENT
#define DEBUG_SETTINGS DEBUG_SETTINGS_CLIENT
#endif
#include "\z\ace\addons\main\script_macros.hpp"