_ip = $ip; $this->_port = $port; $this->_timeout = $phpUA["CONFIG"]["TIMEOUT"]; $this->_interval = $phpUA["CONFIG"]["INTERVAL"]; } function connect() // Connects to the Metamod Plug-in. { if (!$this->_socket = fsockopen($this->_ip, $this->_port, $errno, $errstr, $this->_timeout)) return false; if (!$this->_writeData("SET_REFRESH " . $this->_interval)) return false; return true; } function disconnect() // Disconnects from the Metamod Plug-in. { if (!fclose($this->_socket)) return false; return true; } function _writeData($data) // Sends a packet of data to the Metamod Plug-in. { if (!fwrite($this->_socket, $data . "\n")) return false; return true; } function _readLine() // Reads just one line of data from the Metamod Plug-in. { socket_set_timeout($this->_socket, $this->_timeout + $this->_interval); $line = trim(fgets($this->_socket, 1024), " \t\n\r\0"); if (socket_timeout($this->_socket)) return NULL; return $line; } function getServer() // Wait until we receive a packet of TYPE GET_SERVER and return it. { startBenchmark(__FILE__, __FUNCTION__); if (!$this->_writeData("GET_SERVER")); if (is_null($data = $this->getPacket())) return false; while ($data["TYPE"] != "SERVER") { if (is_null($data = $this->getPacket())) return false; } $array = array(); $array["TYPE"] = "SERVER"; $array["SERVER"] = $data["SERVER"]; endBenchmark(__FILE__, __FUNCTION__); return $array; } function getPacket() // Returns a single TYPE message. PLAYER data is sorted by TEAM then KILLS then DEATHS. { startBenchmark(__FILE__, __FUNCTION__); global $phpUA; if (is_null($header = $this->_readLine())) return NULL; $columns = explode("\t", $header); $type = $columns[1]; $data["TYPE"] = $type; if (is_null($line = $this->_readLine())) return NULL; while (!empty($line)) { $columns = explode("\t", $line); for ($i=1; $i_readLine())) return NULL; } if (($type == "PLAYER") && (!empty($data["PLAYER"]))) { for ($i=0; $i