rendered paste body<?php
class socket {
public $host;
public $port;
public $socket;
public function __construct() {
list($this->host, $this->port) = func_get_args();
if (!is_null($this->host) || !is_null($this->port)) {
if (($this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
if (socket_connect($this->socket, $this->host, $this->port)) {
socket_set_nonblock($this->socket);
echo 'Socket created, locked and loaded... on ' . $this->host . ' [' . $this->socket . ']' . "\n";
return true;
}
else {
return false;
}
}
}
}
}
class internet_relay_chat extends socket {
public $pass;
public $nick;
public $user;
public $realname;
public function __construct() {
list($this->pass, $this->nick, $this->user, $this->realname) = func_get_args();
}
public function register() {
if (is_resource($this->socket)) {
print('Connection to ' . ($this->host or 'NULL') . ' on port ' . ($this->port || 'NULL') . ' was successful ' . '[' . $this->socket . ']' . "\n");
socket_write($this->socket, 'NICK ' . $this->nick . "\n");
socket_write($this->socket, 'USER ' . $this->user . ' 2 3: ' . $this->realname . "\n");
socket_write($this->socket, 'JOIN ' . '#atomiku' . "\n");
}
else {
print('Connection to ' . $this->host . ' on port ' . $this->port . ' failed ' . '[' . $this->socket . ']' . "\n");
}
}
public function interpret() {
}
}
$socket = new socket('athena.irc.atomiku.com', '6667');
var_dump($socket);
$irc_bot = new internet_relay_chat(NULL, 'Mini', 'barryd.it', 'Gorge Washington');
var_dump($irc_bot);
$irc_bot->register();
while(true){
if (socket_select($tmp['read'] = array($socket->socket), $tmp['write'] = NULL, $tmp['except'] = NULL, 0) === false) {
echo 'Failed to socket_select().' . "\n";
}
if (!($tmp['buffer'] = socket_read($socket->socket, 2048, PHP_NORMAL_READ))) {
echo 'Failed to socket_read().' . "\n";
}
print $tmp['buffer'];
if (substr($tmp['buffer'], 0, 4) == 'PING' ) {
socket_write($socket->socket, 'PONG ' . substr($tmp['buffer'], 5) . '');
print("[-]Ping " . substr($tmp['buffer'], 5) . "\r\n");
}
if (eregi("!we", $tmp['buffer'])) {
socket_write($socket->socket, 'PRIVMSG ' . '#atomiku' . ' :weeeeeeeeeeee' . "\n");
}
}
?>
barryd@infotech:~/Projects/PHP/phpMini/etc/packages/ecstasy> php5 ecstasy.php
Socket created, locked and loaded... on athena.irc.atomiku.com [Resource id #4]
object(socket)#1 (3) {
["host"]=>
string(22) "athena.irc.atomiku.com"
["port"]=>
string(4) "6667"
["socket"]=>
resource(4) of type (Socket)
}
object(internet_relay_chat)#2 (7) {
["pass"]=>
NULL
["nick"]=>
string(4) "Mini"
["user"]=>
string(9) "barryd.it"
["realname"]=>
string(16) "Gorge Washington"
["host"]=>
NULL
["port"]=>
NULL
["socket"]=>
NULL
}
Connection to on port failed []
:athena.irc.atomiku.com NOTICE AUTH :*** Looking up your hostname...
:athena.irc.atomiku.com NOTICE AUTH :*** Found your hostname (cached)