- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
function setLastHandshake ($carID) {
$HsList = json_decode(file_get_contents('carconnection.txt'), 1);
if ($HsList == "null" || $HsList == null) {
$HsList = json_decode("[]");
}
$carCount = count($HsList);
$i = 0;
foreach ($HsList as &$row) {
if ($row['car'] == $carID) {
$row['lastHS'] = (string)time();
break;
}
else {
$i++;
}
if ($i == $carCount) {
$HsList[] = array('car' => (string)$carID, 'lastHS' => (string)time());
}
}
if ($HsList == "null" || $HsList == null) {
return -1;
}
$f = fopen('carconnection.txt', 'w');
fwrite($f, json_encode($HsList));
}