Game server and admin dashboard for TerranQuest.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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. if (empty($VARS['code'])) {
  9. $user = User::byUsername($VARS["username"]);
  10. if (!$user->exists()) {
  11. return false;
  12. }
  13. if ($user->checkPassword($VARS["password"], true)) {
  14. $_SESSION["userid"] = User::byUsername($VARS["username"])->getUID();
  15. $_SESSION["munzeeauthed"] = true;
  16. header("Location: https://api.munzee.com/oauth?response_type=code&client_id=" . $SETTINGS["munzee"]["id"] . "&redirect_uri=" . urlencode($SETTINGS["munzee"]["redirecturl"]) . "&scope=read capture_light");
  17. die("OK");
  18. }
  19. die("Login incorrect.");
  20. } else {
  21. if ($_SESSION["munzeeauthed"] !== true) {
  22. die("Invalid session or session expired. Try again.");
  23. }
  24. $code = $VARS['code'];
  25. $url = 'https://api.munzee.com/oauth/login';
  26. $fields = array(
  27. 'client_id' => urlencode($SETTINGS["munzee"]["id"]),
  28. 'client_secret' => urlencode($SETTINGS["munzee"]["secret"]),
  29. 'grant_type' => 'authorization_code',
  30. 'code' => urlencode($code),
  31. 'redirect_uri' => urlencode($SETTINGS["munzee"]["redirecturl"])
  32. );
  33. //url-ify the data for the POST
  34. foreach ($fields as $key => $value) {
  35. $fields_string .= $key . '=' . $value . '&';
  36. }
  37. rtrim($fields_string, '&');
  38. //open connection
  39. $ch = curl_init();
  40. $options = array(
  41. CURLOPT_URL => $url,
  42. CURLOPT_POST => 1,
  43. CURLOPT_POSTFIELDS => $fields_string,
  44. CURLOPT_RETURNTRANSFER => true, // return web page
  45. CURLOPT_HEADER => false, // don't return headers
  46. CURLOPT_FOLLOWLOCATION => true, // follow redirects
  47. CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
  48. CURLOPT_ENCODING => "", // handle compressed
  49. CURLOPT_USERAGENT => "TerranQuest Game Server", // name of client
  50. CURLOPT_AUTOREFERER => true, // set referrer on redirect
  51. CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
  52. CURLOPT_TIMEOUT => 120, // time-out on response
  53. );
  54. curl_setopt_array($ch, $options);
  55. //execute post
  56. $result = curl_exec($ch);
  57. //close connection
  58. curl_close($ch);
  59. $jsonresult = json_decode($result, TRUE);
  60. $data = $jsonresult['data'];
  61. if ($jsonresult['status_code'] == 200) {
  62. if ($database->has('munzee', ['accountid' => $_SESSION['userid']])) {
  63. $database->update('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires']], ['accountid' => $_SESSION['userid']]);
  64. } else {
  65. $database->insert('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires'], 'accountid' => $_SESSION['userid']]);
  66. }
  67. die($Strings->get("Your Munzee account has been linked to TerranQuest!", false));
  68. } else {
  69. die($Strings->get("Munzee is having problems right now. Try again later.", false));
  70. }
  71. }