[TASK] Some Bugfixes.

This commit is contained in:
Jan Philipp Timme 2010-11-28 01:15:20 +00:00
parent bdd9f671ad
commit 3bd7a6e0f9
7 changed files with 38 additions and 8 deletions

View File

@ -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);
}

View File

@ -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");

View File

@ -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;

View File

@ -4,7 +4,7 @@
* @author JPT
* @package Protocol
*/
class IrcProtocolHandler extends Protocol_AbstractProtocolHandler {
class Protocol_IrcProtocolHandler extends Protocol_AbstractProtocolHandler {
/**
* @param string $data

View File

@ -0,0 +1,10 @@
<?php
/**
* Raw ContentObject
* @author JPT
* @package Protocol
*/
class Protocol_RawProtocolContentObject extends Protocol_AbstractProtocolContentObject {
}
?>

View File

@ -0,0 +1,17 @@
<?php
/**
* A 1:1 passthrough handler
* @author JPT
* @package Protocol
*/
class Protocol_RawProtocolHandler extends Protocol_AbstractProtocolHandler {
/**
* @param string $data
* @return Protocol_RawProtocolContentObject
*/
public function parse($data) {
return new Protocol_RawProtocolContentObject($data);
}
}
?>

View File

@ -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",