<?PHP
class irc
{
var $remotehost;
var $remoteport;
var $nick;
var $ircsocket;
var $channel;
var $flag = true;
function irc($remotehost, $remoteport, $nick, $channel)
{
set_time_limit(0);
ob_end_flush();
$this->remotehost = $remotehost;
$this->remoteport = $remoteport;
$this->nick = $nick;
$this->channel= $channel;
}
function ircConnect()
{
$this->ircsocket = fsockopen($this->remotehost, $this->remoteport);
if( ! $this->ircsocket )
die("Keine Verbindung");
fputs( $this->ircsocket, "USER lister 0 0 :who channel\r\n");
fputs( $this->ircsocket, "NICK $this->nick\r\n");
}
function send($message)
{
$message = $message."\r\n";
fputs( $this->ircsocket, $message);
}
function ircParse()
{
while( ! feof($this->ircsocket))
{
$incoming = fgets( $this->ircsocket, 1024 );
$incoming = str_replace("\r", "", $incoming);
$incoming = str_replace("\n", "", $incoming);
if( preg_match("/PING/", $incoming))
{
$ping = explode(":", $incoming);
$this->send("PONG $ping[1]");
}
$params = explode(" ", $incoming);
if( ! $this->flag )
echo $params[4]."<br>";
if( $params[5] == "/MOTD" )
{
$this->send("WHO $this->channel");
$this->flag = false;
}
if( $params[6] == "/WHO" )
$this->send("QUIT bye");
}
$this->send("QUIT bye");
}
}
$test = new irc("irc.bla.net", "6667", "testingWHO", "#channel");
$test->ircConnect();
$test->ircParse();
?>