频道内 IRC 在线计数

发布于 2024-10-19 22:57:53 字数 3177 浏览 0 评论 0原文

我发现的脚本有问题。有时它有效,有时它不起作用......任何人都可以看到它有什么问题吗?或者有更好的吗?

非常感谢

<?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"; 
}
?>

Am having problem's with a script I found. Sometimes it works and sometimes it don't... Can anyone see any problems with it? or have a better one?

Many Thanks

<?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"; 
}
?>

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

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

发布评论

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

评论(1

佞臣 2024-10-26 22:57:53

您可能会更幸运地使用经过测试且稳定的 PHP IRC 库,例如 PEAR 的 Net_SmartIRC - http://pear.php。净/包/Net_SmartIRC

You might have more luck with a tested and stable PHP IRC library like PEAR's Net_SmartIRC - http://pear.php.net/package/Net_SmartIRC

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