From 75cbc3d8156bf1debda83832707d5c844a6d45a0 Mon Sep 17 00:00:00 2001 From: SirCotare Date: Mon, 25 Jun 2012 21:16:42 +0200 Subject: [PATCH] #1470 achievement API for external data access --- .../app_achievements/_API/ach_progress.php | 41 +++++ .../app/app_achievements/_API/ach_struct.php | 99 +++++++++++ .../_API/class/mySQL_class.php | 164 ++++++++++++++++++ code/web/app/app_achievements/_API/conf.php | 12 ++ 4 files changed, 316 insertions(+) create mode 100644 code/web/app/app_achievements/_API/ach_progress.php create mode 100644 code/web/app/app_achievements/_API/ach_struct.php create mode 100644 code/web/app/app_achievements/_API/class/mySQL_class.php create mode 100644 code/web/app/app_achievements/_API/conf.php diff --git a/code/web/app/app_achievements/_API/ach_progress.php b/code/web/app/app_achievements/_API/ach_progress.php new file mode 100644 index 000000000..9665a6bb3 --- /dev/null +++ b/code/web/app/app_achievements/_API/ach_progress.php @@ -0,0 +1,41 @@ +connect($_CONF['mysql_server'],$_CONF['mysql_user'],$_CONF['mysql_pass'],$_CONF['mysql_database']); + + echo ''; + echo ""; + + echo ""; + $res = $DBc->sendSQL("SELECT * FROM ach_player_perk WHERE app_player='".$DBc->mre($_REQUEST['cid'])."'","ARRAY"); + foreach($res as $elem) { + echo ""; + } + echo ""; + + echo ""; + echo ""; + $res = $DBc->sendSQL("SELECT * FROM ach_player_objective WHERE apo_player='".$DBc->mre($_REQUEST['cid'])."'","ARRAY"); + foreach($res as $elem) { + echo ""; + } + echo ""; + $res = $DBc->sendSQL("SELECT ao_id,(SELECT count(*) FROM ach_player_atom,ach_atom WHERE apa_player='".$DBc->mre($_REQUEST['cid'])."' AND atom_id=apa_atom AND atom_objective=ao_id) as anz FROM ach_objective WHERE ao_display='value' AND NOT EXISTS (SELECT * FROM ach_player_objective WHERE apo_player='".$DBc->mre($_REQUEST['cid'])."' AND apo_objective='ao_id') AND EXISTS (SELECT * FROM ach_player_atom,ach_atom WHERE apa_player='".$DBc->mre($_REQUEST['cid'])."' AND atom_id=apa_atom AND atom_objective=ao_id)","ARRAY"); + foreach($res as $elem) { + echo ""; + } + echo ""; + echo ""; + + echo ""; + + exit(0); +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/_API/ach_struct.php b/code/web/app/app_achievements/_API/ach_struct.php new file mode 100644 index 000000000..543479750 --- /dev/null +++ b/code/web/app/app_achievements/_API/ach_struct.php @@ -0,0 +1,99 @@ +connect($_CONF['mysql_server'],$_CONF['mysql_user'],$_CONF['mysql_pass'],$_CONF['mysql_database']); + + echo ''; + + function print_cat(&$iter3) { + while($iter3->hasNext()) { + $curr3 = $iter3->getNext(); + echo "getImage()."'>getName()."]]>"; + if($curr3->getTieRace() != null) { + echo "".$curr3->getTieRace().""; + } + if($curr3->getTieCult() != null) { + echo "".$curr3->getTieCult().""; + } + if($curr3->getTieCiv() != null) { + echo "".$curr3->getTieCiv().""; + } + $iter4 = $curr3->getIterator(); + while($iter4->hasNext()) { + $curr4 = $iter4->getNext(); + echo "getName()."]]>"; + $iter5 = $curr4->getIterator(); + while($iter5->hasNext()) { + $curr5 = $iter5->getNext(); + echo "getMetaImage()."'>getName()."]]>"; + } + echo ""; + } + echo ""; + } + } + + $menu = new AchMenu(0); + $menu->removeChild(0); + + $iter = $menu->getIterator(); + while($iter->hasNext()) { + $curr = $iter->getNext(); + echo "getImage()."'>getName()."]]>"; + $iter2 = $curr->getIterator(); + while($iter2->hasNext()) { + $curr2 = $iter2->getNext(); + echo "getImage()."'>getName()."]]>"; + $cat = new AchCategory($curr2->getID(),null,null); + $iter3 = $cat->getIterator(); + prin_cat($iter3); + echo ""; + } + + $cat = new AchCategory($curr->getID(),null,null); + $iter3 = $cat->getIterator(); + prin_cat($iter3); + echo ""; + } + + echo ""; + + exit(0); +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/_API/class/mySQL_class.php b/code/web/app/app_achievements/_API/class/mySQL_class.php new file mode 100644 index 000000000..67ce66226 --- /dev/null +++ b/code/web/app/app_achievements/_API/class/mySQL_class.php @@ -0,0 +1,164 @@ +$elem) { + $in[$key] = mysql_real_escape_string(stripslashes($elem)); + } + } + else { + $in = mysql_real_escape_string(stripslashes($in)); + } + return $in; + } + + function mySQL($err=false) { + $this->DBstats = array(); + $this->DBc = false; + if($err === "DIE" || $err === "PRINT" || $err === "ALERT" || $err === "HIDE" || $err === "LOG") { + $this->DBerror = $err; + } + else { + $this->DBerror = "HIDE"; + } + $this->resetStats(); + $this->cached = false; + } + + function connect($ip,$user,$pass,$db=false) { + $this->DBc = mysql_pconnect($ip,$user,$pass) or $this->error(mysql_error()); + if($this->DBc && $db) { + $this->database($db); + } + $this->resetStats(); + } + + function database($db) { + if(!$this->DBc) { + return false; + } + mysql_select_db($db,$this->DBc) or $this->error(mysql_error()); + } + + function resetStats() { + $this->DBstats['query'] = 0; + $this->DBstats['error'] = 0; + } + + function getStats() { + return $this->DBstats; + } + + function sqlQuery($query) { + return $this->sendSQL($query,"ARRAY"); + } + + function sendSQL($query,$handling="PLAIN",$buffer=false) { // can be INSERT, DELETE, UPDATE, ARRAY, NONE, PLAIN + #if($this->cached !== false) { + #$this->unlinkSql($this->cached); + #} + if(!$this->DBc) { + return false; + } + + if($buffer === false && $handling !== "PLAIN") { + $res = mysql_unbuffered_query($query,$this->DBc) or $this->error(mysql_error(),$query); + } + else { + $res = mysql_query($query,$this->DBc) or $this->error(mysql_error(),$query); + } + + #$this->cached = $res; + + $this->DBstats['query']++; + + if($res) { + if($handling === "INSERT") { + $tmp = mysql_insert_id($this->DBc) or $this->error(mysql_error());; + $this->unlinkSql($res); + return $tmp; + } + elseif($handling === "DELETE" || $handling === "UPDATE") { + $tmp = mysql_affected_rows($this->DBc) or $this->error(mysql_error()); + $this->unlinkSql($res); + return $tmp; + } + elseif($handling === "ARRAY") { + $tmp = $this->parseSql($res); + $this->unlinkSql($res); + return $tmp; + } + elseif($handling === "NONE") { + $this->unlinkSql($res); + return true; + } + else { + return $res; + } + mysql_free_result($res); + } + else { + return false; + } + } + + function unlinkSql($res) { + @mysql_free_result($res); + } + + private function parseSql($res) { + $data = array(); + $k = 0; + while($tmp = mysql_fetch_array($res,MYSQL_ASSOC)) { + $data[$k] = $tmp; + $k++; + } + + return $data; + } + + function getNext($res) { + if($res) { + if($tmp = mysql_fetch_array($res,MYSQL_ASSOC)) { + return $tmp; + } + else { + return false; + } + } + else { + return false; + } + } + + private function error($error,$query = false) { + $this->DBstats['error']++; + + if($query != false) { + $error .= " -->|".$query."|<--"; + } + + switch($this->DBerror) { + case 'DIE': + die($error); + break; + case 'PRINT': + echo "
".$error."
"; + break; + case 'ALERT': + echo ""; + break; + case 'LOG': + logf("MySQL ERROR: ".$error); + break; + default: + flush(); + break; + } + } + } +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/_API/conf.php b/code/web/app/app_achievements/_API/conf.php new file mode 100644 index 000000000..79f94ca9e --- /dev/null +++ b/code/web/app/app_achievements/_API/conf.php @@ -0,0 +1,12 @@ + \ No newline at end of file