3 * Delete a game from the "push to my OUYA" list
5 * Pushes are stored in the sqlite3 database in push-to-my-ouya.php
7 * @author Christian Weiske <cweiske@cweiske.de>
9 $dbFile = __DIR__ . '/../../../data/push-to-my-ouya.sqlite3';
10 $apiGameDir = __DIR__ . '/details-data/';
12 require_once __DIR__ . '/../../../src/push-to-my-ouya-helpers.php';
14 $ip = $_SERVER['REMOTE_ADDR'];
17 header('X-Fail-Reason: empty ip address');
18 header('HTTP/1.0 204 No Content');
23 if (!isset($_GET['game'])) {
24 header('HTTP/1.0 400 Bad Request');
25 header('Content-type: text/plain');
26 echo 'Game parameter missing' . "\n";
30 $game = $_GET['game'];
31 $cleanGame = preg_replace('#[^a-zA-Z0-9._]#', '', $game);
32 if ($game != $cleanGame || $game == '') {
33 header('HTTP/1.0 400 Bad Request');
34 header('Content-type: text/plain');
35 echo 'Invalid game' . "\n";
40 $db = new SQLite3($dbFile, SQLITE3_OPEN_READWRITE);
41 } catch (Exception $e) {
43 header('X-Fail-Reason: database file not found');
44 header('HTTP/1.0 204 No Content');
48 $rowId = $db->querySingle(
49 'SELECT id FROM pushes'
50 . ' WHERE ip = \'' . SQLite3::escapeString($ip) . '\''
51 . ' AND game =\'' . SQLite3::escapeString($game) . '\''
53 if ($rowId === null) {
54 header('HTTP/1.0 404 Not Found');
55 header('Content-type: text/plain');
56 echo 'Game not queued' . "\n";
60 $db->exec('DELETE FROM pushes WHERE id = ' . intval($rowId));
61 header('HTTP/1.0 204 No Content');