%PDF- %PDF-
| Direktori : /data/www_bck/varak.net_bck/broot.varak.net/ |
| Current File : //data/www_bck/varak.net_bck/broot.varak.net/hacklog.php |
<?php
/**
* recursively create a long directory path
*/
function createPath($path)
{
if (is_dir($path)) return true;
$prev_path = substr($path, 0, strrpos($path, '/', -2) + 1 );
$return = createPath($prev_path);
return ($return && is_writable($prev_path)) ? mkdir($path) : false;
}
function getPlayerLevel($ap, $imaginary = false)
{
if($ap < 10000) return 1;
if($ap < 30000) return 2;
if($ap < 70000) return 3;
if($ap < 150000) return 4;
if($ap < 300000) return 5;
if($ap < 600000) return 6;
if($ap < 1200000) return 7;
if(!$imaginary) return 8;
if($ap < 2400000) return 8;
if($ap < 4800000) return 9;
if($ap < 9600000) return 10;
if($ap < 19200000) return 11;
if($ap < 38400000) return 12;
}
function getPortalLevel($resonatorLevels)
{
$lvl = 0;
foreach($resonatorLevels as $res)
{
$lvl += $res;
}
return $lvl / 8;
}
ini_set('mongo.native_long', 1);
$rawdata = file_get_contents("php://input");
if($rawdata == "")
{
echo "ERROR processing input data";
die;
}
$txt = gzdecode($rawdata);
$fname = uniqid('hack_'.time()."_");
$path = "/var/www/hacks/".date("Y/m/d/");
createPath($path);
file_put_contents($path.$fname.".txt.gz", $rawdata);
$data = json_decode($txt);
$stime = time();
if($data->rpcResult->error == null)
{
$hack = new stdClass();
$hack->serverTime = $stime;
$hack->ingressTime = ($data->rpcResult->gameBasket->inventory[0][1]);
$hack->playerGuid = $data->rpcResult->gameBasket->playerEntity[0];
$hack->playerSide = $data->rpcResult->gameBasket->playerEntity[2]->controllingTeam->team;
$hack->playerLevel = getPlayerlevel($data->rpcResult->gameBasket->playerEntity[2]->playerPersonal->ap);
$hack->playerImaginaryLevel = getPlayerlevel($data->rpcResult->gameBasket->playerEntity[2]->playerPersonal->ap, true);
$hack->playerApGain = 0;
if(count($data->rpcResult->gameBasket->apGains) > 0)
{
foreach($data->rpcResult->gameBasket->apGains as $apg)
{
$hack->playerApGain += $apg->apGainAmount;
}
}
$hack->portalSide = $data->portalTeam->team;
$hack->decimalPortalLevel = getPortalLevel($data->portal->resonatorLevels);
$hack->portalLevel = floor($hack->decimalPortalLevel);
$hack->items = array();
foreach($data->rpcResult->gameBasket->inventory as $item)
{
$it = new stdClass();
if(isset($item[2]->resourceWithLevels))
{
$it->item = $item[2]->resourceWithLevels->resourceType;
$it->level = $item[2]->resourceWithLevels->level;
}
elseif(isset($item[2]->modResource))
{
$it->item = $item[2]->modResource->resourceType;
$it->rarity = $item[2]->modResource->rarity;
}
elseif(isset($item[2]->resource))
{
$it->item = $item[2]->resource->resourceType;
$it->rarity = $item[2]->resource->resourceRarity;
if(isset($item[2]->flipCard))
{
$it->flipCardType = $item[2]->flipCard->flipCardType;
}
}
else
{
$fname = uniqid("unknown_hack_".$stime);
$txt = json_encode($data, JSON_PRETTY_PRINT);
file_put_contents("/var/www/hacks/decompressed/$fname.txt", $txt);
}
$hack->items[] = $it;
}
$m = new MongoClient();
$db = $m->selectDB("ingress");
$col = $db->selectCollection("hacks");
$col->insert($hack);
}
?>