2010-11-21 23:48:11 +01:00
|
|
|
<?php
|
2011-12-03 20:58:08 +01:00
|
|
|
namespace JPT\IrcClient;
|
|
|
|
|
2010-11-21 23:48:11 +01:00
|
|
|
/**
|
2011-12-04 14:31:18 +01:00
|
|
|
* The IrcClientDispatcher for this IrcBot.
|
2011-12-03 20:58:08 +01:00
|
|
|
*
|
2010-11-21 23:48:11 +01:00
|
|
|
* @author jpt
|
|
|
|
* @package Client
|
2011-12-04 14:31:18 +01:00
|
|
|
* @depends \JPT\SocketFramework\Client\AbstractClientDispatcher
|
2010-11-21 23:48:11 +01:00
|
|
|
*/
|
2011-12-04 14:31:18 +01:00
|
|
|
class IrcClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatcher {
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-12-18 15:42:56 +01:00
|
|
|
/**
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2011-06-26 00:13:53 +02:00
|
|
|
protected $joined;
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-12-18 15:42:56 +01:00
|
|
|
/**
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2011-06-26 00:13:53 +02:00
|
|
|
protected $got001;
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-12-18 15:42:56 +01:00
|
|
|
/**
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2010-11-21 23:48:11 +01:00
|
|
|
protected $authed;
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-12-18 15:42:56 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-11-21 23:48:11 +01:00
|
|
|
protected $nick;
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-12-18 15:42:56 +01:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-11-21 23:48:11 +01:00
|
|
|
protected $channels;
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-12-18 15:42:56 +01:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
2010-11-21 23:48:11 +01:00
|
|
|
protected $lines;
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-11-21 23:48:11 +01:00
|
|
|
/**
|
|
|
|
* Default constructor.
|
2010-11-28 01:04:35 +01:00
|
|
|
* @return void
|
2010-11-21 23:48:11 +01:00
|
|
|
*/
|
2010-12-18 15:42:56 +01:00
|
|
|
public function __construct() {
|
2011-12-04 14:31:18 +01:00
|
|
|
$this->outputBuffer = new \JPT\SocketFramework\Misc\Buffer("\r\n");
|
2010-11-21 23:48:11 +01:00
|
|
|
$this->nick = "Serena";
|
|
|
|
$this->channels = array();
|
2010-11-28 17:38:03 +01:00
|
|
|
$this->resetConnectionStatus();
|
|
|
|
}
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-11-28 17:38:03 +01:00
|
|
|
/**
|
|
|
|
* Will reset the clients internal variables concerning the connection status.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function resetConnectionStatus() {
|
2010-11-21 23:48:11 +01:00
|
|
|
$this->lines = 0;
|
2011-06-26 00:13:53 +02:00
|
|
|
$this->got001 = FALSE;
|
2010-11-21 23:48:11 +01:00
|
|
|
$this->joined = FALSE;
|
|
|
|
$this->authed = FALSE;
|
|
|
|
}
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2011-06-26 00:13:53 +02:00
|
|
|
/**
|
|
|
|
* This function gets called every time, the connection is established.
|
|
|
|
* This allows the client to send initial data.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function initializeConnection() {
|
|
|
|
if(!$this->authed) {
|
2011-06-26 16:03:32 +02:00
|
|
|
$data = "USER poweruser as as :JPTs Bot\r\nNICK " . $this->nick . "\r\n";
|
2011-06-26 00:13:53 +02:00
|
|
|
$this->authed = TRUE;
|
|
|
|
}
|
2011-12-04 14:31:18 +01:00
|
|
|
$this->send($data);
|
2011-06-26 00:13:53 +02:00
|
|
|
}
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-11-21 23:48:11 +01:00
|
|
|
/**
|
2011-12-03 20:58:08 +01:00
|
|
|
* Forwards incoming data to the ProtocolHandler
|
|
|
|
* Let's the ProtocolHandler do all the work and forward its results to the Clients.
|
|
|
|
* Return resulting raw data.
|
|
|
|
*
|
|
|
|
* @param string $rawData
|
|
|
|
* @return string
|
2010-11-21 23:48:11 +01:00
|
|
|
*/
|
2011-12-03 20:58:08 +01:00
|
|
|
public function processRawData($rawData) {
|
|
|
|
$data = $rawData;
|
2011-06-26 16:03:32 +02:00
|
|
|
var_dump($data);
|
2011-12-03 20:58:08 +01:00
|
|
|
|
|
|
|
//respond to pings
|
|
|
|
//if($contentObject->getCommand() === "PING") $this->protocolHandler->pong($contentObject->getParams());
|
|
|
|
|
2011-06-26 00:13:53 +02:00
|
|
|
$this->clientManager->sendToGroup("srv", "[#".$this->ID."] ".$data);
|
2011-12-03 20:58:08 +01:00
|
|
|
|
|
|
|
//if($contentObject->getCommand() === "001") $this->got001 = TRUE;
|
|
|
|
|
2010-11-21 23:48:11 +01:00
|
|
|
$return = "";
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-11-21 23:48:11 +01:00
|
|
|
$this->lines++;
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2011-06-26 00:13:53 +02:00
|
|
|
if(!$this->joined && $this->got001) {
|
2010-11-21 23:48:11 +01:00
|
|
|
$this->joined = TRUE;
|
|
|
|
foreach($this->channels AS $channel) $return .= "JOIN " . $channel . "\r\n";
|
|
|
|
}
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2011-06-26 16:03:32 +02:00
|
|
|
if(strpos($data, "musdsdsafgagltivitamin") !== FALSE) {
|
2010-11-21 23:48:11 +01:00
|
|
|
$return .= "PRIVMSG ".$this->channels[0]." :roger that :D\r\n";
|
|
|
|
$return .= "QUIT :lol\r\n";
|
|
|
|
}
|
|
|
|
|
2011-12-04 14:31:18 +01:00
|
|
|
$this->send($return);
|
2010-11-21 23:48:11 +01:00
|
|
|
}
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-11-21 23:48:11 +01:00
|
|
|
/**
|
|
|
|
* Loads the given configuration.
|
|
|
|
* @param array $config
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function loadConfig($config) {
|
|
|
|
$this->nick = $config["nick"];
|
|
|
|
$this->channels = $config["channels"];
|
|
|
|
$this->userident = $config["userident"];
|
|
|
|
}
|
2011-12-03 20:58:08 +01:00
|
|
|
|
2010-11-21 23:48:11 +01:00
|
|
|
}
|
|
|
|
?>
|