#1470 initial achievement tracker

--HG--
branch : gsoc2012-achievements
hg/feature/gsoc2013-dfighter
SirCotare 13 years ago
parent a71989e70f
commit 41ce43d4b9

@ -0,0 +1,94 @@
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors","1");
require_once("class/mySQL_class.php");
require_once("conf.php");
require_once("inlcude/functions_inc.php");
$logfile = false;
if($CONF['logging'] == true) {
$logfile = fopen($CONF['logfile'].'.'.date("Ymd",time()).'.txt','a');
}
//create database connection
$DBc = new mySQL($CONF['mysql_error']);
$DBc->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);
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

@ -0,0 +1,41 @@
<?php
class DataSourceHandler {
private $source;
private $alloc;
function DataSourceHandler() {
$this->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]];
}
}
?>

@ -0,0 +1,24 @@
<?php
abstract class DataSource {
private $types = array();
private $priority = array();
private $write = false;
#MISSING: offered values
function DataSource() {
}
function getTypes() {
return $this->types;
}
function getPriority($type) {
return $this->priority[$type];
}
abstract function getData($type,$ident,$field = array());
abstract function writeData($type,$ident,$field = array(),$value = array());
}
?>

@ -0,0 +1,151 @@
<?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") {
$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 "<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;
default:
flush();
break;
}
}
}
?>

@ -0,0 +1,19 @@
<?php
function logf($txt,$nl = true) {
global $logfile;
if($logfile) {
if($nl) {
$txt .= "\n";
}
fwrite($logfile,"[".date('H:i:s',time())."] ".$txt);
}
}
function logi($txt,$i = 1) {
$tmp = "";
for($v=0;$v<$i;$v++) {
$tmp .= " ";
}
return $tmp."> ".$txt;
}
?>

@ -0,0 +1,26 @@
<?php
class ValueCache extends DataSource {
function ValueCache() {
$this->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;
}
}
}
?>

@ -0,0 +1,19 @@
<?php
class XMLapi extends DataSource {
function XMLapi() {
$this->types[] = "c_stats";
$this->types[] = "c_items";
$this->write = false;
}
function getData() {
}
function writeData() {
return false;
}
}
?>
Loading…
Cancel
Save