Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: IRC Bot skeleton code Jump to:  
Category: >> PHP Code >> IRC Bot skeleton code Bookmark and Share

<< lastnext >>

Snippet Name: IRC Bot skeleton code

Description: Simple skeleton code for an IRC bot that connects to an IRC server you specify and idles.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

<?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();
?>


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 52 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?