cvs: pear /Net_GameServerQuery Config.php GameServerQuery.php Games.xml Socket.php

From: Date: Thu, 01 Jul 2004 14:26:24 +0000
Subject: cvs: pear /Net_GameServerQuery Config.php GameServerQuery.php Games.xml Socket.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-21356@lists.php.net to get a copy of this message
aidan Thu Jul 1 10:26:24 2004 EDT Removed files: /pear/Net_GameServerQuery Games.xml Modified files: /pear/Net_GameServerQuery Config.php GameServerQuery.php Socket.php Log: Switched to new Config getting method http://cvs.php.net/diff.php/pear/Net_GameServerQuery/Config.php?r1=1.2&r2=1.3&ty=u Index: pear/Net_GameServerQuery/Config.php diff -u pear/Net_GameServerQuery/Config.php:1.2 pear/Net_GameServerQuery/Config.php:1.3 --- pear/Net_GameServerQuery/Config.php:1.2 Thu Jul 1 08:08:55 2004 +++ pear/Net_GameServerQuery/Config.php Thu Jul 1 10:26:24 2004 @@ -1,24 +1,36 @@ <?php - /** * Get protocol config options + * + * This needs a more relevant name + * + * @category Net + * @package Net_GameServerQuery_Config + * @author Aidan Lister <aidan@php.net> + * @version $Revision: 1.3 $ */ class Net_GameServerQuery_Config { /** - * A list of all protocol information + * An array of all protocol information * * @var array */ private static $_protocol; /** - * A list of all game information + * An array of all game information * * @var array */ - private static $_game; - + private static $_game; + + + /** + * Constructor + * + * Load the protocol and games information file + */ public function __construct() { // Load the protocol config @@ -51,13 +63,27 @@ return $packet; } + + /** + * Return protocol used by a certain game + * + * @return string The game used + * @param string $game The game + */ public function getprotocol($game) { return $this->_game[$game]; } - public function getdefaultport($protocol) + + /** + * Return default query port used by a certain game + * + * @return string The default query port used + * @param string $game The game + */ + public function getdefaultqueryport($game) { return $this->_protocol[$protocol]['queryport']; http://cvs.php.net/diff.php/pear/Net_GameServerQuery/GameServerQuery.php?r1=1.6&r2=1.7&ty=u Index: pear/Net_GameServerQuery/GameServerQuery.php diff -u pear/Net_GameServerQuery/GameServerQuery.php:1.6 pear/Net_GameServerQuery/GameServerQuery.php:1.7 --- pear/Net_GameServerQuery/GameServerQuery.php:1.6 Thu Jul 1 08:10:07 2004 +++ pear/Net_GameServerQuery/GameServerQuery.php Thu Jul 1 10:26:24 2004 @@ -16,7 +16,7 @@ // | Authors: Aidan Lister <aidan@php.net> | // +----------------------------------------------------------------------+ // -// $Id: GameServerQuery.php,v 1.6 2004/07/01 12:10:07 aidan Exp $ +// $Id: GameServerQuery.php,v 1.7 2004/07/01 14:26:24 aidan Exp $ require_once 'Config.php'; @@ -29,7 +29,7 @@ * @category Net * @package Net_GameServerQuery * @author Aidan Lister <aidan@php.net> - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ class Net_GameServerQuery { @@ -54,20 +54,30 @@ */ private $_config; + /** + * An instance of the Net_GameServerQuery_Socket class + * + * @var object + */ + private $_socket; + /** * Constructor */ - public function __construct () + public function __construct() { // Initialise counter $this->_counter = -1; - // Load the config class + // Load the config class (this could probably be called something more specific) $this->_config = new Net_GameServerQuery_Config; + + // Load the socket class (this needs a new name) + $this->_socket = new Net_GameServerQuery_Socket; } - + /** * Add a server * @@ -77,7 +87,7 @@ * @param string $status A pipe delimited string of query types * @return int The counter */ - public function addServer ($game, $ip, $port = null, $query = 'status') + public function addServer($game, $ip, $port = null, $query = 'status') { // Incriment the counter ++$this->_counter; @@ -113,13 +123,12 @@ * @param int $timeout The timeout in milliseconds * @return array An array of server information */ - public function execute ($timeout = 300) + public function execute($timeout = 60) { // Timeout in millseconds $timeout = $timeout * 1000; - $socket = new Net_GameServerQuery_Socket; - $result = $socket->go($this->_servers, $timeout); + $result = $this->_socket->batchquery($this->_servers, $timeout); return $result; } http://cvs.php.net/diff.php/pear/Net_GameServerQuery/Socket.php?r1=1.4&r2=1.5&ty=u Index: pear/Net_GameServerQuery/Socket.php diff -u pear/Net_GameServerQuery/Socket.php:1.4 pear/Net_GameServerQuery/Socket.php:1.5 --- pear/Net_GameServerQuery/Socket.php:1.4 Thu Jul 1 08:09:51 2004 +++ pear/Net_GameServerQuery/Socket.php Thu Jul 1 10:26:24 2004 @@ -14,13 +14,11 @@ /** * Do the whole lot */ - public function go ($servers, $timeout) + public function batchquery($servers, $timeout) { - $this->_servers = $servers; - - $this->open($this->_servers); - $result = $this->listen($timeout); - $this->close(); + list($sockets, $sockets_list) = $this->open($servers); + $result = $this->listen($sockets, $sockets_list, $timeout); + $this->close($sockets); return $result; } @@ -29,15 +27,15 @@ /** * Open */ - public function open ($servers) + public function open($servers) { - $sockets = array (); - $sockets_list = array (); + $sockets = array(); + $sockets_list = array(); foreach ($servers as $key => $server) { // Open each socket - $ip = "udp://" . $server['ip']; + $ip = "udp://" . $server['ip']; $socket = @fsockopen($ip, $server['port'], $errno, $errstr, 1); if ($socket !== false) { @@ -53,45 +51,42 @@ } } - $this->_sockets = $sockets; - $this->_sockets_list = $sockets_list; - - return true; + return array($sockets, $sockets_list); } /** * Write */ - public function write ($socket, $packet) + public function write($socket, $packet) { - fwrite($socket, $packet); + return fwrite($socket, $packet); } /** * Listen */ - public function listen ($timeout) + public function listen($sockets, $sockets_list, $timeout) { - // Listen to sockets - $result = array (); + $result = array(); $starttime = microtime(true); - $r = $this->_sockets; - + $r = $sockets; + // If we have no sockets don't bother - if (empty($this->_sockets)) { - return array (); + if (empty($sockets)) { + return array(); } - while (stream_select($r, $w = null, $e = null, 0, $timeout - ((microtime(true) - $starttime) * 1000000)) !== 0) + // Listen to sockets + while (stream_select($r, $w = null, $e = null, 0, $timeout - ((microtime(true) - $starttime) * 1000000)) !== 0) { foreach ($r as $socket) { $response = fread($socket, 2048); - $result[$this->_sockets_list[$socket]][] = $response; + $result[$sockets_list[$socket]][] = $response; } - $r = $this->_sockets; + $r = $sockets; } return $result; @@ -101,9 +96,9 @@ /** * Close */ - public function close () + public function close($sockets) { - foreach ($this->_sockets as $socket) { + foreach ($sockets as $socket) { fclose($socket); } }

« previous php.pear.cvs (#21356) next »