mirror of
https://github.com/indig0fox/Arma3-AttendanceTracker.git/
synced 2025-12-08 09:51:47 -06:00
bug fixes
- fixes world/mission log race condition w/ new foreign key constraint in DB - fixes missing world_id sent with mission rows - adds worldName to missionContext hash in sqf
This commit is contained in:
Binary file not shown.
@@ -50,14 +50,6 @@ addMissionEventHandler ["ExtensionCallback", {
|
|||||||
// close any null disconnect values from previous mission
|
// close any null disconnect values from previous mission
|
||||||
"AttendanceTracker" callExtension ["fillLastMissionNull", []];
|
"AttendanceTracker" callExtension ["fillLastMissionNull", []];
|
||||||
|
|
||||||
// log mission info and get back the row Id to send with future messages
|
|
||||||
private _response = "AttendanceTracker" callExtension [
|
|
||||||
"logMission",
|
|
||||||
[
|
|
||||||
[AttendanceTracker getVariable ["missionContext", createHashMap]] call CBA_fnc_encodeJSON
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
// log world info
|
// log world info
|
||||||
private _response = "AttendanceTracker" callExtension [
|
private _response = "AttendanceTracker" callExtension [
|
||||||
"logWorld",
|
"logWorld",
|
||||||
@@ -65,6 +57,14 @@ addMissionEventHandler ["ExtensionCallback", {
|
|||||||
[(call attendanceTracker_fnc_getWorldInfo)] call CBA_fnc_encodeJSON
|
[(call attendanceTracker_fnc_getWorldInfo)] call CBA_fnc_encodeJSON
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// log mission info and get back the row Id to send with future messages
|
||||||
|
private _response = "AttendanceTracker" callExtension [
|
||||||
|
"logMission",
|
||||||
|
[
|
||||||
|
[AttendanceTracker getVariable ["missionContext", createHashMap]] call CBA_fnc_encodeJSON
|
||||||
|
]
|
||||||
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
case "writeMissionInfo": {
|
case "writeMissionInfo": {
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ AttendanceTracker setVariable ["missionContext", createHashMapFromArray [
|
|||||||
["serverName", serverName],
|
["serverName", serverName],
|
||||||
["serverProfile", profileName],
|
["serverProfile", profileName],
|
||||||
["missionStart", AttendanceTracker_missionStartTimestamp],
|
["missionStart", AttendanceTracker_missionStartTimestamp],
|
||||||
["missionHash", AttendanceTracker_missionHash]
|
["missionHash", AttendanceTracker_missionHash],
|
||||||
|
["worldName", toLower worldName]
|
||||||
]];
|
]];
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -194,7 +194,7 @@ func writeWorldInfo(worldInfo string) {
|
|||||||
// write to database
|
// write to database
|
||||||
// check if world exists
|
// check if world exists
|
||||||
var worldID int
|
var worldID int
|
||||||
err = db.QueryRow("SELECT id FROM worlds WHERE workshop_id = ?", wi.WorkshopID).Scan(&worldID)
|
err = db.QueryRow("SELECT id FROM worlds WHERE world_name = ?", wi.WorldName).Scan(&worldID)
|
||||||
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
|
||||||
@@ -257,41 +257,67 @@ type MissionInfo struct {
|
|||||||
ServerProfile string `json:"serverProfile"`
|
ServerProfile string `json:"serverProfile"`
|
||||||
MissionStart string `json:"missionStart"`
|
MissionStart string `json:"missionStart"`
|
||||||
MissionHash string `json:"missionHash"`
|
MissionHash string `json:"missionHash"`
|
||||||
|
WorldName string `json:"worldName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeMissionInfo(missionInfo string) {
|
func writeMissionInfo(missionInfo string) {
|
||||||
functionName := "writeMissionInfo"
|
functionName := "writeMissionInfo"
|
||||||
|
var err error
|
||||||
// writeLog(functionName, fmt.Sprintf(`["%s", "DEBUG"]`, missionInfo))
|
// writeLog(functionName, fmt.Sprintf(`["%s", "DEBUG"]`, missionInfo))
|
||||||
// missionInfo is json, parse it
|
// missionInfo is json, parse it
|
||||||
var mi MissionInfo
|
var mi MissionInfo
|
||||||
fixedString := fixEscapeQuotes(trimQuotes(missionInfo))
|
fixedString := fixEscapeQuotes(trimQuotes(missionInfo))
|
||||||
err := json.Unmarshal([]byte(fixedString), &mi)
|
err = json.Unmarshal([]byte(fixedString), &mi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get MySQL friendly datetime
|
// check if mission exists based on hash
|
||||||
|
var worldID int
|
||||||
|
err = db.QueryRow("SELECT id FROM worlds WHERE world_name = ?", mi.WorldName).Scan(&worldID)
|
||||||
|
if err != nil {
|
||||||
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// write to log as json
|
var stmt *sql.Stmt
|
||||||
// writeLog(functionName, fmt.Sprintf(`["%s", "DEBUG"]`, mi))
|
var res sql.Result
|
||||||
|
|
||||||
// write to database
|
if worldID != 0 {
|
||||||
// every mission is unique, so insert it
|
sqlWorld := fmt.Sprintf(
|
||||||
stmt, err := db.Prepare(fmt.Sprintf(
|
"INSERT INTO %s (mission_name, briefing_name, mission_name_source, on_load_name, author, server_name, server_profile, mission_start, mission_hash, world_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
"INSERT INTO %s (mission_name, briefing_name, mission_name_source, on_load_name, author, server_name, server_profile, mission_start, mission_hash) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
||||||
MISSIONS_TABLE,
|
MISSIONS_TABLE,
|
||||||
))
|
)
|
||||||
|
stmt, err = db.Prepare(sqlWorld)
|
||||||
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(mi.MissionName, mi.BriefingName, mi.MissionNameSource, mi.OnLoadName, mi.Author, mi.ServerName, mi.ServerProfile, mi.MissionStart, mi.MissionHash)
|
|
||||||
|
res, err = stmt.Exec(mi.MissionName, mi.BriefingName, mi.MissionNameSource, mi.OnLoadName, mi.Author, mi.ServerName, mi.ServerProfile, mi.MissionStart, mi.MissionHash, worldID)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// if no world was found, write without it
|
||||||
|
sqlNoWorld := fmt.Sprintf(
|
||||||
|
"INSERT INTO %s (mission_name, briefing_name, mission_name_source, on_load_name, author, server_name, server_profile, mission_start, mission_hash) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
MISSIONS_TABLE,
|
||||||
|
)
|
||||||
|
stmt, err = db.Prepare(sqlNoWorld)
|
||||||
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()
|
||||||
|
res, err = stmt.Exec(mi.MissionName, mi.BriefingName, mi.MissionNameSource, mi.OnLoadName, mi.Author, mi.ServerName, mi.ServerProfile, mi.MissionStart, mi.MissionHash)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
lastID, err := res.LastInsertId()
|
lastID, err := res.LastInsertId()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
|
||||||
|
|||||||
Reference in New Issue
Block a user