mirror of
https://github.com/indig0fox/Arma3-AttendanceTracker.git/
synced 2025-12-08 09:51:47 -06:00
work out world & mission tables in db & gather/write
needs to be tested
This commit is contained in:
Binary file not shown.
@@ -21,6 +21,7 @@ class CfgFunctions {
|
|||||||
class logMissionEvent {};
|
class logMissionEvent {};
|
||||||
class logServerEvent {};
|
class logServerEvent {};
|
||||||
class timestamp {};
|
class timestamp {};
|
||||||
|
class getHash {};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
params [["_value", "", [""]]];
|
||||||
|
("AttendanceTracker" callExtension ["getMissionHash", _value]) select 0;
|
||||||
@@ -14,10 +14,13 @@ _workshopID = '';
|
|||||||
} foreach getLoadedModsInfo;
|
} foreach getLoadedModsInfo;
|
||||||
|
|
||||||
// [_name, _author, _workshopID];
|
// [_name, _author, _workshopID];
|
||||||
|
|
||||||
[
|
[
|
||||||
["worldName", _name],
|
|
||||||
["author", _author],
|
["author", _author],
|
||||||
|
["workshopID", _workshopID],
|
||||||
|
["displayName", _name],
|
||||||
|
["worldName", toLower worldName],
|
||||||
|
["worldNameOriginal", _name],
|
||||||
["worldSize", worldSize],
|
["worldSize", worldSize],
|
||||||
["workshopID", _workshopID]
|
["latitude", getNumber( _world >> "latitude" )],
|
||||||
|
["longitude", getNumber( _world >> "longitude" )]
|
||||||
];
|
];
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
AttendanceTracker = false call CBA_fnc_createNamespace;
|
AttendanceTracker = false call CBA_fnc_createNamespace;
|
||||||
|
|
||||||
AttendanceTracker_missionStartTimestamp = call attendanceTracker_fnc_timestamp;
|
AttendanceTracker_missionStartTimestamp = call attendanceTracker_fnc_timestamp;
|
||||||
AttendanceTracker_missionHash = "AttendanceTracker" callExtension ["getMissionHash", AttendanceTracker_missionStartTimestamp];
|
AttendanceTracker_missionHash = [AttendanceTracker_missionStartTimestamp] call attendanceTracker_fnc_getMissionHash;
|
||||||
|
|
||||||
AttendanceTracker setVariable ["missionContext", createHashMapFromArray [
|
AttendanceTracker setVariable ["missionContext", createHashMapFromArray [
|
||||||
["missionName", missionName],
|
["missionName", missionName],
|
||||||
|
|||||||
80
README.md
80
README.md
@@ -7,31 +7,61 @@
|
|||||||
Create a database with a name of your choosing. Then, run the following SQL command against it to create a table.
|
Create a database with a name of your choosing. Then, run the following SQL command against it to create a table.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
|
-- a3server.attendancelog definition
|
||||||
|
|
||||||
CREATE TABLE `attendancelog` (
|
CREATE TABLE `attendancelog` (
|
||||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`timestamp` DATETIME NOT NULL,
|
`timestamp` datetime NOT NULL,
|
||||||
`event_hash` VARCHAR(100) NOT NULL DEFAULT md5(concat(`server_name`,`mission_name`,`author`,`mission_start`)) COLLATE 'utf8mb3_general_ci',
|
`event_hash` varchar(100) NOT NULL,
|
||||||
`event_type` VARCHAR(100) NOT NULL COLLATE 'utf8mb3_general_ci',
|
`event_type` varchar(100) NOT NULL,
|
||||||
`player_id` VARCHAR(30) NOT NULL COLLATE 'utf8mb3_general_ci',
|
`player_id` varchar(30) NOT NULL,
|
||||||
`player_uid` VARCHAR(100) NOT NULL COLLATE 'utf8mb3_general_ci',
|
`player_uid` varchar(100) NOT NULL,
|
||||||
`profile_name` VARCHAR(100) NOT NULL COLLATE 'utf8mb3_general_ci',
|
`profile_name` varchar(100) NOT NULL,
|
||||||
`steam_name` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
|
`steam_name` varchar(100) DEFAULT NULL,
|
||||||
`is_jip` TINYINT(4) NULL DEFAULT NULL,
|
`is_jip` tinyint(4) DEFAULT NULL,
|
||||||
`role_description` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
|
`role_description` varchar(100) DEFAULT NULL,
|
||||||
`mission_start` DATETIME NOT NULL,
|
`mission_start` datetime NOT NULL,
|
||||||
`mission_name` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
|
`mission_name` varchar(100) DEFAULT NULL,
|
||||||
`briefing_name` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
|
`briefing_name` varchar(100) DEFAULT NULL,
|
||||||
`mission_name_source` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
|
`mission_name_source` varchar(100) DEFAULT NULL,
|
||||||
`on_load_name` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
|
`on_load_name` varchar(100) DEFAULT NULL,
|
||||||
`author` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
|
`author` varchar(100) DEFAULT NULL,
|
||||||
`server_name` VARCHAR(100) NOT NULL COLLATE 'utf8mb3_general_ci',
|
`server_name` varchar(100) NOT NULL,
|
||||||
`server_profile` VARCHAR(100) NOT NULL COLLATE 'utf8mb3_general_ci',
|
`server_profile` varchar(100) NOT NULL,
|
||||||
PRIMARY KEY (`id`) USING BTREE
|
PRIMARY KEY (`id`)
|
||||||
)
|
) ENGINE=InnoDB AUTO_INCREMENT=2713 DEFAULT CHARSET=utf8mb3;
|
||||||
COLLATE='utf8mb3_general_ci'
|
|
||||||
ENGINE=InnoDB
|
-- a3server.`missions` definition
|
||||||
AUTO_INCREMENT=383
|
|
||||||
;
|
CREATE TABLE `missions` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`mission_name` varchar(100) NOT NULL,
|
||||||
|
`mission_name_source` varchar(100) DEFAULT NULL,
|
||||||
|
`briefing_name` varchar(100) DEFAULT NULL,
|
||||||
|
`on_load_name` varchar(100) DEFAULT NULL,
|
||||||
|
`author` varchar(100) DEFAULT NULL,
|
||||||
|
`server_name` varchar(100) DEFAULT NULL,
|
||||||
|
`server_profile` varchar(100) DEFAULT NULL,
|
||||||
|
`mission_start` datetime DEFAULT NULL,
|
||||||
|
`mission_hash` varchar(100) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb3;
|
||||||
|
|
||||||
|
|
||||||
|
-- a3server.`worlds` definition
|
||||||
|
|
||||||
|
CREATE TABLE `worlds` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`author` varchar(100) DEFAULT NULL,
|
||||||
|
`display_name` varchar(100) DEFAULT NULL,
|
||||||
|
`world_name` varchar(100) NOT NULL,
|
||||||
|
`world_name_original` varchar(100) DEFAULT NULL,
|
||||||
|
`world_size` int(11) DEFAULT NULL,
|
||||||
|
`latitude` float DEFAULT NULL,
|
||||||
|
`longitude` float DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb3;
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, copy `config.example.json` to `config.json` and update it with your database credentials.
|
Finally, copy `config.example.json` to `config.json` and update it with your database credentials.
|
||||||
|
|||||||
Binary file not shown.
@@ -160,10 +160,14 @@ func connectDB() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WorldInfo struct {
|
type WorldInfo struct {
|
||||||
WorldName string `json:"worldName"`
|
Author string `json:"author"`
|
||||||
Author string `json:"author"`
|
WorkshopID string `json:"workshopID"`
|
||||||
WorldSize int `json:"worldSize"`
|
DisplayName string `json:"displayName"`
|
||||||
WorkshopID string `json:"workshopID"`
|
WorldName string `json:"worldName"`
|
||||||
|
WorldNameOriginal string `json:"worldNameOriginal"`
|
||||||
|
WorldSize int `json:"worldSize"`
|
||||||
|
Latitude float32 `json:"latitude"`
|
||||||
|
Longitude float32 `json:"longitude"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeWorldInfo(worldInfo string) {
|
func writeWorldInfo(worldInfo string) {
|
||||||
@@ -176,7 +180,7 @@ func writeWorldInfo(worldInfo string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// write to log
|
// write to log
|
||||||
writeLog(functionName, fmt.Sprintf(`["WorldName:%s Author:%s WorldSize:%d WorkshopID:%s", "INFO"]`, wi.WorldName, wi.Author, wi.WorldSize, wi.WorkshopID))
|
writeLog(functionName, fmt.Sprintf(`["Author:%s WorkshopID:%s DisplayName:%s WorldName:%s WorldNameOriginal:%s WorldSize:%d Latitude:%f Longitude:%f", "INFO"]`, wi.Author, wi.WorkshopID, wi.DisplayName, wi.WorldName, wi.WorldNameOriginal, wi.WorldSize, wi.Latitude, wi.Longitude))
|
||||||
|
|
||||||
// write to database
|
// write to database
|
||||||
// check if world exists
|
// check if world exists
|
||||||
@@ -185,13 +189,13 @@ func writeWorldInfo(worldInfo string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
// world does not exist, insert it
|
// world does not exist, insert it
|
||||||
stmt, err := db.Prepare("INSERT INTO worlds (world_name, author, world_size, workshop_id) VALUES (?, ?, ?, ?)")
|
stmt, err := db.Prepare("INSERT INTO worlds (author, workshop_id, display_name, world_name, world_name_original, world_size, latitude, longitude) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
res, err := stmt.Exec(wi.WorldName, wi.Author, wi.WorldSize, wi.WorkshopID)
|
res, err := stmt.Exec(wi.Author, wi.WorkshopID, wi.DisplayName, wi.WorldName, wi.WorldNameOriginal, wi.WorldSize, wi.Latitude, wi.Longitude)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
return
|
return
|
||||||
@@ -208,13 +212,13 @@ func writeWorldInfo(worldInfo string) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// world exists, update it
|
// world exists, update it
|
||||||
stmt, err := db.Prepare("UPDATE worlds SET world_name = ?, author = ?, world_size = ? WHERE id = ?")
|
stmt, err := db.Prepare("UPDATE worlds SET author = ?, workshop_id = ?, display_name = ?, world_name = ?, world_name_original = ?, world_size = ?, latitude = ?, longitude = ? WHERE id = ?")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
res, err := stmt.Exec(wi.WorldName, wi.Author, wi.WorldSize, worldID)
|
res, err := stmt.Exec(wi.Author, wi.WorkshopID, wi.DisplayName, wi.WorldName, wi.WorldNameOriginal, wi.WorldSize, wi.Latitude, wi.Longitude, worldID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
return
|
return
|
||||||
@@ -269,7 +273,7 @@ func writeMissionInfo(missionInfo string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
res, err := stmt.Exec(mi.MissionName, mi.BriefingName, mi.MissionNameSource, mi.OnLoadName, mi.Author, mi.ServerName, mi.ServerProfile, t, mi.MissionHash)
|
res, err := stmt.Exec(mi.MissionName, mi.BriefingName, mi.MissionNameSource, mi.OnLoadName, mi.Author, mi.ServerName, mi.ServerProfile, t, mi.MissionStart, mi.MissionHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
return
|
return
|
||||||
@@ -315,7 +319,7 @@ func writeAttendance(data string) {
|
|||||||
|
|
||||||
// send to DB
|
// send to DB
|
||||||
|
|
||||||
result, err := db.ExecContext(context.Background(), `INSERT INTO AttendanceLog (timestamp, event_type, player_id, player_uid, profile_name, steam_name, is_jip, role_description, mission_hash) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
result, err := db.ExecContext(context.Background(), `INSERT INTO AttendanceLog (event_time, event_type, player_id, player_uid, profile_name, steam_name, is_jip, role_description, mission_hash) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
now,
|
now,
|
||||||
event.EventType,
|
event.EventType,
|
||||||
event.PlayerId,
|
event.PlayerId,
|
||||||
@@ -384,6 +388,12 @@ func goRVExtensionArgs(output *C.char, outputsize C.size_t, input *C.char, argv
|
|||||||
if argc == 1 {
|
if argc == 1 {
|
||||||
go writeWorldInfo(out[0])
|
go writeWorldInfo(out[0])
|
||||||
}
|
}
|
||||||
|
case "getMissionHash":
|
||||||
|
{
|
||||||
|
if argc == 1 {
|
||||||
|
go getMissionHash(out[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a result to Arma
|
// Return a result to Arma
|
||||||
|
|||||||
Reference in New Issue
Block a user