Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Apollo #200

Merged
merged 30 commits into from
Sep 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1200763
Add initial integration of Apollo SQF
jonpas Jul 9, 2016
29bf382
Integrate all mission plugin functionality
jonpas Jul 9, 2016
8ae300f
Don't cleanup weapon holders on disconnect
jonpas Jul 9, 2016
814ab6a
Guarantee initialization
jonpas Jul 9, 2016
ba8dfda
Add settings
jonpas Jul 9, 2016
395f1eb
Make saving event-based with 10 second delay between saves
jonpas Jul 9, 2016
adba5ba
Verify extensions are present
jonpas Jul 9, 2016
88db091
Improve loadout changed saving
jonpas Jul 9, 2016
0c67812
Fix 8192 character limit
jonpas Jul 9, 2016
6c0fd86
Optimize Java invoker function
jonpas Jul 9, 2016
2c62384
Fix one more format
jonpas Jul 9, 2016
4abe766
Finalize JNI invoker
jonpas Jul 9, 2016
1c901f9
Fix undefined variable
jonpas Jul 10, 2016
9c39c2d
Fix invokeJavaMethod
jonpas Aug 23, 2016
d180aac
Adapt Zeus add object to Chronos module, Fix and improve delayed savi…
jonpas Aug 23, 2016
6edfa8d
Rename vehicle ID variable, Fix endMissionError
jonpas Aug 24, 2016
a396620
Don't error into mission end in editor (for testing Armory/Garage)
jonpas Aug 24, 2016
9b445b1
Add info logging, Rename debug variable, Add respawn support without …
jonpas Aug 24, 2016
c80c480
Reduce duplicate code for loading/respawning
jonpas Aug 24, 2016
0cf9a88
Allow damage and enable simulation after vehicles load without delay
jonpas Aug 24, 2016
465a406
Stop complaining Travis
jonpas Aug 24, 2016
ca2fc8d
Fix debug log
jonpas Aug 25, 2016
f6cb6c2
Use GVAR for tracking peristent vehicles rather than loop through all…
jonpas Aug 25, 2016
d13c2fb
Always save, even when there are no players online (makes sure vehicl…
jonpas Aug 25, 2016
143b2a5
Add possible fix for physics not activating on spawned objects
jonpas Aug 26, 2016
4e753bb
Remove redundant variable
jonpas Aug 26, 2016
fec2c8f
Fix invisibility during loading, Add ACE3's lastDamageSource as kille…
jonpas Sep 4, 2016
756fac2
Add forgotten handleConnect file
jonpas Sep 4, 2016
49db712
Run connect state set on every unit, reset as necessary
jonpas Sep 4, 2016
0e18145
Disable debug
jonpas Sep 4, 2016
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/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\tac\addons\apollo
20 changes: 20 additions & 0 deletions addons/apollo/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ACE_Settings {
class GVAR(enabled) {
value = 0;
typeName = "BOOL";
displayName = "$STR_ACE_Common_Enabled";
description = CSTRING(EnabledDesc);
};
class GVAR(enabledPlayers) {
value = 1;
typeName = "BOOL";
displayName = CSTRING(EnabledPlayers);
description = CSTRING(EnabledPlayersDesc);
};
class GVAR(enabledVehicles) {
value = 1;
typeName = "BOOL";
displayName = CSTRING(EnabledVehicles);
description = CSTRING(EnabledVehiclesDesc);
};
};
34 changes: 34 additions & 0 deletions addons/apollo/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
clientInit = QUOTE(call COMPILE_FILE(XEH_postInitClient));
serverInit = QUOTE(call COMPILE_FILE(XEH_postInitServer));
};
};

class Extended_Killed_EventHandlers {
class CAManBase {
class ADDON {
killed = QUOTE(_this call FUNC(handleKilled));
};
};
};

class Extended_Respawn_EventHandlers {
class CAManBase {
class ADDON {
respawn = QUOTE(_this call FUNC(handleRespawn));
};
};
};
37 changes: 37 additions & 0 deletions addons/apollo/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class CfgVehicles {
class ACE_Module;
class GVAR(module): ACE_Module {
author = ECSTRING(main,Author);
category = "TAC";
displayName = CSTRING(Module);
function = QFUNC(moduleInit);
scope = 2;
isGlobal = 1; // Global
isTriggerActivated = 0;
isDisposable = 0;
//icon = QPATHTOF(UI\Icon_Module_Chronos_ca.paa); @todo
class Arguments {
class enabled {
displayName = "$STR_ACE_Common_Enabled";
description = CSTRING(EnabledDesc);
typeName = "BOOL";
defaultValue = 1;
};
class enabledPlayers {
displayName = CSTRING(EnabledPlayers);
description = CSTRING(EnabledPlayersDesc);
typeName = "BOOL";
defaultValue = 1;
};
class enabledVehicles {
displayName = CSTRING(EnabledVehicles);
description = CSTRING(EnabledVehiclesDesc);
typeName = "BOOL";
defaultValue = 1;
};
};
class ModuleDescription {
description = CSTRING(ModuleDesc);
};
};
};
7 changes: 7 additions & 0 deletions addons/apollo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# About

Adds Apollo in-game persistence system (part of Chronos).

### Authors

- [Jonpas](https://github.com/jonpas)
15 changes: 15 additions & 0 deletions addons/apollo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PREP(endMissionError);
PREP(handleConnect);
PREP(handleDisconnect);
PREP(handleKilled);
PREP(handleLoadoutChanged);
PREP(handleRespawn);
PREP(invokeJavaMethod);
PREP(lockerAction);
PREP(moduleInit);
PREP(playerLoadClient);
PREP(playerSingletonSave);
PREP(vehicleLoad);
PREP(vehicleSaveServer);
PREP(vehicleSingletonLoad);
PREP(vehicleSingletonSave);
47 changes: 47 additions & 0 deletions addons/apollo/XEH_postInitClient.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "script_component.hpp"

// Exit on Headless
if (!hasInterface) exitWith {};

[QGVAR(initialized), {
// Check ApolloClient presenece and version
private _apolloClientVersion = "ApolloClient" callExtension "version";
if (_apolloClientVersion == "") exitWith {
ACE_LOGERROR("Failed to initialize - Missing ApolloClient extension!");
["Your connection has been terminated - Missing ApolloClient extension!"] call FUNC(endMissionError);
};
if (_apolloClientVersion != "1.1") exitWith {
ACE_LOGERROR_1("Failed to initialize - Wrong ApolloClient extension version (active: %1 - required: 1.1)!",_apolloClientVersion);
[format ["Your connection has been terminated - Wrong ApolloClient extension version (active: %1 - required: 1.1)!", _apolloClientVersion]] call FUNC(endMissionError);
};

// Terminate to lobby EH
[QGVAR(terminatePlayer), {
ACE_LOGERROR("Connection terminated - Unknown error with Chronos!");
["Your connection has been terminated - Unknown error with Chronos!"] call FUNC(endMissionError);
}] call CBA_fnc_addEventHandler;

// Load player after Respawn EH
[QGVAR(reinitializePlayer), {
params ["_player", "_registeredDeath"];
TRACE_1("Registered Death",_this);

// Load player
if (_registeredDeath == "done") then {
if ([_player] call FUNC(playerLoadClient)) then {
ACE_LOGINFO("Client respawned successfully.")
};
} else {
ACE_LOGERROR("Connection terminated - Death failed to register!");
[localize LSTRING(RespawnReinitialization)] call FUNC(endMissionError);
};
}] call CBA_fnc_addEventHandler;

// Load player and exit if loading failed
if !([player] call FUNC(playerLoadClient)) exitWith {};

// Save on each inventory change with at least 10 seconds between each save
["loadout", FUNC(handleLoadoutChanged)] call CBA_fnc_addPlayerEventHandler;

ACE_LOGINFO("Client loaded successfully.");
}] call CBA_fnc_addEventHandler;
48 changes: 48 additions & 0 deletions addons/apollo/XEH_postInitServer.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "script_component.hpp"

["ace_settingsInitialized", {
if (!GVAR(enabled)) exitWith { TRACE_1("Apollo Disabled",GVAR(enabled)) };

// Check JNI presence
if ("jni" callExtension "version" == "") exitWith {
ACE_LOGERROR("Failed to initialize - Missing JNI extension!");
};

// Set server type (debug or live) globally
private _serverType = ["getServerType"] call FUNC(invokeJavaMethod);
GVAR(isDebug) = [false, true] select (_serverType isEqualTo "debug");
publicVariable QGVAR(isDebug);

if (GVAR(enabledVehicles)) then {
call FUNC(vehicleLoad);
};

if (GVAR(enabledPlayers)) then {
// Save player
[QGVAR(savePlayer), {
params ["_player", "_type"];
[_player, getPlayerUID _player, _type] call FUNC(playerSingletonSave);
}] call CBA_fnc_addEventHandler;

// Player died
[QGVAR(playerDied), {
params ["_player", "_killerUID"];
TRACE_1("Player Died",_this);
private _registeredDeath = ["playerDied", getPlayerUID _player, _killerUID] call FUNC(invokeJavaMethod);
[QGVAR(reinitializePlayer), [_player, _registeredDeath], _player] call CBA_fnc_targetEvent;
}] call CBA_fnc_addEventHandler;

// Hiding and disabling simulation (has to be executed on server, during init there is lag, so we do it on server directly)
["CAManBase", "InitPost", FUNC(handleConnect), true, [], true] call CBA_fnc_addClassEventHandler;

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

// Start client initialization
[QGVAR(initialized), []] call CBA_fnc_globalEventJIP;
};

[QGVAR(lockerAction), FUNC(lockerAction)] call CBA_fnc_addEventHandler;

ACE_LOGINFO_3("Server loaded successfully (Players: %1 - Vehicles: %2 - Debug: %3)",GVAR(enabledPlayers),GVAR(enabledVehicles),GVAR(isDebug));
}] call CBA_fnc_addEventHandler;
11 changes: 11 additions & 0 deletions addons/apollo/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "script_component.hpp"

ADDON = false;

#include "XEH_PREP.hpp"

GVAR(vehiclesLoaded) = false;
GVAR(isDebug) = false;
GVAR(vehiclesList) = [];

ADDON = true;
3 changes: 3 additions & 0 deletions addons/apollo/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
18 changes: 18 additions & 0 deletions addons/apollo/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"tac_main"};
author = ECSTRING(main,Author);
authors[]= {"Jonpas"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

#include "ACE_Settings.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
26 changes: 26 additions & 0 deletions addons/apollo/functions/fnc_endMissionError.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Author: Jonpas
* Ends mission with error message on client.
*
* Arguments:
* 0: Error Message <STRING>
*
* Return Value:
* None
*
* Example:
* ["Error"] call tac_apollo_fnc_endMissionError
*
* Public: No
*/
#include "script_component.hpp"

params ["_errorMessage"];

titleText ["", "BLACK IN", 0];
titleText [_errorMessage, "black"];
titleFadeOut 9999;

[{
["end1", false, 0] call BIS_fnc_endMission;
}, [], 5] call CBA_fnc_waitAndExecute;
43 changes: 43 additions & 0 deletions addons/apollo/functions/fnc_handleConnect.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Author: Jonpas
* Handles unit visibility and simulation on connect during loading.
* Restores state if not player, for players state is restored after successfully loading.
* isPlayer and getPlayerUID are not guaranteed to be set when this runs, thus wait.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [unit] call tac_apollo_fnc_handleConnect
*
* Public: No
*/
#include "script_component.hpp"

params ["_unit"];

_unit enableSimulationGlobal false;
_unit hideObjectGlobal true;
TRACE_4("Handle Client Connect",_unit,isObjectHidden _unit,isPlayer _unit,getPlayerUID _unit);

// Exit if already player (when loading in with server client init finishes sooner)
if (isPlayer _unit) exitWith {
TRACE_1("Handle Client Connect - Is Player",_unit);
};

// Wait until becomes player or 5 seconds, restores state if not player
[{
params ["_unit", "_timeStart"];
isPlayer _unit || {_timeStart + 5 < CBA_missionTime}
}, {
params ["_unit"];

if (!isPlayer _unit) then {
_unit enableSimulationGlobal true;
_unit hideObjectGlobal false;
TRACE_4("Handle Client Connect - Not Player",_unit,isObjectHidden _unit,isPlayer _unit,getPlayerUID _unit);
};
}, [_unit, CBA_missionTime]] call CBA_fnc_waitUntilAndExecute;
28 changes: 28 additions & 0 deletions addons/apollo/functions/fnc_handleDisconnect.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Author: Jonpas
* Handles save and corpse removal on disconnect.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: ID <NUMBER> (unused)
* 2: UID <STRING>
*
* Return Value:
* None
*
* Example:
* [unit, 11, "51792927127296126"] call tac_apollo_fnc_handleDisconnect
*
* Public: No
*/
#include "script_component.hpp"

params ["_unit", "", "_uid"];

if (isNull _unit) exitWith {
ACE_LOGERROR_1("Player not saved on disconnect - null unit (UID: %1)!",getPlayerUID _player);
};

[_unit, _uid, "save"] call FUNC(playerSingletonSave);

deleteVehicle _unit;
36 changes: 36 additions & 0 deletions addons/apollo/functions/fnc_handleKilled.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Author: Jonpas
* Handles killed event (mark in backend for fresh inventory).
* Resets inventory in combination with Respawn event. UID is not valid after quick respawn in Killed event.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Killer <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player, killer] call tac_apollo_fnc_handleKilled
*
* Public: No
*/
#include "script_component.hpp"

params ["_player", "_killer"];
TRACE_1("Handle Killed",_this);

private _killerUID = getPlayerUID _killer;

// Try to get UID from ACE3's damage source (ace_medical uses setDamage which makes killer always objNull)
if (_killerUID == "") then {
_killerUID = getPlayerUID (_player getVariable ["ace_medical_lastDamageSource", objNull]);

// No valid UID found, assume killer was AI or Self
if (_killerUID == "") then {
_killerUID = "AI/Self";
};
};

// Save Killed EH data for use in Respawn EH
_player setVariable [QGVAR(killerUID), _killerUID];
Loading