[TASK] Changed behaviour of protocol register.

This commit is contained in:
Jan Philipp Timme 2010-11-28 02:45:25 +00:00
parent 4bbb9bf548
commit b318595783
6 changed files with 41 additions and 14 deletions

View File

@ -20,6 +20,7 @@ class Client_BotClient extends Client_AbstractClient {
* @return string
*/
public function processContentObject($contentObject) {
$return = "";
$data = $contentObject->rawData;
if(strpos($data, "-") !== FALSE ) {
$data = explode("-", $data);

View File

@ -130,8 +130,8 @@ class Client_ClientManager {
* @param string $className
* @return void
*/
public function registerProtocol($protocol, $className) {
$this->registeredProtocols[$protocol] = $className;
public function registerProtocol($protocol, $classNamePartial) {
$this->registeredProtocols[$protocol] = $classNamePartial;
}
/**
@ -152,10 +152,10 @@ class Client_ClientManager {
*/
protected function createClientForProtocol($protocol) {
//look for the protocol
if(!isset($this->registeredProtocols[$protocol])) {
if(!in_array($protocol, $this->registeredProtocols)) {
throw new Exception_GeneralException("No client registered for protocol: '" . $protocol . "'!", 1290271651);
}
$className = $this->registeredProtocols[$protocol];
$className = "Client_" . $protocol . "Client";
//look for the class
if(class_exists($className)) {
return new $className();
@ -170,7 +170,7 @@ class Client_ClientManager {
* @return void
*/
protected function addClientForConnectionHandler($connectionHandler) {
$protocol = $connectionHandler->getProtocol();
$protocol = $this->registeredProtocols[$connectionHandler->getProtocol()];
//do not try this for raw connections
if($protocol === "RAW") return;
$client = $this->createClientForProtocol($protocol);
@ -178,8 +178,8 @@ class Client_ClientManager {
$client->loadConfig($this->configPool[$connectionHandler->getID()]);
}
$client->injectClientManager($this);
$className = "Protocol_".$protocol."ProtocolHandler";
$protocolHandler = new $className();
$protocolHandlerClass = "Protocol_".$protocol."ProtocolHandler";
$protocolHandler = new $protocolHandlerClass();
$client->injectProtocolHandler($protocolHandler);
$client->setID($connectionHandler->getID());
$client->setGroup($connectionHandler->getGroup());

View File

@ -33,7 +33,6 @@ class Client_IrcClient extends Client_AbstractClient {
* @return string
*/
public function processContentObject($contentObject) {
var_dump($contentObject);
$data = $contentObject->rawData;
//echo "[RECV] ".$data;

View File

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

View File

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

View File

@ -1,9 +1,9 @@
<?php
$clientManager = new Client_ClientManager();
$clientManager->registerProtocol("Irc", "Client_IrcClient");
$clientManager->registerProtocol("jpt", "Client_BotClient");
$clientManager->registerProtocol("irc", "Irc");
$clientManager->registerProtocol("jpt", "Bot");
$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",
@ -30,9 +30,9 @@ $eloxoph = $clientManager->createTcpConnection("eloxoph", "irc");
$clientManager->attachConfig($config_eloxoph, $eloxoph);
$eloxoph->connect("irc.eloxoph.com", 6667);*/
/*$srv = $clientManager->createTcpConnection("srv", "jpt");
$srv = $clientManager->createTcpConnection("srv", "jpt");
$srv->bind("localhost", 7777);
$srv->listen();*/
$srv->listen();
while($clientManager->countConnections() > 0) {
$clientManager->work();