Guest User

Untitled

a guest
May 13th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. set_time_limit(0);
  4. ob_implicit_flush();
  5. $ip = "127.0.0.1";
  6. $port = 6112;
  7. $server = new Server($ip, $port);
  8. while(true)
  9. {
  10. $server->loopFunction();
  11. }
  12. class Server
  13. {
  14.  
  15. public function __construct($ip, $port)
  16. {
  17. $this->header("Login");
  18. $this->write_socket($ip, $port);
  19. }
  20. public function header($type)
  21. {
  22. echo "\n\n ///////////////////////////////////////////\n";
  23. echo " //---------------------------------------//\n";
  24. echo " // Server ------------------- By Prime --//\n";
  25. echo " //---------------------------------------//\n";
  26. echo " ///////////////////////////////////////////\n\n";
  27. }
  28. public function write_socket($ip, $port)
  29. {
  30. if (($this->master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
  31. {
  32. $this->writeOutput("socket_create() failed, reason: " . socket_strerror($this->master) );
  33. }
  34. socket_set_option($this->master, SOL_SOCKET,SO_REUSEADDR, 1);
  35. if (($ret = socket_bind($this->master, $ip, $port)) < 0)
  36. {
  37. $this->writeOutput("socket_bind() failed, reason: " . socket_strerror($ret) );
  38. }
  39. if (($ret = socket_listen($this->master, 5)) < 0)
  40. {
  41. $this->writeOutput("socket_listen() failed, reason: " . socket_strerror($ret));
  42. }
  43. $this->readSockets = array($this->master);
  44. }
  45. public function loopFunction()
  46. {
  47. $changed_sockets = $this->readSockets;
  48. $num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL);
  49. foreach($changed_sockets as $socket)
  50. {
  51. if ($socket == $this->master)
  52. {
  53. if (($client = socket_accept($this->master)) < 0)
  54. {
  55. $this->writeOutput( "socket_accept() failed: reason: " . socket_strerror($msgsock));
  56. continue;
  57. } else {
  58. array_push($this->readSockets, $client);
  59. }
  60. } else {
  61. $bytes = socket_recv($socket, $buffer, 2048, 0);
  62. $this->writeOutput($bytes);
  63. if ($bytes == 0)
  64. {
  65. $index = array_search($socket, $this->readSockets);
  66. unset($this->readSockets[$index]);
  67. socket_close($socket);
  68. }else{
  69. $allclients = $this->readSockets;
  70. array_shift($allclients);
  71. $this->commands($allclients, $socket, $buffer);
  72. }
  73. }
  74. }
  75. }
  76. public function db_connect()
  77. {
  78. mysql_connect("localhost", "root", "server_password");
  79. mysql_Select_db("trobots");
  80. }
  81. public function commands($allclient, $socket, $buf)
  82. {
  83. $xt = explode("%", $buf);
  84. if($xt[0] == "l")
  85. {
  86. $this->db_connect();
  87. $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]) ."'");
  88. $count = mysql_num_rows($sql);
  89. if($count == 1)
  90. {
  91. foreach($allclient as $client)
  92. {
  93. $this->writeOutput($client . " l%" . $xt[1] . "%" . hash("sha512", hash("gost", $xt[2])) . "%" . "w");
  94. socket_write($client, "l%" . $xt[1] . "%" . hash("sha512", hash("gost", $xt[2])) . "%" . "w%" . chr(0));
  95. }
  96. }else{
  97. foreach($allclient as $client)
  98. {
  99. $this->writeOutput($client . " l%" . $xt[1] . "%" . hash("sha512", hash("gost", $xt[2])) . "%" . "w");
  100. socket_write($client, "l%" . $xt[1] . "%" . hash("sha512", hash("gost", $xt[2])) . "%" . "f" . chr(0));
  101. }
  102. }
  103. }
  104. }
  105. public function writeOutput($msg)
  106. {
  107. echo " " . date("l, F jS Y - H:i:s") . " " . $msg . "\n";
  108. }
  109. }
  110. ?>
Add Comment
Please, Sign In to add comment