%PDF- %PDF-
Direktori : /data/www_bck/varak.net_bck/ingress.varak.net/api/ |
Current File : //data/www_bck/varak.net_bck/ingress.varak.net/api/portals.php |
<?php require("config.php"); //set_time_limit(90); function playerNameResolve($pname) { return $pname; } error_reporting(0); header("Content-type: text/plain"); $db = new mysqli($srv, $usr, $pwd, $dbname); $res = $db->query("select time from updated"); $res = $res->fetch_array()[0]; $portals = array(); $sources = array( /*'curl https://www.ingress.com/rpc/dashboard.getThinnedEntitiesV2 --interface eth1:2 --compressed --insecure --header "DNT: 1" --user-agent "'.$ing_user_agent.'" --cookie "'.$ing_cookie.'" --cookie-jar "ingress_intel_chat.cookie.jar" --referer "https://www.ingress.com/intel" --header "X-CSRFToken: '.$ing_csrf.'" --header "X-Requested-With: XMLHttpRequest" --data-binary "'.$ent_brno_1.'"', 'curl https://www.ingress.com/rpc/dashboard.getThinnedEntitiesV2 --compressed --interface eth1:2 --insecure --header "DNT: 1" --user-agent "'.$ing_user_agent.'" --cookie "'.$ing_cookie.'" --cookie-jar "ingress_intel_chat.cookie.jar" --referer "https://www.ingress.com/intel" --header "X-CSRFToken: '.$ing_csrf.'" --header "X-Requested-With: XMLHttpRequest" --data-binary "'.$ent_brno_2.'"', 'curl https://www.ingress.com/rpc/dashboard.getThinnedEntitiesV2 --compressed --interface eth1:2 --insecure --header "DNT: 1" --user-agent "'.$ing_user_agent.'" --cookie "'.$ing_cookie.'" --cookie-jar "ingress_intel_chat.cookie.jar" --referer "https://www.ingress.com/intel" --header "X-CSRFToken: '.$ing_csrf.'" --header "X-Requested-With: XMLHttpRequest" --data-binary "'.$ent_brno_3.'"', 'curl https://www.ingress.com/rpc/dashboard.getThinnedEntitiesV2 --compressed --interface eth1:2 --insecure --header "DNT: 1" --user-agent "'.$ing_user_agent.'" --cookie "'.$ing_cookie.'" --cookie-jar "ingress_intel_chat.cookie.jar" --referer "https://www.ingress.com/intel" --header "X-CSRFToken: '.$ing_csrf.'" --header "X-Requested-With: XMLHttpRequest" --data-binary "'.$ent_brno_4.'"' */ 'curl https://www.ingress.com/rpc/dashboard.getThinnedEntitiesV3 --compressed --interface eth1:2 --insecure --header "DNT: 1" --user-agent "'.$ing_user_agent.'" --cookie "'.$ing_cookie.'" --cookie-jar "ingress_intel_chat.cookie.jar" --referer "https://www.ingress.com/intel" --header "X-CSRFToken: '.$ing_csrf.'" --header "X-Requested-With: XMLHttpRequest" --data-binary "'.$_portdata.'"' ); if(isset($_GET['raw'])) { $rdata = new stdClass(); $rdata->gameBasket = new stdClass(); $rdata->gameBasket->deletedEntityGuids = array(); $rdata->gameBasket->gameEntities = array(); $rdata->gameBasket->inventory = array(); $rdata->result = new stdClass(); $rdata->result->map = new stdClass(); } if(time() > $res+300 || isset($_GET['raw'])) { $db->query("truncate table portal"); $db->query("truncate table portal_resonators"); $j = 1; $hist_ent[$i] = array(); foreach($sources as $src) { //echo $src . "\n"; //die; $entities = false; $i = 0; while((!$entities || !isset($dashboard->result)) && $i < 2) { $i++; $data = ""; $input = popen($src, "r"); //$input = popen("date", "r"); while(!feof($input)) { $data .= fgets($input, 64*1024); } pclose($input); //print_r($data); $entities = json_decode($data); $hist_ent[$j] = $data; if(strstr($data, '{"error":')) sleep(16); } $j++; if(isset($_GET['raw'])) { $rdata->result->minLevelOfDetail = $entities->result->minLevelOfDetail; foreach ($entities->result->map as $tilename => $tile) { $rdata->result->map->{$tilename} = $tile; } } /*foreach ($entities->result->map as $tile) { foreach ($tile->gameEntities as $entity) { if(!isset($entity[2]->portalV2)) continue; $dist = 0; $lvl = 0; $resNum = 0; $topRes = 0; $energy = 0; $rtss = array(); foreach ($entity[2]->resonatorArray->resonators as $resonator) { if(!$resonator) continue; $resNum++; $dist += $resonator->distanceToPortal; $lvl += $resonator->level; $topRes = $topRes < $resonator->level ? $resonator->level : $topRes; $energy += $resonator->energyTotal; $rts = new stdClass(); $rts->slot = $resonator->slot; $rts->level = $resonator->level; $rts->distance = $resonator->distanceToPortal; $rts->energy = $resonator->energyTotal; $rts->owner = $resonator->ownerGuid; $rtss[] = $rts; } $portal = new stdClass(); $portal->level = $lvl / 8; $portal->dist = $dist / $resNum; $portal->topResonator = $topRes; $portal->energy = $energy; $portal->name = str_replace("'", "\\'", $entity[2]->portalV2->descriptiveText->TITLE); $portal->address = str_replace("'", "\\'", $entity[2]->portalV2->descriptiveText->ADDRESS); $portal->owner = playerNameResolve($entity[2]->captured->capturingPlayerId); $portal->faction = $entity[2]->controllingTeam->team; $portal->lat = $entity[2]->locationE6->latE6; $portal->lng = $entity[2]->locationE6->lngE6; $db->query("insert into portal(level, distance, topResonator, energy, name, address, owner, faction, latitude, longitude) values(".$portal->level.", ".$portal->dist.", ".$portal->topResonator.", ".$portal->energy.", '".$portal->name."', '".$portal->address."', '".$portal->owner."', '".$portal->faction."', ".$portal->lat.", ".$portal->lng.")"); $id = $db->insert_id; foreach ($rtss as $rts) { $db->query("insert into portal_resonators(`portal`, `slot`, `energy`, `distance`, `level`, `owner`) values($id, ".$rts->slot.", ".$rts->energy.", ".$rts->distance.", ".$rts->level.", '".$rts->owner."')"); } //$portals[] = $portal; } }*/ } //print_r($hist_ent); //$db->query("insert into portal_hist values(".time().", 'Brno', '".$db->real_escape_string($hist_ent[1])."', '".$db->real_escape_string($hist_ent[2])."', '".$db->real_escape_string($hist_ent[3])."', '".$db->real_escape_string($hist_ent[4])."')"); $stmnt = $db->prepare("insert into portal_hist(`time`, `city`, `entities1`, `entities2`, `entities3`, `entities4`) values(?, ?, ?, ?, ?, ?)"); $time = time(); $city = 'Brno'; $ent1 = $hist_ent[1]; $ent2 = $hist_ent[2]; $ent3 = $hist_ent[3]; $ent4 = $hist_ent[4]; $stmnt->bind_param('isssss', $time, $city, $ent1, $ent2, $ent3, $ent4); //print_r($stmnt); /*$stmnt->bind_param('s', 'Brno'); $stmnt->bind_param('s', $hist_ent[1]); $stmnt->bind_param('s', $hist_ent[2]); $stmnt->bind_param('s', $hist_ent[3]); $stmnt->bind_param('s', $hist_ent[4]);*/ $stmnt->execute(); //print_r($stmnt); //print_r($db); $db->query('update `updated` set `time`='.time()); header("X-Updated: now"); $ret = json_encode($rdata, JSON_PRETTY_PRINT); ///////////////// COMPRESSION // Gzip/Deflate/Bzip2 compression if(stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "bzip2")) { $ret = bzcompress($ret, 9); header("Content-Encoding: bzip2"); } elseif(stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")) { $ret = gzencode($ret, 9); header("Content-Encoding: gzip"); } elseif (stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "deflate")) { $ret = gzdeflate($ret, 9); header("Content-Encoding: deflate"); } header("Content-length: ".strlen($ret)); echo $ret; /////////////// END COMPRESSION die; } else { header("X-Updated: ".(time()-$res)." seconds ago"); } if($_GET['what'] == 'resonator' && $_GET['precise'] == 'false') $res = $db->query('SELECT level, distance, topResonator, energy, name, address, owner, faction, latitude, longitude FROM portal where topResonator >= '.$db->real_escape_string($_GET['level'])); if($_GET['what'] == 'resonator' && $_GET['precise'] == 'true') $res = $db->query('SELECT level, distance, topResonator, energy, name, address, owner, faction, latitude, longitude FROM portal where topResonator = '.$db->real_escape_string($_GET['level'])); if($_GET['what'] == 'portal' && $_GET['precise'] == 'false') $res = $db->query('SELECT level, distance, topResonator, energy, name, address, owner, faction, latitude, longitude FROM portal where level >= '.$db->real_escape_string($_GET['level'])); if($_GET['what'] == 'portal' && $_GET['precise'] == 'true') $res = $db->query('SELECT level, distance, topResonator, energy, name, address, owner, faction, latitude, longitude FROM portal where level = '.$db->real_escape_string($_GET['level'])); while($r = $res->fetch_array()) { $portal = new stdClass(); $portal->level = $r[0]; $portal->distance = $r[1]; $portal->topResonator = $r[2]; $portal->energy = $r[3]; $portal->name = $r[4]; $portal->address = $r[5]; $portal->owner = $r[6]; $portal->faction = $r[7]; $portal->latitude = $r[8]; $portal->longitude = $r[9]; $portals[] = $portal; } $ret = json_encode($portals, JSON_PRETTY_PRINT); // Gzip/Deflate/Bzip2 compression if(stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "bzip2")) { $ret = bzcompress($ret, 9); header("Content-Encoding: bzip2"); } elseif(stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")) { $ret = gzencode($ret, 9); header("Content-Encoding: gzip"); } elseif (stristr($_SERVER["HTTP_ACCEPT_ENCODING"], "deflate")) { $ret = gzdeflate($ret, 9); header("Content-Encoding: deflate"); } header("Content-length: ".strlen($ret)); echo $ret; ?>