rendered paste body<?php
if (!defined('STDIN')) {
define('STDIN', fopen('php://stdin', 'r'));
}
class stdin {
public function stream() {
$read = array(STDIN);
$write = NULL;
$except = NULL;
$buffer = NULL;
stream_set_blocking(STDIN, 0);
stream_select($read, $write, $except, 0);
//var_dump($this->stdin['stdin']['buffer']);
$buffer = trim(fread(STDIN, 1500));
return $buffer;
unset($buffer);
}
}
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)) {
echo 'Socket created, locked and loaded... on ' . $this->host . ':' . $this->port . ' [' . $this->socket . ']' . "\n";
return true;
}
else {
return false;
}
}
}
}
public function stream() {
$read = array(&$this->socket);
$write = NULL;
$except = NULL;
$buffer = NULL;
socket_set_nonblock($this->socket);
socket_select($read, $write, $except, 0);
$buffer = trim(socket_read($this->socket, 2048, PHP_NORMAL_READ));
return $buffer;
unset($buffer);
}
}
class internet_relay_chat extends socket {
public $host;
public $port;
public $socket;
public $pass;
public $nick;
public $user;
public $realname;
public function __construct() {
list($this->host, $this->port, $this->socket, $this->pass, $this->nick, $this->user, $this->realname) = func_get_args();
if (is_resource($this->socket)) {
print('Connection to ' . $this->host . ' on port ' . $this->port . ' 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 ' . '#Lobby' . "\n");
}
else {
print('Connection to ' . $this->host . ' on port ' . $this->port . ' failed ' . '[' . $this->socket . ']' . "\n");
}
}
public function interpret() {
}
}
$stdin = new stdin;
$socket = new socket('irc.firestormirc.net', '6667');
$irc_bot = new internet_relay_chat($socket->host, $socket->port, $socket->socket, NULL, 'Mini', 'barryd.it', 'Gorge Washington');
while(true){
$tmp = array('stdin' => $stdin->stream(), 'socket' => $socket->stream());
echo $tmp['stdin'] . "\n";
socket_write($socket->socket, $tmp['stdin'] . "\n");
echo $tmp['socket'] . "\n";
if (substr($tmp['socket'], 0, 4) == 'PING' ) {
print("[-]Ping " . substr($tmp['socket'], 5) . "\r\n");
socket_write($socket->socket, 'PONG ' . substr($tmp['socket'], 5) . '');
}
if (eregi("!we", $tmp['socket'])) {
socket_write($socket->socket, 'PRIVMSG ' . '#atomiku' . ' :weeeeeeeeeeee' . "\n");
}
unset($tmp);
}
?>