[TASK] Moved the project to namespaces.
[TASK] Removed all the protocol handlers. [TASK] Clients are no longer part of the SocketFramework itself. [TASK] The Framework provides an "interface" to external clients - the ClientDispatcher. [TASK] Added the Core package and added a better ClassLoader. [TASK] Created a bootstrap module to include in other projects. [TASK] Cleaned up comments, reformatted them.
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
<?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
|
||||
*/
|
||||
protected $authed;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $nick;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $channels;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $lines;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->nick = "Serena";
|
||||
$this->channels = array();
|
||||
$this->resetConnectionStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Will reset the clients internal variables concerning the connection status.
|
||||
* @return void
|
||||
*/
|
||||
public function resetConnectionStatus() {
|
||||
$this->lines = 0;
|
||||
$this->got001 = FALSE;
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the resulting ContentObject from a ProtocolHandler.
|
||||
* Does all the hard work.
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
protected function processContentObject($contentObject) {
|
||||
$data = $contentObject->getRawData();
|
||||
//DEBUG
|
||||
var_dump($contentObject);
|
||||
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;
|
||||
|
||||
$return = "";
|
||||
|
||||
$this->lines++;
|
||||
|
||||
if(!$this->joined && $this->got001) {
|
||||
$this->joined = TRUE;
|
||||
foreach($this->channels AS $channel) $return .= "JOIN " . $channel . "\r\n";
|
||||
}
|
||||
|
||||
if(strpos($data, "musdsdsafgagltivitamin") !== FALSE) {
|
||||
$return .= "PRIVMSG ".$this->channels[0]." :roger that :D\r\n";
|
||||
$return .= "QUIT :lol\r\n";
|
||||
}
|
||||
|
||||
//workaround. will be removed soon
|
||||
$this->protocolHandler->sendRaw($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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"];
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user