ircbot/Testcode/Misc/IrcParser.php
Jan Philipp Timme 03a4dfff71 [TASK] Added the ProtocolHandlerException
[TASK] Started to implement the IRC-Protocol
2010-12-12 21:44:19 +00:00

49 lines
1.4 KiB
PHP

<?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";
?>