1

Currently I am making a IRC that sends a message onto the IRC main channel. Here is my code:

<?php


$ircServer = "xxxx";
$ircPort = "6667";
$ircChannel = "#bots";

set_time_limit(0);

$msg = $_GET['msg'];

$ircSocket = fsockopen($ircServer, $ircPort, $eN, $eS);

if ($ircSocket)
{

    fwrite($ircSocket, "USER Lost rawr.test lol :code\n");
    fwrite($ircSocket, "NICK Rawr" . rand() . "\n");
    fwrite($ircSocket, "JOIN " . $ircChannel . "\n");
    fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\n");

    while(1)
    {
        while($data = fgets($ircSocket, 128))
        {
            echo nl2br($data);
            flush();

            // Separate all data
            $exData = explode(' ', $data);

            // Send PONG back to the server
            if($exData[0] == "PING")
            {
                fwrite($ircSocket, "PONG ".$exData[1]."\n");
            }
}
    echo $eS . ": " . $eN;
}
}
?>

<html><body>
<h4>IRC Bot Tester</h4>
<form action="irc.php" method="post"> 
Command: <input type="text" name="msg" />
<input type="submit" />
</form>
</body></html>

My problem is the BOT is not sending any messages to the channel, as you see I used post + get data for the message info sent to the channel.

Here is the log what I recieve:

:irc.underworld.no 366 Rawr30517 #bots :End of /NAMES list. :irc.underworld.no 411 Rawr30517 :No recipient given (PRIVMSG) : 0: 0PING :irc.underworld.no

I do not know which part causes the this:

recipient given (PRIVMSG) : 0: 0PING

Thanks if anyone could help me. I am trying to simply post a message to the bot and the bot delivers the message to the main channel.

hakre
  • 193,403
  • 52
  • 435
  • 836
Ray
  • 341
  • 2
  • 6
  • 17

2 Answers2

4

Change:

$msg = $_GET['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\n");

To:

$msg = $_POST['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " :" . $msg . "\n");
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
  • Now its giving me this error: :irc.underworld.no 366 Rawr6090 #bots :End of /NAMES list. :irc.underworld.no 412 Rawr6090 :No text to send – Ray Nov 19 '10 at 17:13
  • Still giving me the: error: :irc.underworld.no 366 Rawr6090 #bots :End of /NAMES list. :irc.underworld.no 412 Rawr6090 :No text to send. Some how its failing to grab message. – Ray Nov 19 '10 at 17:18
  • How are you calling the script? What does the URL look like? – Sean Bright Nov 19 '10 at 17:19
  • Look above, I have created a simple form. Whatever is entered in field "Command" will send to the bot and the bot should send to the channel. However its not working. – Ray Nov 19 '10 at 17:20
  • That's cause your form is $_POST whereas you're looking for $_GET, change `$_GET` to `$_POST` – Ben Nov 19 '10 at 17:20
  • Explain sir, Im confused. Edit the answer.
    as it post to IRC.php and IRC.php should get.
    – Ray Nov 19 '10 at 17:21
  • Problem, in the form I enter "hello what bye" when it post's to the main IRC channel the result is "hello" or just single words. the "what bye" is missing. – Ray Nov 19 '10 at 17:24
1
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " . $msg = $_GET['msg'] . "\n");

To:

fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " .$msg. "\n");
William T Wild
  • 1,025
  • 1
  • 14
  • 23