#!/usr/bin/php
<?php
// IRC-Config
$conf['irc_server'] = "de.quakenet.org";
$conf['irc_port'] = "6667";
$conf['irc_identd'] = "meinbot";
$conf['irc_host'] = "meinedomain.de";
$conf['irc_nickname'] = "MeinBot4";
$conf['irc_realname'] = "Mein netter Bot";
$conf['irc_channel'] = "#computerbase";
$fp = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
if ( $fp == false ) die();
if ( socket_connect( $fp, $conf['irc_server'], $conf['irc_port'] ) == false ) die();
socket_write( $fp, "USER $conf[irc_identd] $conf[irc_host] $conf[irc_server] :$conf[irc_realname]\n\r" );
socket_write( $fp, "NICK $conf[irc_nickname]\r\n" );
get_response(); // Auf PING antworten
socket_write( $fp, "LIST $conf[irc_channel]\r\n" );
socket_write( $fp, "QUIT\r\n" );
get_response();
socket_close( $fp );
function get_response() {
global $fp, $conf, $glob;
// Nach "NOTICE" muss das LIST-Kommando gesendet werden, daher vorerst abbrechen
while( !stristr( $response, "NOTICE $conf[irc_nickname] :on" ) ) {
if ( !$response = socket_read( $fp, 1024 ) ) die();
// Debug Ausgabe
echo $response;
// Eventuell auf PING antworten
if ( substr( $response, 0, 4 ) == "PING" ) {
socket_write( $fp, str_replace( "PING", "PONG", $response ) );
}
// Antwort auf LIST-Kommando auswerten
if ( preg_match( "/(.*?)".preg_quote( "$conf[irc_nickname] $conf[irc_channel]" )." ([\d]+)/s", $response, $array ) > 0 ) {
$users = mysql_escape_string( $array[2] );
// Hier jetzt $users irgendwo (Datenbank, Dateisystem, ...) abspeichern
echo $users;
}
}
}
?>