#1470 achievement API for external data access

--HG--
branch : gsoc2012-achievements
This commit is contained in:
SirCotare 2012-06-25 21:16:42 +02:00
parent 7d976a22ad
commit a42d6d9a76
4 changed files with 316 additions and 0 deletions

View file

@ -0,0 +1,41 @@
<?php
header('Content-type: text/xml');
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors","1");
require_once("class/mySQL_class.php");
require_once("conf.php");
//create database connection
$DBc = new mySQL($_CONF['mysql_error']);
$DBc->connect($_CONF['mysql_server'],$_CONF['mysql_user'],$_CONF['mysql_pass'],$_CONF['mysql_database']);
echo '<?xml version="1.0" ?><ryzom_progress>';
echo "<character id='".$_REQUEST['cid']."' />";
echo "<perks>";
$res = $DBc->sendSQL("SELECT * FROM ach_player_perk WHERE app_player='".$DBc->mre($_REQUEST['cid'])."'","ARRAY");
foreach($res as $elem) {
echo "<perk id='".$elem['app_perk']."' date='".$elem['app_date']."' />";
}
echo "</perks>";
echo "<objectives>";
echo "<done>";
$res = $DBc->sendSQL("SELECT * FROM ach_player_objective WHERE apo_player='".$DBc->mre($_REQUEST['cid'])."'","ARRAY");
foreach($res as $elem) {
echo "<objective id='".$elem['apo_objective']."' date='".$elem['apo_date']."' />";
}
echo "</done><open>";
$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 "<objective id='".$elem['ao_id']."' value='".$elem['anz']."' />";
}
echo "</open>";
echo "</objectives>";
echo "</ryzom_progress>";
exit(0);
?>

View file

@ -0,0 +1,99 @@
<?php
header('Content-type: text/xml');
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors","1");
require_once("class/mySQL_class.php");
require_once("conf.php");
require_once($_CONF['app_achievements_path']."class/Parentum_abstract.php");
require_once($_CONF['app_achievements_path']."class/AchList_abstract.php");
require_once($_CONF['app_achievements_path']."class/Tieable_inter.php");
require_once($_CONF['app_achievements_path']."class/NodeIterator_class.php");
require_once($_CONF['app_achievements_path']."class/Node_trait.php");
require_once($_CONF['app_achievements_path']."class/AchMenu_class.php");
require_once($_CONF['app_achievements_path']."class/AchMenuNode_class.php");
require_once($_CONF['app_achievements_path']."class/AchSummary_class.php");
require_once($_CONF['app_achievements_path']."class/AchCategory_class.php");
require_once($_CONF['app_achievements_path']."class/AchAchievement_class.php");
require_once($_CONF['app_achievements_path']."class/AchPerk_class.php");
require_once($_CONF['app_achievements_path']."class/AchObjective_class.php");
class RUser() {
function RUser() { }
function getLang() {
return $_REQUEST['lang'];
}
function getID() {
return 0;
}
}
$_USER = new RUser();
//create database connection
$DBc = new mySQL($_CONF['mysql_error']);
$DBc->connect($_CONF['mysql_server'],$_CONF['mysql_user'],$_CONF['mysql_pass'],$_CONF['mysql_database']);
echo '<?xml version="1.0" ?><ryzom_achievements>';
function print_cat(&$iter3) {
while($iter3->hasNext()) {
$curr3 = $iter3->getNext();
echo "<achievement id='".$curr3->getID()."' parent='".$curr3->getParentID()."' image='".$_CONF['image_url']."pic/icon/".$curr3->getImage()."'><name><![CDATA[".$curr3->getName()."]]></name>";
if($curr3->getTieRace() != null) {
echo "<tie type='race'>".$curr3->getTieRace()."</tie>";
}
if($curr3->getTieCult() != null) {
echo "<tie type='cult'>".$curr3->getTieCult()."</tie>";
}
if($curr3->getTieCiv() != null) {
echo "<tie type='civilization'>".$curr3->getTieCiv()."</tie>";
}
$iter4 = $curr3->getIterator();
while($iter4->hasNext()) {
$curr4 = $iter4->getNext();
echo "<perk id='".$curr4->getID()."' parent='".$curr4->getParentID()."' value='".$curr4->getValueOpen()."'><name><![CDATA[".$curr4->getName()."]]></name>";
$iter5 = $curr4->getIterator();
while($iter5->hasNext()) {
$curr5 = $iter5->getNext();
echo "<objective id='".$curr5->getID()."' type='".$curr5->getDisplay()."' value='".$curr5->getValue()."' meta='".$_CONF['image_url']."pic/icon/".$curr5->getMetaImage()."'><name><![CDATA[".$curr5->getName()."]]></name></objective>";
}
echo "</perk>";
}
echo "</achievement>";
}
}
$menu = new AchMenu(0);
$menu->removeChild(0);
$iter = $menu->getIterator();
while($iter->hasNext()) {
$curr = $iter->getNext();
echo "<category id='".$curr->getID()."' order='".$curr->getOrder()."' image='".$_CONF['image_url']."pic/menu/".$curr->getImage()."'><name><![CDATA[".$curr->getName()."]]></name>";
$iter2 = $curr->getIterator();
while($iter2->hasNext()) {
$curr2 = $iter2->getNext();
echo "<category id='".$curr2->getID()."' order='".$curr2->getOrder()."' image='".$_CONF['image_url']."pic/menu/".$curr2->getImage()."'><name><![CDATA[".$curr2->getName()."]]></name>";
$cat = new AchCategory($curr2->getID(),null,null);
$iter3 = $cat->getIterator();
prin_cat($iter3);
echo "</category>";
}
$cat = new AchCategory($curr->getID(),null,null);
$iter3 = $cat->getIterator();
prin_cat($iter3);
echo "</category>";
}
echo "</ryzom_achievements>";
exit(0);
?>

View file

@ -0,0 +1,164 @@
<?php
class mySQL {
var $DBc;
var $DBstats;
var $cached;
function mre($in) {
if(is_array($in)) {
foreach($in as $key=>$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 "<br><b>".$error."</b><br>";
break;
case 'ALERT':
echo "<script language='javascript'>\n<!--\nalert(\"database error:\\n".mysql_real_escape_string($error)."\");\n// -->\n</script>";
break;
case 'LOG':
logf("MySQL ERROR: ".$error);
break;
default:
flush();
break;
}
}
}
?>

View file

@ -0,0 +1,12 @@
<?php
$_CONF = array();
$_CONF['app_achievements_path'] = "../";
$_CONF['image_url'] = "http://www.3025-game.de/special/app_achievements/";
$_CONF['mysql_error'] = "DIE";
$_CONF['mysql_server'] = "localhost";
$_CONF['mysql_user'] = "root";
$_CONF['mysql_pass'] = "";
$_CONF['mysql_database'] = "app_achievements";
?>