Witam czy jest mozliwosc aby plik class.hlsocket.php odczytywał kto aktualnie gra na serwerze chodzi mi o nick gracza i liczbe fragów jezeli tak to jak to zrobic oto plik

  1. <?php
  2. /**
  3.  * File is released under GPL as can be found on
  4.  */
  5.  
  6. /* Info string */
  7. define('A2S_INFO', "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00");
  8.  
  9. /* Replies for HL Version 1 and Version 2 (aka Source) */
  10. define('REPLY_INFO_HL1', 'm');
  11. define('REPLY_INFO_HL2', 'I');
  12.  
  13. /* Definitions of the bytes */
  14. define('BYTE', 1);
  15. define('BYTE_NUM', BYTE + 1);
  16. define('SHORT', BYTE_NUM + 1);
  17. define('LONG', SHORT + 1);
  18. define('FLOAT', LONG + 1);
  19. define('STRING', FLOAT + 1);
  20.  
  21. /**
  22.  * The socket class
  23.  * @author Herwin Weststrate aka Hdez
  24.  * @contact hdez@counter-strike.nl
  25.  * @version 2005.10.21
  26.  */
  27. class HLSocket
  28. {
  29. /* The socket file descriptor */
  30. var $_socket;
  31.  
  32. /* The way to split the incoming data */
  33. var $_split_info_hl2 = array('type' => BYTE, 'bersion' => BYTE_NUM, 'hostname' => STRING, 'map' => STRING, 'gamedir' => STRING, 'gamedesc' => STRING, 'appid' => SHORT, 'unknown' => BYTE_NUM, 'players' => BYTE_NUM, 'max' => BYTE_NUM, 'bots' => BYTE_NUM, 'dedicated' => BYTE, 'os' => BYTE, 'passworded' => BYTE_NUM, 'secure' => BYTE_NUM, 'gameversion' => STRING);
  34. var $_split_info_hl1 = array('type' => BYTE, 'ip' => STRING, 'hostname' => STRING, 'map' => STRING, 'gamedir' => STRING, 'gamedesc' => STRING, 'players' => BYTE_NUM, 'max' => BYTE_NUM, 'version' => BYTE_NUM, 'dedicated' => BYTE, 'os' => BYTE, 'passworded' => BYTE_NUM, 'secure' => BYTE_NUM, 'gameversion' => STRING);
  35.  
  36. /**
  37. * Create a new socket
  38. * @param $host The ip or hostname
  39. * @param $port The port
  40. */
  41. function HLSocket($host, $port)
  42. {
  43. $this->connect($host, $port);
  44. }
  45.  
  46. /**
  47. * Actually make the connection to the host
  48. * @param $host The ip or hostname
  49. * @param $port The port
  50. */
  51. function connect($host, $port)
  52. {
  53. $this->_socket = @fsockopen('udp://'.$host, $port);
  54. if (!$this->_socket)
  55. echo 'Error met connecten';
  56. stream_set_timeout($this->_socket, 1); // Set timeout to 1 sec
  57. }
  58.  
  59. /**
  60. * Close the connection (and the socket fd)
  61. */
  62. function close()
  63. {
  64. fclose($this->_socket);
  65. }
  66.  
  67. /**
  68. * Query the server for the details
  69. * @return associative array with the game info
  70. */
  71. function details()
  72. {
  73. $this->write(A2S_INFO);
  74. $data = $this->read();
  75. $res = array();
  76. switch(substr($data, 0, 1))
  77. {
  78. case REPLY_INFO_HL1:
  79. $res = $this->split($this->_split_info_hl1, $data);
  80. break;
  81. case REPLY_INFO_HL2:
  82. $res = $this->split($this->_split_info_hl2, $data);
  83. break;
  84. }
  85. return $res;
  86. }
  87.  
  88. /**
  89. * Write the given message over the socket
  90. * @param $msg The message to be written
  91. * @deprecated This should be issued as a private function
  92. */
  93. function write($msg)
  94. {
  95. fwrite($this->_socket, $msg);
  96. }
  97.  
  98. /**
  99. * Read from the socket
  100. * @return The data from the socket (excluding the first four [useless] bytes)
  101. * @deprecated This should be issued as a private function
  102. */
  103. function read()
  104. {
  105. $data = fread($this->_socket, 1);
  106. $status = socket_get_status($this->_socket);
  107. if (isset($status['unread_bytes']) && $status['unread_bytes'] > 0)
  108. $data .= fread($this->_socket, $status['unread_bytes']);
  109. return substr($data, 4);
  110. }
  111.  
  112. /**
  113. * Split the given datatype from $data String and return the value
  114. * @param $type The data type [BYTE .. STRING]
  115. * @param $data The current data String
  116. * @return The value of the given data type from $data
  117. * @deprecated This should be issued as a private function
  118. */
  119. function splititem($type, &$data) {
  120. $add = '';
  121. switch ($type)
  122. {
  123. case BYTE:
  124. $add = substr($data, 0, 1);
  125. $data = substr($data, 1);
  126. break;
  127. case BYTE_NUM:
  128. $add = ord(substr($data, 0, 1));
  129. $data = substr($data, 1);
  130. break;
  131. case SHORT:
  132. $add = ord(substr($data, 0, 1));
  133. $data = substr($data, 1);
  134. break;
  135. case LONG:
  136. $add = ord(substr($data, 0, 1));
  137. $data = substr($data, 1);
  138. break;
  139. case STRING:
  140. do
  141. {
  142. $char = substr($data, 0, 1);
  143. if ($char != "\x00")
  144. $add .= $char;
  145. $data = substr($data, 1);
  146. }
  147. while ($char != "\x00");
  148. break;
  149. }
  150. return $add;
  151. }
  152.  
  153. /**
  154. * Split the given datatypes from $data String and return the value
  155. * @param $array The data type [BYTE .. STRING] as values of an
  156. * associative array. The keys are also the keys of
  157. * the return array
  158. * @param $data The current data String
  159. * @return Associative array with keys of $array and values read from $data
  160. * @deprecated This should be issued as a private function
  161. */
  162. function split($array, $data)
  163. {
  164. $res = array();
  165. foreach ($array as $k=>$v)
  166. $res[$k] = $this->splititem($v, $data);
  167. return $res;
  168. }
  169. }
  170. ?>