mirror of
https://github.com/indig0fox/Arma3-AttendanceTracker.git/
synced 2025-12-08 09:51:47 -06:00
implement GORM, expand config, modify the way sessions are handled
This commit is contained in:
@@ -21,6 +21,7 @@ class CfgFunctions {
|
||||
class writeConnect {};
|
||||
class writeDisconnect {};
|
||||
class timestamp {};
|
||||
class getSettings {};
|
||||
class getMissionHash {};
|
||||
class getWorldInfo {};
|
||||
class missionLoaded {};
|
||||
|
||||
@@ -21,7 +21,9 @@ addMissionEventHandler ["ExtensionCallback", {
|
||||
false;
|
||||
};
|
||||
|
||||
diag_log format ["Raw callback: %1: %2", _function, _data];
|
||||
if (missionNamespace getVariable ["AttendanceTracker_" + "debug", true]) then {
|
||||
diag_log format ["Raw callback: %1: %2", _function, _data];
|
||||
};
|
||||
|
||||
// Parse response from string array
|
||||
private "_response";
|
||||
@@ -44,12 +46,7 @@ addMissionEventHandler ["ExtensionCallback", {
|
||||
case "connectDB": {
|
||||
systemChat format ["AttendanceTracker: %1", _response#0];
|
||||
[_response#0, _response#1, _function] call attendanceTracker_fnc_log;
|
||||
if (_response#0 == "SUCCESS") then {
|
||||
missionNamespace setVariable ["AttendanceTracker_DBConnected", true];
|
||||
|
||||
// close any null disconnect values from previous mission
|
||||
"AttendanceTracker" callExtension ["fillLastMissionNull", []];
|
||||
|
||||
if (_response#0 == "SUCCESS") then {
|
||||
// log world info
|
||||
private _response = "AttendanceTracker" callExtension [
|
||||
"logWorld",
|
||||
@@ -65,21 +62,13 @@ addMissionEventHandler ["ExtensionCallback", {
|
||||
[AttendanceTracker getVariable ["missionContext", createHashMap]] call CBA_fnc_encodeJSON
|
||||
]
|
||||
];
|
||||
|
||||
missionNamespace setVariable ["AttendanceTracker_DBConnected", true];
|
||||
};
|
||||
};
|
||||
case "writeMissionInfo": {
|
||||
case "writeMission": {
|
||||
if (_response#0 == "MISSION_ID") then {
|
||||
AttendanceTracker_missionId = parseNumber (_response#1);
|
||||
};
|
||||
};
|
||||
case "writeAttendance": {
|
||||
if (_response#0 == "ATT_LOG") then {
|
||||
(_response#1) params ["_eventType", "_netId", "_rowId"];
|
||||
private _storeIndex = ["SERVER", "MISSION"] find _eventType;
|
||||
((AttendanceTracker getVariable ["rowIds", createHashMap]) getOrDefault [
|
||||
_netId,
|
||||
[nil, nil]
|
||||
]) set [_storeIndex, _rowId];
|
||||
AttendanceTracker_missionId = _response#1;
|
||||
};
|
||||
};
|
||||
default {
|
||||
|
||||
@@ -16,16 +16,52 @@
|
||||
|
||||
(AttendanceTracker getVariable ["allUsers", createHashMap]) set [_networkId, _userInfo];
|
||||
|
||||
[
|
||||
|
||||
[ // write d/c for past events
|
||||
"Server",
|
||||
_playerID,
|
||||
_playerUID,
|
||||
_profileName,
|
||||
_steamName,
|
||||
nil,
|
||||
nil
|
||||
] call attendanceTracker_fnc_writeConnect;
|
||||
_steamName
|
||||
] call attendanceTracker_fnc_writeDisconnect;
|
||||
|
||||
// [
|
||||
// "Server",
|
||||
// _playerID,
|
||||
// _playerUID,
|
||||
// _profileName,
|
||||
// _steamName,
|
||||
// nil,
|
||||
// nil
|
||||
// ] call attendanceTracker_fnc_writeConnect;
|
||||
|
||||
// start CBA PFH
|
||||
[format ["(EventHandler) OnUserConnected: Starting CBA PFH for %1", _playerID], "DEBUG"] call attendanceTracker_fnc_log;
|
||||
[
|
||||
{
|
||||
params ["_args", "_handle"];
|
||||
// check if player is still connected
|
||||
private _playerID = _args select 1;
|
||||
private _playerUID = _args select 2;
|
||||
if (allUsers find _playerID == -1) exitWith {
|
||||
[format ["(EventHandler) OnUserConnected: %1 (UID %2) is no longer connected, exiting CBA PFH", _playerUID], "DEBUG"] call attendanceTracker_fnc_log;
|
||||
_args call attendanceTracker_fnc_writeDisconnect;
|
||||
[_handle] call CBA_fnc_removePerFrameHandler;
|
||||
};
|
||||
|
||||
_args call attendanceTracker_fnc_writeConnect;
|
||||
},
|
||||
missionNamespace getVariable ["AttendanceTracker_" + "dbupdateintervalseconds", 300],
|
||||
[
|
||||
"Server",
|
||||
_playerID,
|
||||
_playerUID,
|
||||
_profileName,
|
||||
_steamName,
|
||||
nil,
|
||||
nil
|
||||
]
|
||||
] call CBA_fnc_addPerFrameHandler;
|
||||
}],
|
||||
["OnUserDisconnected", {
|
||||
params ["_networkId", "_clientStateNumber", "_clientState"];
|
||||
@@ -75,15 +111,56 @@
|
||||
|
||||
(AttendanceTracker getVariable ["allUsers", createHashMap]) set [_playerID, _userInfo];
|
||||
|
||||
[
|
||||
|
||||
[ // write d/c for past events
|
||||
"Mission",
|
||||
_playerID,
|
||||
_playerUID,
|
||||
_profileName,
|
||||
_steamName,
|
||||
_jip,
|
||||
roleDescription _unit
|
||||
] call attendanceTracker_fnc_writeConnect;
|
||||
nil
|
||||
] call attendanceTracker_fnc_writeDisconnect;
|
||||
|
||||
// [
|
||||
// "Mission",
|
||||
// _playerID,
|
||||
// _playerUID,
|
||||
// _profileName,
|
||||
// _steamName,
|
||||
// _jip,
|
||||
// roleDescription _unit
|
||||
// ] call attendanceTracker_fnc_writeConnect;
|
||||
|
||||
// start CBA PFH
|
||||
[format ["(EventHandler) PlayerConnected: Starting CBA PFH for %1", _playerID], "DEBUG"] call attendanceTracker_fnc_log;
|
||||
[
|
||||
{
|
||||
params ["_args", "_handle"];
|
||||
// check if player is still connected
|
||||
private _playerID = _args select 1;
|
||||
private _playerUID = _args select 2;
|
||||
private _userInfo = getUserInfo _playerID;
|
||||
private _clientStateNumber = _userInfo select 6;
|
||||
if (_clientStateNumber < 6) exitWith {
|
||||
[format ["(EventHandler) PlayerConnected: %1 (UID) is no longer connected to the mission, exiting CBA PFH", _playerID], "DEBUG"] call attendanceTracker_fnc_log;
|
||||
_args call attendanceTracker_fnc_writeDisconnect;
|
||||
[_handle] call CBA_fnc_removePerFrameHandler;
|
||||
};
|
||||
|
||||
_args call attendanceTracker_fnc_writeConnect;
|
||||
},
|
||||
missionNamespace getVariable ["AttendanceTracker_" + "dbupdateintervalseconds", 300],
|
||||
[
|
||||
"Mission",
|
||||
_playerID,
|
||||
_playerUID,
|
||||
_profileName,
|
||||
_steamName,
|
||||
_jip,
|
||||
roleDescription _unit
|
||||
]
|
||||
] call CBA_fnc_addPerFrameHandler;
|
||||
}],
|
||||
["PlayerDisconnected", {
|
||||
// NOTE: HandleDisconnect returns a DIFFERENT _id than PlayerDisconnected and above handlers, so we can't use it here
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
parseSimpleArray ('AttendanceTracker' callExtension "getSettings");
|
||||
@@ -7,7 +7,7 @@ params [
|
||||
if (isNil "_message") exitWith {false};
|
||||
if (
|
||||
missionNamespace getVariable ["AttendanceTracker_debug", false] &&
|
||||
_level == "DEBUG"
|
||||
_level != "WARN" && _level != "ERROR"
|
||||
) exitWith {};
|
||||
|
||||
"AttendanceTracker" callExtension ["log", [_level, _message]];
|
||||
|
||||
@@ -6,7 +6,22 @@ diag_log format ["AttendanceTracker: Mission started at %1", AttendanceTracker_m
|
||||
AttendanceTracker_missionHash = call attendanceTracker_fnc_getMissionHash;
|
||||
diag_log format ["AttendanceTracker: Mission hash is %1", AttendanceTracker_missionHash];
|
||||
|
||||
_settings = call attendanceTracker_fnc_getSettings;
|
||||
if (count _settings > 0) then {
|
||||
for "_i" from 0 to (count _settings) - 1 do {
|
||||
_setting = _settings select _i;
|
||||
_key = _setting select 0;
|
||||
_value = _setting select 1;
|
||||
missionNamespace setVariable ["AttendanceTracker_" + _key, _value];
|
||||
};
|
||||
} else {
|
||||
[format["Failed to parse settings: %1", _settings], "ERROR"] call attendanceTracker_fnc_log;
|
||||
};
|
||||
call attendanceTracker_fnc_connectDB;
|
||||
|
||||
AttendanceTracker setVariable ["missionContext", createHashMapFromArray [
|
||||
["missionHash", AttendanceTracker_missionHash],
|
||||
["missionStart", AttendanceTracker_missionStartTimestamp],
|
||||
["missionName", missionName],
|
||||
["briefingName", briefingName],
|
||||
["missionNameSource", missionNameSource],
|
||||
@@ -24,9 +39,6 @@ AttendanceTracker setVariable ["missionContext", createHashMapFromArray [
|
||||
// store all user details in a hash when they connect so we can reference it in disconnect events
|
||||
AttendanceTracker setVariable ["allUsers", createHashMap];
|
||||
AttendanceTracker setVariable ["rowIds", createHashMap];
|
||||
missionNamespace setVariable ["AttendanceTracker_debug", false];
|
||||
|
||||
call attendanceTracker_fnc_connectDB;
|
||||
|
||||
{
|
||||
if (!isServer) exitWith {};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
// need date for MySQL in format 2006-01-02 15:04:05
|
||||
|
||||
systemTimeUTC params [
|
||||
systemTimeUTC apply {if (_x < 10) then {"0" + str _x} else {str _x}} params [
|
||||
"_year",
|
||||
"_month",
|
||||
"_day",
|
||||
|
||||
@@ -17,8 +17,12 @@ _hash set ["profileName", _profileName];
|
||||
_hash set ["steamName", _steamName];
|
||||
_hash set ["isJIP", _isJIP];
|
||||
_hash set ["roleDescription", _roleDescription];
|
||||
_hash set ["missionHash", missionNamespace getVariable ["AttendanceTracker_missionHash", ""]];
|
||||
|
||||
"AttendanceTracker" callExtension ["writeAttendance", [[_hash] call CBA_fnc_encodeJSON]];
|
||||
[
|
||||
{missionNamespace getVariable ["AttendanceTracker_DBConnected", false]},
|
||||
{"AttendanceTracker" callExtension ["writeAttendance", [[_this] call CBA_fnc_encodeJSON]]},
|
||||
_hash, // args
|
||||
30 // timeout in seconds. if DB never connects, we don't want these building up
|
||||
] call CBA_fnc_waitUntilAndExecute;
|
||||
|
||||
true;
|
||||
@@ -17,8 +17,12 @@ _hash set ["profileName", _profileName];
|
||||
_hash set ["steamName", _steamName];
|
||||
_hash set ["isJIP", _isJIP];
|
||||
_hash set ["roleDescription", _roleDescription];
|
||||
_hash set ["missionHash", missionNamespace getVariable ["AttendanceTracker_missionHash", ""]];
|
||||
|
||||
"AttendanceTracker" callExtension ["writeDisconnectEvent", [[_hash] call CBA_fnc_encodeJSON]];
|
||||
[
|
||||
{missionNamespace getVariable ["AttendanceTracker_DBConnected", false]},
|
||||
{"AttendanceTracker" callExtension ["writeDisconnectEvent", [[_this] call CBA_fnc_encodeJSON]]},
|
||||
_hash, // args
|
||||
30 // timeout in seconds. if DB never connects, we don't want these building up
|
||||
] call CBA_fnc_waitUntilAndExecute;
|
||||
|
||||
true;
|
||||
Reference in New Issue
Block a user