Advertisement
Sugisaki

AMX BANS CLASS

Nov 29th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.98 KB | None | 0 0
  1. <?php
  2. class Steam
  3. {
  4.     protected $STEAM_API = "";
  5.  
  6.     public function ConvertID($steamId)
  7.     {
  8.         $iServer = "0";
  9.         $iAuthID = "0";
  10.  
  11.         $szTmp = strtok(trim($steamId), ":");
  12.  
  13.         while(($szTmp = strtok(":")) !== false)
  14.         {
  15.             $szTmp2 = strtok(":");
  16.             if($szTmp2 !== false)
  17.             {
  18.                 $iServer = $szTmp;
  19.                 $iAuthID = $szTmp2;
  20.             }
  21.         }
  22.         if($iAuthID == "0")
  23.         {
  24.             return false;
  25.         }
  26.  
  27.         $steamId64 = bcmul($iAuthID, "2");
  28.         $steamId64 = bcadd($steamId64, bcadd("76561197960265728", $iServer));  
  29.  
  30.         return $steamId64;
  31.     }
  32.     public function is_valid_steamid($steamId)
  33.     {
  34.         if(empty($this->STEAM_API))
  35.         {
  36.             return true;
  37.         }
  38.         $s = $this->ConvertID(trim($steamId));
  39.         if($s == flase)
  40.         {
  41.             return false;
  42.         }
  43.         $url = "https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=".$this->STEAM_API."&format=json&steamids=".$s;
  44.         $json = json_decode(file_get_contents($url));
  45.         if(sizeof($json->response->players) == 0)
  46.         {
  47.             return false;
  48.         }
  49.         return true;
  50.     }
  51. }
  52. Class database extends Steam
  53. {
  54.     protected $mysqli;
  55.     protected $HOST = "127.0.0.1";
  56.     protected $USER = "amxbans";
  57.     protected $PASS = "amxbans";
  58.     protected $DB = "amxbans";
  59.  
  60.     protected $TABLA_BANEOS = "amx_bans";
  61.     protected $TABLA_ADMINS = "amx_admins";
  62.     protected $TABLA_SERVERS = "amx_servers";
  63.     protected $TABLA_SERVERADMINS = "amx_serveradmins";
  64.     protected $TABLA_USERS = "amx_webusers";
  65.    
  66.     public function init()
  67.     {
  68.         $this->mysqli = new mysqli($this->HOST, $this->USER, $this->PASS, $this->DB);
  69.         if($this->mysqli->connect_errno)
  70.         {
  71.             die($this->mysqli->connect_error);
  72.         }
  73.     }
  74.     public function close()
  75.     {
  76.         $this->mysqli->close();
  77.     }
  78.     public function get_bans($start, $max)
  79.     {
  80.         $s = $this->mysqli->real_escape_string(trim($start));
  81.         $m = $this->mysqli->real_escape_string(trim($max));
  82.         $r = $this->mysqli->query("SELECT * FROM $this->TABLA_BANEOS LIMIT $s, $m");
  83.         if($r == false)
  84.         {
  85.             die($this->mysqli->error);
  86.         }
  87.         $array = array();
  88.         while($row = $r->fetch_assoc())
  89.         {
  90.             $row['fecha'] = date('d/m/y', $row['inicio']);
  91.             $row['steamid64'] = $this->ConvertID($row['steamid']);
  92.             $row['inicio2'] = date("d/m/Y - H:i:s", $row['inicio']);
  93.             $array[] = $row;
  94.         }
  95.         return $array;
  96.     }
  97.     public function get_bans_pages($bans_per_page)
  98.     {
  99.         $r = $this->mysqli->query("SELECT * FROM $this->TABLA_BANEOS");
  100.         if($r == false)
  101.         {
  102.             die($this->mysqli->error);
  103.         }
  104.         $num = $r->num_rows;
  105.         return intval($num / $bans_per_page);
  106.     }
  107.     public function find_ban($type, $key)
  108.     {
  109.         $t = $this->mysqli->real_escape_string(trim($type));
  110.         $k = $this->mysqli->real_escape_string(trim($key));
  111.  
  112.         $r = $this->mysqli->query("SELECT * FROM $this->TABLA_BANEOS WHERE $t='$k'");
  113.         if($r == false)
  114.         {
  115.             die($this->mysqli->error);
  116.         }
  117.         if($r->num_rows > 0)
  118.         {
  119.             $row = $r->fetch_assoc();
  120.             return $row['id'];
  121.         }
  122.         return false;
  123.     }
  124.     public function get_ban_stats($banid)
  125.     {
  126.         $escaped = $this->mysqli->real_escape_string(trim($banid));
  127.         $r = $this->mysqli->query("SELECT * FROM $this->TABLA_BANEOS WHERE id='$escaped'");
  128.         if($r == false)
  129.         {
  130.             die($this->mysqli->error);
  131.         }
  132.         if($r->num_rows < 1)
  133.         {
  134.             return false;
  135.         }
  136.         return $r->fetch_assoc();
  137.     }
  138.     public function delelte_ban($baind)
  139.     {
  140.         $escaped = $this->mysqli->real_escape_string(trim($banid));
  141.         $r = $this->mysqli->query("DELETE FROM $this->TABLA_BANEOS WHERE id='$escaped'");
  142.         if($r == false)
  143.         {
  144.             die($this->mysqli->error);
  145.         }
  146.         return true;
  147.     }
  148.     public function insert_admin($authd, $pass, $access, $flags)
  149.     {
  150.         $array = array(
  151.             $this->mysqli->real_escape_string(trim($authd)),
  152.             $this->mysqli->real_escape_string(trim($pass)),
  153.             $this->mysqli->real_escape_string(trim($access)),
  154.             $this->mysqli->real_escape_string(trim($flags))
  155.         );
  156.         $r = $this->mysqli->query("INSERT INTO $this->TABLA_ADMINS ( auth, password, access, flags ) VALUES ( '$array[0]', '$array[1]', '$array[2]', '$array[3]' )");
  157.         if($r == false)
  158.         {
  159.             die($this->mysqli->error);
  160.         }
  161.         if($this->mysqli->affected_rows > 0)
  162.         {
  163.             return true;
  164.         }
  165.         return false;
  166.     }
  167.     public function delete_admin($adminid)
  168.     {
  169.         $escaped = $this->mysqli->real_escape_string(trim($adminid));
  170.         $r = $this->mysqli->query("DELETE FROM $this->TABLA_ADMINS WHERE id='$escaped'");
  171.         if(1062 != $this->mysqli->errno)
  172.         {
  173.             if($r == false)
  174.             {
  175.                 die($this->mysqli->error);
  176.             }
  177.             if($this->mysqli->affected_rows > 0)
  178.             {
  179.                 return true;
  180.             }
  181.         }
  182.         return false;
  183.     }
  184.     public function insert_server($ip, $port, $name='')
  185.     {
  186.         $array = array(
  187.             $this->mysqli->real_escape_string(trim($ip)),
  188.             $this->mysqli->real_escape_string(trim($port)),
  189.             $this->mysqli->real_escape_string(trim($name))
  190.         );
  191.         $r = $this->mysqli->query("INSERT INTO $this->TABLA_SERVERS ( ip , name) VALUES ( '$array[0]:$array[1]', '$array[2]')");
  192.         if(1062 != $this->mysqli->errno)
  193.         {
  194.             if($r == false)
  195.             {
  196.                 die($this->mysqli->error);
  197.             }
  198.             if($this->mysqli->affected_rows > 0)
  199.             {
  200.                 return true;
  201.             }
  202.         }
  203.         return false;
  204.     }
  205.     public function insert_user($user, $pass, $email, $level)
  206.     {
  207.         $array = array(
  208.             $this->mysqli->real_escape_string(trim($user)),
  209.             md5($pass),
  210.             $this->mysqli->real_escape_string(trim($email)),
  211.             $this->mysqli->real_escape_string(trim($level))
  212.         );
  213.         $r = $this->mysqli->query("INSERT INTO $this->TABLA_USERS (id,user,pass,level,email) VALUES ( '$array[0]', '$array[1]', '$array[2]', '$array[3]' )");
  214.         if(1062 != $this->mysqli->errno)
  215.         {
  216.             if($r == false)
  217.             {
  218.                 die($this->mysqli->error);
  219.             }
  220.             if($this->mysqli->affected_rows > 0)
  221.             {
  222.                 return true;
  223.             }
  224.         }
  225.         return false;
  226.     }
  227.     public function login($user,$pass)
  228.     {
  229.         $u = $this->mysqli->real_escape_string(trim($user));
  230.         $p = md5(trim($pass));
  231.         $r = $this->mysqli->query("SELECT * FROM $this->TABLA_USERS WHERE user='$u' AND pass='$p'");
  232.         if($r == false)
  233.         {
  234.             die($this->mysqli->error);
  235.         }
  236.         if($r->num_rows == 1)
  237.         {
  238.             return $r->fetch_assoc();
  239.         }
  240.         return false;
  241.     }
  242.     public function delete_user($userid)
  243.     {
  244.         $u = $this->mysqli->real_escape_string(trim($userid));
  245.         $r = $this->mysqli->query("DELETE FROM $this->TABLA_USERS WHERE id='$u'");
  246.         if(1062 != $this->mysqli->errno)
  247.         {
  248.             if($r == false)
  249.             {
  250.                 die($this->mysqli->error);
  251.             }
  252.             if($this->mysqli->affected_rows > 0)
  253.             {
  254.                 return true;
  255.             }
  256.         }
  257.         return false;
  258.     }
  259.     public function getTimeFromNTP($host = 'pool.ntp.org', $timeout = 5)
  260.     {
  261.         $socket = stream_socket_client('udp://' . $host . ':123', $errno, $errstr, (int)$timeout);
  262.         if($errno)
  263.         {
  264.             $e = explode(".", $host);
  265.             if(is_numeric($e[0]))
  266.             {
  267.                 $p = intval($e[0]) + 1 . '.pool.ntp.org';
  268.                 return $this->getTimeFromNTP($p);
  269.             }
  270.             else
  271.             {
  272.                 return $this->getTimeFromNTP('0.pool.ntp.org');
  273.             }
  274.         }
  275.         $msg = "\010" . str_repeat("\0", 47);
  276.         fwrite($socket, $msg);
  277.         $response = fread($socket, 48);
  278.         fclose($socket);
  279.         $data = unpack('N12', $response);
  280.         $timestamp = sprintf('%u', $data[9]);
  281.         $timestamp -= 2208988800;
  282.         return $timestamp;
  283.     }
  284.  
  285. }
  286. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement