Page 1 of 1

Channel list

Posted: Fri Nov 14, 2008 1:11 am
by DJ24966
I'm trying to create PHP file that will return the currently opened channels, and allow the user to join. This is what I have right now.

Code: Select all

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
    $botnick = "Chatterup";
    $server = "chatterup.webhop.net";
    $port = "6667";
    $channel = "";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Room List</title>
</head>
<body>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" id="AutoNumber1" style="border-collapse: collapse">
  <tr>
    <td width="8%" height="20" align="center" valign="middle" bgcolor="#FFFFCC" style="border-left:1px solid #333333;border-bottom:1px solid;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;">&nbsp;Users</td>
    <td width="15%" height="20" align="left" valign="middle" bgcolor="#FFFFCC" style="border-bottom:1px solid;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;">&nbsp;Roomname:</td>
    <td width="77%" height="20" align="left" valign="middle" bgcolor="#FFFFCC" style="border-right:1px solid #333333;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;">&nbsp;Topic:</td>
  </tr>
<?php
    $fp = fsockopen($server, $port, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    }
    else {
        fputs($fp,"USER $botnick $botnick 127.0.0.1 :php\n");
        $nick = $botnick . rand(10000,99999);
        fputs($fp,"NICK $nick\n");
        while (!feof($fp)) {
            usleep(50);
            $fget = @fgets($fp, 128);
            echo "$fget <br>\n";
            $match = explode(" ", $fget);
            $fget = ereg_replace ("\n", "", $fget);
            $fget = ereg_replace ("\r", "", $fget);
            if ($match[1] == "001") {
                fputs($fp,"LIST\n");
            }
            else if ($match[0] == "PING") {
                fputs($fp, "PONG :" . $match[1]);
            }
            else if ($match[1] == "433") {
                $nick = $botnick . rand(10000,99999);
                fputs($fp,"NICK $nick\n");
            }
            else if ($match[1] == "323") {
                fputs($fp, "QUIT :bye!\n");
                break;
            }
            else if ($match[1] == "322") {
                $match[3] = ereg_replace ("#", "", $match[3]);
                if (eregi ("$channel(.*)", $match[3], $chan)) {
                    $topic = explode(":", $fget);
                    unset($topic[0]);
                    unset($topic[1]);
                    $topic = implode(":", $topic);
                    if ($color == "FBFBF7") {
                        $color = "FFFFFF";
                    }
                    else {
                        $color = "FBFBF7";
                    }
                    ?>
  <tr>
    <td width="8%" align="center" valign="middle" bgcolor="#<?php echo $color; ?>" style="border-top:1px solid #333333;border-left:1px solid #333333;border-bottom:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"><?php echo $match[4]; ?></td>
    <td width="15%" style="border-bottom:1px solid #333333;bordertop:1px solid #333333;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;" bgcolor="#<?php echo $color; ?>">&nbsp;<a href="./chat.php?action=Chat&rmname=[EN]<?php echo $chan[1]; ?>">
      <?php echo $chan[1]; ?>
      </a></td>
    <td width="77%" style="border-right:1px solid #333333;border-bottom:1px solid #333333;FONT-FAMILY:;border-top:1px solid #333333; verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"bgcolor="#<?php echo $color; ?>">&nbsp;
      <?php echo $topic; ?></td>
  </tr>
                      <?php
                }
            }
        }
        fclose($fp);
    }
?>
</table>
</body>
</html>
However, I'm getting the following message:

:chatterup.webhop.net NOTICE AUTH :*** Looking up your hostname...
:chatterup.webhop.net NOTICE AUTH :*** Found your hostname (cached)
PING :FDA20F3F
:FDA20F3F![email protected] PRIVMSG Chatterup51976 :VERSION
ERROR :Closing Link: Chatterup51976[127.0.0.1] (Ping timeout)

Can someone point in the in the right direction here?

Thanks

Re: Channel list

Posted: Fri Nov 14, 2008 1:33 am
by zEkE
I'd set some debug lines to echo things, particularly around the PONG point - looking at the code I'd suspect it is sending the reply with two :'s, thus PING :request generates PONG ::request - could be causing problems.

So I'd say set lines to find out what the script is sending to the server, and go from there.

Re: Channel list

Posted: Fri Nov 14, 2008 1:48 am
by DJ24966
zEkE wrote:I'd set some debug lines to echo things, particularly around the PONG point - looking at the code I'd suspect it is sending the reply with two :'s, thus PING :request generates PONG ::request - could be causing problems.

So I'd say set lines to find out what the script is sending to the server, and go from there.
Well, I'll be the first to admit I'm not a php expert, you think you could help me out a bit? I'm a bit confused.

Re: Channel list

Posted: Fri Nov 14, 2008 1:59 am
by zEkE

Code: Select all

 else if ($match[0] == "PING") {
                fputs($fp, "PONG :" . $match[1]);
            }
Should become

Code: Select all

 else if ($match[0] == "PING") {
                echo "PONG :" . $match[1];
                echo "\n";
                fputs($fp, "PONG :" . $match[1]);
            }
This will echo what the fputs function is sending to the socket. If the output has a double-colon, the solution might be as easy as removing the colon from the fputs line (and removing the echo lines)

Re: Channel list

Posted: Fri Nov 14, 2008 2:12 am
by DJ24966
zEkE wrote:

Code: Select all

 else if ($match[0] == "PING") {
                fputs($fp, "PONG :" . $match[1]);
            }
Should become

Code: Select all

 else if ($match[0] == "PING") {
                echo "PONG :" . $match[1];
                echo "\n";
                fputs($fp, "PONG :" . $match[1]);
            }
This will echo what the fputs function is sending to the socket. If the output has a double-colon, the solution might be as easy as removing the colon from the fputs line (and removing the echo lines)
That seems to be working now :D

Thanks, is there anyway to remove where it says Pong above the table?

http://chatterup.webhop.net/site/?n=pages/older

Here is the current code.

Code: Select all

http://chatterup.webhop.net/site/?n=pages/older

Re: Channel list

Posted: Fri Nov 14, 2008 2:17 am
by zEkE
Remove the two 'echo' lines that you added above the fputs :)

Re: Channel list

Posted: Fri Nov 14, 2008 2:20 am
by DJ24966
zEkE wrote:Remove the two 'echo' lines that you added above the fputs :)
Thanks again.