function getMove($d, $ip, $token) { //do we need to verify identity here? //need to start session if we don't check token session_start(); //retrieve updated game info from DB $gameId = filter_var($d, FILTER_SANITIZE_STRING); $game = json_decode(getGameData($gameId)); foreach ($game as $player) { if ($player->player == $_SESSION['user_id']) { //these are your boards $you = $player; } else { //these are opponents $opp = $player; } } $yourHealth = checkShipsArray(buildShipsArr($you->ships)); if ($yourHealth == 0) { //you lose endGame($opp->player, $_SESSION['user_id'], $gameId); } //return the number of ships you have left and the previous round of shots fired by opponent return json_encode(array($yourHealth, $opp->shots)); }
$dates = mysqli_query($con, "select Start from schedule where Status=1 order by Start")->fetch_array() or die("No games currently in progress.<br>"); //strip hyphens $dates[0] = str_replace("-", "", $dates[0]); //Decrement days left where people are zombies mysqli_query($con, "update _" . $dates[0] . " set daysLeft=daysLeft - 1 where status=0") or die("Error: " . mysqli_error($con)); echo "Decremented daysLeft on all zombies.<br>"; //Kill people who have no days left mysqli_query($con, "update _" . $dates[0] . " set status=-1 where daysLeft<1") or die("Error: " . mysqli_error($con)); echo "Killed all zombies with no days left to live.<br>"; } //Check which button was pressed if (isset($_POST["initServer"])) { initiateServer(dbConnect()); } if (isset($_POST["endGame"])) { endGame(dbConnect()); } if (isset($_POST["scheduleZombies"])) { scheduleZombies(dbConnect()); } if (isset($_POST["scheduleAssassins"])) { scheduleAssassins(dbConnect()); } if (isset($_POST["startGame"])) { startGame(dbConnect()); } if (isset($_POST["newDay"])) { newDay(dbConnect()); } ?>