Example #1
0
<?php

if (!isset($_POST['data'])) {
    echo "[Error] Post data is not set.";
    mysqli_close($con);
    return;
}
$resultTmp = mysqli_query($con, "\tSELECT * FROM game\r\n\t\tWHERE deviceID = '{$deviceID}'");
$result = array();
while ($row = $resultTmp->fetch_assoc()) {
    $result[] = $row;
}
if (count($result) === 0) {
    if (!$allowInfoWithoutGame) {
        echo "[Error] No gameID found.";
        mysqli_close($con);
        return;
    }
    $gameID = 0;
} else {
    $gameID = $result[0]['gameID'];
}
$information = mysqli_real_escape_string($con, $_POST['data']);
$datetime = time();
mysqli_query($con, "INSERT INTO game_info (gameID, deviceID, datetime, information)\r\n\t\tVALUES({$gameID}, '{$deviceID}', {$datetime}, '{$information}')");
$gameId = mysqli_query($con, "SELECT gameID FROM game WHERE deviceID = '{$deviceID}'");
$gameId = $gameId->fetch_assoc();
$gameId = $gameId['gameID'];
require_once 'scripts/LogHelperFunctions.php';
logInsertGameInfo($deviceID, $gameId, $_POST['data']);
echo 'ok';
<?php

$del = time() - $gameTimeOut;
$resultTmp = mysqli_query($con, "SELECT id, gameID, deviceID FROM game WHERE last_update < {$del}");
$gameTimeouts = array();
while ($row = $resultTmp->fetch_assoc()) {
    $gameTimeouts[] = $row;
}
$datetime = time();
foreach ($gameTimeouts as $gameTimeout) {
    mysqli_query($con, "DELETE FROM game WHERE id = {$gameTimeout['id']}");
    $gameIDdel = mysqli_real_escape_string($con, $gameTimeout['gameID']);
    $deviceIDdel = mysqli_real_escape_string($con, $gameTimeout['deviceID']);
    mysqli_query($con, "INSERT INTO game_info (gameID, deviceID, datetime, information)\r\n\t\t\tVALUES({$gameIDdel}, '{$deviceIDdel}', {$datetime}, 'Timeout - Kick from game table.')");
    require_once 'scripts/LogHelperFunctions.php';
    logInsertGameInfo($deviceIDdel, $gameIDdel, "REMOVED FROM GAME TABLE ({$gameTimeOut} sec inactive)");
}