php - IRC Online Count within channel -
am having problem's script found. works , don't... can see problems it? or have 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 server. fputs($socket,"user socks socks socks :socks\r\n"); // send username. fputs($socket,"nick $irc_nick \r\n"); // set our nick. fputs($socket,"list $irc_channel \r\n"); // list provided channel. // $handle = fopen('log.txt',a); // log if want. // set initial value. $users = 0; // receive incoming data. while(1) { $sock_data = fgets($socket,1024); // each line of data response. // fwrite($handle,"$sock_data\r\n"); // write log. // information section of desired responses. $sep = explode(':',$sock_data); // separate colons. $info = $sep[1]; // after first colon important information. $message = $sep[2]; // break down response , id , sent it. $info_sep = explode(' ',$info); // separate spaces. $full_who = $info_sep[0]; // person sent first item in list. $id = $info_sep[1]; // id second item in list. $who_sep = explode('!',$full_who); // separate exclamation points. $who = $who_sep[0]; // nick of person part before exclamation point. // saw scripts checking this, so... if ($who == 'ping') { fputs($socket,"pong $message"); } // privmsg indicates sending message. // need reply version , ping requests. if ($id == 'privmsg') { if (substr($message, 0, 8) == 'version') { // reply version response. fputs($socket,"notice $who :".chr(1)."version getusers v0.1b".chr(1)."\r\n"); } elseif (strstr($message, 'ping') !== false) { // ping them if needed. fputs($socket,"notice $who :$message"); } } // 322 list response. // should number of users on provided channel. if ($id == '322') { $users = $info_sep[4]; // number of users. // fclose($handle); // close log. fclose($socket); // close connection. break; // end loop. } // 323 end list response. // in case there no 322 response (the channel doesn't exist, maybe?) if ($id == '323') { // fclose($handle); // close log. fclose($socket); // close connection. break; // end loop. } // 263 failed response. // wait 2 seconds , retry. if ($id == '263') { sleep(2); // pause 2 seconds. fputs($socket,"list $irc_channel \r\n"); // list provided channel. } } // display results on page. if ($users == '1') { echo "1"; } else { echo "$users"; } ?>
you might have more luck tested , stable php irc library pear's net_smartirc - http://pear.php.net/package/net_smartirc
Comments
Post a Comment