Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/apollo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PREP(invokeJavaMethod);
PREP(lockerAction);
PREP(playerLoadClient);
PREP(playerSaveClient);
PREP(playerSingletonLoad);
PREP(playerSingletonSave);
PREP(vehicleLoad);
PREP(vehicleSaveServer);
Expand Down
10 changes: 8 additions & 2 deletions addons/apollo/XEH_postInitServer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ if (GVAR(enabledPlayers)) then {
// Save player
[QGVAR(savePlayer), {
params ["_player", "_name", "_type"];
[_player, getPlayerUID _player, _name, _type] call FUNC(playerSingletonSave);
private _uid = getPlayerUID _player;

if (_type == "validate") then {
[_player, _uid, _name] call FUNC(playerSingletonLoad);
};

[_player, _uid, _name, _type] call FUNC(playerSingletonSave);
}] call CBA_fnc_addEventHandler;

// Player died
Expand All @@ -46,7 +52,7 @@ if (GVAR(enabledPlayers)) then {
[QGVAR(reinitializePlayer), [_player, _registeredDeath], _player] call CBA_fnc_targetEvent;
}] call CBA_fnc_addEventHandler;

// Corpse removal (prevent item multiplication when leaving nicely)
// Corpse removal (prevent item multiplication when leaving nicely) and additional runtime data handler
addMissionEventHandler ["HandleDisconnect", FUNC(handleDisconnect)];

// Start client initialization
Expand Down
4 changes: 4 additions & 0 deletions addons/apollo/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ if (isServer) then {

GVAR(isDebug) = false;

if (isServer) then {
GVAR(playerRuntimeData) = createHashMap;
};

ADDON = true;
1 change: 1 addition & 0 deletions addons/apollo/functions/fnc_handleDisconnect.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*
* Author: Jonpas
* Handles save and corpse removal on disconnect.
* Runs only on server.
*
* Arguments:
* 0: Unit <OBJECT>
Expand Down
1 change: 1 addition & 0 deletions addons/apollo/functions/fnc_playerLoadClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if (!isNil "_result") then {
// Validate
// Delay to allow Arma server to get the new loadout before attempting to validate
// Validation does nothing at this moment as it was never properly implemented in the backend
// This is also used to load runtime (current mission run) data
[{
[QGVAR(savePlayer), [_this, profileName, "validate"]] call CBA_fnc_serverEvent;
}, _player, 1] call CBA_fnc_waitAndExecute;
Expand Down
49 changes: 49 additions & 0 deletions addons/apollo/functions/fnc_playerSingletonLoad.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "script_component.hpp"
/*
* Author: Jonpas
* Loads runtime (current mission run) player data on the server.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Player UID <STRING>
* 2: Player Name <STRING>
*
* Return Value:
* None
*
* Example:
* [player, "36182159512951925", "Banana"] call tac_apollo_fnc_playerSingletonLoad
*
* Public: No
*/

params ["_player", "_uid", "_name"];

private _playerRuntimeData = GVAR(playerRuntimeData) get _uid;
if (isNil "_playerRuntimeData") exitWith {}; // didn't actually disconnect
INFO_2("Player '%1' (%2) reconnected",_name,_uid);

_playerRuntimeData params ["_oldGroup", "_oldTeam", "_oldVehicle", "_oldMedical"];

// Group
if ((group _player) isNotEqualTo _oldGroup && {!isNull _oldGroup}) then {
[_player] join _oldGroup;
};

// Team
if (assignedTeam _player != _oldTeam && {_oldTeam != ""}) then {
_player assignTeam _oldTeam;
};

// Vehicle
if (!isNull _oldVehicle) then {
if !(_player moveInAny _oldVehicle) then {
WARNING_2("Failed to move player '%1' back into vehicle!",_player,_oldVehicle);
};
};

// Medical
[_player, _oldMedical] call ACEFUNC(medical,deserializeState);

// Clear for correct disconect check
GVAR(playerRuntimeData) deleteAt _uid;
9 changes: 9 additions & 0 deletions addons/apollo/functions/fnc_playerSingletonSave.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ private _selectedWeapon = currentWeapon _player;
// Variables TODO
private _playerVariables = [];

// Save additional data relevant only for the current mission run
GVAR(playerRuntimeData) set [_uid, [
group _player,
assignedTeam _player,
vehicle _player,
[_player] call ACEFUNC(medical,serializeState)
]];

// Send to backend
private _serverReply = ["storeInfantry", _type, _uid, _name, _playerPos, _playerDir, _loadout, _selectedWeapon, _playerVariables] call FUNC(invokeJavaMethod);

TRACE_2("Singleton Save",_type,_serverReply);
Expand Down