<?php header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Key"); header("Access-Control-Allow-Methods: POST"); require_once './src/libsse.php'; if (!isset($_POST['gameId'])) { http_response_code(400); var_dump($_POST); echo 'gameId is required'; return; } $data = new SSEData('file', array('path' => './data', 'gc_lifetime' => 16000)); $game = $data->get($_POST['gameId']); if (strlen($game) < 1) { http_response_code(404); echo 'Could not find game with that ID.'; return; } $game = json_decode($game); // Discard played cards if ($game->currentBlack) { array_push($game->blackDiscarded, $game->currentBlack); $game->currentBlack = null; } if ($game->currentWhite) { foreach ($game->currentWhite as $played) { array_push($game->whiteDiscarded, $played->card); } $game->currentWhite = array(); }
<?php header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Key"); header("Access-Control-Allow-Methods: POST"); require_once './src/libsse.php'; if (!isset($_POST['id'])) { http_response_code(400); var_dump($_POST); echo 'Id is required'; return; } $data = new SSEData('file', array('path' => './data', 'gc_lifetime' => 16000)); $game = $data->get($_POST['id']); if (strlen($game) < 1) { http_response_code(404); echo 'Could not find game with that ID.'; return; } $game = json_decode($game); // Start Game $game->started = true; $game->startedTime = time(); // Update Log array_push($game->log, array('message' => 'Game has started.', 'time' => time(), 'from' => 'system')); // Shuffle Decks shuffle($game->blackDeck); shuffle($game->whiteDeck); // Update updated time $game->updated = time(); // Save
<?php header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Key"); header("Access-Control-Allow-Methods: GET"); require_once './src/libsse.php'; if (!isset($_GET['id']) || !isset($_GET['userid']) || !isset($_GET['username'])) { http_response_code(400); var_dump($_GET); echo 'ID,userid, and username are required'; return; } $data = new SSEData('file', array('path' => './data', 'gc_lifetime' => 16000)); $game = $data->get($_GET['id']); if (strlen($game) < 1) { http_response_code(404); echo 'Could not find game with that ID.'; } $game = json_decode($game); if ($game->host === $_GET['userid']) { echo 'User is host'; return; } $userFound = false; foreach ($game->players as $player) { if ($player->id === $_GET['userId']) { $userFound = true; break; } } if ($userFound) {