From 3bd7a6e0f913f38bb2f8e96c7d398f2915d70416 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 28 Nov 2010 01:15:20 +0000 Subject: [PATCH] [TASK] Some Bugfixes. --- Classes/Client/AbstractClient.php | 4 ++-- Classes/Client/BotClient.php | 3 ++- Classes/Client/ClientManager.php | 6 ++++-- Classes/Protocol/IrcProtocolHandler.php | 2 +- Classes/Protocol/RawProtocolContentObject.php | 10 ++++++++++ Classes/Protocol/RawProtocolHandler.php | 17 +++++++++++++++++ Testcode/Client/ClientManagerTest.php | 4 ++-- 7 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 Classes/Protocol/RawProtocolContentObject.php create mode 100644 Classes/Protocol/RawProtocolHandler.php diff --git a/Classes/Client/AbstractClient.php b/Classes/Client/AbstractClient.php index 8ac20c1..5188dce 100644 --- a/Classes/Client/AbstractClient.php +++ b/Classes/Client/AbstractClient.php @@ -30,7 +30,7 @@ abstract class Client_AbstractClient { /** * Injects ProtocolHandler - * @param unknown_type $protocolHandler + * @param mixed $protocolHandler instance of Protocol_AbstractProtocolHandler * @return void */ public function injectProtocolHandler($protocolHandler) { @@ -43,7 +43,7 @@ abstract class Client_AbstractClient { * @param string $rawData * @return void */ - public function putRawData($rawData) { + public function processRawData($rawData) { $contentObject = $this->protocolHandler->parse($rawData); $this->processContentObject($contentObject); } diff --git a/Classes/Client/BotClient.php b/Classes/Client/BotClient.php index 59a7795..5f5fae4 100644 --- a/Classes/Client/BotClient.php +++ b/Classes/Client/BotClient.php @@ -19,7 +19,8 @@ class Client_BotClient extends Client_AbstractClient { * @param string $data * @return string */ - public function processData($data) { + public function processContentObject($contentObject) { + $data = $contentObject->rawData; if(strpos($data, "-") !== FALSE ) { $data = explode("-", $data); $this->clientManager->sendToID((int) $data[0], $data[1]."\r\n"); diff --git a/Classes/Client/ClientManager.php b/Classes/Client/ClientManager.php index 1c5dbdd..8296a5c 100644 --- a/Classes/Client/ClientManager.php +++ b/Classes/Client/ClientManager.php @@ -94,7 +94,7 @@ class Client_ClientManager { if(isset($this->clientPool[$connectionHandler->getID()])) { //let the client process the data, send the results back. while($data = $connectionHandler->read()) { - $result = $this->clientPool[$connectionHandler->getID()]->processData($data); + $result = $this->clientPool[$connectionHandler->getID()]->processRawData($data); if($result !== "") { $connectionHandler->write($result); } @@ -178,7 +178,9 @@ class Client_ClientManager { $client->loadConfig($this->configPool[$connectionHandler->getID()]); } $client->injectClientManager($this); - $client->injectProtocolHandler(new Protocol_IrcProtocolHandler()); + $className = "Protocol_".$protocol."ProtocolHandler"; + $protocolHandler = new $className(); + $client->injectProtocolHandler($protocolHandler); $client->setID($connectionHandler->getID()); $client->setGroup($connectionHandler->getGroup()); $this->clientPool[$connectionHandler->getID()] = $client; diff --git a/Classes/Protocol/IrcProtocolHandler.php b/Classes/Protocol/IrcProtocolHandler.php index c4e87b5..df21ffd 100644 --- a/Classes/Protocol/IrcProtocolHandler.php +++ b/Classes/Protocol/IrcProtocolHandler.php @@ -4,7 +4,7 @@ * @author JPT * @package Protocol */ -class IrcProtocolHandler extends Protocol_AbstractProtocolHandler { +class Protocol_IrcProtocolHandler extends Protocol_AbstractProtocolHandler { /** * @param string $data diff --git a/Classes/Protocol/RawProtocolContentObject.php b/Classes/Protocol/RawProtocolContentObject.php new file mode 100644 index 0000000..ae6f582 --- /dev/null +++ b/Classes/Protocol/RawProtocolContentObject.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/Classes/Protocol/RawProtocolHandler.php b/Classes/Protocol/RawProtocolHandler.php new file mode 100644 index 0000000..377f5f6 --- /dev/null +++ b/Classes/Protocol/RawProtocolHandler.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/Testcode/Client/ClientManagerTest.php b/Testcode/Client/ClientManagerTest.php index 44dde73..3f56f6d 100644 --- a/Testcode/Client/ClientManagerTest.php +++ b/Testcode/Client/ClientManagerTest.php @@ -3,7 +3,7 @@ $clientManager = new Client_ClientManager(); $clientManager->registerProtocol("irc", "Client_IrcClient"); $clientManager->registerProtocol("jpt", "Client_BotClient"); -$freenode = $clientManager->createTcpConnection("freenode", "irc"); +$freenode = $clientManager->createTcpConnection("freenode", "Irc"); $clientManager->attachConfig(array( "nick" => "Testinstanz", "userident" => "uzuguck", @@ -11,7 +11,7 @@ $clientManager->attachConfig(array( ), $freenode); $freenode->connect("irc.freenode.net", 6667); -$freenode = $clientManager->createTcpConnection("freenode", "irc"); +$freenode = $clientManager->createTcpConnection("freenode", "Irc"); $clientManager->attachConfig(array( "nick" => "Testinstanz2", "userident" => "uzuguck",