Skip to content

Commit

Permalink
Merge pull request #306 from CBATeam/usePlayerConnectedMissionEvent
Browse files Browse the repository at this point in the history
use mission event for PlayerConnected
  • Loading branch information
Killswitch00 committed Apr 22, 2016
2 parents b9614f7 + 1d40d41 commit 62f7ee3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
5 changes: 5 additions & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ GVAR(addons) = _addons;
// BWC
#include "backwards_comp.sqf"

// band aid - remove this once they fix PlayerConnected mission event handler
// https://forums.bistudio.com/topic/143930-general-discussion-dev-branch/page-942#entry3003074
[QGVAR(OPC_FIX), "onPlayerConnected", {}] call BIS_fnc_addStackedEventHandler;
[QGVAR(OPC_FIX), "onPlayerConnected"] call BIS_fnc_removeStackedEventHandler;

ADDON = true;
14 changes: 11 additions & 3 deletions addons/common/init_perFrameHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ if (isMultiplayer) then {
GVAR(lastTickTime) = _tickTime;
};

["CBA_SynchMissionTime", "onPlayerConnected", {
_owner publicVariableClient "CBA_missionTime";
}] call BIS_fnc_addStackedEventHandler;
if (isNil {canSuspend}) then {
// pre v1.58
["CBA_SynchMissionTime", "onPlayerConnected", {
_owner publicVariableClient "CBA_missionTime";
}] call BIS_fnc_addStackedEventHandler;
} else {
// v1.58 and later
addMissionEventHandler ["PlayerConnected", {
(_this select 4) publicVariableClient "CBA_missionTime";
}];
};
} else {
CBA_missionTime = -1;

Expand Down
41 changes: 30 additions & 11 deletions addons/network/XEH_postServerInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,37 @@ LOG(MSG_INIT);
// Why would we send __SERVER__ to an on PLAYER connected event,
// [["__SERVER__","0",objNull,true]] call CBA_fnc_globalEvent;

// OPC gets _id, _uid, _name
[QUOTE(GVAR(opc)), "onPlayerConnected", {
if (_name=="__SERVER__") exitWith {};
_obj=objNull;
{
if (_name == name _x) then
if (isNil {canSuspend}) then {
// pre v1.58
// OPC gets _id, _uid, _name
[QUOTE(GVAR(opc)), "onPlayerConnected", {
if (_name=="__SERVER__") exitWith {};
_obj=objNull;
{
_obj=_x;
if (_name == name _x) then
{
_obj=_x;
};
} forEach playableUnits;
if (!isNull _obj) then {[_name, _uid, _obj] call FUNC(opc);};
}] call BIS_fnc_addStackedEventhandler;
} else {
// v1.58 and later
addMissionEventHandler ["PlayerConnected", {
params ["_id", "_uid", "_name", "_jip", "_owner"];

if (_name == "__SERVER__") exitWith {};

private _object = objNull;
{
if (name _x == _name) exitWith { _object = _x; };
} forEach playableUnits;

if (!isNull _object) then {
[_name, _uid, _object] call FUNC(opc);
};
} forEach playableUnits;
if (!isNull _obj) then {[_name, _uid, _obj] call FUNC(opc);};
}] call BIS_fnc_addStackedEventhandler;
}];
};

// Announce the completion of the initialization of the script
ADDON = true;
ADDON = true;

0 comments on commit 62f7ee3

Please sign in to comment.