#1470 XMLApi connector initially finished; testing needed

This commit is contained in:
SirCotare 2012-06-18 21:17:44 +02:00
parent 89c0071156
commit a84b0aae5e
2 changed files with 203 additions and 5 deletions

View file

@ -8,19 +8,217 @@
$this->xml_path = $CONF['xml_path']; $this->xml_path = $CONF['xml_path'];
} }
function getData($ident,$field,$type) { function loadData($ident,$type) {
switch($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"; $path = $this->xml_path."full/".$ident.".xml";
break; break;
case "c_items": case 'c_items':
$path = $this->xml_path."item/".$ident.".xml"; $path = $this->xml_path."item/".$ident.".xml";
break; break;
default: default:
return false; return false;
break; 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];
}
#<position x="17027.559" y="-32943.011" head="-1.981871"/>
$r = $xml->xpath("position");
$attr = $r->attributes();
$dta['pos_x'] = $attr['x'];
$dta['pos_y'] = $attr['y'];
$dta['pos_head'] = $attr['head'];
#<hitpoints max="3941">3941</hitpoints>
#<stamina max="1790">1790</stamina>
#<sap max="1890">1890</sap>
#<focus max="2750">2750</focus>
$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) { function writeData($ident,$field,$data,$type) {

View file

@ -1,7 +1,7 @@
<?php <?php
$CONF = array(); $CONF = array();
$CONF['types'] = array("c_stats*","c_items*"); $CONF['types'] = array("c_stats","c_items","c_connection","c_gear","c_fp","c_skills","c_fame","c_pet");
$CONF['write'] = false; $CONF['write'] = false;
$CONF['xml_path'] = "foo/bar/xml/"; // this is a dummy ^^ $CONF['xml_path'] = "foo/bar/xml/"; // this is a dummy ^^