[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
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function processContentObject($contentObject) {
|
public function processContentObject($contentObject) {
|
||||||
|
$return = "";
|
||||||
$data = $contentObject->rawData;
|
$data = $contentObject->rawData;
|
||||||
if(strpos($data, "-") !== FALSE ) {
|
if(strpos($data, "-") !== FALSE ) {
|
||||||
$data = explode("-", $data);
|
$data = explode("-", $data);
|
||||||
|
|||||||
@ -130,8 +130,8 @@ class Client_ClientManager {
|
|||||||
* @param string $className
|
* @param string $className
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function registerProtocol($protocol, $className) {
|
public function registerProtocol($protocol, $classNamePartial) {
|
||||||
$this->registeredProtocols[$protocol] = $className;
|
$this->registeredProtocols[$protocol] = $classNamePartial;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,10 +152,10 @@ class Client_ClientManager {
|
|||||||
*/
|
*/
|
||||||
protected function createClientForProtocol($protocol) {
|
protected function createClientForProtocol($protocol) {
|
||||||
//look for the 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);
|
throw new Exception_GeneralException("No client registered for protocol: '" . $protocol . "'!", 1290271651);
|
||||||
}
|
}
|
||||||
$className = $this->registeredProtocols[$protocol];
|
$className = "Client_" . $protocol . "Client";
|
||||||
//look for the class
|
//look for the class
|
||||||
if(class_exists($className)) {
|
if(class_exists($className)) {
|
||||||
return new $className();
|
return new $className();
|
||||||
@ -170,7 +170,7 @@ class Client_ClientManager {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function addClientForConnectionHandler($connectionHandler) {
|
protected function addClientForConnectionHandler($connectionHandler) {
|
||||||
$protocol = $connectionHandler->getProtocol();
|
$protocol = $this->registeredProtocols[$connectionHandler->getProtocol()];
|
||||||
//do not try this for raw connections
|
//do not try this for raw connections
|
||||||
if($protocol === "RAW") return;
|
if($protocol === "RAW") return;
|
||||||
$client = $this->createClientForProtocol($protocol);
|
$client = $this->createClientForProtocol($protocol);
|
||||||
@ -178,8 +178,8 @@ class Client_ClientManager {
|
|||||||
$client->loadConfig($this->configPool[$connectionHandler->getID()]);
|
$client->loadConfig($this->configPool[$connectionHandler->getID()]);
|
||||||
}
|
}
|
||||||
$client->injectClientManager($this);
|
$client->injectClientManager($this);
|
||||||
$className = "Protocol_".$protocol."ProtocolHandler";
|
$protocolHandlerClass = "Protocol_".$protocol."ProtocolHandler";
|
||||||
$protocolHandler = new $className();
|
$protocolHandler = new $protocolHandlerClass();
|
||||||
$client->injectProtocolHandler($protocolHandler);
|
$client->injectProtocolHandler($protocolHandler);
|
||||||
$client->setID($connectionHandler->getID());
|
$client->setID($connectionHandler->getID());
|
||||||
$client->setGroup($connectionHandler->getGroup());
|
$client->setGroup($connectionHandler->getGroup());
|
||||||
|
|||||||
@ -33,7 +33,6 @@ class Client_IrcClient extends Client_AbstractClient {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function processContentObject($contentObject) {
|
public function processContentObject($contentObject) {
|
||||||
var_dump($contentObject);
|
|
||||||
$data = $contentObject->rawData;
|
$data = $contentObject->rawData;
|
||||||
//echo "[RECV] ".$data;
|
//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
|
<?php
|
||||||
$clientManager = new Client_ClientManager();
|
$clientManager = new Client_ClientManager();
|
||||||
$clientManager->registerProtocol("Irc", "Client_IrcClient");
|
$clientManager->registerProtocol("irc", "Irc");
|
||||||
$clientManager->registerProtocol("jpt", "Client_BotClient");
|
$clientManager->registerProtocol("jpt", "Bot");
|
||||||
|
|
||||||
$freenode = $clientManager->createTcpConnection("freenode", "Irc");
|
$freenode = $clientManager->createTcpConnection("freenode", "irc");
|
||||||
$clientManager->attachConfig(array(
|
$clientManager->attachConfig(array(
|
||||||
"nick" => "Testinstanz",
|
"nick" => "Testinstanz",
|
||||||
"userident" => "uzuguck",
|
"userident" => "uzuguck",
|
||||||
@ -11,7 +11,7 @@ $clientManager->attachConfig(array(
|
|||||||
), $freenode);
|
), $freenode);
|
||||||
$freenode->connect("irc.freenode.net", 6667);
|
$freenode->connect("irc.freenode.net", 6667);
|
||||||
|
|
||||||
$freenode = $clientManager->createTcpConnection("freenode", "Irc");
|
$freenode = $clientManager->createTcpConnection("freenode", "irc");
|
||||||
$clientManager->attachConfig(array(
|
$clientManager->attachConfig(array(
|
||||||
"nick" => "Testinstanz2",
|
"nick" => "Testinstanz2",
|
||||||
"userident" => "uzuguck",
|
"userident" => "uzuguck",
|
||||||
@ -30,9 +30,9 @@ $eloxoph = $clientManager->createTcpConnection("eloxoph", "irc");
|
|||||||
$clientManager->attachConfig($config_eloxoph, $eloxoph);
|
$clientManager->attachConfig($config_eloxoph, $eloxoph);
|
||||||
$eloxoph->connect("irc.eloxoph.com", 6667);*/
|
$eloxoph->connect("irc.eloxoph.com", 6667);*/
|
||||||
|
|
||||||
/*$srv = $clientManager->createTcpConnection("srv", "jpt");
|
$srv = $clientManager->createTcpConnection("srv", "jpt");
|
||||||
$srv->bind("localhost", 7777);
|
$srv->bind("localhost", 7777);
|
||||||
$srv->listen();*/
|
$srv->listen();
|
||||||
|
|
||||||
while($clientManager->countConnections() > 0) {
|
while($clientManager->countConnections() > 0) {
|
||||||
$clientManager->work();
|
$clientManager->work();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user