ircbot/Classes/Client/IrcClient.php

122 lines
2.4 KiB
PHP
Raw Normal View History

2010-11-21 23:48:11 +01:00
<?php
/**
* IrcClient class that contains all the Plugins
* @author jpt
* @package Client
* @depends Client_AbstractClient
*/
class Client_IrcClient extends Client_AbstractClient {
/**
* @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;
/**
* Default constructor.
2010-11-28 01:04:35 +01:00
* @return void
2010-11-21 23:48:11 +01:00
*/
public function __construct() {
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->protocolHandler->sendRaw($data);
}
2010-11-21 23:48:11 +01:00
/**
* Processes the resulting ContentObject from a ProtocolHandler.
2010-11-21 23:48:11 +01:00
* Does all the hard work.
* @param string $data
* @return void
2010-11-21 23:48:11 +01:00
*/
protected function processContentObject($contentObject) {
$data = $contentObject->getRawData();
//DEBUG
//var_dump($contentObject);
//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 = "";
$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, "multivitamin") !== FALSE) {
2010-11-21 23:48:11 +01:00
$return .= "PRIVMSG ".$this->channels[0]." :roger that :D\r\n";
$return .= "QUIT :lol\r\n";
}
//workaround. will be removed soon
$this->protocolHandler->sendRaw($return);
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"];
}
}
?>