Add Munzee integration
parent
16516db98b
commit
c3a96d6ab6
@ -1,3 +1,4 @@
|
||||
error*
|
||||
stats*
|
||||
vendor*
|
||||
vendor*
|
||||
settings.php
|
||||
|
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
if (!isset($database) || ($database == null)) {
|
||||
sendError("Please don't do that.", true);
|
||||
}
|
||||
|
||||
/* If the user has a Munzee key */
|
||||
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
|
||||
|
||||
|
||||
/* Check if we need to refresh the bearer token first */
|
||||
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid'], 'expires[<=]' => (time() + 30)])) {
|
||||
$url = 'https://api.munzee.com/oauth/login';
|
||||
$fields = array(
|
||||
'client_id' => urlencode(MUNZEE_KEY),
|
||||
'client_secret' => urlencode(MUNZEE_SECRET),
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => urlencode($database->select('munzee', 'refreshtoken', ['player_uuid' => $_SESSION['uuid']]))
|
||||
);
|
||||
|
||||
foreach ($fields as $key => $value) {
|
||||
$fields_string .= $key . '=' . $value . '&';
|
||||
}
|
||||
rtrim($fields_string, '&');
|
||||
|
||||
$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)", // 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);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$data = json_decode($result, TRUE);
|
||||
|
||||
if ($data['status_code'] == 200) {
|
||||
$database->update('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires']], ['player_uuid' => $_SESSION['uuid']]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Check again now */
|
||||
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid'], 'expires[>]' => (time() + 30)])) {
|
||||
$url = 'https://api.munzee.com/capture/light/';
|
||||
$header = array(
|
||||
'Content-type: application/json',
|
||||
'Authorization: ' . $database->select('munzee', ['bearertoken'], ['player_uuid' => $_SESSION['uuid']])[0]
|
||||
);
|
||||
|
||||
|
||||
$fields_string = 'data={"language":"EN","latitude":' . $latitude . ',"longitude":' . $longitude . ',"code":"' . $origcode . '","time":' . time() . ',"accuracy":' . $accuracy . '}';
|
||||
//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)", // 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);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
//close connection
|
||||
curl_close($ch);
|
||||
|
||||
$data = json_decode($result, TRUE);
|
||||
|
||||
// Add munzee capture info to response
|
||||
$returndata["messages"][] = ["title" => "Captured a Munzee!", "text" => $data["data"]["result"]];
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
require 'required.php';
|
||||
require 'onlyloggedin.php';
|
||||
|
||||
header("Content-Type: text/html");
|
||||
|
||||
if (!is_empty($_GET['code'])) {
|
||||
$code = $_GET['code'];
|
||||
$url = 'https://api.munzee.com/oauth/login';
|
||||
// "client_id=yourclientid&client_secret=yourclientsecret&grant_type=authorization_code&code=JkEQQmjgbPavmqtJtbYEyAD7lYAMYLKBEZhlfeTn&redirect_uri=https://myfancymunzeeapp.org/handle_oauth"
|
||||
$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)", // 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'];
|
||||
if ($jsonresult['status_code'] == 200) {
|
||||
$database->insert('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires'], 'player_uuid' => $_SESSION['uuid']]);
|
||||
echo "Your Munzee account has been linked to TerranQuest!<br /><a href='about:closeme'>Back to game</a>";
|
||||
die();
|
||||
} else {
|
||||
echo "Munzee is having problems right now. Try again later.<br /><a href='about:closeme'>Back to game</a>";
|
||||
die();
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
define("DB_TYPE", "mysql");
|
||||
define("DB_NAME", "gs-terranquest");
|
||||
define("DB_SERVER", "localhost");
|
||||
define("DB_USER", "terranquest");
|
||||
define("DB_PASS", "");
|
||||
define("DB_CHARSET", "latin1");
|
||||
|
||||
define("PDB_TYPE", "mysql");
|
||||
define("PDB_NAME", "c0places");
|
||||
define("PDB_SERVER", "earth.apis.netsyms.net");
|
||||
define("PDB_USER", "c0terranquestgs");
|
||||
define("PDB_PASS", "sTcGg3@3");
|
||||
define("PDB_CHARSET", "latin1");
|
||||
|
||||
define("GEOCACHE_KEY", "z6BxjV5ssS7DYrzfF7pw");
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
|
||||
define("DB_TYPE", "mysql");
|
||||
define("DB_NAME", "");
|
||||
define("DB_SERVER", "");
|
||||
define("DB_USER", "");
|
||||
define("DB_PASS", "");
|
||||
define("DB_CHARSET", "latin1");
|
||||
|
||||
define("PDB_TYPE", "mysql");
|
||||
define("PDB_NAME", "");
|
||||
define("PDB_SERVER", "");
|
||||
define("PDB_USER", "");
|
||||
define("PDB_PASS", "");
|
||||
define("PDB_CHARSET", "latin1");
|
||||
|
||||
define("GEOCACHE_KEY", "");
|
||||
define("MUNZEE_KEY", "");
|
||||
define("MUNZEE_SECRET", "");
|
Reference in New Issue