%PDF- %PDF-
| Direktori : /data/www_bck/varak.net_bck/broot.varak.net/ |
| Current File : //data/www_bck/varak.net_bck/broot.varak.net/newhack.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;
}
$rawdata = file_get_contents("php://input");
$fname = uniqid('hack_' . time() . "_");
$path = "/www/varak.net/broot.varak.net/data/" . date("Y/m/d/");
createPath($path);
file_put_contents($path . $fname . ".txt", json_encode(json_decode($rawdata), JSON_PRETTY_PRINT));
// And save hack to DB
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;
}
include "dibi.php";
dibi::connect(array(
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'waritko',
'password' => 'blade666',
'database' => 'ingress',
'charset' => 'utf8',
));
$data = json_decode($rawdata);
//print_r($data);
$stime = time();
if (!isset($data->error) || $data->error == null)
{
$hack = new stdClass();
$hack->serverTime = new DateTime();
$hack->ingressTime = ($data->gameBasket->inventory[0][1]);
$hack->playerGuid = $data->gameBasket->playerEntity[0];
$hack->playerSide = $data->gameBasket->playerEntity[2]->controllingTeam->team;
$hack->playerLevel = getPlayerlevel($data->gameBasket->playerEntity[2]->playerPersonal->ap);
$hack->playerImaginaryLevel = getPlayerlevel($data->gameBasket->playerEntity[2]->playerPersonal->ap, true);
$hack->playerApGain = 0;
$hack->glyphBonus = false;
$glyphGuids = array();
if (count($data->gameBasket->apGains) > 0)
{
foreach ($data->gameBasket->apGains as $apg)
{
$hack->playerApGain += $apg->apGainAmount;
}
}
// Get the bonus hack guids
if(isset($data->result) && isset($data->result->glyphResponse->bonusGuids) && count($data->result->glyphResponse->bonusGuids) > 0)
{
// We have bonus from glyph hacking
$hack->glyphBonus = true;
// Copy GUIDs for checking
foreach($data->result->glyphResponse->bonusGuids as $g)
{
$glyphGuids[] = $g;
}
}
$vals = array(
'servertime' => $hack->serverTime,
'ingresstime' => $hack->ingressTime,
'playerguid' => $hack->playerGuid,
'playerside' => $hack->playerSide,
'playerlevel' => $hack->playerLevel,
'playerapgain' => $hack->playerApGain,
'glyphbonus' => $hack->glyphBonus
);
dibi::query("insert into [hacks]", $vals);
$newid = dibi::insertId();
$hack->items = array();
foreach ($data->gameBasket->inventory as $item)
{
$it = new stdClass();
// Check if item is bonus from glyph hacking
if(in_array($it->item = $item[0], $glyphGuids))
$it->isBonus = true;
else
$it->isBonus = false;
if (isset($item[2]->resourceWithLevels))
{
$it->item = $item[2]->resourceWithLevels->resourceType;
$it->level = $item[2]->resourceWithLevels->level;
$vals = array(
'hackid' => $newid,
'type' => 'LEVELED',
'item' => $it->item,
'level' => $it->level
);
}
elseif (isset($item[2]->modResource))
{
$it->item = $item[2]->modResource->resourceType;
$it->rarity = $item[2]->modResource->rarity;
$vals = array(
'hackid' => $newid,
'type' => 'MOD',
'item' => $it->item,
'rarity' => $it->rarity
);
}
elseif (isset($item[2]->resource))
{
$it->item = $item[2]->resource->resourceType;
$it->rarity = $item[2]->resource->resourceRarity;
$vals = array(
'hackid' => $newid,
'type' => 'RESOURCE',
'item' => $it->item,
'rarity' => $it->rarity
);
if (isset($item[2]->flipCard))
{
$it->flipCardType = $item[2]->flipCard->flipCardType;
$vals['type'] = $it->flipCardType;
}
}
else
{
$fname = uniqid("unknown_hack_" . $stime);
$txt = json_encode($data, JSON_PRETTY_PRINT);
file_put_contents("./data/$fname.txt", $txt);
}
$vals['bonus'] = $it->isBonus;
dibi::query("insert into [hack_items]", $vals);
$hack->items[] = $it;
}
//print_r($hack);
echo json_encode($hack, JSON_PRETTY_PRINT);
dibi::query("insert into [hackobj]([data]) values(%s)", json_encode($hack, JSON_PRETTY_PRINT));
}
?>