PHP IRC

    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.

    I'm getting hung up though... and it's in my processing call where I intake data from the user, and then either do something with the client, or inject data to the server. It takes 1 command, 1 command only, and then stops responding to me, but continues to read from the server just fine. Here's the snippet of code that does the processing, down to the INIT for the actual starting of the processing loop.

    function onping($code,$nick,$ident,$host,$dest,$data) {
    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);
    }

    Source: http://community.livejournal.com/php/560662.html

« Regex favour || a little help making sense... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home