mirror of
https://github.com/indig0fox/Arma3-AttendanceTracker.git/
synced 2025-12-08 09:51:47 -06:00
Compare commits
3 Commits
ee0c28d2c8
...
3b5b4b32b6
| Author | SHA1 | Date | |
|---|---|---|---|
|
3b5b4b32b6
|
|||
|
8c5cfc40ed
|
|||
|
c250310d58
|
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,5 +1,8 @@
|
||||
|
||||
*.log
|
||||
*.bak
|
||||
|
||||
\@AttendanceTracker/config.json
|
||||
*.pbo
|
||||
*.dll
|
||||
config.json
|
||||
**/AttendanceTracker_x64.h
|
||||
**/AttendanceTracker.h
|
||||
/extension/@AttendanceTracker/
|
||||
|
||||
Binary file not shown.
@@ -1,86 +0,0 @@
|
||||
/* Code generated by cmd/cgo; DO NOT EDIT. */
|
||||
|
||||
/* package main.go */
|
||||
|
||||
|
||||
#line 1 "cgo-builtin-export-prolog"
|
||||
|
||||
#include <stddef.h> /* for ptrdiff_t below */
|
||||
|
||||
#ifndef GO_CGO_EXPORT_PROLOGUE_H
|
||||
#define GO_CGO_EXPORT_PROLOGUE_H
|
||||
|
||||
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
||||
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Start of preamble from import "C" comments. */
|
||||
|
||||
|
||||
#line 3 "main.go"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "extensionCallback.h"
|
||||
|
||||
#line 1 "cgo-generated-wrapper"
|
||||
|
||||
|
||||
/* End of preamble from import "C" comments. */
|
||||
|
||||
|
||||
/* Start of boilerplate cgo prologue. */
|
||||
#line 1 "cgo-gcc-export-header-prolog"
|
||||
|
||||
#ifndef GO_CGO_PROLOGUE_H
|
||||
#define GO_CGO_PROLOGUE_H
|
||||
|
||||
typedef signed char GoInt8;
|
||||
typedef unsigned char GoUint8;
|
||||
typedef short GoInt16;
|
||||
typedef unsigned short GoUint16;
|
||||
typedef int GoInt32;
|
||||
typedef unsigned int GoUint32;
|
||||
typedef long long GoInt64;
|
||||
typedef unsigned long long GoUint64;
|
||||
typedef GoInt64 GoInt;
|
||||
typedef GoUint64 GoUint;
|
||||
typedef __SIZE_TYPE__ GoUintptr;
|
||||
typedef float GoFloat32;
|
||||
typedef double GoFloat64;
|
||||
typedef float _Complex GoComplex64;
|
||||
typedef double _Complex GoComplex128;
|
||||
|
||||
/*
|
||||
static assertion to make sure the file is being used on architecture
|
||||
at least with matching size of GoInt.
|
||||
*/
|
||||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
||||
|
||||
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
||||
typedef _GoString_ GoString;
|
||||
#endif
|
||||
typedef void *GoMap;
|
||||
typedef void *GoChan;
|
||||
typedef struct { void *t; void *v; } GoInterface;
|
||||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
||||
|
||||
#endif
|
||||
|
||||
/* End of boilerplate cgo prologue. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern __declspec(dllexport) void goRVExtensionVersion(char* output, size_t outputsize);
|
||||
extern __declspec(dllexport) void goRVExtensionArgs(char* output, size_t outputsize, char* input, char** argv, int argc);
|
||||
extern __declspec(dllexport) void goRVExtension(char* output, size_t outputsize, char* input);
|
||||
extern __declspec(dllexport) void goRVExtensionRegisterCallback(extensionCallback fnc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Binary file not shown.
@@ -55,6 +55,15 @@ addMissionEventHandler ["ExtensionCallback", {
|
||||
]
|
||||
];
|
||||
|
||||
missionNamespace setVariable ["AttendanceTracker_DBConnected", true];
|
||||
};
|
||||
};
|
||||
case "writeWorldInfo": {
|
||||
if (_response#0 == "WORLD_ID") then {
|
||||
AttendanceTracker_worldId = _response#1;
|
||||
|
||||
// world info written. mission info depends on that, so now we'll write it
|
||||
|
||||
// log mission info and get back the row Id to send with future messages
|
||||
private _response = "AttendanceTracker" callExtension [
|
||||
"logMission",
|
||||
@@ -62,12 +71,11 @@ addMissionEventHandler ["ExtensionCallback", {
|
||||
[AttendanceTracker getVariable ["missionContext", createHashMap]] call CBA_fnc_encodeJSON
|
||||
]
|
||||
];
|
||||
|
||||
missionNamespace setVariable ["AttendanceTracker_DBConnected", true];
|
||||
};
|
||||
};
|
||||
case "writeMission": {
|
||||
if (_response#0 == "MISSION_ID") then {
|
||||
// mission has written so lets finish out init and set missionId for the returned PK, activating the ability for attendance records to send.
|
||||
AttendanceTracker_missionId = _response#1;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -40,6 +40,19 @@ AttendanceTracker setVariable ["missionContext", createHashMapFromArray [
|
||||
AttendanceTracker setVariable ["allUsers", createHashMap];
|
||||
AttendanceTracker setVariable ["rowIds", createHashMap];
|
||||
|
||||
// update the extension with the current server time to identify restarts
|
||||
[
|
||||
{
|
||||
'AttendanceTracker' callExtension [
|
||||
"updateServerTime",
|
||||
[
|
||||
round(diag_tickTime)
|
||||
]
|
||||
]
|
||||
},
|
||||
30
|
||||
] call CBA_fnc_addPerFrameHandler;
|
||||
|
||||
{
|
||||
if (!isServer) exitWith {};
|
||||
_x params ["_ehName", "_code"];
|
||||
|
||||
@@ -13,7 +13,7 @@ systemTimeUTC apply {if (_x < 10) then {"0" + str _x} else {str _x}} params [
|
||||
];
|
||||
|
||||
format[
|
||||
"%1-%2-%3 %4:%5:%6",
|
||||
"%1-%2-%3T%4:%5:%6.000Z",
|
||||
_year,
|
||||
_month,
|
||||
_day,
|
||||
|
||||
@@ -19,7 +19,10 @@ _hash set ["isJIP", _isJIP];
|
||||
_hash set ["roleDescription", _roleDescription];
|
||||
|
||||
[
|
||||
{missionNamespace getVariable ["AttendanceTracker_DBConnected", false]},
|
||||
{
|
||||
missionNamespace getVariable ["AttendanceTracker_DBConnected", false] &&
|
||||
missionNamespace getVariable ["AttendanceTracker_missionId", -1] > 0
|
||||
},
|
||||
{"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
|
||||
|
||||
@@ -19,7 +19,10 @@ _hash set ["isJIP", _isJIP];
|
||||
_hash set ["roleDescription", _roleDescription];
|
||||
|
||||
[
|
||||
{missionNamespace getVariable ["AttendanceTracker_DBConnected", false]},
|
||||
{
|
||||
missionNamespace getVariable ["AttendanceTracker_DBConnected", false] &&
|
||||
missionNamespace getVariable ["AttendanceTracker_missionId", -1] > 0
|
||||
},
|
||||
{"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
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
},
|
||||
"armaConfig": {
|
||||
"dbUpdateIntervalSeconds": 90,
|
||||
"serverEventFillNullMinutes": 90,
|
||||
"missionEventFillNullMinutes": 15,
|
||||
"debug": false
|
||||
}
|
||||
}
|
||||
104
LICENSE.md
Normal file
104
LICENSE.md
Normal file
@@ -0,0 +1,104 @@
|
||||
# Arma Public License Share Alike (APL-SA)
|
||||
|
||||
## Brief summary of this Licence
|
||||
|
||||
PLEASE, NOTE THAT THIS SUMMARY HAS NO LEGAL EFFECT AND IS ONLY OF AN INFORMATORY NATURE DESIGNED FOR YOU TO GET THE BASIC INFORMATION ABOUT THE CONTENT OF THIS LICENCE. THE ONLY LEGALLY BINDING PROVISIONS ARE THOSE IN THE ORIGINAL AND FULL TEXT OF THIS LICENCE.
|
||||
|
||||
With this licence you are free to adapt (i.e. modify, rework or update) and share (i.e. copy, distribute or transmit) the material under the following conditions:
|
||||
|
||||
Attribution - You must attribute the material in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the material).
|
||||
Noncommercial - You may not use this material for any commercial purposes.
|
||||
Arma Only - You may not convert or adapt this material to be used in other games than Arma.
|
||||
Share Alike - If you adapt, or build upon this material, you may distribute the resulting material only under the same license.
|
||||
|
||||
## Full version of licence
|
||||
|
||||
By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Arma Public License - Share Alike ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
|
||||
|
||||
Section 1 – Definitions
|
||||
Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
|
||||
Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
|
||||
ArmaOnly means primarily intended for or directed towards the use in any of existing and future Arma games, including but not limited to Arma: Cold War Assault, Arma, Arma 2 and Arma 3 and its official sequels and expansion packs.
|
||||
Arma Public Share Alike Compatible License means a license listed at <https://www.bohemia.net/community/licenses> as essentially the equivalent of this Public License.
|
||||
Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
|
||||
Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
|
||||
Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
|
||||
Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
|
||||
Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
|
||||
Licensor means the individual(s) or entity(ies) granting rights under this Public License.
|
||||
NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange.
|
||||
Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
|
||||
Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
|
||||
You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
|
||||
Section 2 – Scope
|
||||
License grant
|
||||
Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
|
||||
reproduce and Share the Licensed Material, in whole or in part, for NonCommercial and ArmaOnly purposes only; and
|
||||
produce, reproduce, and Share Adapted Material for NonCommercial and ArmaOnly purposes only.
|
||||
Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
|
||||
Term. The term of this Public License is specified in Section 6(a).
|
||||
Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
|
||||
Downstream recipients.
|
||||
Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
|
||||
Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.
|
||||
No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
|
||||
No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(a)(i).
|
||||
Other rights
|
||||
Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
|
||||
Patent and trademark rights are not licensed under this Public License.
|
||||
To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial and ArmaOnly purposes.
|
||||
Section 3 – License Conditions
|
||||
Your exercise of the Licensed Rights is expressly made subject to the following conditions.
|
||||
|
||||
Attribution
|
||||
If You Share the Licensed Material (including in modified form), You must:
|
||||
|
||||
retain the following if it is supplied by the Licensor with the Licensed Material:
|
||||
identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
|
||||
a copyright notice;
|
||||
a notice that refers to this Public License;
|
||||
a notice that refers to the disclaimer of warranties;
|
||||
a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
|
||||
indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
|
||||
indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
|
||||
You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
|
||||
If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(a) to the extent reasonably practicable.
|
||||
ShareAlike
|
||||
In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply.
|
||||
|
||||
The Adapter’s License You apply must be this Public License, or an Arma Public Share Alike Compatible License.
|
||||
You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.
|
||||
You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.
|
||||
Section 4 – Sui Generis Database Rights
|
||||
Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
|
||||
|
||||
for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial and ArmaOnly purposes only;
|
||||
if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and
|
||||
You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.
|
||||
For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
|
||||
|
||||
Section 5 – Disclaimer of Warranties and Limitation of Liability
|
||||
Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
|
||||
To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.
|
||||
The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
|
||||
Section 6 – Term and Termination
|
||||
This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
|
||||
Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
|
||||
|
||||
automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
|
||||
upon express reinstatement by the Licensor.
|
||||
For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
|
||||
|
||||
For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
|
||||
Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
|
||||
Section 7 – Other Terms and Conditions
|
||||
The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
|
||||
Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
|
||||
Section 8 – Interpretation
|
||||
For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
|
||||
To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
|
||||
No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
|
||||
Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.
|
||||
Bohemia Interactive Notices
|
||||
Bohemia Interactive a.s. is not a party to this License, and makes no warranty whatsoever in connection with the Licensed Material. Bohemia Interactive a.s. will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, Bohemia Interactive a.s. may elect to apply the Public License to material it publishes and in those instances it becomes the "Licensor".
|
||||
Except for the limited purpose of indicating to the public that the Licensed Material is shared under this Public License, Bohemia Interactive a.s. does not authorize the use by either party of the trademarks "Arma", "Bohemia Interactive" or any related trademark or logo of Arma or Bohemia Interactive without the prior written consent of Bohemia Interactive a.s.
|
||||
234
README.md
234
README.md
@@ -1,83 +1,157 @@
|
||||
# Arma 3 Attendance Tracker
|
||||
|
||||
---
|
||||
|
||||
## Setup
|
||||
|
||||
### Set Up a Database Engine
|
||||
|
||||
**You will need a running MySQL or MariaDB instance.**
|
||||
|
||||
The following SQL commands will set up the necessary tables for the application. You can run them from the MySQL command line or from a tool like phpMyAdmin.
|
||||
If you do not have a MySQL or MariaDB instance, you can use one of the following:
|
||||
|
||||
*In future, an ORM will be used to set this up automatically.*
|
||||
- [MySQL Community Server](https://dev.mysql.com/downloads/mysql/) (free)
|
||||
- [MariaDB](https://mariadb.org/) (free)
|
||||
- [Docker](https://www.docker.com/) (free)
|
||||
- [MySQL Docker Image](https://hub.docker.com/_/mysql)
|
||||
- [MariaDB Docker Image](https://hub.docker.com/_/mariadb)
|
||||
|
||||
The tested and recommended database engine is MariaDB version 11.0.2.
|
||||
|
||||
### Create a Database
|
||||
|
||||
You will need to create a database in your instance. You can do this using your preferred MySQL client or one of the following:
|
||||
|
||||
- [phpMyAdmin](https://www.phpmyadmin.net/) (web based)
|
||||
- [HeidiSQL](https://www.heidisql.com/) (Windows only and simpler)
|
||||
- [MySQL Workbench](https://www.mysql.com/products/workbench/) (feature rich but heavy)
|
||||
- [DBeaver](https://dbeaver.io/) (feature rich but heavy)
|
||||
|
||||
You could also use a CLI client such as the `mysql` command line client to run the following command:
|
||||
|
||||
```sql
|
||||
CREATE DATABASE `arma3_attendance` /*!40100 DEFAULT CHARACTER SET utf8mb3 */;
|
||||
|
||||
USE `arma3_attendance`;
|
||||
|
||||
-- a3server.missions definition
|
||||
CREATE TABLE `missions` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`world_id` int(11) DEFAULT NULL,
|
||||
`mission_hash` varchar(100) NOT NULL DEFAULT '',
|
||||
`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 COMMENT 'In UTC',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `mission_hash` (`mission_hash`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
-- arma3_attendance.attendance definition
|
||||
CREATE TABLE `attendance` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`join_time` datetime DEFAULT NULL COMMENT 'Stored in UTC',
|
||||
`disconnect_time` datetime DEFAULT NULL COMMENT 'Stored in UTC',
|
||||
`mission_hash` varchar(100) DEFAULT NULL,
|
||||
`event_type` varchar(100) NOT NULL,
|
||||
`player_id` varchar(30) NOT NULL,
|
||||
`player_uid` varchar(100) NOT NULL,
|
||||
`profile_name` varchar(100) NOT NULL,
|
||||
`steam_name` varchar(100) DEFAULT NULL,
|
||||
`is_jip` tinyint(4) DEFAULT NULL,
|
||||
`role_description` varchar(100) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `mission_hash` (`mission_hash`),
|
||||
CONSTRAINT `attendance_ibfk_1` FOREIGN KEY (`mission_hash`) REFERENCES `missions` (`mission_hash`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 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,
|
||||
`workshop_id` varchar(50) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `world_name` (`world_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb3;
|
||||
CREATE DATABASE `arma3_attendance`;
|
||||
```
|
||||
|
||||
Finally, copy `config.example.json` to `config.json` and update it with your database credentials and path.
|
||||
### Mod Installation
|
||||
|
||||
## QUERIES
|
||||
1. Download the latest release from the [releases page](https://github.com/indig0fox/Arma3-AttendanceTracker/releases).
|
||||
1. Extract the .zip and move `@AttendanceTracker` to your Arma 3 server's root directory.
|
||||
1. Inside of `@AttendanceTracker` you will find a `config.json` file. Open this file and configure it to your circumstances. See the [Configuration](#configuration) section for more information.
|
||||
1. Add the mod to your server's startup parameters. For example: `-serverMod="@AttendanceTracker;"`
|
||||
|
||||
At next run, the Arma 3 server will launch with the mod running.
|
||||
|
||||
### Configuration
|
||||
|
||||
The configuration file example is located at `@AttendanceTracker/config.json.example`. This should be copied to `@AttendanceTracker/config.json` and edited to suit your circumstances.
|
||||
|
||||
The following table describes the configuration options.
|
||||
|
||||
| Key | Type | Description | Default |
|
||||
| --- | --- | --- | --- |
|
||||
| sqlConfig.mySqlHost | string | The hostname of your MySQL instance. | localhost |
|
||||
| sqlConfig.mySqlPort | integer | The port of your MySQL instance. | 3306 |
|
||||
| sqlConfig.mySqlUser | string | The username to use when connecting to your MySQL instance. | root |
|
||||
| sqlConfig.mySqlPassword | string | The password to use when connecting to your MySQL instance. | root |
|
||||
| sqlConfig.mySqlDatabase | string | The name of the database to use. | arma3_attendance |
|
||||
| armaConfig.dbUpdateIntervalSeconds | integer | The number of seconds between disconnect_time updates per user. | 90 |
|
||||
| armaConfig.serverEventFillNullMinutes | integer | The max session duration to fill in for missing server disconnect_time values. | 90 |
|
||||
| armaConfig.missionEventFillNullMinutes | integer | The max session duration to fill in for missing mission disconnect_time values. | 15 |
|
||||
| armaConfig.debug | boolean | Whether or not to enable debug logging. | false |
|
||||
|
||||
## Usage
|
||||
|
||||
The extension uses [GORM](https://gorm.io/) for database access and will automatically create the schema in the database you specify in the configuration file.
|
||||
|
||||
---
|
||||
|
||||
## Important Notes
|
||||
|
||||
### Logging
|
||||
|
||||
"debug": true:
|
||||
The extension will log ERROR and WARN events to the Arma 3 server's RPT file, which can be found in the server's profile folder.
|
||||
|
||||
"debug": false:
|
||||
The extension will log ERROR, WARN, INFO, and DEBUG events to the Arma 3 server's RPT file, which can be found in the server's profile folder.
|
||||
|
||||
All events will be always be logged to `@AttendanceTracker/attendanceTracker.log` in log line format.
|
||||
|
||||
### Timezone
|
||||
|
||||
All times will be logged as UTC time. This is to ensure that all times are logged in a consistent manner, regardless of the timezone of the server. Because these are DATETIME fields, they will not be adjusted to your local time when viewing them in a database client.
|
||||
|
||||
To do so, you can use the following function in your queries:
|
||||
|
||||
```sql
|
||||
CONVERT_TZ(<field>, 'UTC', 'US/Eastern')
|
||||
```
|
||||
|
||||
A full list of timezones available to your database can be found this way:
|
||||
|
||||
```sql
|
||||
SELECT *
|
||||
FROM mysql.time_zone_name
|
||||
```
|
||||
|
||||
### Performance
|
||||
|
||||
The extension will update the disconnect_time field for each player every `dbUpdateIntervalSeconds` seconds. This is to ensure that the disconnect_time field is updated in the event that the server crashes or the mission ends without a disconnect event.
|
||||
|
||||
These calls are threaded in the Go runtime and will not block the Arma 3 server while processing. The default value of 90 seconds should be sufficient for most servers. Each period begins when a player connects to the server or connects to a mission, which provides a natural offset.
|
||||
|
||||
### NULL disconnect_time Values
|
||||
|
||||
In the event that the server crashes or a disconnect event for a mission is not sent, the next join for each will update past rows based on the following:
|
||||
|
||||
If the join time for a row is within [`{event_type}EventFillNullMinutes`](#configuration) minutes of the previous disconnect time, the previous disconnect time will be updated to the new join time. Otherwise, it will be set as [`{event_type}EventFillNullMinutes`](#configuration) from the join time for that row.
|
||||
|
||||
This is an attempt to account for missing events for individual players while not attributing large gap periods to their calculated session times. If the server crashes, the extension will update all rows with a NULL disconnect_time to the current time. See [Server Crash Time Filling](#server-crash-time-filling) for more information.
|
||||
|
||||
#### Server Crash Time Filling
|
||||
|
||||
The addon will update `@AttendanceTracker/lastServerTime.txt` with Arma 3's `diag_tickTime` every 30 seconds. This is to ensure that the server time is always available to the extension, even if the server crashes. This file is not used for any other purpose.
|
||||
|
||||
On each time update, the extension will check this file and compare the received value to it. If the lastServerTime < lastServerTime.txt, the extension will assume that the server has restarted and will update all event rows with a NULL disconnect_time to the current time OR the threshold specified in the configuration file, whichever produces the smaller session duration.
|
||||
|
||||
---
|
||||
|
||||
## Database Schema
|
||||
|
||||
| Table Name | Description |
|
||||
| --- | --- |
|
||||
| worlds | Stores world information. |
|
||||
| missions | Stores mission information. |
|
||||
| attendance_items | Stores rows that indicate player information and join/disconnect times. |
|
||||
|
||||
### Worlds
|
||||
|
||||
The worlds table will store basic info about the world. This is used to link missions to worlds.
|
||||
|
||||
### Missions
|
||||
|
||||
The missions table will store basic info about the mission. This is used to link attendance items to missions.
|
||||
|
||||
### Attendance Items
|
||||
|
||||
The attendance_items table will store rows that indicate player information and join/disconnect times. This can be used to calculate play time per player per mission. Each row is also linked to a mission, so that these records can be grouped.
|
||||
|
||||
---
|
||||
|
||||
## Useful Queries
|
||||
|
||||
### Show missions with attendance
|
||||
|
||||
This will retrieve a view showing all missions with attendance data, sorted by the most recent mission joins first. Mission events without a mission disconnect_time (due to server crash or in-progress mission) will be ignored.
|
||||
|
||||
See [Timezone](#timezone) for more information on converting times to your local timezone.
|
||||
|
||||
```sql
|
||||
select
|
||||
a.server_profile as Server,
|
||||
a.briefing_name as "Mission Name",
|
||||
a.mission_start as "Start Time",
|
||||
CONVERT_TZ(a.mission_start, 'UTC', 'US/Eastern') as "Start Time",
|
||||
b.display_name as "World",
|
||||
c.profile_name as "Player Name",
|
||||
c.player_uid as "Player UID",
|
||||
@@ -86,11 +160,11 @@ select
|
||||
c.join_time,
|
||||
c.disconnect_time
|
||||
) as "Play Time (m)",
|
||||
c.join_time as "Join Time",
|
||||
c.disconnect_time as "Leave Time"
|
||||
CONVERT_TZ(c.join_time, 'UTC', 'US/Eastern') as "Join Time",
|
||||
CONVERT_TZ(c.disconnect_time, 'UTC', 'US/Eastern') as "Leave Time"
|
||||
from missions a
|
||||
LEFT JOIN worlds b ON a.world_id = b.id
|
||||
LEFT JOIN attendance c ON a.mission_hash = c.mission_hash
|
||||
LEFT JOIN attendance_items c ON a.mission_hash = c.mission_hash
|
||||
where
|
||||
c.event_type = 'Mission'
|
||||
AND c.disconnect_time IS NOT NULL
|
||||
@@ -100,3 +174,39 @@ where
|
||||
c.disconnect_time
|
||||
) > 0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
||||
|
||||
---
|
||||
|
||||
## Development
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- [Go 1.16.4](https://golang.org/doc/install)
|
||||
- [MinGW-w64](https://sourceforge.net/projects/mingw-w64/) (Windows only)
|
||||
- [GCC](https://gcc.gnu.org/) (Linux only)
|
||||
|
||||
### Building
|
||||
|
||||
```bash
|
||||
cd ./extension
|
||||
$ENV:GOARCH = "amd64"
|
||||
$ENV:CGO_ENABLED = 1
|
||||
go1.16.4 build -o ../@AttendanceTracker/AttendanceTracker_x64.dll -buildmode=c-shared .
|
||||
```
|
||||
|
||||
To prepare the addon, you'll need some PBO manager utility to pack this folder:
|
||||
[`@AttendanceTracker/addons/AttendanceTracker`](@AttendanceTracker/addons/AttendanceTracker)
|
||||
|
||||
---
|
||||
|
||||
## Credits
|
||||
|
||||
- [Go](https://golang.org/)
|
||||
- [Go Arma 3 Extension Template](https://github.com/code34/armago_x64/tree/master)
|
||||
- [GORM](https://gorm.io/)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"mysqlHost": "127.0.0.1",
|
||||
"mysqlPort": 3306,
|
||||
"mysqlUser": "root",
|
||||
"mysqlPassword": "root",
|
||||
"mysqlDatabase": "arma3_attendance"
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"mysqlHost": "127.0.0.1",
|
||||
"mysqlPort": 3306,
|
||||
"mysqlUser": "root",
|
||||
"mysqlPassword": "root",
|
||||
"mysqlDatabase": "testgorm"
|
||||
}
|
||||
Binary file not shown.
@@ -1,86 +0,0 @@
|
||||
/* Code generated by cmd/cgo; DO NOT EDIT. */
|
||||
|
||||
/* package main.go */
|
||||
|
||||
|
||||
#line 1 "cgo-builtin-export-prolog"
|
||||
|
||||
#include <stddef.h> /* for ptrdiff_t below */
|
||||
|
||||
#ifndef GO_CGO_EXPORT_PROLOGUE_H
|
||||
#define GO_CGO_EXPORT_PROLOGUE_H
|
||||
|
||||
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
||||
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Start of preamble from import "C" comments. */
|
||||
|
||||
|
||||
#line 3 "main.go"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "extensionCallback.h"
|
||||
|
||||
#line 1 "cgo-generated-wrapper"
|
||||
|
||||
|
||||
/* End of preamble from import "C" comments. */
|
||||
|
||||
|
||||
/* Start of boilerplate cgo prologue. */
|
||||
#line 1 "cgo-gcc-export-header-prolog"
|
||||
|
||||
#ifndef GO_CGO_PROLOGUE_H
|
||||
#define GO_CGO_PROLOGUE_H
|
||||
|
||||
typedef signed char GoInt8;
|
||||
typedef unsigned char GoUint8;
|
||||
typedef short GoInt16;
|
||||
typedef unsigned short GoUint16;
|
||||
typedef int GoInt32;
|
||||
typedef unsigned int GoUint32;
|
||||
typedef long long GoInt64;
|
||||
typedef unsigned long long GoUint64;
|
||||
typedef GoInt64 GoInt;
|
||||
typedef GoUint64 GoUint;
|
||||
typedef __SIZE_TYPE__ GoUintptr;
|
||||
typedef float GoFloat32;
|
||||
typedef double GoFloat64;
|
||||
typedef float _Complex GoComplex64;
|
||||
typedef double _Complex GoComplex128;
|
||||
|
||||
/*
|
||||
static assertion to make sure the file is being used on architecture
|
||||
at least with matching size of GoInt.
|
||||
*/
|
||||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
||||
|
||||
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
||||
typedef _GoString_ GoString;
|
||||
#endif
|
||||
typedef void *GoMap;
|
||||
typedef void *GoChan;
|
||||
typedef struct { void *t; void *v; } GoInterface;
|
||||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
||||
|
||||
#endif
|
||||
|
||||
/* End of boilerplate cgo prologue. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern __declspec(dllexport) void goRVExtensionVersion(char* output, size_t outputsize);
|
||||
extern __declspec(dllexport) void goRVExtensionArgs(char* output, size_t outputsize, char* input, char** argv, int argc);
|
||||
extern __declspec(dllexport) void goRVExtension(char* output, size_t outputsize, char* input);
|
||||
extern __declspec(dllexport) void goRVExtensionRegisterCallback(extensionCallback fnc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -12,11 +12,13 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
@@ -33,6 +35,7 @@ var extensionCallbackFnc C.extensionCallback
|
||||
var ADDON_FOLDER string = getDir() + "\\@AttendanceTracker"
|
||||
var LOG_FILE string = ADDON_FOLDER + "\\attendanceTracker.log"
|
||||
var CONFIG_FILE string = ADDON_FOLDER + "\\config.json"
|
||||
var SERVER_TIME_FILE string = ADDON_FOLDER + "\\lastServerTime.txt"
|
||||
|
||||
var ATTENDANCE_TABLE string = "attendance"
|
||||
var MISSIONS_TABLE string = "missions"
|
||||
@@ -47,8 +50,10 @@ var ATConfig ATSQLConfig
|
||||
var A3Config ArmaConfig
|
||||
|
||||
type ArmaConfig struct {
|
||||
DBUpdateIntervalSeconds int `json:"dbUpdateIntervalSeconds"`
|
||||
Debug bool `json:"debug"`
|
||||
DBUpdateIntervalSeconds int `json:"dbUpdateIntervalSeconds"`
|
||||
Debug bool `json:"debug"`
|
||||
ServerEventFillNullMinutes int `json:"serverEventFillNullMinutes"`
|
||||
MissionEventFillNullMinutes int `json:"missionEventFillNullMinutes"`
|
||||
}
|
||||
|
||||
type ATSQLConfig struct {
|
||||
@@ -159,7 +164,7 @@ func getMissionHash() string {
|
||||
functionName := "getMissionHash"
|
||||
// get md5 hash of string
|
||||
// https://stackoverflow.com/questions/2377881/how-to-get-a-md5-hash-from-a-string-in-golang
|
||||
hash := md5.Sum([]byte(time.Now().UTC().Format("2006-01-02 15:04:05")))
|
||||
hash := md5.Sum([]byte(time.Now().Format("2006-01-02 15:04:05")))
|
||||
|
||||
// convert to string
|
||||
hashString := fmt.Sprintf(`%x`, hash)
|
||||
@@ -169,26 +174,82 @@ func getMissionHash() string {
|
||||
|
||||
func updateServerTime(serverTime uint64) {
|
||||
functionName := "updateServerTime"
|
||||
|
||||
var err error
|
||||
|
||||
// check .txt file for server time
|
||||
// first, check if it exists
|
||||
if _, err := os.Stat(SERVER_TIME_FILE); os.IsNotExist(err) {
|
||||
// file does not exist, create it and write serverTime to it
|
||||
writeLog(functionName, `["Server time file does not exist, creating it", "DEBUG"]`)
|
||||
err = ioutil.WriteFile(SERVER_TIME_FILE, []byte(strconv.FormatUint(serverTime, 10)), 0666)
|
||||
if err != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["Error writing server time to file: %v", "ERROR"]`, err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// file exists, read it
|
||||
line, err := ioutil.ReadFile(SERVER_TIME_FILE)
|
||||
if err != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["Error reading server time file: %v", "ERROR"]`, err))
|
||||
return
|
||||
}
|
||||
|
||||
// convert to uint64
|
||||
LAST_SERVER_TIME, err := strconv.ParseUint(string(line), 10, 64)
|
||||
if err != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["Error converting server time to uint64: %v", "ERROR"]`, err))
|
||||
return
|
||||
}
|
||||
|
||||
// if serverTime is less than last server time, close server events
|
||||
if serverTime < LAST_SERVER_TIME {
|
||||
writeLog(functionName, `["Server has restarted, closing pending server sessions in attendance", "INFO"]`)
|
||||
closeServerEvents()
|
||||
}
|
||||
LAST_SERVER_TIME = serverTime
|
||||
|
||||
// write server time to file
|
||||
err = ioutil.WriteFile(SERVER_TIME_FILE, []byte(strconv.FormatUint(serverTime, 10)), 0666)
|
||||
if err != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["Error writing server time to file: %v", "ERROR"]`, err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func closeServerEvents() {
|
||||
functionName := "closeServerEvents"
|
||||
writeLog(functionName, `["Closing server events", "INFO"]`)
|
||||
// get all server events with null DisconnectTime & set DisconnectTime to current time
|
||||
op := db.Model(&AttendanceItem{}).Where(`event_type = ? AND disconnect_time IS NULL`).Update("disconnect_time", time.Now().UTC())
|
||||
if op.Error != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, op.Error))
|
||||
return
|
||||
writeLog(functionName, `["Filling missing disconnect events due to server restart.", "DEBUG"]`)
|
||||
// get all events with null DisconnectTime & set DisconnectTime to current time
|
||||
var events []AttendanceItem
|
||||
db.Where("disconnect_time = '0000-00-00 00:00:00'").Find(&events)
|
||||
for _, event := range events {
|
||||
|
||||
// if difference between JoinTime and current time is greater than threshold, set to threshold
|
||||
if event.EventType == "Server" {
|
||||
var timeThreshold time.Time = event.JoinTime.Add(-time.Duration(A3Config.ServerEventFillNullMinutes) * time.Minute)
|
||||
if event.JoinTime.Before(timeThreshold) {
|
||||
event.DisconnectTime = timeThreshold
|
||||
} else {
|
||||
event.DisconnectTime = time.Now()
|
||||
}
|
||||
} else if event.EventType == "Mission" {
|
||||
var timeThreshold time.Time = event.JoinTime.Add(-time.Duration(A3Config.MissionEventFillNullMinutes) * time.Minute)
|
||||
if event.JoinTime.Before(timeThreshold) {
|
||||
event.DisconnectTime = timeThreshold
|
||||
} else {
|
||||
event.DisconnectTime = time.Now()
|
||||
}
|
||||
}
|
||||
db.Save(&event)
|
||||
if db.Error != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["Error filling missing disconnects: %v", "ERROR"]`, db.Error))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// log how many
|
||||
writeLog(functionName, fmt.Sprintf(`["%d server events closed", "INFO"]`, op.RowsAffected))
|
||||
writeLog(functionName, fmt.Sprintf(`["%d missing disconnects filled.", "INFO"]`, len(events)))
|
||||
}
|
||||
|
||||
func connectDB() error {
|
||||
@@ -199,7 +260,7 @@ func connectDB() error {
|
||||
// connect to database
|
||||
var err error
|
||||
dsn := fmt.Sprintf(
|
||||
"%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
|
||||
"%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True",
|
||||
ATConfig.MySQLUser,
|
||||
ATConfig.MySQLPassword,
|
||||
ATConfig.MySQLHost,
|
||||
@@ -271,6 +332,7 @@ func writeWorldInfo(worldInfo string) {
|
||||
|
||||
// write world if not exist
|
||||
var world World
|
||||
var returnId uint
|
||||
db.Where("world_name = ?", wi.WorldName).First(&world)
|
||||
if world.ID == 0 {
|
||||
writeLog(functionName, `["World not found, writing new world", "INFO"]`)
|
||||
@@ -280,24 +342,28 @@ func writeWorldInfo(worldInfo string) {
|
||||
return
|
||||
}
|
||||
writeLog(functionName, fmt.Sprintf(`["World written with ID %d", "INFO"]`, wi.ID))
|
||||
returnId = wi.ID
|
||||
} else {
|
||||
// return ID
|
||||
writeLog(functionName, fmt.Sprintf(`["World exists with ID %d", "INFO"]`, world.ID))
|
||||
returnId = world.ID
|
||||
}
|
||||
|
||||
writeLog(functionName, fmt.Sprintf(`["WORLD_ID", %d]`, returnId))
|
||||
}
|
||||
|
||||
type Mission struct {
|
||||
gorm.Model
|
||||
MissionName string `json:"missionName"`
|
||||
BriefingName string `json:"briefingName"`
|
||||
MissionNameSource string `json:"missionNameSource"`
|
||||
OnLoadName string `json:"onLoadName"`
|
||||
Author string `json:"author"`
|
||||
ServerName string `json:"serverName"`
|
||||
ServerProfile string `json:"serverProfile"`
|
||||
MissionStart string `json:"missionStart"`
|
||||
MissionHash string `json:"missionHash"`
|
||||
WorldName string `json:"worldName" gorm:"-"`
|
||||
MissionName string `json:"missionName"`
|
||||
BriefingName string `json:"briefingName"`
|
||||
MissionNameSource string `json:"missionNameSource"`
|
||||
OnLoadName string `json:"onLoadName"`
|
||||
Author string `json:"author"`
|
||||
ServerName string `json:"serverName"`
|
||||
ServerProfile string `json:"serverProfile"`
|
||||
MissionStart time.Time `json:"missionStart" gorm:"type:datetime"`
|
||||
MissionHash string `json:"missionHash"`
|
||||
WorldName string `json:"worldName" gorm:"-"`
|
||||
WorldID uint
|
||||
World World `gorm:"foreignkey:WorldID"`
|
||||
Attendees []AttendanceItem
|
||||
@@ -384,22 +450,16 @@ func writeDisconnectEvent(data string) {
|
||||
var attendanceRows []AttendanceItem
|
||||
db.Where("player_uid = ? AND event_type = ? AND disconnect_time = '0000-00-00 00:00:00'", event.PlayerUID, event.EventType).Find(&attendanceRows)
|
||||
for _, row := range attendanceRows {
|
||||
// put to json
|
||||
json, err := json.Marshal(row)
|
||||
if err != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||
return
|
||||
}
|
||||
writeLog(functionName, fmt.Sprintf(`["Updating disconnect time for %s", "INFO"]`, json))
|
||||
if row.JoinTime.Before(time.Now().UTC().Add(-1*time.Hour)) && row.EventType == "Mission" {
|
||||
// update disconnect time
|
||||
if row.JoinTime.Before(time.Now().Add(-1*time.Hour)) && row.EventType == "Mission" {
|
||||
// if mission JoinTime is more than 1 hour ago, simplify this to write DisconnectTime as 1 hour from JoinTime. this to account for crashes where people don't immediately rejoin
|
||||
row.DisconnectTime = time.Now().UTC().Add(-1 * time.Hour)
|
||||
} else if row.JoinTime.Before(time.Now().UTC().Add(-6*time.Hour)) && row.EventType == "Server" {
|
||||
row.DisconnectTime = row.JoinTime.Add(-1 * time.Hour)
|
||||
} else if row.JoinTime.Before(time.Now().Add(-6*time.Hour)) && row.EventType == "Server" {
|
||||
// if server JoinTime is more than 6 hours ago, simplify this to write DisconnectTime as 6 hours from JoinTime. this to account for server crashes where people don't immediately rejoin without overwriting valid (potentially lengthy) server sessions
|
||||
row.DisconnectTime = time.Now().UTC().Add(-6 * time.Hour)
|
||||
row.DisconnectTime = row.JoinTime.Add(-6 * time.Hour)
|
||||
} else {
|
||||
// otherwise, update DisconnectTime to now
|
||||
row.DisconnectTime = time.Now().UTC()
|
||||
row.DisconnectTime = time.Now()
|
||||
}
|
||||
db.Save(&row)
|
||||
}
|
||||
@@ -445,7 +505,7 @@ func writeAttendance(data string) {
|
||||
|
||||
} else {
|
||||
// insert new row
|
||||
event.JoinTime = time.Now().UTC()
|
||||
event.JoinTime = time.Now()
|
||||
row := db.Create(&event)
|
||||
if row.Error != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, row.Error))
|
||||
@@ -469,14 +529,14 @@ func writeAttendance(data string) {
|
||||
db.Where("player_id = ? AND player_uid = ? AND event_type = ? AND mission_hash = ?", event.PlayerId, event.PlayerUID, event.EventType, event.MissionHash).Order("join_time desc").First(&attendance)
|
||||
if attendance.ID != 0 {
|
||||
// update disconnect time
|
||||
row := db.Model(&attendance).Update("disconnect_time", time.Now().UTC())
|
||||
row := db.Model(&attendance).Update("disconnect_time", time.Now())
|
||||
if row.Error != nil {
|
||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, row.Error))
|
||||
return
|
||||
}
|
||||
rowId, playerUid = attendance.ID, attendance.PlayerUID
|
||||
} else {
|
||||
event.JoinTime = time.Now().UTC()
|
||||
event.JoinTime = time.Now()
|
||||
// insert new row
|
||||
row := db.Create(&event)
|
||||
if row.Error != nil {
|
||||
@@ -532,11 +592,22 @@ func goRVExtensionArgs(output *C.char, outputsize C.size_t, input *C.char, argv
|
||||
}
|
||||
case "logMission":
|
||||
if argc == 1 {
|
||||
writeMission(out[0])
|
||||
go writeMission(out[0])
|
||||
}
|
||||
case "logWorld":
|
||||
if argc == 1 {
|
||||
writeWorldInfo(out[0])
|
||||
go writeWorldInfo(out[0])
|
||||
}
|
||||
case "updateServerTime":
|
||||
if argc == 1 {
|
||||
// convert to uint64
|
||||
serverTime, err := strconv.ParseUint(out[0], 10, 64)
|
||||
if err != nil {
|
||||
writeLog("updateServerTime", fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||
temp = "ERROR parsing server time"
|
||||
} else {
|
||||
go updateServerTime(serverTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +639,7 @@ func callBackExample() {
|
||||
func getTimestamp() string {
|
||||
// get the current unix timestamp in nanoseconds
|
||||
// return time.Now().Local().Unix()
|
||||
return time.Now().UTC().Format("2006-01-02 15:04:05")
|
||||
return time.Now().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
func trimQuotes(s string) string {
|
||||
|
||||
Reference in New Issue
Block a user