Here is the code I am currently using:
//This function handles all games and their attributes
function handleGames(){
sql.query('SELECT id FROM games', function (err, rows){
if(err){
console.log(String(err).error.bgWhite);
} else {
for(var i = 0; i < rows.length; i++) {
var timeNow = new Date().getTime();
//Game Expiration
//0 = Open | 4 = Expired | 5 = Generic Error
//Generic error --> Expired
if(rows[i]["status"] == 5){
sql.query('UPDATE games SET status = 4 WHERE id = "' + rows[i]["id"] + '"', function (err, rows){
if(err) console.log(String(err).error.bgWhite);
console.log(("Updating status for game " + rows[i]["id"] + " to 4").info.bgWhite);
});
}
//Set game status to expired if it has lasted more than 5 minutes (300s)
if(((rows[i]["starttime"] + 300) >= timeNow) && (rows[i]["status"] == 0)){
sql.query('UPDATE games SET status = 4 WHERE id = "' + rows[i]["id"] + '"', function (err, rows){
if(err) console.log(String(err).error.bgWhite);
});
}
};
}
});
}
Using this data:
https://i.stack.imgur.com/1NWxm.png
This program is designed for Node and aims to update the status of any game that has been active for 5 minutes (300s), but there seems to be an issue with how the keys are accessed. The game status remains unchanged.
JSON Version
SQL Export:
-- phpMyAdmin SQL Dump
...
... (rest of the SQL export content)
...