rendered paste body<?php
if (!defined('STDIN')) {
define('STDIN', fopen('php://stdin', 'r'));
}
class stdin {
public $stdin;
public function stream() {
stream_set_blocking(STDIN, 0);
stream_select($this->stdin['read'] = array(STDIN), $this->stdin['write'] = NULL, $this->stdin['except'] = NULL, 0);
//var_dump($this->stdin['stdin']['buffer']);
$this->stdin['buffer'] = fread(STDIN, 1500);
return $this->stdin['buffer'];
unset($this->stdin['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['read'] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
if (socket_connect($this->socket['read'], $this->host, $this->port)) {
echo 'Socket created, locked and loaded... on ' . $this->host . ' [' . $this->socket['read'] . ']' . "\n";
return true;
}
else {
return false;
}
}
}
}
public function stream() {
$read = array(&$this->socket['read']);
socket_set_nonblock($this->socket['read']);
socket_select($read, $this->socket['write'] = NULL, $this->socket['except'] = NULL, 0);
$this->socket['buffer'] = trim(socket_read($this->socket['read'], 2048, PHP_NORMAL_READ));
return $this->socket['buffer'];
unset($this->socket['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 ' . '#atomiku' . "\n");
}
else {
print('Connection to ' . $this->host . ' on port ' . $this->port . ' failed ' . '[' . $this->socket . ']' . "\n");
}
}
public function interpret() {
}
}
$stdin = new stdin;
$socket = new socket('athena.irc.atomiku.com', '6667');
//athena.irc.atomiku.com
$irc_bot = new internet_relay_chat($socket->host, $socket->port, $socket->socket['read'], NULL, 'Mini', 'barryd.it', 'Gorge Washington');
while(true){
if (($tmp['stdin']['stream'] = $stdin->stream()) != NULL) {
/*
if (!($tmp['buffer'] = $player->command($tmp['stream']))) {
echo 'Responce from player object, request to shut down.' . "\n";
break 2;
}
*/
echo $tmp['stdin']['stream'] . "\n";
socket_write($socket->socket['read'], $tmp['stdin']['stream'] . "\n");
}
if (($tmp['socket']['stream'] = $socket->stream()) != NULL) {
/*
if (!($tmp['buffer'] = $player->command($tmp['stream']))) {
echo 'Responce from player object, request to shut down.' . "\n";
break 2;
}
*/
if (substr($tmp['socket']['stream'], 0, 4) == 'PING' ) {
print("[-]Ping " . substr($tmp['socket']['buffer'], 5) . "\r\n");
socket_write($socket->socket['read'], 'PONG ' . substr($tmp['socket']['buffer'], 5) . '');
}
if (eregi("!we", $tmp['socket']['stream'])) {
socket_write($socket->socket['read'], 'PRIVMSG ' . '#atomiku' . ' :weeeeeeeeeeee' . "\n");
}
echo $tmp['socket']['stream'] . "\n";
}
unset($tmp);
}
?>