[TASK] Added function for clients, so they're able to send initial data right after connecting to a server.
[TASK] Restructured parts of the core to support sending data right after connecting. [TASK] Adapted core part for automatic reconnect to support sending initial data, too.
This commit is contained in:
@@ -10,12 +10,12 @@ class Client_IrcClient extends Client_AbstractClient {
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $got_001;
|
||||
protected $joined;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $joined;
|
||||
protected $got001;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
@@ -53,44 +53,52 @@ class Client_IrcClient extends Client_AbstractClient {
|
||||
*/
|
||||
public function resetConnectionStatus() {
|
||||
$this->lines = 0;
|
||||
$this->got_001 = FALSE;
|
||||
$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
|
||||
*/
|
||||
public function processContentObject($contentObject) {
|
||||
protected function processContentObject($contentObject) {
|
||||
$data = $contentObject->getRawData();
|
||||
//DEBUG
|
||||
//DEBUG
|
||||
//var_dump($contentObject);
|
||||
//echo "[RECV] ".$data;
|
||||
|
||||
//respond to pings
|
||||
if($contentObject->getCommand() === "PING") $this->protocolHandler->pong($contentObject->getParams());
|
||||
|
||||
$this->clientManager->sendToGroup("srv", "[#".$this->ID."] ".$data."\r\n\r\n");
|
||||
$this->clientManager->sendToGroup("srv", "[#".$this->ID."] ".$data);
|
||||
|
||||
if($contentObject->getCommand() === "001") $this->got001 = TRUE;
|
||||
|
||||
$return = "";
|
||||
|
||||
if(preg_match("/001/", $data)) $this->got_001 = TRUE;
|
||||
$this->lines++;
|
||||
|
||||
if(!$this->authed && $this->lines > 1) {
|
||||
$return .= "USER as as as :Asdfg\r\nNICK :" . $this->nick . "\r\n";
|
||||
$this->authed = TRUE;
|
||||
}
|
||||
|
||||
if($this->got_001 && !$this->joined) {
|
||||
if(!$this->joined && $this->got001) {
|
||||
$this->joined = TRUE;
|
||||
foreach($this->channels AS $channel) $return .= "JOIN " . $channel . "\r\n";
|
||||
}
|
||||
|
||||
if(strpos($data, "hau ab") !== FALSE) {
|
||||
if(strpos($data, "multivitamin") !== FALSE) {
|
||||
$return .= "PRIVMSG ".$this->channels[0]." :roger that :D\r\n";
|
||||
$return .= "QUIT :lol\r\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user