%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /data/www_bck/varak.net_bck/broot.varak.net/
Upload File :
Create Path :
Current File : //data/www_bck/varak.net_bck/broot.varak.net/inventory.php

<?php
	class Inventory
	{
		var $owner = "";
		var $ap = 0;
		var $xm = 0;
		var $time;
		var $resonators;
		var $bursters;
		var $powerCubes;
		var $media;
		var $ultraStrikes;
		var $shields;
		var $heatsinks;
		var $multihacks;
		var $forceamps;
		var $linkamps;
		var $turrets;
		var $ADAs;
		var $JARVISes;
		var $keys = array();

		public function __construct()
		{
			$this->time = time();
			$this->resonators = array(new LeveledItem(1), new LeveledItem(2), new LeveledItem(3), new LeveledItem(4), new LeveledItem(5), new LeveledItem(6), new LeveledItem(7), new LeveledItem(8));
			$this->bursters = array(new LeveledItem(1), new LeveledItem(2), new LeveledItem(3), new LeveledItem(4), new LeveledItem(5), new LeveledItem(6), new LeveledItem(7), new LeveledItem(8));
			$this->powerCubes = array(new LeveledItem(1), new LeveledItem(2), new LeveledItem(3), new LeveledItem(4), new LeveledItem(5), new LeveledItem(6), new LeveledItem(7), new LeveledItem(8));
			$this->media = array(new LeveledItem(1), new LeveledItem(2), new LeveledItem(3), new LeveledItem(4), new LeveledItem(5), new LeveledItem(6), new LeveledItem(7), new LeveledItem(8));
			$this->ultraStrikes = array(new LeveledItem(1), new LeveledItem(2), new LeveledItem(3), new LeveledItem(4), new LeveledItem(5), new LeveledItem(6), new LeveledItem(7), new LeveledItem(8));
			$this->shields = array(new ModItem("COMMON"), new ModItem("RARE"), new ModItem("VERY_RARE"));
			$this->heatsinks = array(new ModItem("COMMON"), new ModItem("RARE"), new ModItem("VERY_RARE"));
			$this->multihacks = array(new ModItem("COMMON"), new ModItem("RARE"), new ModItem("VERY_RARE"));
			$this->forceamps = array(new ModItem("RARE"));
			$this->linkamps = array(new ModItem("RARE"));
			$this->turrets = array(new ModItem("RARE"));
			$this->ADAs = array(new ModItem("VERY_RARE"));
			$this->JARVISes = array(new ModItem("VERY_RARE"));
		}
	}

	class LeveledItem
	{
		var $level = 0;
		var $amount = 0;

		public function __construct($level)
		{
			$this->level = $level;
		}
	}

	class ModItem
	{
		var $rarity = "VERY_COMMON";
		var $amount = 0;
		public function __construct($rarity)
		{
			$this->rarity = $rarity;
		}
	}

	class KeyItem
	{
		var $portalGuid = "";
		var $portalName = "";
		var $amount = 0;
	}

	ini_set('mongo.native_long', 1);
	// Receiving of POST data
	$rawdata = file_get_contents("php://input");
	if($rawdata == "")
	{
		echo "ERROR processing input data";
		die;
	}
	$txt = gzdecode($rawdata);
	$fname = uniqid('inventory/inventory_'.time()."_");
	file_put_contents("/var/www/hacks/".$fname.".txt.gz", $rawdata);

	$inventory = new Inventory();
	$data = json_decode($txt);
	$inventory->ap = $data->currentAP;
	$inventory->xm = $data->currentXM;
	$inventory->owner = $data->playerName;
	foreach($data->rpcResult as $item)
	{
		if(isset($item[2]->resourceWithLevels))
		{
			if($item[2]->resourceWithLevels->resourceType == "POWER_CUBE")
			{
				$lvl = $item[2]->resourceWithLevels->level-1;
				$inventory->powerCubes[$lvl]->amount++;
			}
			elseif($item[2]->resourceWithLevels->resourceType == "EMP_BURSTER")
			{
				$lvl = $item[2]->resourceWithLevels->level-1;
				$inventory->bursters[$lvl]->amount++;
			}
			elseif($item[2]->resourceWithLevels->resourceType == "EMITTER_A")
			{
				$lvl = $item[2]->resourceWithLevels->level-1;
				$inventory->resonators[$lvl]->amount++;
			}
			elseif($item[2]->resourceWithLevels->resourceType == "MEDIA")
			{
				$lvl = $item[2]->resourceWithLevels->level-1;
				$inventory->media[$lvl]->amount++;
			}
			elseif($item[2]->resourceWithLevels->resourceType == "ULTRA_STRIKE")
			{
				$lvl = $item[2]->resourceWithLevels->level-1;
				$inventory->ultraStrikes[$lvl]->amount++;
			}
		}
		elseif(isset($item[2]->modResource))
		{
			if($item[2]->modResource->resourceType == "RES_SHIELD")
			{
				switch($item[2]->modResource->rarity)
				{
					case "COMMON":
					{
						$inventory->shields[0]->amount++;
						break;
					}
					case "RARE":
					{
						$inventory->shields[1]->amount++;
						break;
					}
					case "VERY_RARE":
					{
						$inventory->shields[2]->amount++;
						break;
					}
				}
			}
			elseif($item[2]->modResource->resourceType == "HEATSINK")
			{
				switch($item[2]->modResource->rarity)
				{
					case "COMMON":
					{
						$inventory->heatsinks[0]->amount++;
						break;
					}
					case "RARE":
					{
						$inventory->heatsinks[1]->amount++;
						break;
					}
					case "VERY_RARE":
					{
						$inventory->heatsinks[2]->amount++;
						break;
					}
				}
			}
			elseif($item[2]->modResource->resourceType == "MULTIHACK")
			{
				switch($item[2]->modResource->rarity)
				{
					case "COMMON":
					{
						$inventory->multihacks[0]->amount++;
						break;
					}
					case "RARE":
					{
						$inventory->multihacks[1]->amount++;
						break;
					}
					case "VERY_RARE":
					{
						$inventory->multihacks[2]->amount++;
						break;
					}
				}
			}
			elseif($item[2]->modResource->resourceType == "TURRET")
			{
				if($item[2]->modResource->rarity == "RARE")
				{
					$inventory->turrets[0]->amount++;
				}
			}
			elseif($item[2]->modResource->resourceType == "FORCE_AMP")
			{
				if($item[2]->modResource->rarity == "RARE")
				{
					$inventory->forceamps[0]->amount++;
				}
			}
			elseif($item[2]->modResource->resourceType == "LINK_AMPLIFIER")
			{
				if($item[2]->modResource->rarity == "RARE")
				{
					$inventory->linkamps[0]->amount++;
				}
			}
		}
		elseif(isset($item[2]->portalCoupler))
		{
			// Try to find the key
			$found = false;
			foreach($inventory->keys as $key)
			{
				if($item[2]->portalCoupler->portalGuid == $key->portalGuid)
				{
					$key->amount++;
					$found = true;
					break;
				}
			}
			if(!$found)
			{
				$key = new KeyItem();
				$key->portalGuid = $item[2]->portalCoupler->portalGuid;
				$key->portalName = $item[2]->portalCoupler->portalTitle;
				$key->amount = 1;
				$inventory->keys[] = $key;
			}
		}
		elseif(isset($item[2]->flipCard))
		{
			if($item[2]->flipCard->flipCardType == "JARVIS")
			{
				$inventory->JARVISes[0]->amount++;
			}
			// Check ADA after hacking one
			elseif($item[2]->flipCard->flipCardType == "ADA")
			{
				$inventory->ADAs[0]->amount++;
			}
		}
	}

	$m = new MongoClient();
	$db = $m->selectDB("ingress");
	$col = $db->selectCollection("inventory");
	$col->insert($inventory);

	// Insert into BEER items (temporary feature)
	//
	// Function Q
function q($query,$assoc=0) 
{
	echo $query."\n";
   $r = @mysql_query($query);
   if( mysql_errno() ) {
       $error = 'MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). "</small><br><VAR>$query</VAR>";
       echo($error); return FALSE;
   }
   $queries++;
   if( strtolower(substr($query,0,6)) != 'select' ) return array(mysql_affected_rows(),mysql_insert_id());
   $count = @mysql_num_rows($r);
   if( !$count ) return 0;
   if( $count == 1 ) {
       if( $assoc ) $f = mysql_fetch_assoc($r);
       else $f = mysql_fetch_row($r);
       mysql_free_result($r);
       if( count($f) == 1 ) {
           list($key) = array_keys($f);   
           return $f[$key];
       } else {
           $all = array();
           $all[] = $f;
           return $all;
       }
   } else {
       $all = array();
       for( $i = 0; $i < $count; $i++ ) {
           if( $assoc ) $f = mysql_fetch_assoc($r);
           else $f = mysql_fetch_row($r);
           $all[] = $f;
       }
       mysql_free_result($r);
       return $all;
   }
}
	ob_start();	
	echo "=================== ".date("Y-m-d H:i:s")." ===================\n";
	// CODE
	$conn = mysql_connect("localhost", "beer", "hubertus88");
	mysql_select_db("beer", $conn);
	$usrinfo = q("select id, role from uzivatele where ingame_nick like '".$inventory->owner."'");
	print_r($usrinfo);
	if($usrinfo && count($usrinfo) == 1 && $usrinfo[0][1] > 0)
	{
		$uid = $usrinfo[0][0];
		$pid = q("insert into predmety_akce(`nazev`, `user_id`, `time`) values('Imported from Broot', $uid, NOW())");
		print_r($pid);
		$pid = $pid[1];
		// Resonators
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 1, ".$inventory->resonators[0]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 2, ".$inventory->resonators[1]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 3, ".$inventory->resonators[2]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 4, ".$inventory->resonators[3]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 5, ".$inventory->resonators[4]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 6, ".$inventory->resonators[5]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 7, ".$inventory->resonators[6]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 8, ".$inventory->resonators[7]->amount.", $pid)");
		// Bursters
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 9, ".$inventory->bursters[0]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 10, ".$inventory->bursters[1]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 11, ".$inventory->bursters[2]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 12, ".$inventory->bursters[3]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 13, ".$inventory->bursters[4]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 14, ".$inventory->bursters[5]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 15, ".$inventory->bursters[6]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 16, ".$inventory->bursters[7]->amount.", $pid)");
		// Shields
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 17, ".$inventory->shields[0]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 18, ".$inventory->shields[1]->amount.", $pid)");
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 19, ".$inventory->shields[2]->amount.", $pid)");
		// AP
		q("insert into predmety(`user`, `item_id`, `amount`, `akce`) values($uid, 20, ".$inventory->ap.", $pid)");
	}

	mysql_close($conn);
	echo "\n\n";
	$txt = ob_get_clean();
	$f = fopen("debug.log", 'a');
	fputs($f, $txt);
	fclose($f);
?>

Zerion Mini Shell 1.0