PHP - IRC 连接
这是我的脚本:
$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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几年前我用 Perl 编写了几个 IRC 机器人,说实话,我已经不记得它们了。无论如何,要向所有用户发送私信,首先您需要获取频道中的所有用户。
无论如何,发送私人消息的命令是:
是的,它会回显“Sup?”在#channel。对于用户来说也是如此:
您所需要做的就是获取所有用户。为此:
代码由您决定。祝你好运。
编辑:要获取用户的百分比,只需将它们加载到数组中,然后使用
shuffle()
shuffle($array);
如果你想随机化它们的位置。然后使用count()
$size = count($array);
对于数组大小,将大小乘以百分比。$target = $size * 0.10;
为 10%。然后使用round()
获取四舍五入 -关闭号码。现在,循环用户数组并将限制设置为
$target
。就这样,你就有了。编辑:这是一个示例代码(其余代码由您决定:
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:
Yeah, it will echo "Sup?" at the #channel. Then same goes for a user:
All you need to do is get all the users. To do this:
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 usecount()
$size = count($array);
for the array size, multiply the size by the percentage.$target = $size * 0.10;
for 10%. Then useround()
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: