change_game_mode.php 947 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * File for changing the game mode.
  4. *
  5. * Implements an action function to be called from the {@see Controller}.
  6. *
  7. * @category Action
  8. */
  9. /**
  10. * Sets the score for a team.
  11. *
  12. * Reads the POST parameters looking for the following KEYS:
  13. * player
  14. * team
  15. * score
  16. * Validates the data and sets the score.
  17. *
  18. * @return int 201 on success, HTTP error codes on failure.
  19. * @category Action
  20. */
  21. function action(){
  22. $player = filter_input(INPUT_GET, "player");
  23. $mode = filter_input(INPUT_GET, "mode");
  24. if (mode != GAME_MODE_ID::NORMAL && mode != GAME_MODE_ID::RTA){
  25. return 400;
  26. }
  27. $statement = get_context()->get_db()->prepare("
  28. UPDATE player
  29. SET mode = :mode
  30. WHERE id = :id;
  31. ");
  32. $statement->bindValue(":mode", $mode, SQLITE3_TEXT);
  33. $statement->bindValue(":id", $player, SQLITE3_TEXT);
  34. $statement->execute();
  35. header("HTTP/1.1 201 OK");
  36. die();
  37. return 201;
  38. }