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:
2023-06-28 21:54:57 -07:00
parent dbd3d68537
commit fc53ecb770
5 changed files with 51 additions and 24 deletions

View File

@@ -50,14 +50,6 @@ addMissionEventHandler ["ExtensionCallback", {
// close any null disconnect values from previous mission
"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
private _response = "AttendanceTracker" callExtension [
"logWorld",
@@ -65,6 +57,14 @@ addMissionEventHandler ["ExtensionCallback", {
[(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": {

View File

@@ -15,7 +15,8 @@ AttendanceTracker setVariable ["missionContext", createHashMapFromArray [
["serverName", serverName],
["serverProfile", profileName],
["missionStart", AttendanceTracker_missionStartTimestamp],
["missionHash", AttendanceTracker_missionHash]
["missionHash", AttendanceTracker_missionHash],
["worldName", toLower worldName]
]];

Binary file not shown.

View File

@@ -194,7 +194,7 @@ func writeWorldInfo(worldInfo string) {
// write to database
// check if world exists
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 == sql.ErrNoRows {
// world does not exist, insert it
@@ -257,41 +257,67 @@ type MissionInfo struct {
ServerProfile string `json:"serverProfile"`
MissionStart string `json:"missionStart"`
MissionHash string `json:"missionHash"`
WorldName string `json:"worldName"`
}
func writeMissionInfo(missionInfo string) {
functionName := "writeMissionInfo"
var err error
// writeLog(functionName, fmt.Sprintf(`["%s", "DEBUG"]`, missionInfo))
// missionInfo is json, parse it
var mi MissionInfo
fixedString := fixEscapeQuotes(trimQuotes(missionInfo))
err := json.Unmarshal([]byte(fixedString), &mi)
err = json.Unmarshal([]byte(fixedString), &mi)
if err != nil {
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
return
}
// get MySQL friendly datetime
// write to log as json
// writeLog(functionName, fmt.Sprintf(`["%s", "DEBUG"]`, mi))
// write to database
// every mission is unique, so insert it
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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
MISSIONS_TABLE,
))
// 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
}
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)
var stmt *sql.Stmt
var res sql.Result
if worldID != 0 {
sqlWorld := 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
MISSIONS_TABLE,
)
stmt, err = db.Prepare(sqlWorld)
if err != nil {
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
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, 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 {
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))
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()
if err != nil {
writeLog(functionName, fmt.Sprintf(`["%s", "ERROR"]`, err))