Connects to an IRC server you specify and idles. Basically this is a frame for an IRC bot.
<?php
class Client
{
var $server;
function server($dstaddr=NULL)
{
if (!$dstaddr)
{
return $this->server;
}
$this->server = $dstaddr;
}
var $port;
function port($dstport=NULL)
{
if (!$dstport)
{
return $this->port;
}
$this->port = $dstport;
}
var $nick;
function nick($alias=NULL)
{
if (!$alias)
{
return $this->nick;
}
$this->nick = $alias;
}
var $ident;
function ident($user=NULL)
{
if (!$user)
{
return $this->ident;
}
$this->ident = $user;
}
var $gecos;
function gecos($name=NULL)
{
if (!$name)
{
return $this->gecos;
}
$this->gecos = $name;
}
var $fd;
var $BUFFER_SIZE = 512;
function run()
{
$canonical = gethostbyname($this->server());
if ($canonical == $this->server())
{
return;
}
$this->fd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!$this->fd)
{
return;
}
$err = socket_connect($this->fd, $this->server(), $this->port());
if (!$err)
{
return;
}
socket_write($this->fd, "NICK " . $this->nick() . "\r\n");
socket_write($this->fd, "USER " . $this->ident() . " \"\" \"\" :" . $this->gecos() . "\r\n");
while (($in = socket_read($this->fd, $this->BUFFER_SIZE)))
{
if (preg_match("/^PING (:[^ ]+)$/i", $in, $regex))
{
socket_write($this->fd, "PONG " . $regex[0] . "\r\n");
}
}
}
}
?>
<?php
$client = new Client();
$client->server("irc.kingskrown.com");
$client->port(6667);
$client->nick("php");
$client->ident("svs");
$client->gecos("php");
$client->run();
?>
Of course this won't work in mIRC, it's PHP. :|
Okay, i've got this connected to a server and modified it according to this snippet so I can easily make it respond to commands: http://www.hawkee.com/snippet/6223/
However, the ping does not seem to be working. Can anyone help me on this? Code: http://pastebin.com/m44c64848