%PDF- %PDF-
Direktori : /www/old2/_music/ingress/ |
Current File : /www/old2/_music/ingress/test.php |
<?php $players = array(); $cnt = 0; $end = false; $toInsert = array(); $guids = array(); $last = 0; $iter = 0; header("Content-type: text/plain"); $spojeni = mysql_connect("localhost", "waritko", "blade666"); mysql_select_db("ingress2", $spojeni); $res = mysql_query("select id, name from players"); while($r = mysql_fetch_array($res)) { $players[$r[1]] = $r[0]; } $maxtime = 0; $res = mysql_query("select max(`when`) from actions"); if($res != false) { if($r = mysql_fetch_array($res)) { $maxtime = $r[0]; } } $maxtimems = -1; while(!$end) { $dashboard = false; while(!$dashboard || !isset($dashboard->result)) { $data = ""; $input = popen('curl http://www.ingress.com/rpc/dashboard.getPaginatedPlextsV2 --compressed --user-agent "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0" --cookie "csrftoken=qNLeSS6rhSk88MijSmM73NkPnA6qSQLS; ACSID=AJKiYcEklz8Hk4tzR-UufJcvQipt6GngmdwuxKTGX1F5k0b26H5nAjLFDaGpCedUrAZZA2aF1aTKDGMr-SkglvaC57qRIYmHUf2-2TMI6bmvoJueMX2SSnwmitPvuGmTEgTLKBWRZE2ORchKrv8K7k2pTBXQHoSX-Hq98_C1qEvWkK6LlMG25jk4uY9trc44hmEPgRyvJN3aqrBiv3Hb62M1ljIYMwwBDyyWI7GZG-zrg425u7qaAHcu6DH63WWfXS32ypbxpKpFSjGUiT-B-ztQw3MWcKVblLBaOMzpDUfwT1gCuQE323_ahIh_tJPuOpSyvpxHZkZd5j8iqkyKPbZyRnYMfx8SNdLoYv51V-10Vu61DhqeJJmRPeEij8HJLOw_z5NPGENcP6JYjFGZk35PVxWGpx13KodYgIUJURtICTpCHUZfOeoTQDPf4aREvvNmNDFjKsn2GG_XVJkrARRjmw4p6HW27BBZufnIFaMsSITWMBBnNREdkhjl4lpRCui_mSeJw6C1djqwBOJtK8oUaKijm11wNSYPQH12ptmL9m6AQ_7UnhprFM4vsIHQHpOrnwC_cFxUFalwoYtqGUDr5wRqAD44eQ; ingress.intelmap.lat=49.241173489463954; ingress.intelmap.lng=16.572124063183537; ingress.intelmap.zoom=11" --cookie-jar "ingress_intel_chat.cookie.jar" --referer "http://www.ingress.com/intel" --header "X-CSRFToken: qNLeSS6rhSk88MijSmM73NkPnA6qSQLS" --header "X-Requested-With: XMLHttpRequest" --data-binary "{\"desiredNumItems\":50,\"minLatE6\":49128973,\"minLngE6\":16015598,\"maxLatE6\":49353120,\"maxLngE6\":17128650,\"minTimestampMs\":-1,\"maxTimestampMs\":'.$maxtimems.',\"method\":\"dashboard.getPaginatedPlextsV2\"}"', "r"); while(!feof($input)) { $data .= fgets($input, 64*1024); } pclose($input); //print_r($data); $dashboard = json_decode($data); } $last = $dashboard->result[0][1]; foreach($dashboard->result as $res) { $maxtimems = $res[1]; if(in_array($res[0], $guids)) continue; // Ignore existing record if($res[2]->plext->plextType == "PLAYER_GENERATED") continue; if($res[2]->plext->team == "NEUTRAL") continue; if($res[2]->plext->plextType == "SYSTEM_NARROWCAST") continue; if($res[2]->plext->markup[0][0] != "PLAYER") { print_r($res); continue; } $level = 0; $time = (int)substr($res[1], 0, 10); $guids[] = $res[0]; if($time <= $maxtime) { $end = true; continue; } $who = $res[2]->plext->markup[0][1]->plain; $side = $res[2]->plext->markup[0][1]->team; // Get player ID or insert into DB if(!isset($players[$who])) { mysql_query("insert into players(name, side) values('$who', '$side')"); $players[$who] = mysql_insert_id(); echo "Inserting player $who (#".$players[$who].")\n"; } $who = $players[$who]; $action = $res[2]->plext->markup[1][1]->plain; $ap = 0; switch(trim($action)) { case 'destroyed an': { $level = (int)substr($res[2]->plext->markup[2][1]->plain, 1); $action = 'resonator_destroy'; $ap = 75; break; } case 'destroyed the Link': { $action = 'link_destroy'; $ap = 187; break; } case 'destroyed a Control Field @': { $action = 'field_destroy'; $ap = 750; break; } case 'deployed an': { $level = (int)substr($res[2]->plext->markup[2][1]->plain, 1); $action = 'resonator_create'; $ap = 125; break; } case 'linked': { $action = 'link_create'; $ap = 313; break; } case 'created a Control Field @': { $action = "field_create"; $ap = 1250; break; } case 'captured': { $action = 'capture'; $ap = 500; break; } default: { print_r($res); break; } } $query = "insert into actions(who, `when`, action, level, ap) values($who, $time, '$action', $level, $ap)"; //echo $query."\n"; if($maxtimems != $last) { $last = $maxtimems; foreach ($toInsert as $act) { mysql_query($act); $cnt++; } $toInsert = array(); $guids = array(); $toInsert[] = $query; } else { $toInsert[] = $query; } } $iter++; echo "Request $iter...\n"; if($iter > 10) $end = true; } mysql_close(); echo "Inserted $cnt actions"; if($end == false) echo "END NOT REACHED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; ?>