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\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")
{
f开发者_如何学Pythonwrite($ircSocket, "PONG ".$exData[1]."\n");
}
}
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 . "\n");
}
}
?>
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.
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]}\n";
fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "\n");
}
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
精彩评论