Advertisement
Guest User

Untitled

a guest
Jul 31st, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.37 KB | None | 0 0
  1. <?php
  2.  
  3. class template{
  4.  
  5.   function load($filepath){
  6.     $this->template = preg_replace("#\{(.*)\}#","<?php echo $1; ?>",file_get_contents($filepath));
  7.   }
  8.  
  9.   function replace($var,$content){
  10.     $this->template = str_replace("%$var%",$content,$this->template);
  11.   }
  12.  
  13.   function content(){
  14.     return $this->template;
  15.   }
  16.  
  17. }
  18.  
  19. class mysql{
  20.  
  21.   protected $hostname;
  22.   protected $database;
  23.   protected $username;
  24.   protected $password;
  25.   protected $_handle = null;
  26.  
  27.   public function __construct($hostname = null,$database = null,$username = null,$password = null){
  28.     $this->hostname = $hostname;
  29.     $this->database = $database;
  30.     $this->username = $username;
  31.     $this->password = $password;
  32.   }
  33.  
  34.   public function __call($method,$args){
  35.     if(!$this->_handle)
  36.       $this->connect();
  37.     return call_user_func_array(array($this,$method),$args);
  38.   }
  39.  
  40.   function connect(){
  41.     global $client;
  42.     try{
  43.       $this->_handle = new PDO("mysql:host={$this->hostname};dbname={$this->database};charset=utf8",$this->username,$this->password);
  44.       $this->_handle->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
  45.       $this->_handle->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  46.     }catch(PDOException $e){
  47.       $this->error($e->getMessage(),$this->hostname);
  48.     }
  49.   }
  50.  
  51.   function error($error,$hostname){
  52.     $file = fopen(PATH_ROOT."errorLog.txt","a");
  53.     fwrite($file,date("H:i:s d/m/Y",time()).": ".$error." (".$_SERVER['REMOTE_ADDR'].")\n");
  54.     fclose($file);
  55.   }
  56.  
  57.   protected function select($query,$array){
  58.     if(!$this->_handle){
  59.       return false;
  60.     }
  61.     try{
  62.       $statement = $this->_handle->prepare($query);
  63.       $statement->execute($array);
  64.       $data = $statement->fetchAll();
  65.       if(count($data) == 1)
  66.         return $data[0];
  67.       return $data;
  68.     }catch(PDOException $e){
  69.       $this->error($e->getMessage(),$this->hostname);
  70.       return false;
  71.     }
  72.   }
  73.  
  74.   protected function execute($query,$array){
  75.     if(!$this->_handle){
  76.       return false;
  77.     }
  78.     try{
  79.       $statement = $this->_handle->prepare($query);
  80.       $statement->execute($array);
  81.       return $statement->rowCount();
  82.     }catch(PDOException $e){
  83.       if($e->getCode() != "23000")
  84.         $this->error($e->getMessage(),$this->hostname);
  85.       return $this->error($e->getMessage(),$this->hostname);
  86.     }
  87.   }
  88.  
  89.   protected function isConnected(){
  90.     return $this->_handle != null;
  91.   }
  92.  
  93.   protected function test(){
  94.     try{
  95.       $this->_handle = new PDO("mysql:host={$this->hostname};dbname={$this->database}",$this->username,$this->password);
  96.       $this->_handle->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
  97.       $this->_handle->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  98.       return true;
  99.     }catch(PDOException $e){
  100.       return $e->getMessage();
  101.     }
  102.   }
  103.  
  104. }
  105.  
  106. class log{
  107.  
  108.   function format($log,$arguments){
  109.     return vsprintf($log,$arguments);
  110.   }
  111.  
  112.   function add($log){
  113.     global $mysqlClientLoginServer;
  114.     global $queryLogin;
  115.     global $player;
  116.     $mysqlClientLoginServer->execute("INSERT INTO `acp_logs` (`serverId`,`account`,`characterId`,`log`,`time`) VALUES (?,?,?,?,?);",array((($player['server']) ? $player['server'] : 0),$player['account'],(($player['character']['id']) ? $player['character']['id'] : 0),$log,time()));
  117.   }
  118.  
  119. }
  120.  
  121. $log = new log();
  122.  
  123. class mail{
  124.  
  125.   function send($to,$message){
  126.     global $settings;
  127.     $headers = "From: \" { ".$settings['projectName']." } \" < { ".$settings['projectEmail']." } >"."\n";
  128.     $headers .= "MIME-Version: 1.0"."\n";
  129.     $headers .= "Content-type: text/html; charset=iso-8859-1"."\r\n";
  130.     mail($to,$settings['projectName'],$message,$headers);
  131.   }
  132.  
  133. }
  134.  
  135. class validate{
  136.  
  137.   function account($account){
  138.     return (preg_match("/^[A-Za-z0-9]{1,20}$/",$account));
  139.   }
  140.  
  141.   function character($id){
  142.     return (preg_match("/^[0-9]{9,10}$/",$id));
  143.   }
  144.  
  145.   function password($password){
  146.     return (preg_match("/^[A-Za-z0-9]{1,20}$/",$password));
  147.   }
  148.  
  149.   function numeric($value){
  150.     return (preg_match("/^\d+$/",$value));
  151.   }
  152.  
  153.   function money($value){
  154.     return (preg_match("/^[0-9]+(?:\.[0-9]{0,2})?$/",$value));
  155.   }
  156.  
  157.   function pin($value){
  158.     return (preg_match("/^[a-z0-9 ]{19}$/",$value));
  159.   }
  160.  
  161.   function email($email){
  162.     return (filter_var($email,FILTER_VALIDATE_EMAIL));
  163.   }
  164.  
  165.   function blank($value){
  166.     if($value !== null && (is_array($value) || strlen($value) > 0)){
  167.       return TRUE;
  168.     }else{
  169.       return FALSE;
  170.     }
  171.   }
  172.  
  173.   function match($value1,$value2){
  174.     return ($value1 === $value2);
  175.   }
  176.  
  177.   function gameserver($id){
  178.     return ($this->numeric($id));
  179.   }
  180.  
  181.   function escape($string){
  182.     return (preg_match("/^[A-Za-z0-9\\.\\_]{0,30}$/",$string));
  183.   }
  184.  
  185.   function sessionID($string){
  186.     return (preg_match("/^[a-f0-9]{30}$/",$string));
  187.   }
  188.  
  189.   function letters($string){
  190.     return (preg_match("/^[a-zA-Z]+$/",$string));
  191.   }
  192.  
  193. }
  194.  
  195. $validate = new validate();
  196.  
  197. class cookie{
  198.  
  199.   function add($name,$value,$duration){
  200.     global $client;
  201.     setCookie('acp['.$client['id'].']['.$name.']',$value,$duration,'/');
  202.   }
  203.  
  204.   function set($name){
  205.     global $client;
  206.     return (isset($_COOKIE['acp'][$client['id']][$name]));
  207.   }
  208.  
  209.   function get($name){
  210.     global $client;
  211.     return (isset($_COOKIE['acp'][$client['id']][$name]));
  212.   }
  213.  
  214.   function destroy($name){
  215.     global $client;
  216.     unset($_COOKIE['acp'][$client['id']][$name]);
  217.     setCookie("acp[".$client['id']."][".$name."]","",time() - 10,"/");
  218.   }
  219.  
  220. }
  221.  
  222. $cookie = new cookie();
  223.  
  224. class session{
  225.  
  226.   function add($name,$value){
  227.     global $client;
  228.     $_SESSION['acp'][$client['id']][$name] = $value;
  229.   }
  230.  
  231.   function set($name){
  232.     global $client;
  233.     return (isset($_SESSION['acp'][$client['id']][$name]));
  234.   }
  235.  
  236.   function get($name){
  237.     global $client;
  238.     return $_SESSION['acp'][$client['id']][$name];
  239.   }
  240.  
  241.   function destroy($name){
  242.     global $client;
  243.     unset($_SESSION['acp'][$client['id']][$name]);
  244.   }
  245.  
  246. }
  247.  
  248. $session = new session();
  249.  
  250. class items{
  251.  
  252.   function findItemXML($item){
  253.     $file = "";
  254.     $XMLfiles = opendir(PATH_LIBRARIES."xml/items");
  255.     while($XMLfile = readdir($XMLfiles)){
  256.       if($XMLfile != "." && $XMLfile != ".." && $XMLfile != "index.html"){
  257.         $XMLfile = str_replace(".xml","",$XMLfile);
  258.         $range = explode('-',$XMLfile);
  259.         if($item >= $range[0] && $item <= $range[1]){
  260.           $file = $XMLfile.".xml";
  261.           break;
  262.         }
  263.       }
  264.     }
  265.     return $file;
  266.   }
  267.  
  268.   function findItemInXML($item_id){
  269.     $itemXML = "";
  270.     $items = simplexml_load_file(PATH_LIBRARIES."xml/items/".$this->findItemXML($item_id));
  271.     foreach($items as $item){
  272.       if($item_id == $item->attributes()->id){
  273.         $itemXML = $item;
  274.       }
  275.     }
  276.     return $itemXML;
  277.   }
  278.  
  279.   function getType($item){
  280.     return (string)$item->attributes()->type;
  281.   }
  282.  
  283.   function getName($item){
  284.     return (string)$item->attributes()->name;
  285.   }
  286.  
  287.   function getIcon($item){
  288.     $item = $item->xpath('set[@name="icon"]');
  289.     if(isset($item[0])){
  290.       return (string)str_replace("icon.","",$item[0]->attributes()->val);
  291.     }else{
  292.       return FALSE;
  293.     }
  294.   }
  295.  
  296.   function getStackable($item){
  297.     $item = $item->xpath('set[@name="is_stackable"]');
  298.  
  299.     if(!$item){
  300.       return FALSE;
  301.     }
  302.     return (bool)$item[0]->attributes()->val;
  303.   }
  304.  
  305.   function getEnchantable($item){
  306.     $item = $item->xpath('set[@name="enchant_enabled"]');
  307.     if(!$item)
  308.       return false;
  309.     return (bool)($item[0]->attributes()->val == 1);
  310.   }
  311.  
  312.   function getGrade($item){
  313.     $item = $item->xpath('set[@name="crystal_type"]');
  314.     if(!$item)
  315.       return "none";
  316.     return (string)$item[0]->attributes()->val;
  317.   }
  318.  
  319.   function add($itemXML,$item_id,$count,$enchant_level,$enchanted_set){
  320.     global $mysqlClientGameServer;
  321.     global $queryGame;
  322.     global $player;
  323.     global $telnet;
  324.     global $config;
  325.  
  326.     if($player['character']['online'] == 1){
  327.       return FALSE;
  328.     }
  329.     if($this->getStackable($itemXML) == 1){
  330.       $itemData = $mysqlClientGameServer->select($queryGame['selectPlayerItemData'],array($player['character']['id'],$item_id));
  331.       if($itemData){
  332.         $up1 = $mysqlClientGameServer->execute($queryGame['updatePlayerItemCount'],array($count,$itemData['object_id']));
  333.         if($up1){
  334.           return TRUE;
  335.         }else{
  336.           return FALSE;
  337.         }
  338.       }else{
  339.         $up2 = $mysqlClientGameServer->execute($queryGame['addItemToPlayerInventory'],array($player['character']['id'],$item_id,$count,$enchant_level,'INVENTORY'));
  340.         if($up2){
  341.           return TRUE;
  342.         }else{
  343.           return FALSE;
  344.         }
  345.       }
  346.     }else{
  347.       for($i = 1; $i <= $count; $i++){
  348.         $up3 = $mysqlClientGameServer->execute($queryGame['addItemToPlayerInventory'],array($player['character']['id'],$item_id,1,$enchant_level,'INVENTORY'));
  349.       }
  350.       if($up3){
  351.         return TRUE;
  352.       }else{
  353.         return FALSE;
  354.       }
  355.     }
  356.   }
  357.  
  358. }
  359.  
  360. $items = new items();
  361.  
  362. class telnet{
  363.  
  364.   function give($character,$id,$count){
  365.     $socket = fsockopen($config['mysqlHostname'],$config['telnetPort'],$errno,$errstr,30);
  366.     if($socket){
  367.       fputs($socket,$config['telnetPassword']);
  368.       fputs($socket,"\r\n");
  369.       fputs($socket,"give ".$character." ".$id." ".$count);
  370.       fputs($socket,"\r\n");
  371.       fputs($socket,"exit\r\n");
  372.       while(!feof($socket)){
  373.         $line = fgets($socket,2000);
  374.         if(strstr($line,"Player not found"))
  375.           return false;
  376.       }
  377.       fclose($socket);
  378.       return true;
  379.     }
  380.     return false;
  381.   }
  382.  
  383. }
  384.  
  385. $telnet = new telnet();
  386.  
  387. class credits{
  388.  
  389.   function increase($credits){
  390.     global $mysqlClientLoginServer;
  391.     global $queryLogin;
  392.     global $player;
  393.     if(!$mysqlClientLoginServer->execute("UPDATE `acp_players` SET `balance` = balance+? WHERE `account` = ?;",array($credits,$player['account'])))
  394.       exit("REFRESH");
  395.     return true;
  396.   }
  397.  
  398.   function reduce($credits){
  399.     global $mysqlClientLoginServer;
  400.     global $queryLogin;
  401.     global $player;
  402.     if($credits == 0){
  403.       return FALSE;
  404.     }
  405.     $reduz = $mysqlClientLoginServer->execute("UPDATE `acp_players` SET `balance` = balance-? WHERE `account` = ?;",array($credits,$player['account']));
  406.     if($reduz){
  407.       return TRUE;
  408.     }else{
  409.       return FALSE;
  410.     }
  411.   }
  412.  
  413. }
  414.  
  415. $credits = new credits();
  416. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement