cvs: pear /Net_GameServerQuery GameServerQuery.php
| From: | Aidan Lister | Date: | Mon, 26 Apr 2004 08:15:48 +0000 |
| Subject: | cvs: pear /Net_GameServerQuery GameServerQuery.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-18747@lists.php.net to get a copy of this message | ||
aidan Mon Apr 26 04:15:48 2004 EDT
Modified files:
/pear/Net_GameServerQuery GameServerQuery.php
Log:
Fixed misc. things, replaced tabs with spaces, changed syntax for require.
http://cvs.php.net/diff.php/pear/Net_GameServerQuery/GameServerQuery.php?r1=1.1&r2=1.2&ty=u
Index: pear/Net_GameServerQuery/GameServerQuery.php
diff -u pear/Net_GameServerQuery/GameServerQuery.php:1.1
pear/Net_GameServerQuery/GameServerQuery.php:1.2
--- pear/Net_GameServerQuery/GameServerQuery.php:1.1 Sun Apr 25 06:08:27 2004
+++ pear/Net_GameServerQuery/GameServerQuery.php Mon Apr 26 04:15:47 2004
@@ -14,14 +14,17 @@
// +----------------------------------------------------------------------+
// | Author: Aidan Lister <aidan@virtualexplorer.com.au> |
// +----------------------------------------------------------------------+
+//
+// $id$
+// $revision$
-require_once ('PEAR.php');
+require_once 'PEAR.php';
/**
* Error Constants
*/
-define('NET_GAMESERVERQUERY_ERROR_INVALIDGAME', 0);
-define('NET_GAMESERVERQUERY_ERROR_PROTOCOLNOTFOUND', 1);
+define('NET_GAMESERVERQUERY_ERROR_INVALIDGAME', 0);
+define('NET_GAMESERVERQUERY_ERROR_PROTOCOLNOTFOUND', 1);
define('NET_GAMESERVERQUERY_ERROR_COULDNOTCONNECT', 2);
define('NET_GAMESERVERQUERY_ERROR_NOREPLY', 3);
define('NET_GAMESERVERQUERY_ERROR_COULDNOTSEND', 4);
@@ -38,9 +41,9 @@
/**
* Factory Method
- *
- * Creates a connection (socket) object to the server, then loads and returns
- * the protocol object.
+ *
+ * Creates a connection (socket) object to the server, then loads and returns
+ * the protocol object.
*
* @version 1.0
* @param string $game The game we are talking to
@@ -50,87 +53,87 @@
* @access public
*/
public function query ($ip, $port = null, $game)
- {
- // Read our XML file, find the game information
- $xml = simplexml_load_string(file_get_contents('Net/GameServerQuery/Games.xml', true));
- $protobj = $xml->xpath("/games/game[@key=\"$game\"]");
-
- // If we didn't find any protocol information, unsupported game error
- if (!empty($protobj)) {
- $protocol = $protobj[0]->protocol; }
- else {
- return $this->_throwerror(NET_GAMESERVERQUERY_ERROR_INVALIDGAME); }
-
- // Make a new connection object
- require_once ('Net/GameServerQuery/Objects/Socket.php');
- $socket = new Net_GameServerQuery_Socket;
-
- // If we fail to connect, return an error object
- if ($port === null) {
- $port = (int)$protobj[0]->defaultport; }
- if ($socket->connect($ip, $port) === false || empty($ip)) {
- return $this->_throwerror(NET_GAMESERVERQUERY_ERROR_COULDNOTCONNECT); }
-
- // Check the protocol file exists
- $protocol_file = 'Net/GameServerQuery/Protocols/' . $protocol . '.php';
- if (!$this->file_exists_incpath($protocol_file)) {
- return $this->_throwerror(NET_GAMESERVERQUERY_ERROR_PROTOCOLNOTFOUND); }
-
- // Load protocol
- require_once ($protocol_file);
- $classname = 'Net_GameServerQuery_Protocol_' . $protocol;
-
- // Return our new protocol object (Socket object sent as an argument)
- return new $classname ($socket);
- }
-
-
- /**
- * Wraparound to throw an error.
- *
- * @version 1.0
- * @access public
- * @return string Microtime as a string
- */
- private function _throwerror ($errno)
- {
- include ('Net/GameServerQuery/Objects/Error.php');
- return new Net_GameServerQuery_Error ($errno);
- }
-
-
- /**
- * Return microtime as a single string.
- *
- * @version 1.0
- * @access public
- * @return string Microtime as a string
- */
- public function microtime_str()
- {
- list ($msec, $sec) = explode (" ", microtime());
- $microtime = (float)$msec + (float)$sec;
- return $microtime;
- }
-
-
- /**
- * Check if a file exists in the include path
- *
- * @version 1.0
- * @return bool True if the file exists, False if it does not
- */
- public function file_exists_incpath ($file)
- {
- foreach (explode(';', get_include_path()) as $path)
- {
- $fullpath = $path . '/' . $file;
- if (file_exists($fullpath)) {
- return true; }
- }
+ {
+ // Read our XML file, find the game information
+ $xml = simplexml_load_string(file_get_contents('Net/GameServerQuery/Games.xml',
true));
+ $protobj = $xml->xpath("/games/game[@key=\"$game\"]");
+
+ // If we didn't find any protocol information, unsupported game error
+ if (!empty($protobj)) {
+ $protocol = $protobj[0]->protocol; }
+ else {
+ return $this->_throwerror(NET_GAMESERVERQUERY_ERROR_INVALIDGAME); }
+
+ // Make a new connection object
+ require_once ('Net/GameServerQuery/Objects/Socket.php');
+ $socket = new Net_GameServerQuery_Socket;
+
+ // If we fail to connect, return an error object
+ if ($port === null) {
+ $port = (int)$protobj[0]->defaultport; }
+ if ($socket->connect($ip, $port) === false || empty($ip)) {
+ return $this->_throwerror(NET_GAMESERVERQUERY_ERROR_COULDNOTCONNECT); }
+
+ // Check the protocol file exists
+ $protocol_file = 'Net/GameServerQuery/Protocols/' . $protocol . '.php';
+ if (!$this->file_exists_incpath($protocol_file)) {
+ return $this->_throwerror(NET_GAMESERVERQUERY_ERROR_PROTOCOLNOTFOUND); }
+
+ // Load protocol
+ require_once ($protocol_file);
+ $classname = 'Net_GameServerQuery_Protocol_' . $protocol;
+
+ // Return our new protocol object (Socket object sent as an argument)
+ return new $classname ($socket);
+ }
+
+
+ /**
+ * Wraparound to throw an error.
+ *
+ * @version 1.0
+ * @access public
+ * @return string Microtime as a string
+ */
+ private function _throwerror ($errno)
+ {
+ include_once 'Net/GameServerQuery/Objects/Error.php';
+ return new Net_GameServerQuery_Error ($errno);
+ }
+
+
+ /**
+ * Return microtime as a single string.
+ *
+ * @version 1.0
+ * @access public
+ * @return string Microtime as a string
+ */
+ public function microtime_str()
+ {
+ list ($msec, $sec) = explode (" ", microtime());
+ $microtime = (float)$msec + (float)$sec;
+ return $microtime;
+ }
+
+
+ /**
+ * Check if a file exists in the include path
+ *
+ * @version 1.0
+ * @return bool True if the file exists, False if it does not
+ */
+ public function file_exists_incpath ($file)
+ {
+ foreach (explode(';', get_include_path()) as $path)
+ {
+ $fullpath = $path . '/' . $file;
+ if (file_exists($fullpath)) {
+ return true; }
+ }
- return false;
- }
+ return false;
+ }
}