1
我遇到了問題,我找到了一個腳本。有時它有效,有時它不會......任何人都可以看到它的任何問題?或者有更好的?頻道內的IRC在線計數
非常感謝
<?php
/* CONFIGURATIONS! */
$irc_server = 'xxxxxxxxxx'; // Server
$irc_port = '6667'; // Port
//$irc_nick = ''; // Nick
$irc_channel = '#xxxxxxxx'; // Channel
/* END CONFIGURATIONS! */
$socket = fsockopen($irc_server,$irc_port); // Connect to the server.
fputs($socket,"USER SOCKS SOCKS SOCKS :SOCKS\r\n"); // Send the username.
fputs($socket,"NICK $irc_nick \r\n"); // Set our nick.
fputs($socket,"LIST $irc_channel \r\n"); // List the provided channel.
// $handle = fopen('log.txt',a); // Log if you want.
// Set initial value.
$users = 0;
// Receive the incoming data.
while(1) {
$sock_data = fgets($socket,1024); // Get each line of data from the response.
// fwrite($handle,"$sock_data\r\n"); // Write the log.
// Get the information section of the desired responses.
$sep = explode(':',$sock_data); // Separate by colons.
$info = $sep[1]; // After the first colon is the important information.
$message = $sep[2];
// Break down the response and get the id and who sent it.
$info_sep = explode(' ',$info); // Separate by spaces.
$full_who = $info_sep[0]; // The person who sent it is the first item in the list.
$id = $info_sep[1]; // The id is the second item in the list.
$who_sep = explode('!',$full_who); // Separate by exclamation points.
$who = $who_sep[0]; // The nick of the person is the part before the exclamation point.
// I saw some scripts checking for this, so...
if ($who == 'PING') {
fputs($socket,"PONG $message");
}
// PRIVMSG indicates someone is sending you a message.
// We just need this to reply to the VERSION and PING requests.
if ($id == 'PRIVMSG') {
if (substr($message, 0, 8) == 'VERSION') { // Reply to the version response.
fputs($socket,"NOTICE $who :".chr(1)."VERSION getUsers v0.1b".chr(1)."\r\n");
} elseif (strstr($message, 'PING') !== false) { // Ping them back if needed.
fputs($socket,"NOTICE $who :$message");
}
}
// 322 is the list response.
// This should get the number of users on the provided channel.
if ($id == '322') {
$users = $info_sep[4]; // The number of users.
// fclose($handle); // Close the log.
fclose($socket); // Close the connection.
break; // End the loop.
}
// 323 is the end list response.
// This is in case there is no 322 response (the channel doesn't exist, maybe?)
if ($id == '323') {
// fclose($handle); // Close the log.
fclose($socket); // Close the connection.
break; // End the loop.
}
// 263 is the failed response.
// Wait 2 seconds and retry.
if ($id == '263') {
sleep(2); // Pause for 2 seconds.
fputs($socket,"LIST $irc_channel \r\n"); // List the provided channel.
}
}
// Display the results on the page.
if ($users == '1') {
echo "1";
} else {
echo "$users";
}
?>
你能更具體?你期待什麼行爲?什麼不行?它在什麼條件下工作或不工作? – glomad 2011-03-02 00:41:50