PHP game server for TerranQuest (version 1) https://terranquest.net
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

63 lines
2.6 KiB

<?php
require 'required.php';
require 'onlyloggedin.php';
header("Content-Type: text/html");
if (!is_empty($_GET['code'])) {
//file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " is attempting OAuth.\n", FILE_APPEND);
$code = $_GET['code'];
$url = 'https://api.munzee.com/oauth/login';
$fields = array(
'client_id' => urlencode(MUNZEE_KEY),
'client_secret' => urlencode(MUNZEE_SECRET),
'grant_type' => 'authorization_code',
'code' => urlencode($code),
'redirect_uri' => urlencode("http://gs.terranquest.net/munzee.php")
);
//url-ify the data for the POST
foreach ($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $fields_string,
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "TerranQuest Game Server (terranquest.net; Ubuntu; Linux x86_64; PHP 7)", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
);
curl_setopt_array($ch, $options);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
$jsonresult = json_decode($result, TRUE);
$data = $jsonresult['data'];
//file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " OAuth result:\n", FILE_APPEND);
//file_put_contents("munzee.log", " Result: $result\n\n", FILE_APPEND);
if ($jsonresult['status_code'] == 200) {
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
$database->update('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires']], ['player_uuid' => $_SESSION['uuid']]);
} else {
$database->insert('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires'], 'player_uuid' => $_SESSION['uuid']]);
}
echo MUNZEE_LINKED_HTML;
die();
} else {
echo MUNZEE_FAILED_HTML;
die();
}
}