PHP - IRC Bot Not sending message Help

2019-03-01 12:22发布

问题:

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.

回答1:

Change:

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

To:

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


回答2:

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

To:

fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " .$msg. "\n");


标签: php irc