Game server and admin dashboard for TerranQuest.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. require __DIR__ . '/../required.php';
  8. require __DIR__ . '/functions.php';
  9. require __DIR__ . '/apisettings.php';
  10. $VARS = $_GET;
  11. if ($_SERVER['REQUEST_METHOD'] != "GET") {
  12. $VARS = array_merge($VARS, $_POST);
  13. }
  14. $requestbody = file_get_contents('php://input');
  15. $requestjson = json_decode($requestbody, TRUE);
  16. if (json_last_error() == JSON_ERROR_NONE) {
  17. $requestdata = array_merge($requestdata, $requestjson);
  18. }
  19. // If we're not using the old api.php file, allow more flexible requests
  20. if (strpos($_SERVER['REQUEST_URI'], "/api.php") === FALSE) {
  21. $route = explode("/", substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "api/") + 4));
  22. if (count($route) > 1) {
  23. $VARS["action"] = $route[0];
  24. }
  25. if (count($route) >= 2 && strpos($route[1], "?") !== 0) {
  26. $VARS["key"] = $route[1];
  27. for ($i = 2; $i < count($route); $i++) {
  28. $key = explode("=", $route[$i], 2)[0];
  29. $val = explode("=", $route[$i], 2)[1];
  30. $VARS[$key] = $val;
  31. }
  32. }
  33. if (strpos($route[count($route) - 1], "?") === 0) {
  34. $morevars = explode("&", substr($route[count($route) - 1], 1));
  35. foreach ($morevars as $var) {
  36. $key = explode("=", $var, 2)[0];
  37. $val = explode("=", $var, 2)[1];
  38. $VARS[$key] = $val;
  39. }
  40. }
  41. }
  42. if (!authenticate()) {
  43. http_response_code(403);
  44. die("403 Unauthorized");
  45. }
  46. if (empty($VARS['action'])) {
  47. http_response_code(404);
  48. die("404 No action specified");
  49. }
  50. if (!isset($APIS[$VARS['action']])) {
  51. http_response_code(404);
  52. die("404 Action not defined");
  53. }
  54. $APIACTION = $APIS[$VARS["action"]];
  55. if (!file_exists(__DIR__ . "/actions/" . $APIACTION["load"])) {
  56. http_response_code(404);
  57. die("404 Action not found");
  58. }
  59. if (!empty($APIACTION["vars"])) {
  60. checkVars($APIACTION["vars"]);
  61. }
  62. require_once __DIR__ . "/actions/" . $APIACTION["load"];