[TASK] Added an outputBuffer to the AbstractClientDispatcher.
[TASK] Added support for the new outputBuffer - it can be used in addition to the default behaviour "return a string on processRawData()".
This commit is contained in:
parent
e702124895
commit
d0de3823a9
@ -1,31 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace JPT\IrcClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IrcClient class that contains all the Plugins
|
* BotClient class that handles the controls or whatever...edit this later...
|
||||||
|
*
|
||||||
* @author jpt
|
* @author jpt
|
||||||
* @package Client
|
* @package Client
|
||||||
* @depends Client_AbstractClient
|
* @depends \JPT\SocketFramework\Client\AbstractClientDispatcher
|
||||||
*/
|
*/
|
||||||
class Client_BotClient extends Client_AbstractClient {
|
class BotClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatcher {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Forwards incoming data to the ProtocolHandler
|
||||||
* @return void
|
* Let's the ProtocolHandler do all the work and forward its results to the Clients.
|
||||||
|
* Return resulting raw data.
|
||||||
|
*
|
||||||
|
* @param string $rawData
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function processRawData($rawData) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does all the hard work.
|
|
||||||
* @param object $contentObject
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function processContentObject($contentObject) {
|
|
||||||
$return = "";
|
$return = "";
|
||||||
$rawData = $contentObject->getRawData();
|
|
||||||
|
|
||||||
if(trim($rawData) === "list") {
|
if(trim($rawData) === "list") {
|
||||||
$return = print_r(array("IDs" => $this->clientManager->getIDs(), "Groups" => $this->clientManager->getGroups()), TRUE);
|
$return = print_r(array(
|
||||||
|
"IDs" => $this->clientManager->getIDs(),
|
||||||
|
"Groups" => $this->clientManager->getGroups()
|
||||||
|
), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strpos($rawData, "-") !== FALSE ) {
|
if(strpos($rawData, "-") !== FALSE ) {
|
||||||
@ -42,7 +42,7 @@ class Client_BotClient extends Client_AbstractClient {
|
|||||||
|
|
||||||
//TODO: implement this correctly
|
//TODO: implement this correctly
|
||||||
$return = str_replace("\n", "\r\n", $return);
|
$return = str_replace("\n", "\r\n", $return);
|
||||||
$this->protocolHandler->sendRaw($return);
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -2,12 +2,13 @@
|
|||||||
namespace JPT\IrcClient;
|
namespace JPT\IrcClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ClientDispatcher for this IrcBot.
|
* The IrcClientDispatcher for this IrcBot.
|
||||||
*
|
*
|
||||||
* @author jpt
|
* @author jpt
|
||||||
* @package Client
|
* @package Client
|
||||||
|
* @depends \JPT\SocketFramework\Client\AbstractClientDispatcher
|
||||||
*/
|
*/
|
||||||
class ClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatcher {
|
class IrcClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatcher {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
@ -44,6 +45,7 @@ class ClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatc
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
$this->outputBuffer = new \JPT\SocketFramework\Misc\Buffer("\r\n");
|
||||||
$this->nick = "Serena";
|
$this->nick = "Serena";
|
||||||
$this->channels = array();
|
$this->channels = array();
|
||||||
$this->resetConnectionStatus();
|
$this->resetConnectionStatus();
|
||||||
@ -70,7 +72,7 @@ class ClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatc
|
|||||||
$data = "USER poweruser as as :JPTs Bot\r\nNICK " . $this->nick . "\r\n";
|
$data = "USER poweruser as as :JPTs Bot\r\nNICK " . $this->nick . "\r\n";
|
||||||
$this->authed = TRUE;
|
$this->authed = TRUE;
|
||||||
}
|
}
|
||||||
//$this->protocolHandler->sendRaw($data);
|
$this->send($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,7 +108,7 @@ class ClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatc
|
|||||||
$return .= "QUIT :lol\r\n";
|
$return .= "QUIT :lol\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
$this->send($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -22,6 +22,13 @@ abstract class AbstractClientDispatcher implements \JPT\SocketFramework\Client\C
|
|||||||
*/
|
*/
|
||||||
protected $group;
|
protected $group;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains data that the ClientDispatcher sends.
|
||||||
|
*
|
||||||
|
* @var \JPT\SocketFramework\Misc\Buffer
|
||||||
|
*/
|
||||||
|
protected $outputBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains a reference to the ClientManager in order to change stuff on the fly.
|
* Contains a reference to the ClientManager in order to change stuff on the fly.
|
||||||
*
|
*
|
||||||
@ -29,6 +36,35 @@ abstract class AbstractClientDispatcher implements \JPT\SocketFramework\Client\C
|
|||||||
*/
|
*/
|
||||||
protected $clientManager;
|
protected $clientManager;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
* Creates the outputBuffer.
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
$this->outputBuffer = new \JPT\SocketFramework\Misc\Buffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds data that shall be sent to the outputBuffer.
|
||||||
|
* Feel free to overwrite this if you need something different.
|
||||||
|
*
|
||||||
|
* @param string $rawData
|
||||||
|
*/
|
||||||
|
protected function send($rawData) {
|
||||||
|
$this->outputBuffer->addData($rawData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all data from the outputBuffer.
|
||||||
|
* Feel free to overwrite this if you need something different.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getOutputData() {
|
||||||
|
return $this->outputBuffer->getAllBufferContents();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forwards incoming data to the ProtocolHandler
|
* Forwards incoming data to the ProtocolHandler
|
||||||
* Let's the ProtocolHandler do all the work and forward its results to the Clients.
|
* Let's the ProtocolHandler do all the work and forward its results to the Clients.
|
||||||
|
@ -131,7 +131,12 @@ class ClientManager {
|
|||||||
unset($data);
|
unset($data);
|
||||||
|
|
||||||
//call the registered client
|
//call the registered client
|
||||||
if(isset($this->clientDispatcherPool[$connectionHandler->getID()])) $outgoingData .= $this->clientDispatcherPool[$connectionHandler->getID()]->processRawData($incomingData);
|
if(isset($this->clientDispatcherPool[$connectionHandler->getID()])) {
|
||||||
|
//other output data has priority.
|
||||||
|
$outgoingData .= $this->clientDispatcherPool[$connectionHandler->getID()]->getOutputData();
|
||||||
|
//returned data from the processing will be sent.
|
||||||
|
$outgoingData .= $this->clientDispatcherPool[$connectionHandler->getID()]->processRawData($incomingData);
|
||||||
|
}
|
||||||
|
|
||||||
//i don't know what to do here... maybe call a connection bridge?
|
//i don't know what to do here... maybe call a connection bridge?
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
$clientManager = new \JPT\SocketFramework\Client\ClientManager();
|
$clientManager = new \JPT\SocketFramework\Client\ClientManager();
|
||||||
$clientManager->registerClientDispatcherByProtocol("irc", "\JPT\IrcClient\ClientDispatcher");
|
$clientManager->registerClientDispatcherByProtocol("irc", "\JPT\IrcClient\IrcClientDispatcher");
|
||||||
|
$clientManager->registerClientDispatcherByProtocol("jpt_control", "\JPT\IrcClient\BotClientDispatcher");
|
||||||
|
|
||||||
$freenode = $clientManager->createTcpConnection("freenode", "irc");
|
$freenode = $clientManager->createTcpConnection("freenode", "irc");
|
||||||
$clientManager->attachConfig(array(
|
$clientManager->attachConfig(array(
|
||||||
@ -45,7 +46,7 @@ $eloxoph->connect("irc.eloxoph.com", 6667);*/
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
$srv = $clientManager->createTcpConnection("srv", "RAW");
|
$srv = $clientManager->createTcpConnection("srv", "jpt_control");
|
||||||
$srv->bind("localhost", 7777);
|
$srv->bind("localhost", 7777);
|
||||||
$srv->listen();
|
$srv->listen();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user