mirror of
https://github.com/indig0fox/Arma3-AttendanceTracker.git/
synced 2025-12-08 09:51:47 -06:00
initial version
This commit is contained in:
25
@17thAttendanceTracker/addons/AttendanceTracker/config.cpp
Normal file
25
@17thAttendanceTracker/addons/AttendanceTracker/config.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
class CfgPatches {
|
||||
class AttendanceTracker {
|
||||
units[] = {};
|
||||
weapons[] = {};
|
||||
requiredVersion = 2.10;
|
||||
requiredAddons[] = {};
|
||||
author[] = {"IndigoFox"};
|
||||
authorUrl = "http://example.com";
|
||||
};
|
||||
};
|
||||
|
||||
class CfgFunctions {
|
||||
class attendanceTracker {
|
||||
class functions {
|
||||
file = "\AttendanceTracker\functions";
|
||||
class postInit {postInit = 1;};
|
||||
class eventHandlers {};
|
||||
class callbackHandler {postInit = 1;};
|
||||
class log {};
|
||||
class logMissionEvent {};
|
||||
class logServerEvent {};
|
||||
class timestamp {};
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
addMissionEventHandler ["ExtensionCallback", {
|
||||
params ["_name", "_function", "_data"];
|
||||
if !(_name == "AttendanceTracker") exitWith {};
|
||||
|
||||
// Validate data param
|
||||
if (isNil "_data") then {_data = ""};
|
||||
|
||||
if (_data isEqualTo "") exitWith {
|
||||
[
|
||||
format ["Callback empty data: %1", _function],
|
||||
"WARN"
|
||||
] call attendanceTracker_fnc_log;
|
||||
false;
|
||||
};
|
||||
|
||||
if (typeName _data != "STRING") exitWith {
|
||||
[
|
||||
format ["Callback invalid data: %1: %2", _function, _data],
|
||||
"WARN"
|
||||
] call attendanceTracker_fnc_log;
|
||||
false;
|
||||
};
|
||||
|
||||
// Parse response from string array
|
||||
private "_response";
|
||||
try {
|
||||
// diag_log format ["Raw callback: %1: %2", _function, _data];
|
||||
_response = parseSimpleArray _data;
|
||||
} catch {
|
||||
[
|
||||
format ["Callback invalid data: %1: %2: %3", _function, _data, _exception],
|
||||
"WARN"
|
||||
] call attendanceTracker_fnc_log;
|
||||
};
|
||||
|
||||
if (isNil "_response") exitWith {false};
|
||||
|
||||
switch (_function) do {
|
||||
case "connectDB": {
|
||||
systemChat format ["AttendanceTracker: %1", _response#0];
|
||||
[_response#0, _response#1, _function] call attendanceTracker_fnc_log;
|
||||
};
|
||||
default {
|
||||
_response call attendanceTracker_fnc_log;
|
||||
};
|
||||
};
|
||||
true;
|
||||
}];
|
||||
@@ -0,0 +1,78 @@
|
||||
[
|
||||
["OnUserConnected", {
|
||||
params ["_networkId", "_clientStateNumber", "_clientState"];
|
||||
private _userInfo = (getUserInfo _networkId);
|
||||
_userInfo params ["_playerID", "_ownerId", "_playerUID", "_profileName", "_displayName", "_steamName", "_clientState", "_isHC", "_adminState", "_networkInfo", "_unit"];
|
||||
if (_isHC) exitWith {};
|
||||
|
||||
[
|
||||
"ConnectedServer",
|
||||
_playerUID,
|
||||
_profileName,
|
||||
_steamName
|
||||
] call attendanceTracker_fnc_logServerEvent;
|
||||
|
||||
(AttendanceTracker getVariable ["allUsers", createHashMap]) set [_networkId, _userInfo];
|
||||
|
||||
[format ["(EventHandler) OnUserConnected fired: %1", _this], "DEBUG"] call attendanceTracker_fnc_log;
|
||||
}],
|
||||
["OnUserDisconnected", {
|
||||
params ["_networkId", "_clientStateNumber", "_clientState"];
|
||||
private _userInfo = (AttendanceTracker getVariable ["allUsers", createHashMap]) get [_networkId, nil];
|
||||
if (isNil "_userInfo") exitWith {};
|
||||
|
||||
_userInfo params ["_playerID", "_ownerId", "_playerUID", "_profileName", "_displayName", "_steamName", "_clientState", "_isHC", "_adminState", "_networkInfo", "_unit"];
|
||||
if (_isHC) exitWith {};
|
||||
|
||||
[
|
||||
"DisconnectedServer",
|
||||
_playerUID,
|
||||
_profileName,
|
||||
_steamName
|
||||
] call attendanceTracker_fnc_logServerEvent;
|
||||
|
||||
[format ["(EventHandler) OnUserDisconnected fired: %1", _this], "DEBUG"] call attendanceTracker_fnc_log;
|
||||
}],
|
||||
["PlayerConnected", {
|
||||
params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];
|
||||
private _userInfo = (getUserInfo _idstr);
|
||||
if (isNil "_userInfo") exitWith {};
|
||||
|
||||
_userInfo params ["_playerID", "_ownerId", "_playerUID", "_profileName", "_displayName", "_steamName", "_clientState", "_isHC", "_adminState", "_networkInfo", "_unit"];
|
||||
|
||||
(AttendanceTracker getVariable ["allUsers", createHashMap]) set [_playerID, _userInfo];
|
||||
|
||||
if (_isHC) exitWith {};
|
||||
|
||||
[
|
||||
"ConnectedMission",
|
||||
_playerUID,
|
||||
_profileName,
|
||||
_steamName,
|
||||
_jip,
|
||||
roleDescription _unit
|
||||
] call attendanceTracker_fnc_logMissionEvent;
|
||||
|
||||
[format ["(EventHandler) PlayerConnected fired: %1", _this], "DEBUG"] call attendanceTracker_fnc_log;
|
||||
}],
|
||||
["HandleDisconnect", {
|
||||
params ["_unit", "_id", "_uid", "_name"];
|
||||
private _userInfo = (AttendanceTracker getVariable ["allUsers", createHashMap]) get [_id toFixed 0, nil];
|
||||
if (isNil "_userInfo") exitWith {};
|
||||
|
||||
_userInfo params ["_playerID", "_ownerId", "_playerUID", "_profileName", "_displayName", "_steamName", "_clientState", "_isHC", "_adminState", "_networkInfo", "_unit"];
|
||||
|
||||
if (_isHC) exitWith {};
|
||||
|
||||
[
|
||||
"DisconnectedMission",
|
||||
_playerUID,
|
||||
_profileName,
|
||||
_steamName,
|
||||
_jip
|
||||
] call attendanceTracker_fnc_logMissionEvent;
|
||||
|
||||
[format ["(EventHandler) HandleDisconnect fired: %1", _this], "DEBUG"] call attendanceTracker_fnc_log;
|
||||
false;
|
||||
}]
|
||||
];
|
||||
@@ -0,0 +1,17 @@
|
||||
params [
|
||||
["_message", "", [""]],
|
||||
["_level", "INFO", [""]],
|
||||
"_function"
|
||||
];
|
||||
|
||||
if (isNil "_message") exitWith {false};
|
||||
|
||||
"AttendanceTracker" callExtension ["log", [_level, _message]];
|
||||
|
||||
if (!isNil "_function") then {
|
||||
diag_log formatText["[AttendanceTracker] (%1): <%2> %3", _level, _function, _message];
|
||||
} else {
|
||||
diag_log formatText["[AttendanceTracker] (%1): %2", _level, _message];
|
||||
};
|
||||
|
||||
true;
|
||||
@@ -0,0 +1,20 @@
|
||||
params [
|
||||
["_eventType", ""],
|
||||
["_playerUID", ""],
|
||||
["_profileName", ""],
|
||||
["_steamName", ""],
|
||||
["_isJIP", false, [true, false]],
|
||||
["_roleDescription", ""]
|
||||
];
|
||||
|
||||
private _hash = + (AttendanceTracker getVariable ["missionContext", createHashMap]);
|
||||
_hash set ["eventType", _eventType];
|
||||
_hash set ["playerUID", _playerUID];
|
||||
_hash set ["profileName", _profileName];
|
||||
_hash set ["steamName", _steamName];
|
||||
_hash set ["isJIP", _isJIP];
|
||||
_hash set ["roleDescription", _roleDescription];
|
||||
|
||||
"AttendanceTracker" callExtension ["logAttendance", [[_hash] call CBA_fnc_encodeJSON]];
|
||||
|
||||
true;
|
||||
@@ -0,0 +1,19 @@
|
||||
params [
|
||||
["_eventType", ""],
|
||||
["_playerUID", ""],
|
||||
["_profileName", ""],
|
||||
["_steamName", ""]
|
||||
];
|
||||
|
||||
|
||||
private _hash = + (AttendanceTracker getVariable ["missionContext", createHashMap]);
|
||||
_hash set ["eventType", _eventType];
|
||||
_hash set ["playerUID", _playerUID];
|
||||
_hash set ["profileName", _profileName];
|
||||
_hash set ["steamName", _steamName];
|
||||
_hash set ["isJIP", ""];
|
||||
_hash set ["roleDescription", ""];
|
||||
|
||||
"AttendanceTracker" callExtension ["logAttendance", [[_hash] call CBA_fnc_encodeJSON]];
|
||||
|
||||
true;
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
AttendanceTracker = false call CBA_fnc_createNamespace;
|
||||
|
||||
AttendanceTracker setVariable ["missionContext", createHashMapFromArray [
|
||||
["missionName", missionName],
|
||||
["briefingName", briefingName],
|
||||
["missionNameSource", missionNameSource],
|
||||
["onLoadName", getMissionConfigValue ["onLoadName", ""]],
|
||||
["author", getMissionConfigValue ["author", ""]],
|
||||
["serverName", serverName],
|
||||
["serverProfile", profileName],
|
||||
["missionStart", call attendanceTracker_fnc_timestamp]
|
||||
]];
|
||||
|
||||
// store all user details in a hash when they connect so we can reference it in disconnect events
|
||||
AttendanceTracker setVariable ["allUsers", createHashMap];
|
||||
|
||||
private _database = "AttendanceTracker" callExtension "connectDB";
|
||||
systemChat "AttendanceTracker: Connecting to database...";
|
||||
["Connecting to database...", "INFO"] call attendanceTracker_fnc_log;
|
||||
|
||||
{
|
||||
if (!isServer) exitWith {};
|
||||
_x params ["_ehName", "_code"];
|
||||
|
||||
_handle = (addMissionEventHandler [_ehName, _code]);
|
||||
if (isNil "_handle") then {
|
||||
[format["Failed to add Mission event handler: %1", _x], "ERROR"] call attendanceTracker_fnc_log;
|
||||
false;
|
||||
} else {
|
||||
missionNamespace setVariable [
|
||||
("AttendanceTracker" + "_MEH_" + _ehName),
|
||||
_handle
|
||||
];
|
||||
true;
|
||||
};
|
||||
} forEach (call attendanceTracker_fnc_eventHandlers);
|
||||
@@ -0,0 +1 @@
|
||||
(parseSimpleArray ("AttendanceTracker" callExtension "getTimestamp")) select 0;
|
||||
Reference in New Issue
Block a user