Entries is array with keys as indexes * and $obj->Entries['MyNVaultKey']->iPointer contain position data in file. * * Warning: * $obj->Entries['MyKey']->Value is undefined in this step! * * $numberOfEntries = count($obj->Entries); * * @return true on success */ public function LoadEntries(); /** * Fill Value and Timestamp in one element of Entries array. * Use when want value of specific field without loading all data. * * @param entry nVault`s key, index */ public function getEntry($entry); /** * Fill Value and Timestamp in whole Entries array */ public function getAllEntries(); /** * Set keys filter for load only some group of entries * * @param callback * function cb($key){} * return 1 when want to load */ public function setKeyFilter($callback); /** * Print debug listing of entries */ public function print_r(); }; /** * BinaryReader */ class BinaryReader{ /** * File Pointer */ private $fp; public function BinaryReader($fp){ $this->fp = $fp; } public function ReadAddr(&$buffer, $size){ if($size <= 0) return false; if(($buffer = fread($this->fp, $size)) !== false) return true; return false; } public function ReadUInt32(){ $num; if(!$this->ReadAddr($num, 4)) throw new Exception("Read failed"); $res = unpack("i", $num); return $res[1]; } public function ReadInt32(){ $num; if(!$this->ReadAddr($num, 4)) throw new Exception("Read failed"); $res = unpack("I", $num); return $res[1]; } public function ReadUInt16(){ $num; if(!$this->ReadAddr($num, 2)) throw new Exception("Read failed"); $res = unpack("v", $num); return $res[1]; } public function ReadInt16(){ $num; if(!$this->ReadAddr($num, 2)) throw new Exception("Read failed"); $res = unpack("s", $num); return $res[1]; } public function ReadUInt8(){ $num; if(!$this->ReadAddr($num, 1)) throw new Exception("Read failed"); $res = unpack("C", $num); return $res[1]; } public function ReadInt8(){ $num; if(!$this->ReadAddr($num, 1)) throw new Exception("Read failed"); $res = unpack("c", $num); return $res[1]; } public function ReadChars(&$buffer, $len){ return $this->ReadAddr($buffer, $len); } }; class Vault{ public $iPointer; public $iKeyLen, $iValLen; public $Value; public $iTimestamp; public function Vault($pos, $value, $tstamp){ $this->iPointer = $pos; $this->Value = $value; $this->iTimestamp = $tstamp; } }; class nVaultRead implements inVaultRead{ /** * Name of vault file */ private $szFileName; /** * Binary reader object */ private $binread; /** * Vault version $iMajorVer.$iMinorVer */ public $iMinorVer, $iMajorVer; /** * Array of vault entries */ public $Entries; /** * Filter function */ public $callback; public function Open($file){ $this->szFileName = $file; $fp = fopen($file, "rb"); if(!$fp) return false; $br = new BinaryReader($fp); try{ if($br->ReadUInt32() != VAULT_MAGIC) return false; }catch(Exception $ex){ return false; } fclose($fp); $callback = NULL; return true; } public function fullLoadEntries(){ $fp = fopen($this->szFileName, "rb"); if(!$fp) return false; $br = new BinaryReader($fp); try{ if($br->ReadUInt32() != VAULT_MAGIC) return false; $this->iMinorVer = $br->ReadUInt8(); $this->iMajorVer = $br->ReadUInt8(); $iEntries = $br->ReadUInt32(); } catch(Exception $ex){ die("
"; print_r($this->Entries); echo ""; } public function setKeyFilter($callback){ $this->callback = $callback; } public function sort(){ uasort($this->Entries, 'ByXp'); } }; function ByXP($a, $b){ $temp = $a->Value; $temp = explode("#",$temp); $xpA = intVal($temp[1]); $temp = $b->Value; $temp = explode("#",$temp); $xpB = intVal($temp[1]); if($xpA == $xpB) return 0; return ($xpA > $xpB)?-1:1; } ?>