ircbot/IrcClient/Classes/IrcClientDispatcher.php

126 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2010-11-21 23:48:11 +01:00
<?php
namespace JPT\IrcClient;
2010-11-21 23:48:11 +01:00
/**
* The IrcClientDispatcher for this IrcBot.
*
2010-11-21 23:48:11 +01:00
* @author jpt
* @package Client
* @depends \JPT\SocketFramework\Client\AbstractClientDispatcher
2010-11-21 23:48:11 +01:00
*/
class IrcClientDispatcher extends \JPT\SocketFramework\Client\AbstractClientDispatcher {
/**
* @var boolean
*/
protected $joined;
/**
* @var boolean
*/
protected $got001;
/**
* @var boolean
*/
2010-11-21 23:48:11 +01:00
protected $authed;
/**
* @var string
*/
2010-11-21 23:48:11 +01:00
protected $nick;
/**
* @var array
*/
2010-11-21 23:48:11 +01:00
protected $channels;
/**
* @var int
*/
2010-11-21 23:48:11 +01:00
protected $lines;
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
*/
public function __construct() {
$this->outputBuffer = new \JPT\SocketFramework\Misc\Buffer("\r\n");
2010-11-21 23:48:11 +01:00
$this->nick = "Serena";
$this->channels = array();
$this->resetConnectionStatus();
}
/**
* 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;
$this->got001 = FALSE;
2010-11-21 23:48:11 +01:00
$this->joined = FALSE;
$this->authed = FALSE;
}
/**
* 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) {
$data = "USER poweruser as as :JPTs Bot\r\nNICK " . $this->nick . "\r\n";
$this->authed = TRUE;
}
$this->send($data);
}
2010-11-21 23:48:11 +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
*/
public function processRawData($rawData) {
$data = $rawData;
var_dump($data);
//respond to pings
//if($contentObject->getCommand() === "PING") $this->protocolHandler->pong($contentObject->getParams());
$this->clientManager->sendToGroup("srv", "[#".$this->ID."] ".$data);
//if($contentObject->getCommand() === "001") $this->got001 = TRUE;
2010-11-21 23:48:11 +01:00
$return = "";
2010-11-21 23:48:11 +01:00
$this->lines++;
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";
}
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";
}
$this->send($return);
2010-11-21 23:48:11 +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"];
}
2010-11-21 23:48:11 +01:00
}
?>