From a84b0aae5e9c3b23e47ad3995b1f499ed3739e3b Mon Sep 17 00:00:00 2001 From: SirCotare Date: Mon, 18 Jun 2012 21:17:44 +0200 Subject: [PATCH] #1470 XMLApi connector initially finished; testing needed --- .../source/XMLapi/XMLapi_class.php | 206 +++++++++++++++++- .../_AchWebParser/source/XMLapi/conf.php | 2 +- 2 files changed, 203 insertions(+), 5 deletions(-) diff --git a/code/web/app/app_achievements/_AchWebParser/source/XMLapi/XMLapi_class.php b/code/web/app/app_achievements/_AchWebParser/source/XMLapi/XMLapi_class.php index e1b2270f0..9ba55aa0a 100644 --- a/code/web/app/app_achievements/_AchWebParser/source/XMLapi/XMLapi_class.php +++ b/code/web/app/app_achievements/_AchWebParser/source/XMLapi/XMLapi_class.php @@ -8,19 +8,217 @@ $this->xml_path = $CONF['xml_path']; } - function getData($ident,$field,$type) { + function loadData($ident,$type) { switch($type) { - case "c_stats": + case 'c_stats': + case 'c_connection': + case 'c_gear': + case 'c_fp': + case 'c_skills': + case 'c_fame': + case 'c_pet': $path = $this->xml_path."full/".$ident.".xml"; break; - case "c_items": + case 'c_items': $path = $this->xml_path."item/".$ident.".xml"; break; default: return false; break; } - $xml = new SimpleXMLElement($string); + + $xml = new SimpleXMLElement(file_get_contents($path)); + + switch($type) { + case 'c_stats': + $this->loadStats($xml); + break; + case 'c_connection': + $this->loadConnection($xml); + break; + case 'c_gear': + $this->loadGear($xml); + break; + case 'c_fp': + $this->loadFp($xml); + break; + case 'c_skills': + $this->loadSkills($xml); + break; + case 'c_fame': + $this->loadFame($xml); + break; + case 'c_pet': + $this->loadPet($xml); + break; + case 'c_items': + $this->loadItems($xml); + break; + default: + return false; + break; + } + } + + private function getItems(&$xml) { + $dta = array(); + + $r = $xml->xpath('item'); + $dta[] = $r->attributes(); + + return $dta; + } + + private function loadGear(&$xml) { + $this->data['c_gear'] = $this->getItems($xml); + } + + private function loadFp(&$xml) { + $dta = array(); + + $r = $xml->xpath('faction_points'); + foreach($r->children() as $elem) { + $dta[] = array($elem->getName()=>$elem); + } + + $this->data['c_fp'] = $dta; + } + + private function loadSkills(&$xml) { + $dta = array(); + + $r = $xml->xpath('skills'); + foreach($r->children() as $elem) { + $dta[] = array($elem->getName()=>$elem); + } + + $this->data['c_skills'] = $dta; + } + + private function loadPet(&$xml) { + $dta = array(); + + $r = $xml->xpath('pet'); + foreach($r as $pet) { + $tmp = $pet->attributes(); + $child = $pet->children(); + $tmp = array_merge($tmp,$child[0]->attributes()); + + $dta[] = $tmp; + } + + $this->data['c_pet'] = $dta; + } + + private function loadFame(&$xml) { + $dta = array(); + + $r = $xml->xpath('fames'); + foreach($r->children() as $elem) { + $dta[] = array($elem->getName()=>$elem); + } + + $this->data['c_fame'] = $dta; + } + + private function loadItems(&$xml) { + $this->data['c_items'] = $this->getItems($xml); + } + + private function loadConnection(&$xml) { + $dta = array(); + + $r = $xml->xpath('log'); + + while(list( , $node) = each($r)) { + #$attr = $node->attributes(); + #$dta[] = array("in"=>$attr[],"out"=>$attr[1],"duration"=>$attr[2]); + $dta[] = $node->attributes(); + } + + $this->data['c_connection'] = $dta; + } + + private function loadStats(&$xml) { + $dta = array(); + + $slist = array( 'name', + 'shard', + 'uid', + 'slot', + 'cid', + 'race', + 'gender', + 'titleid', + 'played_time', + 'latest_login', + 'latest_logout', + 'hair_type', + 'hair_color', + 'tattoo', + 'eyes_color', + 'gabarit_height', + 'gabarit_torso_width', + 'gabarit_arms_width', + 'gabarit_legs_width', + 'gabarit_breast_size', + 'morph1', + 'morph2', + 'morph3', + 'morph4', + 'morph5', + 'morph6', + 'morph7', + 'morph8', + 'gid', + 'name', + 'icon', + 'money', + 'cult', + 'civ', + 'constitution', + 'metabolism', + 'intelligence', + 'wisdom', + 'strength', + 'wellbalanced', + 'dexterity', + 'will', + 'building'); + + foreach($slist as $elem) { + $r = $xml->xpath($elem); + $dta[$elem] = $r[0]; + } + + # + $r = $xml->xpath("position"); + $attr = $r->attributes(); + $dta['pos_x'] = $attr['x']; + $dta['pos_y'] = $attr['y']; + $dta['pos_head'] = $attr['head']; + + #3941 + #1790 + #1890 + #2750 + $r = $xml->xpath("hitpoints"); + $attr = $r->attributes(); + $dta['hitpoints'] = $attr['hitpoints']; + + $r = $xml->xpath("stamina"); + $attr = $r->attributes(); + $dta['stamina'] = $attr['stamina']; + + $r = $xml->xpath("sap"); + $attr = $r->attributes(); + $dta['sap'] = $attr['sap']; + + $r = $xml->xpath("focus"); + $attr = $r->attributes(); + $dta['focus'] = $attr['focus']; + + $this->data['c_stats'] = array($dta); } function writeData($ident,$field,$data,$type) { diff --git a/code/web/app/app_achievements/_AchWebParser/source/XMLapi/conf.php b/code/web/app/app_achievements/_AchWebParser/source/XMLapi/conf.php index d71249d09..d243c6a67 100644 --- a/code/web/app/app_achievements/_AchWebParser/source/XMLapi/conf.php +++ b/code/web/app/app_achievements/_AchWebParser/source/XMLapi/conf.php @@ -1,7 +1,7 @@