diff --git a/.gitignore b/.gitignore index 27390aa..40b48aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ error* stats* -vendor* \ No newline at end of file +vendor* +settings.php diff --git a/capturemunzee.php b/capturemunzee.php new file mode 100644 index 0000000..1cfb107 --- /dev/null +++ b/capturemunzee.php @@ -0,0 +1,94 @@ +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"]]; + } +} \ No newline at end of file diff --git a/code2item.php b/code2item.php index 6015c19..2b309de 100644 --- a/code2item.php +++ b/code2item.php @@ -29,6 +29,9 @@ class Random { } $origcode = $VARS['code']; +$latitude = $VARS['latitude']; +$longitude = $VARS['longitude']; +$accuracy = $VARS['accuracy']; if (is_empty($origcode)) { sendError("Bad code!", true); @@ -40,6 +43,7 @@ if ($database->has('claimedcodes', ["AND" => ['code' => $origcode, 'playeruuid' $codearray = str_split($origcode); + $codeint = 0; foreach ($codearray as $chr) { $codeint += ord($chr); @@ -51,4 +55,16 @@ $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 = [ + "status" => "OK", + "messages" => [ + ] +]; + +$returndata["messages"][] = ["title" => "Found an item!", "text" => "Found one $itemname"]; + +if (strpos($origcode, "munzee") > 1) { + include 'capturemunzee.php'; +} sendOK($itemname); diff --git a/database.mwb b/database.mwb index c794fbe..6c42934 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/database.mwb.bak b/database.mwb.bak index 5136645..c794fbe 100644 Binary files a/database.mwb.bak and b/database.mwb.bak differ diff --git a/munzee.php b/munzee.php new file mode 100644 index 0000000..1e02645 --- /dev/null +++ b/munzee.php @@ -0,0 +1,57 @@ + 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!
Back to game"; + die(); + } else { + echo "Munzee is having problems right now. Try again later.
Back to game"; + die(); + } +} \ No newline at end of file diff --git a/settings.php b/settings.php deleted file mode 100644 index 607bc87..0000000 --- a/settings.php +++ /dev/null @@ -1,18 +0,0 @@ -