目前我正在制作一个向IRC主频道发送消息的IRC。这是我的代码:
<?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>
我的问题是BOT没有向频道发送任何消息,因为您看到我使用post + get数据来发送到频道的消息信息。
以下是我收到的日志:
:irc.underworld.no 366 Rawr30517 #bots :结束/ NAMES列表。 :irc.underworld.no 411 Rawr30517:没有 收件人(PRIVMSG):0:0PING :irc.underworld.no
我不知道哪个部分导致了这个:
收件人(PRIVMSG):0:0PING
谢谢,如果有人能帮助我。我试图简单地向机器人发送消息,并且机器人将消息传递到主要渠道。
答案 0 :(得分:4)
变化:
$msg = $_GET['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\n");
要:
$msg = $_POST['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " :" . $msg . "\n");
答案 1 :(得分:1)
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " . $msg = $_GET['msg'] . "\n");
要:
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " .$msg. "\n");