From 41ce43d4b94d742895ac11ab6f674dee0e77ff80 Mon Sep 17 00:00:00 2001 From: SirCotare Date: Mon, 4 Jun 2012 00:34:26 +0200 Subject: [PATCH] #1470 initial achievement tracker --HG-- branch : gsoc2012-achievements --- .../_AchWebParser/AchWebParser.php | 94 +++++++++++ .../_AchWebParser/_doc/Class_scheme.dia | Bin 0 -> 1648 bytes .../_AchWebParser/_doc/Class_scheme.png | Bin 0 -> 4524 bytes .../class/DataSourceHandler_class.php | 41 +++++ .../class/DataSource_abstract.php | 24 +++ .../_AchWebParser/class/mySQL_class.php | 151 ++++++++++++++++++ .../_AchWebParser/include/functions_inc.php | 19 +++ .../source/ValueCache/ValueCache_class.php | 26 +++ .../source/XMLapi/XMLapi_class.php | 19 +++ 9 files changed, 374 insertions(+) create mode 100644 code/web/app/app_achievements/_AchWebParser/AchWebParser.php create mode 100644 code/web/app/app_achievements/_AchWebParser/_doc/Class_scheme.dia create mode 100644 code/web/app/app_achievements/_AchWebParser/_doc/Class_scheme.png create mode 100644 code/web/app/app_achievements/_AchWebParser/class/DataSourceHandler_class.php create mode 100644 code/web/app/app_achievements/_AchWebParser/class/DataSource_abstract.php create mode 100644 code/web/app/app_achievements/_AchWebParser/class/mySQL_class.php create mode 100644 code/web/app/app_achievements/_AchWebParser/include/functions_inc.php create mode 100644 code/web/app/app_achievements/_AchWebParser/source/ValueCache/ValueCache_class.php create mode 100644 code/web/app/app_achievements/_AchWebParser/source/XMLapi/XMLapi_class.php diff --git a/code/web/app/app_achievements/_AchWebParser/AchWebParser.php b/code/web/app/app_achievements/_AchWebParser/AchWebParser.php new file mode 100644 index 000000000..3e2cae8df --- /dev/null +++ b/code/web/app/app_achievements/_AchWebParser/AchWebParser.php @@ -0,0 +1,94 @@ +connect($CONF['mysql_server'],$CONF['mysql_user'],$CONF['mysql_pass'],$CONF['mysql_database']); + + #MISSING: mode -> single, cron, debug + + require_once("class/DataSourceHandler_class.php"); + require_once("class/DataSource_abstract.php"); + + //create datasource handler + $_DATA = new DataSourceHandler(); + foreach($CONF['data_source'] as $elem) { //populate + require_once("source/".$elem."/".$elem."_class.php"); + eval('$tmp = new '.$elem.'();'); + $_DATA->registerDataSource($tmp); + } + + #MISSING: fetch candidates + + foreach() { + #MISSING: fetch objectives to evaluate + foreach() { + #MISSING: fetch atoms + foreach() { + #MISSING: evaluate atoms + } + #MISSING: evaluate objective + } + #MISSING: evaluate perk + } + + #WORKPAD:#### + + Trigger: + by value + (by event) + + Sources: + XML + valuecache + (Achievement Service) + (Mirror Service) + + + VALUE dappers = c_money + if(dappers >= 5000) { + GRANT + } + + VALUE tmp = c_fame[scorchers] + if(tmp == 0) { + DENY:3600 + } + + EVENT:player_death + ON player_death { + UNLOCK + } + + ############# + + + + #MISSING: self call on cron mode + if() { + $fp = fsockopen($CONF['self_host'], 80, $errno, $errstr, 30); + if(!$fp) { + logf("ERROR: self call; socket: ".$errstr." (."$errno.")"); + } + else { + $out = "GET ".$CONF['self_path']." HTTP/1.1\r\n"; + $out .= "Host: ".$CONF['self_host']."\r\n"; + $out .= "Connection: Close\r\n\r\n"; + + fwrite($fp, $out); + fclose($fp); + } + } + + exit(0); +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/_AchWebParser/_doc/Class_scheme.dia b/code/web/app/app_achievements/_AchWebParser/_doc/Class_scheme.dia new file mode 100644 index 0000000000000000000000000000000000000000..aa0d65c93a07d46cd55f38324c879282a997de35 GIT binary patch literal 1648 zcmV-$29Nn4iwFP!000003+-H4lcP2eexF}KF|RW+hi&Yg^=u`ZO6Fm=@{nvQZ!Q_j zSXqIH5HsUE2@8T^EjA7mi&Q4hKu0 zGR`38MaUJU1VJxBF~lyZ)j^95=A2gae*;NSM}g$@!P}a8uEX&9vg2l2 zlt_8OYrb8+4rH!G`fecU&p5y0v!X6EtZ) zJvbp=qo87#W!scU+NRA$RaVcpt819#RBp14AqdCJq#!V%qMqa zpilA!D29(RfYmB5pNZ~6&mri55kWlY1~Bh*tsN2~$X(i$dBxnIKXq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6)?mEMRnY(NX#m?C%aibhI{T(YRb}#33qfLE!3^ z)-B&`?J)J~5yXAK;PTEJHtz*DTPh-DFlWE9mR3z=e*-zK zoi_dyakFM^V1g%49_t4m)?5*HG@uh^A=y(v(_rN3Osz_buuMYQOjUNHs|O zGG4ywqo1ul2|`|lI-(OMdQgcy58(9EcQnU@bOUyh;wkoO@0R#YB;=|7X!+O@{~rO# z&cTVJ1o|Hz40e{*2(`8Z=VpHl-vAgU0CIZRjeKff;`Fr}zZ6(99aH6k}! zda`s{C+cHr7OjVrArBTO8=u#1^Qnc3aA7bRe*%Q`5KbzHR2Bt-6X588mL0+#) ze7nc)Hv{vhUAz4YMCRV=pFsZR>*r7%A3fIjhXF>J-QVfH70)tdb#AE@x{8)x04qzo KYh@Nbzx)qj3G#&i literal 0 HcmV?d00001 diff --git a/code/web/app/app_achievements/_AchWebParser/class/DataSourceHandler_class.php b/code/web/app/app_achievements/_AchWebParser/class/DataSourceHandler_class.php new file mode 100644 index 000000000..53b64d8d6 --- /dev/null +++ b/code/web/app/app_achievements/_AchWebParser/class/DataSourceHandler_class.php @@ -0,0 +1,41 @@ +source = array(); + $this->alloc = array(); + + + } + + function registerDataSource($src) { + $i = sizeof($this->source); + $this->source[$i] = $src; + foreach($src->getTypes() as $elem) { + if(!is_array($this->alloc[$elem])) { + $this->alloc[$elem] = array(); + } + //add to list + $this->alloc[$elem][$src->getPriority($elem)] = $i; + } + } + + function getData($type,$field,$ident) { + return $this->getDataSource($type)->getData($type,$field,$ident); + } + + private function getDataSource($type) { + //find the highest priority datasource for given type + if(!$this->alloc[$type]) { + return false; //unknown type + } + $pos = array_keys($this->alloc[$type]); + if(sizeof($pos) == 0) { + return false; //no datasource for type // should not happen since type is defined by datasource + } + return $this->alloc[$type][$pos[0]]; + } + } +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/_AchWebParser/class/DataSource_abstract.php b/code/web/app/app_achievements/_AchWebParser/class/DataSource_abstract.php new file mode 100644 index 000000000..4b5d64bf6 --- /dev/null +++ b/code/web/app/app_achievements/_AchWebParser/class/DataSource_abstract.php @@ -0,0 +1,24 @@ +types; + } + + function getPriority($type) { + return $this->priority[$type]; + } + + abstract function getData($type,$ident,$field = array()); + + abstract function writeData($type,$ident,$field = array(),$value = array()); + } +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/_AchWebParser/class/mySQL_class.php b/code/web/app/app_achievements/_AchWebParser/class/mySQL_class.php new file mode 100644 index 000000000..4202ffcd8 --- /dev/null +++ b/code/web/app/app_achievements/_AchWebParser/class/mySQL_class.php @@ -0,0 +1,151 @@ +$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") { + $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($db) { + $this->database($db); + } + $this->resetStats(); + } + + function database($db) { + 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 sendSQL($query,$handling="PLAIN",$buffer=false) { // can be INSERT, DELETE, UPDATE, ARRAY, NONE, PLAIN + #if($this->cached !== false) { + #$this->unlinkSql($this->cached); + #} + + 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; + default: + flush(); + break; + } + } + } +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/_AchWebParser/include/functions_inc.php b/code/web/app/app_achievements/_AchWebParser/include/functions_inc.php new file mode 100644 index 000000000..17e9a89ae --- /dev/null +++ b/code/web/app/app_achievements/_AchWebParser/include/functions_inc.php @@ -0,0 +1,19 @@ + ".$txt; + } +?> \ No newline at end of file diff --git a/code/web/app/app_achievements/_AchWebParser/source/ValueCache/ValueCache_class.php b/code/web/app/app_achievements/_AchWebParser/source/ValueCache/ValueCache_class.php new file mode 100644 index 000000000..84c174124 --- /dev/null +++ b/code/web/app/app_achievements/_AchWebParser/source/ValueCache/ValueCache_class.php @@ -0,0 +1,26 @@ +types[] = "c_cache"; + + $this->write = true; + } + + function getData($type,$ident,$field) { + + } + + function writeData($type,$ident,$field = array(),$value = array()) { + global $DBc; + + if($type == "c_cache") { + $DBc->sendSQL("INSERT INTO ach_player_valuecache () VALUES () ON DUPLICATE KEY UPDATE "); + + return true; + } + else { + return false; + } + } + } +?> \ No newline at end of file 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 new file mode 100644 index 000000000..6ae24a6ac --- /dev/null +++ b/code/web/app/app_achievements/_AchWebParser/source/XMLapi/XMLapi_class.php @@ -0,0 +1,19 @@ +types[] = "c_stats"; + $this->types[] = "c_items"; + + $this->write = false; + } + + function getData() { + + } + + function writeData() { + return false; + } + + } +?> \ No newline at end of file