[TASK] Changed behaviour of protocol register.
This commit is contained in:
parent
4bbb9bf548
commit
b318595783
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
||||
|
10
Classes/Protocol/BotProtocolContentObject.php
Normal file
10
Classes/Protocol/BotProtocolContentObject.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Raw ContentObject
|
||||
* @author JPT
|
||||
* @package Protocol
|
||||
*/
|
||||
class Protocol_BotProtocolContentObject extends Protocol_AbstractProtocolContentObject {
|
||||
|
||||
}
|
||||
?>
|
17
Classes/Protocol/BotProtocolHandler.php
Normal file
17
Classes/Protocol/BotProtocolHandler.php
Normal 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);
|
||||
}
|
||||
}
|
||||
?>
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user