All pastes #492011 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-16 23:38 UTC
rendered paste body
IRC Client for phpMini http://sourceforge.net/project/showfiles.php?group_id=195564

GNU/GPL -- Barry R. Dick <barryd.it@gmail.com>

<?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->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 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($socket->host, $socket->port, $socket->socket, NULL, 'Mini', 'barryd.it', 'Gorge Washington');
var_dump($irc_bot);

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");
  }
}
?>