More Munzee stuff. It still doesn't capture though :\
This commit is contained in:
parent
96587b1eb0
commit
cbd3019cad
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
error*
|
error/
|
||||||
stats*
|
stats/
|
||||||
vendor*
|
vendor/
|
||||||
settings.php
|
settings.php
|
||||||
|
*.log
|
@ -9,7 +9,7 @@ if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
|
|||||||
|
|
||||||
file_put_contents("munzee.log", "Checking if user " . $_SESSION['uuid'] . " has an unexpired token\n", FILE_APPEND);
|
file_put_contents("munzee.log", "Checking if user " . $_SESSION['uuid'] . " has an unexpired token\n", FILE_APPEND);
|
||||||
/* Check if we need to refresh the bearer token first */
|
/* Check if we need to refresh the bearer token first */
|
||||||
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid'], 'expires[<=]' => (time() + 30)])) {
|
if ($database->has('munzee', ["AND" => ['player_uuid' => $_SESSION['uuid'], 'expires[<=]' => (time() + 30)]])) {
|
||||||
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " has an expired token. Refreshing.\n", FILE_APPEND);
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " has an expired token. Refreshing.\n", FILE_APPEND);
|
||||||
$url = 'https://api.munzee.com/oauth/login';
|
$url = 'https://api.munzee.com/oauth/login';
|
||||||
$fields = array(
|
$fields = array(
|
||||||
@ -35,7 +35,7 @@ if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
|
|||||||
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
||||||
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
||||||
CURLOPT_ENCODING => "", // handle compressed
|
CURLOPT_ENCODING => "", // handle compressed
|
||||||
CURLOPT_USERAGENT => "TerranQuest Game Server (terranquest.net)", // name of client
|
CURLOPT_USERAGENT => "TerranQuest Game Server (terranquest.net; Ubuntu; Linux x86_64; PHP 7)", // name of client
|
||||||
CURLOPT_AUTOREFERER => true, // set referrer on redirect
|
CURLOPT_AUTOREFERER => true, // set referrer on redirect
|
||||||
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
|
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
|
||||||
CURLOPT_TIMEOUT => 120, // time-out on response
|
CURLOPT_TIMEOUT => 120, // time-out on response
|
||||||
@ -53,46 +53,58 @@ 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']]);
|
$database->update('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires']], ['player_uuid' => $_SESSION['uuid']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " has an valid token.\n", FILE_APPEND);
|
||||||
|
|
||||||
/* Check again now */
|
/* Check again now */
|
||||||
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid'], 'expires[>]' => (time() + 30)])) {
|
if ($database->has('munzee', ["AND" => ['player_uuid' => $_SESSION['uuid'], 'expires[>]' => (time() + 30)]])) {
|
||||||
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " attempting capture of $origcode.\n", FILE_APPEND);
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " attempting capture of $origcode.\n", FILE_APPEND);
|
||||||
$url = 'https://api.munzee.com/capture/light/';
|
$url = 'https://api.munzee.com/capture/light/';
|
||||||
$header = array(
|
$header = array(
|
||||||
'Content-type: application/json',
|
'Content-type: application/json',
|
||||||
'Authorization: ' . $database->select('munzee', ['bearertoken'], ['player_uuid' => $_SESSION['uuid']])[0]
|
'Authorization: ' . $database->select('munzee', ['bearertoken'], ['player_uuid' => $_SESSION['uuid']])[0]['bearertoken']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$time = time();
|
||||||
$fields_string = 'data={"language":"EN","latitude":' . $latitude . ',"longitude":' . $longitude . ',"code":"' . $origcode . '","time":' . time() . ',"accuracy":' . $accuracy . '}';
|
$fields_string = 'data={"language":"EN","latitude":"'.$latitude.'","longitude":"'.$longitude.'","code":"'.$origcode.'","time":'.$time.',"accuracy":'.$accuracy.'}';
|
||||||
//open connection
|
//open connection
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
CURLOPT_URL => $url,
|
CURLOPT_URL => $url,
|
||||||
CURLOPT_POST => 1,
|
CURLOPT_POST => true,
|
||||||
CURLOPT_POSTFIELDS => $fields_string,
|
CURLOPT_POSTFIELDS => $fields_string,
|
||||||
|
CURLOPT_HTTPHEADER => $header,
|
||||||
CURLOPT_RETURNTRANSFER => true, // return web page
|
CURLOPT_RETURNTRANSFER => true, // return web page
|
||||||
CURLOPT_HEADER => false, // don't return headers
|
CURLOPT_HEADER => false, // don't return headers
|
||||||
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
||||||
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
||||||
CURLOPT_ENCODING => "", // handle compressed
|
CURLOPT_ENCODING => "", // handle compressed
|
||||||
CURLOPT_USERAGENT => "TerranQuest Game Server (terranquest.net)", // name of client
|
CURLOPT_USERAGENT => "TerranQuest Game Server (terranquest.net; Ubuntu; Linux x86_64; PHP 7)", // name of client
|
||||||
CURLOPT_AUTOREFERER => true, // set referrer on redirect
|
CURLOPT_AUTOREFERER => true, // set referrer on redirect
|
||||||
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
|
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
|
||||||
CURLOPT_TIMEOUT => 120, // time-out on response
|
CURLOPT_TIMEOUT => 120, // time-out on response
|
||||||
);
|
);
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
|
|
||||||
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " attempting to capture $origcode:\n", FILE_APPEND);
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
//close connection
|
//close connection
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
|
||||||
$data = json_decode($result, TRUE);
|
$data = json_decode($result, TRUE);
|
||||||
|
if ($data['status_code'] == 200) {
|
||||||
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " captured $origcode:\n", FILE_APPEND);
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " captured $origcode:\n", FILE_APPEND);
|
||||||
file_put_contents("munzee.log", " $result\n\n", FILE_APPEND);
|
file_put_contents("munzee.log", " Sent data: $fields_string\n\n", FILE_APPEND);
|
||||||
|
file_put_contents("munzee.log", " Result: $result\n\n", FILE_APPEND);
|
||||||
|
|
||||||
// Add munzee capture info to response
|
// Add munzee capture info to response
|
||||||
$returndata["messages"][] = ["title" => "Captured a Munzee!", "text" => $data["data"]["result"]];
|
$returndata["messages"][] = ["title" => "Munzee", "text" => $data["data"]["result"]];
|
||||||
|
} else {
|
||||||
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " did not capture $origcode:\n", FILE_APPEND);
|
||||||
|
file_put_contents("munzee.log", " Sent headers: " . var_export($header, true) . "\n\n", FILE_APPEND);
|
||||||
|
file_put_contents("munzee.log", " Sent data: $fields_string\n\n", FILE_APPEND);
|
||||||
|
file_put_contents("munzee.log", " Response: " . var_export($result, true) . "\n\n", FILE_APPEND);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,30 +46,38 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($database->has('claimedcodes', ["AND" => ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]])) {
|
if ($database->has('claimedcodes', ["AND" => ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]])) {
|
||||||
//sendError("You've already found this code!", true);
|
sendError("You've already found this code!", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$codearray = str_split($origcode);
|
if ($origcode == "http://terranquest.net/#9001") {
|
||||||
|
// Secret awesome codez
|
||||||
|
$database->insert('inventory', ['playeruuid' => $_SESSION['uuid'], 'itemid' => 9001]);
|
||||||
|
$database->insert('claimedcodes', ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]);
|
||||||
|
$itemname = $database->select('items', ['itemname'], ['itemid' => 9001])[0]['itemname'];
|
||||||
|
} else {
|
||||||
|
$codearray = str_split($origcode);
|
||||||
|
|
||||||
|
|
||||||
$codeint = 0;
|
$codeint = 0;
|
||||||
foreach ($codearray as $chr) {
|
foreach ($codearray as $chr) {
|
||||||
$codeint += ord($chr);
|
$codeint += ord($chr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Random::seed($codeint);
|
||||||
|
$itemcode = Random::num(1, 6);
|
||||||
|
|
||||||
|
$database->insert('inventory', ['playeruuid' => $_SESSION['uuid'], 'itemid' => $itemcode]);
|
||||||
|
$database->insert('claimedcodes', ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]);
|
||||||
|
$itemname = $database->select('items', ['itemname'], ['itemid' => $itemcode])[0]['itemname'];
|
||||||
}
|
}
|
||||||
|
|
||||||
Random::seed($codeint);
|
|
||||||
$itemcode = Random::num(1, 6);
|
|
||||||
|
|
||||||
$database->insert('inventory', ['playeruuid' => $_SESSION['uuid'], 'itemid' => $itemcode]);
|
|
||||||
$database->insert('claimedcodes', ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]);
|
|
||||||
$itemname = $database->select('items', ['itemname'], ['itemid' => $itemcode])[0]['itemname'];
|
|
||||||
|
|
||||||
$returndata = [
|
$returndata = [
|
||||||
"status" => "OK",
|
"status" => "OK",
|
||||||
"messages" => [
|
"messages" => [
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$returndata["message"] = "$itemname"; // Don't break older versions
|
||||||
$returndata["messages"][] = ["title" => "Found an item!", "text" => "Found one $itemname"];
|
$returndata["messages"][] = ["title" => "Found an item!", "text" => "Found one $itemname"];
|
||||||
|
|
||||||
sendOK($itemname);
|
die(json_encode($returndata));
|
||||||
|
@ -6,6 +6,7 @@ require 'onlyloggedin.php';
|
|||||||
header("Content-Type: text/html");
|
header("Content-Type: text/html");
|
||||||
|
|
||||||
if (!is_empty($_GET['code'])) {
|
if (!is_empty($_GET['code'])) {
|
||||||
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " is attempting OAuth.\n", FILE_APPEND);
|
||||||
$code = $_GET['code'];
|
$code = $_GET['code'];
|
||||||
$url = 'https://api.munzee.com/oauth/login';
|
$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"
|
// "client_id=yourclientid&client_secret=yourclientsecret&grant_type=authorization_code&code=JkEQQmjgbPavmqtJtbYEyAD7lYAMYLKBEZhlfeTn&redirect_uri=https://myfancymunzeeapp.org/handle_oauth"
|
||||||
@ -33,7 +34,7 @@ if (!is_empty($_GET['code'])) {
|
|||||||
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
||||||
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
||||||
CURLOPT_ENCODING => "", // handle compressed
|
CURLOPT_ENCODING => "", // handle compressed
|
||||||
CURLOPT_USERAGENT => "TerranQuest Game Server (terranquest.net)", // name of client
|
CURLOPT_USERAGENT => "TerranQuest Game Server (terranquest.net; Ubuntu; Linux x86_64; PHP 7)", // name of client
|
||||||
CURLOPT_AUTOREFERER => true, // set referrer on redirect
|
CURLOPT_AUTOREFERER => true, // set referrer on redirect
|
||||||
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
|
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
|
||||||
CURLOPT_TIMEOUT => 120, // time-out on response
|
CURLOPT_TIMEOUT => 120, // time-out on response
|
||||||
@ -46,8 +47,14 @@ if (!is_empty($_GET['code'])) {
|
|||||||
|
|
||||||
$jsonresult = json_decode($result, TRUE);
|
$jsonresult = json_decode($result, TRUE);
|
||||||
$data = $jsonresult['data'];
|
$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 ($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']]);
|
$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>";
|
echo "Your Munzee account has been linked to TerranQuest!<br /><a href='about:closeme'>Back to game</a>";
|
||||||
die();
|
die();
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user