Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- set_time_limit(0);
- ob_implicit_flush();
- $ip = "127.0.0.1";
- $port = 6112;
- $server = new Server($ip, $port);
- while(true)
- {
- $server->loopFunction();
- }
- class Server
- {
- public function __construct($ip, $port)
- {
- $this->header("Login");
- $this->write_socket($ip, $port);
- }
- public function header($type)
- {
- echo "\n\n ///////////////////////////////////////////\n";
- echo " //---------------------------------------//\n";
- echo " // Server ------------------- By Prime --//\n";
- echo " //---------------------------------------//\n";
- echo " ///////////////////////////////////////////\n\n";
- }
- public function write_socket($ip, $port)
- {
- if (($this->master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
- {
- $this->writeOutput("socket_create() failed, reason: " . socket_strerror($this->master) );
- }
- socket_set_option($this->master, SOL_SOCKET,SO_REUSEADDR, 1);
- if (($ret = socket_bind($this->master, $ip, $port)) < 0)
- {
- $this->writeOutput("socket_bind() failed, reason: " . socket_strerror($ret) );
- }
- if (($ret = socket_listen($this->master, 5)) < 0)
- {
- $this->writeOutput("socket_listen() failed, reason: " . socket_strerror($ret));
- }
- $this->readSockets = array($this->master);
- }
- public function loopFunction()
- {
- $changed_sockets = $this->readSockets;
- $num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL);
- foreach($changed_sockets as $socket)
- {
- if ($socket == $this->master)
- {
- if (($client = socket_accept($this->master)) < 0)
- {
- $this->writeOutput( "socket_accept() failed: reason: " . socket_strerror($msgsock));
- continue;
- } else {
- array_push($this->readSockets, $client);
- }
- } else {
- $bytes = socket_recv($socket, $buffer, 2048, 0);
- $this->writeOutput($bytes);
- if ($bytes == 0)
- {
- $index = array_search($socket, $this->readSockets);
- unset($this->readSockets[$index]);
- socket_close($socket);
- }else{
- $allclients = $this->readSockets;
- array_shift($allclients);
- $this->commands($allclients, $socket, $buffer);
- }
- }
- }
- }
- public function db_connect()
- {
- mysql_connect("localhost", "root", "server_password");
- mysql_Select_db("trobots");
- }
- public function commands($allclient, $socket, $buf)
- {
- $xt = explode("%", $buf);
- if($xt[0] == "l")
- {
- $this->db_connect();
- $sql = mysql_query("SELECT * FROM users WHERE username='" . $xt[1] . "' AND password='" . hash("sha512", hash("gost", $xt[2])) . "' AND login_key='". hash("crc32b", $xt[1]) ."'");
- $count = mysql_num_rows($sql);
- if($count == 1)
- {
- foreach($allclient as $client)
- {
- $this->writeOutput($client . " l%" . $xt[1] . "%" . hash("sha512", hash("gost", $xt[2])) . "%" . "w");
- socket_write($client, "l%" . $xt[1] . "%" . hash("sha512", hash("gost", $xt[2])) . "%" . "w%" . chr(0));
- }
- }else{
- foreach($allclient as $client)
- {
- $this->writeOutput($client . " l%" . $xt[1] . "%" . hash("sha512", hash("gost", $xt[2])) . "%" . "w");
- socket_write($client, "l%" . $xt[1] . "%" . hash("sha512", hash("gost", $xt[2])) . "%" . "f" . chr(0));
- }
- }
- }
- }
- public function writeOutput($msg)
- {
- echo " " . date("l, F jS Y - H:i:s") . " " . $msg . "\n";
- }
- }
- ?>
Add Comment
Please, Sign In to add comment