%PDF- %PDF-
Direktori : /www/old2/_music/ingress/ |
Current File : /www/old2/_music/ingress/getActions.php |
<?php $players = array(); $cnt = 0; $end = false; $toInsert = array(); $guids = array(); $last = 0; $iter = 0; $msgs = array(); require("config.php"); header("Content-type: text/plain"); $spojeni = mysql_connect($srv, $usr, $pwd); mysql_select_db($dbname, $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; $i = 0; while((!$dashboard || !isset($dashboard->result)) && $i < 3) { $i++; $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 "'.$ing_cookie.'" --cookie-jar "ingress_intel_chat.cookie.jar" --referer "http://www.ingress.com/intel" --header "X-CSRFToken: '.$ing_csrf.'" --header "X-Requested-With: XMLHttpRequest" --data-binary "{\"desiredNumItems\":200,\"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) { $time = (int)substr($res[1], 0, 10); if($time <= $maxtime) { $end = true; continue; } $msg = "insert into messages(time, guid, message) values(".$res[1].", '".$res[0]."', '".str_replace("'", "\\'", json_encode($res))."')"; $msgs[] = $msg; //print_r($msgs); $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; $guids[] = $res[0]; $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++; } foreach ($msgs as $m) { mysql_query($m); } $toInsert = array(); $guids = array(); $msgs = array(); $toInsert[] = $query; } else { $toInsert[] = $query; } } $iter++; echo "Request $iter...\n"; if($iter > 30) $end = true; } mysql_close(); echo "Inserted $cnt actions"; if($end == false) echo "END NOT REACHED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; ?>