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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题