PHP - IRC 连接

发布于 2024-10-02 21:07:41 字数 877 浏览 8 评论 0原文

这是我的脚本:

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

set_time_limit(0);

$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");

    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");
            }
        }
    }
} else {
    echo $eS . ": " . $eN;
}

我在添加一个函数时遇到问题,该函数将向 IRC 频道上的每个人发送私人消息。我尝试了 $read 和其他方法,但它不起作用并且 IRC 挂起。

注意:这是出于教育/私人目的,不会造成任何伤害。

Here is my script:

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

set_time_limit(0);

$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");

    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");
            }
        }
    }
} else {
    echo $eS . ": " . $eN;
}

I am having problem's adding a function that will Private message everyone on the IRC channel. I tried $read and other methods it does not work and IRC hangs.

NOTE: This is for educational/private purposes no harm is done or made.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

格子衫的從容 2024-10-09 21:07:41

几年前我用 Perl 编写了几个 IRC 机器人,说实话,我已经不记得它们了。无论如何,要向所有用户发送私信,首先您需要获取频道中的所有用户。

无论如何,发送私人消息的命令是:

PRIVMSG #channel :Sup?

是的,它会回显“Sup?”在#channel。对于用户来说也是如此:

PRIVMSG John :Sup?

您所需要做的就是获取所有用户。为此:

NAMES #channel

代码由您决定。祝你好运。

编辑:要获取用户的百分比,只需将它们加载到数组中,然后使用 shuffle() shuffle($array); 如果你想随机化它们的位置。然后使用 count() $size = count($array); 对于数组大小,将大小乘以百分比。 $target = $size * 0.10; 为 10%。然后使用 round() 获取四舍五入 -关闭号码。

现在,循环用户数组并将限制设置为 $target。就这样,你就有了。

编辑:这是一个示例代码(其余代码由您决定:

...

$msg = $_POST['message'];
$pr = $_POST['percentage'];
$pr /= $100; // if the input is already 0.10 or something, no need to do this.

...

shuffle($users);
$size = count($users);
$target = $size * $pr;
$target = $round($target);

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

...

I've written several IRC bots years ago in Perl, and to be honest, I can't remember them anymore. Anyway, to send a private message to all the users, first you need to get all the users in the channel.

Anyway, the command to send a private message is:

PRIVMSG #channel :Sup?

Yeah, it will echo "Sup?" at the #channel. Then same goes for a user:

PRIVMSG John :Sup?

All you need to do is get all the users. To do this:

NAMES #channel

The code is up to you. Good luck.

EDIT: To get a percentage of the users, simply load them in an array, then use shuffle() shuffle($array); if you want to randomize their positions. Then use count() $size = count($array); for the array size, multiply the size by the percentage. $target = $size * 0.10; for 10%. Then use round() to get the rounded-off number.

Now, loop the array of users and set the limit to $target. There you have it.

EDIT: Here's a sample code (the rest of the code is up to you ofc:

...

$msg = $_POST['message'];
$pr = $_POST['percentage'];
$pr /= $100; // if the input is already 0.10 or something, no need to do this.

...

shuffle($users);
$size = count($users);
$target = $size * $pr;
$target = $round($target);

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

...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文