2012-06-25 13:04:51 +00:00
< ? php
2012-07-08 16:11:25 +00:00
class AdmAtom extends Node implements ADM {
2012-08-20 13:52:35 +00:00
#########################
# PHP 5.3 compatible
# AdmDispatcher_trait replaces this in PHP 5.4
2012-08-07 15:41:50 +00:00
function insertNode ( $n ) {
$n -> setParent ( $this );
$n -> insert ();
$this -> addChild ( $n );
}
function removeNode ( $id ) {
$res = $this -> getChildDataByID ( $id );
if ( $res != null ) {
$res -> delete_me ();
$this -> removeChild ( $id );
}
}
function updateNode ( $id ) { // PROBABLY USELESS!
$res = $this -> getChildDataByID ( $id );
if ( $res != null ) {
$res -> update ();
}
}
function getPathID ( $path = " " ) {
if ( $path != " " ) {
$path = " ; " . $path ;
}
$path = $this -> getID () . $path ;
if ( $this -> parent != null ) {
return $this -> parent -> getPathID ( $path );
}
return $path ;
}
function getElementByPath ( $pid ) {
$tmp = explode ( " ; " , $pid );
if ( $tmp [ 0 ] == $this -> getID ()) {
if ( sizeof ( $tmp ) > 1 ) {
$c = $this -> getChildDataByID ( $tmp [ 1 ]);
if ( $c != null ) {
unset ( $tmp [ 0 ]);
return $c -> getElementByPath ( implode ( " ; " , $tmp ));
}
return null ;
}
else {
return $this ;
}
}
return null ;
}
2012-08-20 13:52:35 +00:00
#########################
2012-08-07 15:41:50 +00:00
2012-06-25 13:04:51 +00:00
protected $objective ;
protected $mandatory ;
protected $ruleset ;
protected $ruleset_parsed ;
2012-07-02 16:56:13 +00:00
protected $parent_id ;
2012-06-25 13:04:51 +00:00
function AdmAtom ( $data , $parent ) {
$this -> parent = $parent ;
$this -> id = $data [ 'atom_id' ];
$this -> objective = $data [ 'atom_objective' ];
$this -> mandatory = $data [ 'atom_mandatory' ];
$this -> ruleset = $data [ 'atom_ruleset' ];
$this -> ruleset_parsed = $data [ 'atom_ruleset_parsed' ];
}
function delete_me () { // aaaaand... it's gone ^^
global $DBc ;
$DBc -> sqlQuery ( " DELETE FROM ach_atom WHERE atom_id=' " . $this -> id . " ' " );
$DBc -> sqlQuery ( " DELETE FROM ach_player_atom WHERE apa_atom=' " . $this -> id . " ' " );
}
2012-08-20 13:52:35 +00:00
function update () { // write updated data to database
2012-08-07 15:41:50 +00:00
global $DBc ;
$DBc -> sqlQuery ( " UPDATE ach_atom SET atom_mandatory=' " . $this -> getMandatory () . " ',atom_ruleset=' " . $DBc -> sqlEscape ( $this -> getRuleset ()) . " ',atom_ruleset_parsed=' " . $DBc -> sqlEscape ( $this -> getRulesetParsed ()) . " ' WHERE atom_id=' " . $this -> id . " ' " );
2012-06-25 13:04:51 +00:00
}
2012-08-20 13:52:35 +00:00
function insert () { // insert atoms as new row
2012-08-07 15:41:50 +00:00
global $DBc ;
$DBc -> sqlQuery ( " INSERT INTO ach_atom (atom_objective,atom_mandatory,atom_ruleset,atom_ruleset_parsed) VALUES (' " . $this -> getObjective () . " ',' " . $this -> getMandatory () . " ',' " . $DBc -> sqlEscape ( $this -> getRuleset ()) . " ',' " . $DBc -> sqlEscape ( $this -> getRulesetParsed ()) . " ') " );
$id = $DBc -> insertID ();
2012-06-25 13:04:51 +00:00
$this -> setID ( $id );
}
2012-08-07 15:41:50 +00:00
function getObjective () {
return $this -> objective ;
}
function setObjective ( $o ) {
$this -> objective = $o ;
}
2012-06-25 13:04:51 +00:00
function setMandatory ( $ft ) {
if ( $ft == true ) {
$this -> mandatory = 1 ;
}
else {
$this -> mandatory = 0 ;
}
}
function setRuleset ( $r ) {
$this -> ruleset = $r ;
$this -> parse ();
}
function getMandatory () {
return $this -> mandatory ;
}
function isMandatory () {
return ( $this -> mandatory == 1 );
}
function getRuleset () {
return $this -> ruleset ;
}
2012-08-07 15:41:50 +00:00
function getRulesetParsed () {
return $this -> ruleset_parsed ;
}
2012-08-20 13:52:35 +00:00
private function parse () { // parsing the ruleset
2012-08-07 15:41:50 +00:00
/*
VALUE _money AS $money {
CACHE blach AS $test ;
2012-06-25 13:04:51 +00:00
2012-08-07 15:41:50 +00:00
if ( $money >= 10000 && $test == 0 ) {
RESET ;
GRANT $money UNTIL TIMER : 3600 ;
FINAL ;
}
else {
CACHE blach SET $money ;
}
SCRIPT wealth ( $money ) AS $res ;
if ( $res == " lol " ) {
DENY ;
}
}
ENTITY _pos AS $pos {
SCRIPT inside ( $pos , " majestic_garden " ) AS $region ;
if ( $region == true ) {
GRANT ;
}
}
*/
2012-07-09 17:10:44 +00:00
$res = $this -> ruleset ;
2012-08-07 15:41:50 +00:00
#VALUE ([^ ]+) AS ([$][^ ]+) {#
2012-07-09 17:10:44 +00:00
$match = array ();
2012-08-07 15:41:50 +00:00
preg_match_all ( " #VALUE ([^ ]+) AS ([ $ ][^ ]+) { # " , $this -> ruleset , $match );
2012-07-09 17:10:44 +00:00
foreach ( $match [ 0 ] as $key => $elem ) {
$func = " _ " . md5 ( microtime ());
$tmp = '$this->registerValue("' . $match [ 1 ][ $key ] . '","' . $func . ' " );
2012-08-07 15:41:50 +00:00
function '.$func.' ( '.$match[2][$key].' , $_P , $_CB ) {
global $_CACHE ;
$_IDENT = " '. $match[1] [ $key ].' " ; ' ;
2012-07-09 17:10:44 +00:00
//replace
$res = str_replace ( $elem , $tmp , $res );
}
2012-08-07 15:41:50 +00:00
#ENTITY ([^ ]+) AS ([$][^ ]+) {#
2012-07-09 17:10:44 +00:00
$match = array ();
2012-08-07 15:41:50 +00:00
preg_match_all ( " #ENTITY ([^ ]+) AS ([ $ ][^ ]+) { # " , $this -> ruleset , $match );
2012-07-09 17:10:44 +00:00
foreach ( $match [ 0 ] as $key => $elem ) {
$func = " _ " . md5 ( microtime ());
$tmp = '$this->registerEntity("' . $match [ 1 ][ $key ] . '","' . $func . ' " );
2012-08-07 15:41:50 +00:00
function '.$func.' ( '.$match[2][$key].' , $_P , $_CB ) {
global $_CACHE ;
$_IDENT = " '. $match[1] [ $key ].' " ; ' ;
2012-07-09 17:10:44 +00:00
//replace
$res = str_replace ( $elem , $tmp , $res );
}
2012-08-07 15:41:50 +00:00
#EVENT ([^ ]+) AS ([$][^ ]+) {#
2012-07-09 17:10:44 +00:00
$match = array ();
2012-08-07 15:41:50 +00:00
preg_match_all ( " #EVENT ([^ ]+) AS ([ $ ][^ ]+) { # " , $this -> ruleset , $match );
2012-07-09 17:10:44 +00:00
foreach ( $match [ 0 ] as $key => $elem ) {
$func = " _ " . md5 ( microtime ());
$tmp = '$this->registerEvent("' . $match [ 1 ][ $key ] . '","' . $func . ' " );
2012-08-07 15:41:50 +00:00
function '.$func.' ( '.$match[2][$key].' , $_P , $_CB ) {
global $_CACHE ;
$_IDENT = " '. $match[1] [ $key ].' " ; ' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#GRANT ([^;]*);#
$match = array ();
preg_match_all ( " #GRANT ([^;]*);# " , $this -> ruleset , $match );
foreach ( $match [ 0 ] as $key => $elem ) {
$tmp = '$_P->grant(' . $match [ 1 ][ $key ] . ');' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#GRANT;#
$match = array ();
preg_match_all ( " #GRANT;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->grant();' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#DENY;#
$match = array ();
preg_match_all ( " #DENY;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->deny();' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#UNLOCK;#
$match = array ();
preg_match_all ( " #UNLOCK;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->unlock();' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#RESET;#
$match = array ();
preg_match_all ( " #RESET;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->reset_();' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#UNLOCK_ALL;#
$match = array ();
preg_match_all ( " #UNLOCK_ALL;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->unlock_all();' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#RESET_ALL;#
$match = array ();
preg_match_all ( " #RESET_ALL;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->reset_all();' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#FINAL VALUE;#
$match = array ();
preg_match_all ( " #FINAL VALUE;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->unregisterValue($_IDENT,$_CB);' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#FINAL ENTITY;#
$match = array ();
preg_match_all ( " #FINAL ENTITY;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->unregisterEntity($_IDENT,$_CB);' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#FINAL EVENT;#
$match = array ();
preg_match_all ( " #FINAL EVENT;# " , $this -> ruleset , $match );
2012-08-20 13:52:35 +00:00
foreach ( $match [ 0 ] as $elem ) {
2012-08-07 15:41:50 +00:00
$tmp = '$_P->unregisterEvent($_IDENT,$_CB);' ;
//replace
$res = str_replace ( $elem , $tmp , $res );
}
#CACHE ([^ ]+) AS ([$][^ ]+);#
$match = array ();
2012-12-10 14:07:13 +00:00
preg_match_all ( " #CACHE ([^ ]+) AS ([ $ ][^;]+);# " , $this -> ruleset , $match );
2012-08-07 15:41:50 +00:00
foreach ( $match [ 0 ] as $key => $elem ) {
2012-12-10 14:07:13 +00:00
$tmp = $match [ 2 ][ $key ] . ' = $_CACHE->getData(\'' . $match [ 1 ][ $key ] . '\');' ;
2012-07-09 17:10:44 +00:00
//replace
$res = str_replace ( $elem , $tmp , $res );
}
2012-08-07 15:41:50 +00:00
#CACHE ([^ ]+) SET ([$][^ ]+);#
$match = array ();
2012-12-10 14:07:13 +00:00
preg_match_all ( " #CACHE ([^ ]+) SET ([ $ ][^;]+);# " , $this -> ruleset , $match );
2012-08-07 15:41:50 +00:00
foreach ( $match [ 0 ] as $key => $elem ) {
2012-12-10 14:07:13 +00:00
$tmp = '$_CACHE->writeData(\'' . $match [ 1 ][ $key ] . '\',' . $match [ 2 ][ $key ] . ');' ;
2012-08-07 15:41:50 +00:00
//replace
$res = str_replace ( $elem , $tmp , $res );
}
2012-07-09 17:10:44 +00:00
2012-08-07 15:41:50 +00:00
#SCRIPT ([^ ]+) AS ([$][^ ]+);#
$match = array ();
2012-12-10 14:07:13 +00:00
preg_match_all ( " #SCRIPT ([^ \ (]+) \ (([^ \ )]*) \ ) AS ([ $ ][^;]+);# " , $this -> ruleset , $match );
2012-08-07 15:41:50 +00:00
foreach ( $match [ 0 ] as $key => $elem ) {
$tmp = '@include_once("script/' . $match [ 1 ][ $key ] . ' _script . php " );
'.$match[3][$key].' = '.$match[1][$key].' ( '.$match[2][$key].' ); ' ;
2012-07-02 16:56:13 +00:00
2012-08-07 15:41:50 +00:00
//replace
$res = str_replace ( $elem , $tmp , $res );
}
2012-07-02 16:56:13 +00:00
2012-08-07 15:41:50 +00:00
$this -> ruleset_parsed = $res ;
2012-07-02 16:56:13 +00:00
}
2012-06-25 13:04:51 +00:00
}
?>