Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Steam
- {
- protected $STEAM_API = "";
- public function ConvertID($steamId)
- {
- $iServer = "0";
- $iAuthID = "0";
- $szTmp = strtok(trim($steamId), ":");
- while(($szTmp = strtok(":")) !== false)
- {
- $szTmp2 = strtok(":");
- if($szTmp2 !== false)
- {
- $iServer = $szTmp;
- $iAuthID = $szTmp2;
- }
- }
- if($iAuthID == "0")
- {
- return false;
- }
- $steamId64 = bcmul($iAuthID, "2");
- $steamId64 = bcadd($steamId64, bcadd("76561197960265728", $iServer));
- return $steamId64;
- }
- public function is_valid_steamid($steamId)
- {
- if(empty($this->STEAM_API))
- {
- return true;
- }
- $s = $this->ConvertID(trim($steamId));
- if($s == flase)
- {
- return false;
- }
- $url = "https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=".$this->STEAM_API."&format=json&steamids=".$s;
- $json = json_decode(file_get_contents($url));
- if(sizeof($json->response->players) == 0)
- {
- return false;
- }
- return true;
- }
- }
- Class database extends Steam
- {
- protected $mysqli;
- protected $HOST = "127.0.0.1";
- protected $USER = "amxbans";
- protected $PASS = "amxbans";
- protected $DB = "amxbans";
- protected $TABLA_BANEOS = "amx_bans";
- protected $TABLA_ADMINS = "amx_admins";
- protected $TABLA_SERVERS = "amx_servers";
- protected $TABLA_SERVERADMINS = "amx_serveradmins";
- protected $TABLA_USERS = "amx_webusers";
- public function init()
- {
- $this->mysqli = new mysqli($this->HOST, $this->USER, $this->PASS, $this->DB);
- if($this->mysqli->connect_errno)
- {
- die($this->mysqli->connect_error);
- }
- }
- public function close()
- {
- $this->mysqli->close();
- }
- public function get_bans($start, $max)
- {
- $s = $this->mysqli->real_escape_string(trim($start));
- $m = $this->mysqli->real_escape_string(trim($max));
- $r = $this->mysqli->query("SELECT * FROM $this->TABLA_BANEOS LIMIT $s, $m");
- if($r == false)
- {
- die($this->mysqli->error);
- }
- $array = array();
- while($row = $r->fetch_assoc())
- {
- $row['fecha'] = date('d/m/y', $row['inicio']);
- $row['steamid64'] = $this->ConvertID($row['steamid']);
- $row['inicio2'] = date("d/m/Y - H:i:s", $row['inicio']);
- $array[] = $row;
- }
- return $array;
- }
- public function get_bans_pages($bans_per_page)
- {
- $r = $this->mysqli->query("SELECT * FROM $this->TABLA_BANEOS");
- if($r == false)
- {
- die($this->mysqli->error);
- }
- $num = $r->num_rows;
- return intval($num / $bans_per_page);
- }
- public function find_ban($type, $key)
- {
- $t = $this->mysqli->real_escape_string(trim($type));
- $k = $this->mysqli->real_escape_string(trim($key));
- $r = $this->mysqli->query("SELECT * FROM $this->TABLA_BANEOS WHERE $t='$k'");
- if($r == false)
- {
- die($this->mysqli->error);
- }
- if($r->num_rows > 0)
- {
- $row = $r->fetch_assoc();
- return $row['id'];
- }
- return false;
- }
- public function get_ban_stats($banid)
- {
- $escaped = $this->mysqli->real_escape_string(trim($banid));
- $r = $this->mysqli->query("SELECT * FROM $this->TABLA_BANEOS WHERE id='$escaped'");
- if($r == false)
- {
- die($this->mysqli->error);
- }
- if($r->num_rows < 1)
- {
- return false;
- }
- return $r->fetch_assoc();
- }
- public function delelte_ban($baind)
- {
- $escaped = $this->mysqli->real_escape_string(trim($banid));
- $r = $this->mysqli->query("DELETE FROM $this->TABLA_BANEOS WHERE id='$escaped'");
- if($r == false)
- {
- die($this->mysqli->error);
- }
- return true;
- }
- public function insert_admin($authd, $pass, $access, $flags)
- {
- $array = array(
- $this->mysqli->real_escape_string(trim($authd)),
- $this->mysqli->real_escape_string(trim($pass)),
- $this->mysqli->real_escape_string(trim($access)),
- $this->mysqli->real_escape_string(trim($flags))
- );
- $r = $this->mysqli->query("INSERT INTO $this->TABLA_ADMINS ( auth, password, access, flags ) VALUES ( '$array[0]', '$array[1]', '$array[2]', '$array[3]' )");
- if($r == false)
- {
- die($this->mysqli->error);
- }
- if($this->mysqli->affected_rows > 0)
- {
- return true;
- }
- return false;
- }
- public function delete_admin($adminid)
- {
- $escaped = $this->mysqli->real_escape_string(trim($adminid));
- $r = $this->mysqli->query("DELETE FROM $this->TABLA_ADMINS WHERE id='$escaped'");
- if(1062 != $this->mysqli->errno)
- {
- if($r == false)
- {
- die($this->mysqli->error);
- }
- if($this->mysqli->affected_rows > 0)
- {
- return true;
- }
- }
- return false;
- }
- public function insert_server($ip, $port, $name='')
- {
- $array = array(
- $this->mysqli->real_escape_string(trim($ip)),
- $this->mysqli->real_escape_string(trim($port)),
- $this->mysqli->real_escape_string(trim($name))
- );
- $r = $this->mysqli->query("INSERT INTO $this->TABLA_SERVERS ( ip , name) VALUES ( '$array[0]:$array[1]', '$array[2]')");
- if(1062 != $this->mysqli->errno)
- {
- if($r == false)
- {
- die($this->mysqli->error);
- }
- if($this->mysqli->affected_rows > 0)
- {
- return true;
- }
- }
- return false;
- }
- public function insert_user($user, $pass, $email, $level)
- {
- $array = array(
- $this->mysqli->real_escape_string(trim($user)),
- md5($pass),
- $this->mysqli->real_escape_string(trim($email)),
- $this->mysqli->real_escape_string(trim($level))
- );
- $r = $this->mysqli->query("INSERT INTO $this->TABLA_USERS (id,user,pass,level,email) VALUES ( '$array[0]', '$array[1]', '$array[2]', '$array[3]' )");
- if(1062 != $this->mysqli->errno)
- {
- if($r == false)
- {
- die($this->mysqli->error);
- }
- if($this->mysqli->affected_rows > 0)
- {
- return true;
- }
- }
- return false;
- }
- public function login($user,$pass)
- {
- $u = $this->mysqli->real_escape_string(trim($user));
- $p = md5(trim($pass));
- $r = $this->mysqli->query("SELECT * FROM $this->TABLA_USERS WHERE user='$u' AND pass='$p'");
- if($r == false)
- {
- die($this->mysqli->error);
- }
- if($r->num_rows == 1)
- {
- return $r->fetch_assoc();
- }
- return false;
- }
- public function delete_user($userid)
- {
- $u = $this->mysqli->real_escape_string(trim($userid));
- $r = $this->mysqli->query("DELETE FROM $this->TABLA_USERS WHERE id='$u'");
- if(1062 != $this->mysqli->errno)
- {
- if($r == false)
- {
- die($this->mysqli->error);
- }
- if($this->mysqli->affected_rows > 0)
- {
- return true;
- }
- }
- return false;
- }
- public function getTimeFromNTP($host = 'pool.ntp.org', $timeout = 5)
- {
- $socket = stream_socket_client('udp://' . $host . ':123', $errno, $errstr, (int)$timeout);
- if($errno)
- {
- $e = explode(".", $host);
- if(is_numeric($e[0]))
- {
- $p = intval($e[0]) + 1 . '.pool.ntp.org';
- return $this->getTimeFromNTP($p);
- }
- else
- {
- return $this->getTimeFromNTP('0.pool.ntp.org');
- }
- }
- $msg = "\010" . str_repeat("\0", 47);
- fwrite($socket, $msg);
- $response = fread($socket, 48);
- fclose($socket);
- $data = unpack('N12', $response);
- $timestamp = sprintf('%u', $data[9]);
- $timestamp -= 2208988800;
- return $timestamp;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement