drt5813 2010-11-18 22:08
浏览 53
已采纳

PHP - IRC私人消息功能帮助

For some reason my bot wont private message a % of people on the IRC Channel. Here is my script:

<?php

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

set_time_limit(0);


$msg = $_POST['message'];
$pr = $_POST['percentage'];
$pr /= 100;

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

if ($ircSocket)
{

    fwrite($ircSocket, "USER Lost rawr.test lol :code
");
    fwrite($ircSocket, "NICK Rawr" . rand() . "
");
    fwrite($ircSocket, "JOIN " . $ircChannel . "
");

    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]."
");
            }
}
    echo $eS . ": " . $eN;
}
shuffle($users);
$size = count($users);
$target = $size * $pr;
$target = $round($target);

for ($i = 0; $i <= $target; $i++) {
    fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "
");
}
}
?>

Here is the log on what I recieve:

:StatServ!stats@Mazzzzz.com PRIVMSG Rawr30566 :VERSION

I have even tried removing the Post data and replaced this part with this:

$msg = $_POST['message'];

With

$msg = hello;

The other people on the channel does not get a private message.

  • 写回答

1条回答 默认 最新

  • dougu0824 2010-11-18 22:15
    关注

    Is this your entire script? $users isn't set to anything; you probably meant to set it to an array of usernames. $round also isn't set; you probably meant to just call the built-in round() function. If you add a debugging line in the for loop you can at least tell which users (if any) should be getting messages:

    for ($i = 0; $i <= $target; $i++) {
        echo "Sending message to ${users[$i]}
    ";
        fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "
    ");
    }
    

    The IRC protocol stuff looks right. The receive log you were worried about doesn't have anything to do with it; StatServ on the IRC server is sending your bot a CTCP VERSION request. Normally clients respond with their name and version, and StatServ probably logs it so opers can see what clients are common on the network

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错