[TASK] Introduced addLine() to the buffer class.

[TASK] Made createBuffer function protected in ProtocolHandler classes.
This commit is contained in:
Jan Philipp Timme 2011-06-26 14:03:32 +00:00
parent df030e453d
commit 8e32f35edf
8 changed files with 50 additions and 21 deletions

View File

@ -65,7 +65,7 @@ class Client_IrcClient extends Client_AbstractClient {
*/
public function initializeConnection() {
if(!$this->authed) {
$data = "USER poweruser as as :JPTs Bot\r\nNICK :" . $this->nick . "\r\n";
$data = "USER poweruser as as :JPTs Bot\r\nNICK " . $this->nick . "\r\n";
$this->authed = TRUE;
}
$this->protocolHandler->sendRaw($data);
@ -80,7 +80,8 @@ class Client_IrcClient extends Client_AbstractClient {
protected function processContentObject($contentObject) {
$data = $contentObject->getRawData();
//DEBUG
//var_dump($contentObject);
var_dump($contentObject);
var_dump($data);
//respond to pings
if($contentObject->getCommand() === "PING") $this->protocolHandler->pong($contentObject->getParams());
@ -98,7 +99,7 @@ class Client_IrcClient extends Client_AbstractClient {
foreach($this->channels AS $channel) $return .= "JOIN " . $channel . "\r\n";
}
if(strpos($data, "multivitamin") !== FALSE) {
if(strpos($data, "musdsdsafgagltivitamin") !== FALSE) {
$return .= "PRIVMSG ".$this->channels[0]." :roger that :D\r\n";
$return .= "QUIT :lol\r\n";
}

View File

@ -370,7 +370,7 @@ class Connection_ConnectionHandler {
* @param boolean $connected
* @return void
*/
private function setConnected($connected) {
protected function setConnected($connected) {
return $this->socketHandler->setConnected($connected);
}

View File

@ -119,7 +119,7 @@ class Connection_ConnectionPool {
if($connectionHandler->canWrite() === TRUE && $connectionHandler->isServer() === FALSE) {
$write[] = $connectionSocket;
//the line above does not work for freshly connected stuff.
//this is the fallback(?) - just write the stuff - no matter what happens.
//this is the fallback - just write the stuff - no matter what happens.
if($connectionHandler->writeFromBuffer() === FALSE) $this->removeConnectionHandler($connectionHandler);
}
}
@ -143,7 +143,7 @@ class Connection_ConnectionPool {
}
break;
case "write":
//this might still work on active connections that are "in use".
//this might still work on active connections that are "in use" and already received data.
//however, it does not for freshly connected ones.
if($connectionHandler->writeFromBuffer() === FALSE) $this->removeConnectionHandler($connectionHandler);
break;

View File

@ -59,6 +59,16 @@ class Misc_Buffer {
$this->pruneEmptyLines();
}
/**
* Appends data + linebreak to the buffer.
* @param string $data
* @return void
*/
public function addLine($data) {
$this->buffer .= $data . $this->linebreak;
$this->pruneEmptyLines();
}
/**
* Returns the next line in the buffer and removes it from the buffer.
* @return string

View File

@ -29,7 +29,7 @@ abstract class Protocol_AbstractProtocolHandler {
* put them in $bufferIncoming and $bufferOutgoing.
* @return void
*/
abstract public function createBuffers();
abstract protected function createBuffers();
/**
* General constructor.

View File

@ -11,7 +11,7 @@ class Protocol_BotProtocolHandler extends Protocol_AbstractProtocolHandler {
* Shall create the two buffers and set them up.
* @return void
*/
public function createBuffers() {
protected function createBuffers() {
$linebreak = "\r\n";
$this->bufferIncoming = new Misc_Buffer($linebreak);
$this->bufferOutgoing = new Misc_Buffer($linebreak);
@ -45,7 +45,7 @@ class Protocol_BotProtocolHandler extends Protocol_AbstractProtocolHandler {
* @return void
*/
public function sendRaw($data) {
$this->bufferOutgoing->addData($data);
$this->bufferOutgoing->addLine($data);
}
}

View File

@ -16,7 +16,7 @@ class Protocol_IrcProtocolHandler extends Protocol_AbstractProtocolHandler {
* Shall create the two buffers and set them up.
* @return void
*/
public function createBuffers() {
protected function createBuffers() {
$this->linebreak = "\n";
$this->bufferIncoming = new Misc_Buffer($this->linebreak);
$this->bufferOutgoing = new Misc_Buffer($this->linebreak);
@ -52,25 +52,29 @@ class Protocol_IrcProtocolHandler extends Protocol_AbstractProtocolHandler {
//determine what command was sent
$command = "";
if(strpos($data, " ") !== FALSE) {
list($command, $data) = explode(" ", $data, 2);
} else {
$command = $data;
}
$contentObject->setCommand($command);
//we'll write these values into the contentObject later!
//contains a user or the channel a command is addressed to.
$target = "";
$target = NULL;
//parameters of the command
$params = "";
$params = NULL;
//content or message
$message = "";
//affected nickname
$subject = "";
$message = NULL;
//affected nickname(s) (e.g. by a KICK or MODE +b)
$subject = NULL;
//command-dependent parsing
switch($command) {
case "PRIVMSG":
case "NOTICE":
list($target, $message) = explode(" ", $data, 2);
list($target, $params) = explode(" ", $data, 2);
//cut the colon
$message = substr($params, 1);
break;
@ -83,8 +87,12 @@ class Protocol_IrcProtocolHandler extends Protocol_AbstractProtocolHandler {
case "ERROR":
case "QUIT":
//cut the colon
$message = substr($data, 1);
if(strpos($data, " :") !== FALSE) {
list($params, $message) = explode(" :", $data);
$message = substr($message, 1);
} else {
$params = $data;
}
break;
case "PING":
@ -95,7 +103,7 @@ class Protocol_IrcProtocolHandler extends Protocol_AbstractProtocolHandler {
//channel, <comment>
case "PART":
if(strpos(" :", $data) !== FALSE) {
if(strpos($data, " :") !== FALSE) {
list($params, $message) = explode(" :", $data);
$message = substr($message, 1);
} else {

View File

@ -17,11 +17,21 @@ $euirc = $clientManager->createTcpConnection("euirc", "irc");
$clientManager->attachConfig(array(
"nick" => "Pb42",
"userident" => "Serena",
"channels" => array("#kuzuru-subs")
"channels" => array()
), $euirc);
$euirc->connect("irc.euirc.net", 6667);
$euirc->setReconnect(TRUE);
/*$osuIRC = $clientManager->createTcpConnection("osuIRC", "irc");
$clientManager->attachConfig(array(
"nick" => "Pb42",
"userident" => "Serena",
"channels" => array("#osu", "#german")
), $osuIRC);
$osuIRC->connect("irc.ppy.sh", 6667);
$osuIRC->setReconnect(TRUE);*/
/*$config_eloxoph = array(
"nick" => "Frischmilch",