cvs: pear /Net_GameServerQuery/GameServerQuery Protocol.php

From: Date: Tue, 18 Jan 2005 04:58:12 +0000
Subject: cvs: pear /Net_GameServerQuery/GameServerQuery Protocol.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-28649@lists.php.net to get a copy of this message
aidan Mon Jan 17 23:58:12 2005 EDT Modified files: /pear/Net_GameServerQuery/GameServerQuery Protocol.php Log: Switched from Response to Buffer class. Added support for elegant handling of multipacket responses. A multipacketjoin method is defined in the abstract class (this file) which can later be overrided in the protocol file if more specific parsing is required. The multipacketjoin method is called whenever the result is an array, and is called before being loaded into the buffer. http://cvs.php.net/diff.php/pear/Net_GameServerQuery/GameServerQuery/Protocol.php?r1=1.33&r2=1.34&ty=u Index: pear/Net_GameServerQuery/GameServerQuery/Protocol.php diff -u pear/Net_GameServerQuery/GameServerQuery/Protocol.php:1.33 pear/Net_GameServerQuery/GameServerQuery/Protocol.php:1.34 --- pear/Net_GameServerQuery/GameServerQuery/Protocol.php:1.33 Fri Jan 14 14:01:44 2005 +++ pear/Net_GameServerQuery/GameServerQuery/Protocol.php Mon Jan 17 23:58:12 2005 @@ -16,11 +16,11 @@ // | Tom Buskens <ortega@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Protocol.php,v 1.33 2005/01/14 19:01:44 aidan Exp $ +// $Id: Protocol.php,v 1.34 2005/01/18 04:58:12 aidan Exp $ -require_once NET_GAMESERVERQUERY_BASE . 'Response.php'; -require_once NET_GAMESERVERQUERY_BASE . 'Result.php'; +require_once NET_GAMESERVERQUERY_BASE . 'Process/Buffer.php'; +require_once NET_GAMESERVERQUERY_BASE . 'Process/Result.php'; /** @@ -30,7 +30,7 @@ * @package Net_GameServerQuery * @author Aidan Lister <aidan@php.net> * @author Tom Buskens <ortega@php.net> - * @version $Revision: 1.33 $ + * @version $Revision: 1.34 $ */ abstract class Net_GameServerQuery_Protocol { @@ -38,8 +38,9 @@ * Parse server response according to packet type * * @access public - * @param array $packet Array containing the packet and its type - * @return array Array containing formatted server response + * @param string $packetname The name of the packet + * @param string|array $response The packet + * @return array Array containing formatted server response */ public function parse($packetname, $response) { @@ -50,10 +51,16 @@ if (!is_callable($callback)) { throw new InvalidPacketException; } - + + // If the response is an array then multiple packets were recieved + // Ask the protocol to join them together as a single response + if (is_array($response)) { + $response = $this->multipacketjoin($response); + } + // Response class - $response = new Net_GameServerQuery_Response($response); - $result = new Net_GameServerQuery_Result(); + $response = new Net_GameServerQuery_Process_Buffer($response); + $result = new Net_GameServerQuery_Process_Result(); // Parse packet $result = call_user_func(array($this, $packetname), $response, $result); @@ -66,6 +73,20 @@ return $result; } + + /** + * Join multiple packet responses into a single response + * + * This is usually overrided by the protocol specific method + * + * @access public + * @param array $packets Array containing the packets + * @return string Joined server response + */ + protected function multipacketjoin($packets) + { + return implode('', $packets); + } } ?> \ No newline at end of file

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