diff --git a/.gitignore b/.gitignore
index 40b48aa..7d18118 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
-error*
-stats*
-vendor*
+error/
+stats/
+vendor/
settings.php
+*.log
\ No newline at end of file
diff --git a/capturemunzee.php b/capturemunzee.php
index d8580fd..22ca424 100644
--- a/capturemunzee.php
+++ b/capturemunzee.php
@@ -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);
/* 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);
$url = 'https://api.munzee.com/oauth/login';
$fields = array(
@@ -35,7 +35,7 @@ if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
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_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
@@ -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']]);
}
}
-
+ file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " has an valid token.\n", FILE_APPEND);
/* 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);
$url = 'https://api.munzee.com/capture/light/';
$header = array(
'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']
);
-
-
- $fields_string = 'data={"language":"EN","latitude":' . $latitude . ',"longitude":' . $longitude . ',"code":"' . $origcode . '","time":' . time() . ',"accuracy":' . $accuracy . '}';
+
+ $time = time();
+ $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_POST => true,
CURLOPT_POSTFIELDS => $fields_string,
+ CURLOPT_HTTPHEADER => $header,
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_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);
+ file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " attempting to capture $origcode:\n", FILE_APPEND);
$result = curl_exec($ch);
//close connection
curl_close($ch);
+
$data = json_decode($result, TRUE);
- file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " captured $origcode:\n", FILE_APPEND);
- file_put_contents("munzee.log", " $result\n\n", FILE_APPEND);
- // Add munzee capture info to response
- $returndata["messages"][] = ["title" => "Captured a Munzee!", "text" => $data["data"]["result"]];
+ if ($data['status_code'] == 200) {
+ file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " captured $origcode:\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
+ $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);
+ }
}
}
\ No newline at end of file
diff --git a/code2item.php b/code2item.php
index 52e1f64..54e30e5 100644
--- a/code2item.php
+++ b/code2item.php
@@ -46,23 +46,30 @@ try {
}
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;
-foreach ($codearray as $chr) {
- $codeint += ord($chr);
-}
+ $codeint = 0;
+ foreach ($codearray as $chr) {
+ $codeint += ord($chr);
+ }
-Random::seed($codeint);
-$itemcode = Random::num(1, 6);
+ 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'];
+ $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 = [
"status" => "OK",
@@ -70,6 +77,7 @@ $returndata = [
]
];
+$returndata["message"] = "$itemname"; // Don't break older versions
$returndata["messages"][] = ["title" => "Found an item!", "text" => "Found one $itemname"];
-sendOK($itemname);
+die(json_encode($returndata));
diff --git a/munzee.php b/munzee.php
index 1e02645..5b22edf 100644
--- a/munzee.php
+++ b/munzee.php
@@ -6,6 +6,7 @@ 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';
// "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_MAXREDIRS => 10, // stop after 10 redirects
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_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
@@ -43,11 +44,17 @@ if (!is_empty($_GET['code'])) {
$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) {
- $database->insert('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires'], 'player_uuid' => $_SESSION['uuid']]);
+ 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 "Your Munzee account has been linked to TerranQuest!
Back to game";
die();
} else {