Date: 04/14/07 (PHP Community) Keywords: php, java Normally I try to help with simple scripts when i can here and there, but recently, i've been trying a new endeavor: a replacement to the crappy Java-based IRC clients, and instead, writing my own SAJAX/phpIRC (both APIs) client so I have the freedom and breathing room of PHP scripting rather than the comparitively limited scripting language of mIRC. function onping($code,$nick,$ident,$host,$dest,$d unset($input); if ($input=file("ircinput") && $input[0]!=NULL) { //print_r($input); foreach ($input as $num => $indata) { if ($indata == NULL) { return; } chop($indata); $command=explode(" ",str_replace("\r","",$indata)); echo "{$command[0]}\n"; if ($command[0] == "/join") { if (irc_join($command[1], $command[2])) $curchan=$command[1]; } if ($command[0] == "/msg") { $msg=getfrom($command," ",2); irc_privmsg($command[1], $msg); } if ($command[0] == "/notice") { $msg=getfrom($command," ",2); irc_notice($command[1], $msg); } if ($command[0] == "/me" && $curchan) { $msg=getfrom($command," ",2); irc_action($curchan, $msg); } if ($command[0] == "/kick" && $curchan) { $msg=getfrom($command," ",2); irc_kick($curchan, $command[1], $msg); } if ($command[0] == "/quit") { $msg=getfrom($command," ",1); irc_disconnect($msg); } if ($command[0][0] != "/" && $curchan) { irc_privmsg($curchan, $indata); } } unset($input); file_put_contents("ircinput", ""); } usleep(250000); irc_ctcp_ping($username); usleep(250000); irc_idle(IRCCB_ONCTCPPING); } if (!irc_init()) { die("IRC API Init error!"); } irc_change_nick($username); if (!irc_connect($address,$port)) { die("IRC Connection failed."); } irc_add_callback(IRCCB_ONJOIN, "onjoin"); irc_add_callback(IRCCB_ONPART, "onpart"); irc_add_callback(IRCCB_ONQUIT, "onquit"); irc_add_callback(IRCCB_ONACTION, "onaction"); irc_add_callback(IRCCB_ONNOTICE, "onnotice"); irc_add_callback(IRCCB_ONPRIVMSG, "onprivmsg"); irc_add_callback(IRCCB_ONCTCPPING, "onping"); irc_ctcp_ping($username); usleep(250000); irc_idle(IRCCB_ONCTCPPING); If anyone can help me unstick this thing, it'd be much much appreciated. PHP 5.2.1 Oh, and I forgot to mention, the getfrom(&array $array, string $reconstruct_using, int $reconstruct_from) function, is a little function I wrote to recontruct a string from $array, using the data from $reconstruct_from onwards in the $array, combining them using $reconstruct_using. function getfrom($array,$use,$from) { while ($from != 0) { array_shift($array); $from--; } return implode($use,$array); }
|