<?php include "../db/DBCommunication.php"; // Checks the input if (isset($_POST["player"]) && empty($_POST['player']) === false) { // Decode our JSON into PHP objects $player = json_decode($_POST["player"]); $regex = "/[A-Za-z]{1,20}/"; // Regular Expression: Only English letters, Up to 20 characters // Check if the email is a valid email address if (filter_var($player->email, FILTER_VALIDATE_EMAIL) === false) { echo "Invalid email"; } elseif (preg_match($regex, $player->firsName, $match)) { echo "Invalid firstName"; } else { // Taking Only the string -> Cancel injection $dbconncet = new DbComunication(); $player->firsName = mysqli_real_escape_string($dbconncet->db, $player->firsName); $player->lastName = mysqli_real_escape_string($dbconncet->db, $player->lastName); $player->nickname = mysqli_real_escape_string($dbconncet->db, $player->nickname); echo $dbconncet->insertNewPlayer($player); } }
<?php include "../db/DBCommunication.php"; $dbconncet = new DbComunication(); $data = json_decode($_GET["data"]); $gameId = $data->gameId; $counter = $data->counter; $timeStart = time(); while (true) { // Infinite loop until break $recordGame = $dbconncet->getRecordGameOfGame($gameId); // Get the length of the recordGame from the table if (empty($recordGame) && $recordGame != 0 || is_null($recordGame)) { $counterOfrecordGame = 0; } else { $counterOfrecordGame = (strlen($recordGame) + 1) / 2; } if ($counterOfrecordGame > $counter) { // Return recordGame echo $recordGame; break; } elseif (time() - $timeStart > 30) { // Check id the time has passed // Return time-out $dbconncet->deleteGame($gameId); echo "timeOut"; break; } else { // wait for 1 sec sleep(1); continue;
<?php include "../db/DBCommunication.php"; if (isset($_POST['id']) == true && empty($_POST['id']) === false) { $dbconncet = new DbComunication(); $returnValue = $dbconncet->getPlayerbyId($_POST['id']); // Return the Player object of the player id echo json_encode($returnValue); }
<?php include "../db/DBCommunication.php"; if (isset($_POST['nickname']) == true && empty($_POST['nickname']) === false) { $dbconncet = new DbComunication(); // kepp only the string of the nickname $nickname = mysqli_real_escape_string($dbconncet->db, $_POST['nickname']); $returnValue = $dbconncet->getIdOfPlayerNic($nickname); // Return the id of a nickname echo $returnValue; }
<?php include "../db/DBCommunication.php"; $dbconncet = new DbComunication(); echo $dbconncet->checkConnection(); //Creates a new table (deletes, if exist) //echo $dbconncet ->createPlayersTable(); //echo $dbconncet ->createGamesTable(); //להוסיף סיסמא או משהו שמונע מכל אחד לגשת
<?php include "../db/DBCommunication.php"; if (isset($_POST['setGameId']) == true && empty($_POST['setGameId']) === false) { $setGameId = json_decode($_POST["setGameId"]); $dbconncet = new DbComunication(); // Set the game id in the Player table echo $dbconncet->setGameIdToPlayer($setGameId->playerId, $setGameId->gameId); }
<!-- increment the score--> <?php include "../db/DBCommunication.php"; // Checks the input if (isset($_POST['incrementScore']) == true && empty($_POST['incrementScore']) === false) { $incrementScore = json_decode($_POST["incrementScore"]); $dbconncet = new DbComunication(); if ($incrementScore->column == "win") { // Increment to "wins" $returnValue = $dbconncet->incrementScore("wins", $incrementScore->id); } else { if ($incrementScore->column == "lose") { $returnValue = $dbconncet->incrementScore("lose", $incrementScore->id); } else { if ($incrementScore->column == "tie") { $returnValue = $dbconncet->incrementScore("tie", $incrementScore->id); } else { $returnValue = $incrementScore->column . " Error"; } } } echo $returnValue; }
<?php include "../db/DBCommunication.php"; $dbconncet = new DbComunication(); if (isset($_POST['playerId']) == true && empty($_POST['playerId']) === false) { $returnValue = $dbconncet->checkPlayerInGamesTable($_POST['playerId']); if ($returnValue == true) { $returnValue = $dbconncet->getidOfGameWithOnePlayer(); // Return the id of a Game with one player echo json_encode($returnValue); } else { echo "user_already_play"; } }
<?php include "../db/DBCommunication.php"; // Change the connected field in Players table if (isset($_POST['changePlayNow']) == true && empty($_POST['changePlayNow']) === false) { // Decode our JSON into PHP objects $changePlayNow = json_decode($_POST["changePlayNow"]); $dbconncet = new DbComunication(); $returnValue = $dbconncet->changePlayNowTo($changePlayNow->playerId, $changePlayNow->changeTo); echo $returnValue; }
<?php include "../db/DBCommunication.php"; $dbconncet = new DbComunication(); $dbconncet->setGameStatus(454, 1); // echo $dbconncet -> addCellToRecordGame(7, 19); // $timeStart= time(); // while (true) { // $answer=$dbconncet-> waitingForOpponent(277); // if (intval(trim($answer,"\n"))>0){ // // echo "==". $gameId. " - " .$counterOfrecordGame . "-- " . $recordGame; // echo $answer; // break; // } // elseif(time()-$timeStart>5){ // echo $dbconncet-> deleteGame(277); // echo "timeOut"; // break; // } // else { // // wait for 1 sec // sleep( 1 ); // continue; // } // } // $returnValue =$dbconncet -> getidOfGameWithOnePlayer(); // echo json_encode($returnValue); // $counter=1; // $recordGame=$dbconncet-> getRecordGameOfGame(26); // if ((empty($recordGame) && $recordGame!=0) || is_null($recordGame)){ // $counterOfrecordGame=0;
<?php include "../db/DBCommunication.php"; if (isset($_POST['addUpdateGame']) == true && empty($_POST['addUpdateGame']) === false) { // Decode our JSON into PHP objects $addUpdateGame = json_decode($_POST["addUpdateGame"]); $dbconncet = new DbComunication(); if (empty($addUpdateGame->gameId)) { // Adds a new game to Games id echo $dbconncet->newGame($addUpdateGame->id); } else { // Adds to game id a second player echo $dbconncet->addSecondPlayerToGame($addUpdateGame->id, $addUpdateGame->gameId); } }
<?php include "../db/DBCommunication.php"; $dbconncet = new DbComunication(); $data = json_decode($_GET["data"]); $gameId = $data->gameId; $counter = $data->counter; $timeStart = time(); while (true) { // Infinite loop until break $answer = $dbconncet->waitingForOpponent($gameId); if (intval(trim($answer, "\n")) > 0) { // Found an opponent echo $answer; break; } elseif (time() - $timeStart > 30) { // Too long time $dbconncet->deleteGame($gameId); echo "timeOut"; break; } else { // wait for 1 sec sleep(1); continue; } }
<?php include "../db/DBCommunication.php"; $dbconncet = new DbComunication(); // Return json of top-10 list $send = $dbconncet->getTopTen2(); echo json_encode($send);
<?php include "../db/DBCommunication.php"; // Change gameStatus in Games Table if (isset($_POST['changeGameStatus']) == true && empty($_POST['changeGameStatus']) === false) { // Decode our JSON into PHP objects $changeGameStatus = json_decode($_POST["changeGameStatus"]); $dbconncet = new DbComunication(); // GameStatus -> wait=(-1), start=0, end=1 if ($changeGameStatus->changeTo <= 1 && $changeGameStatus->changeTo >= -1) { $returnValue = $dbconncet->setGameStatus($changeGameStatus->gameId, $changeGameStatus->changeTo); echo $returnValue; } else { echo "Error"; } }
<?php include "../db/DBCommunication.php"; if (isset($_POST['addRecoredGame']) == true && empty($_POST['addRecoredGame']) === false) { // Decode our JSON into PHP objects $recoredGame = json_decode($_POST["addRecoredGame"]); $dbconncet = new DbComunication(); // Add the cell to record game echo $dbconncet->addCellToRecordGame($recoredGame->cellNum, $recoredGame->gameId); }