[TASK] Added the ProtocolHandlerException

[TASK] Started to implement the IRC-Protocol
This commit is contained in:
Jan Philipp Timme
2010-12-12 21:44:19 +00:00
parent b1a7ac5fdb
commit 03a4dfff71
10 changed files with 365 additions and 14 deletions
+2 -2
View File
@@ -15,9 +15,9 @@ $freenode->setReconnect(TRUE);
$freenode = $clientManager->createTcpConnection("freenode", "irc");
$clientManager->attachConfig(array(
"nick" => "Testinstanz2",
"nick" => "Pb42",
"userident" => "uzuguck",
"channels" => array("#mstasty")
"channels" => array("#mstasty", "#starsim")
), $freenode);
$freenode->connect("irc.freenode.net", 6667);
+49
View File
@@ -0,0 +1,49 @@
<?php
/**
* Parser for Clientside-IRC.
* @param string $msg
* @return array
*/
function parse($msg){
//skip empty
if(trim($msg) === "") return;
$from = "";
if($msg[0] === ":") {
$piece = explode(" ", $msg, 2);
list($from, $msg) = $piece;
unset($piece);
//cut the colon
$from = substr($from, 1);
}
$command = "";
$piece = explode(" ", $msg, 2);
list($command, $msg) = $piece;
unset($piece);
return array("From" => $from, "Command" => $command, "Msg" => $msg);
}
$lines = array();
$lines[] = ":kornbluth.freenode.net 376 JPT|test :End of /MOTD command.";
$lines[] = ":frigg!~frigg@freenode/utility-bot/frigg PRIVMSG JPT|test :VERSION";
$lines[] = ":kornbluth.freenode.net 333 JPT|test #botted rotw!~rotw@p5B133ADF.dip.t-dialin.net 1291741910";
$lines[] = ":ChanServ!ChanServ@services. NOTICE JPT|test :[#botted] Für Statistiken siehe !stats. Wenn du nicht in diesen Auftauchen willst, wende dich bitte an samohT";
$lines[] = ":kornbluth.freenode.net NOTICE * :*** Found your hostname";
$lines[] = ":thomasbot!~thomasbot@unaffiliated/thomas/x-476237/bot/thomasbot PRIVMSG #botted :*pong*";
$lines[] = ":n|ki!~niki@star-sim.de MODE #botted -v JPT";
$lines[] = "ERROR :Closing Link: dslb-088-070-011-158.pools.arcor-ip.net (Client Quit)";
foreach($lines AS $line) {
var_dump(parse($line));
}
echo "\r\n\r\n";
?>