Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/ifaqo (16-Aug @ 17:18)

Syntax Highlighted Code

  1. <?php
  2. //(Re)Connect function need to be fixed!
  3.  
  4.  
  5.  
  6. // define your variables
  7. $host = "irc.ircworld.nl";
  8. $port=6667;
  9. $nick="SanBot";
  10. $ident="SanBot";
  11. $chan="#ibot";
  12. $readbuffer="";
  13. $realname = "Sanbot";
  14. $cmdprefix = ",";
  15. $autoreconnect = 1;
  16. $is_connected = 0;
  17.  
  18. $irc = connect($host, $port);
  19.  
  20. function connect($_host, $_port)
  21. {
  22.     echo "Conneting to: ".$_host.":".$_port."\n";
  23.    
  24.     // open a socket connection to the IRC server
  25.     $connection = fsockopen($_host, $_port, $erno, $errstr, 30);
  26.    
  27.     if (!$connection) {
  28.         echo "No connection\n";
  29.         echo $errstr." (".$errno.")<br />\n";
  30.     } else {
  31.         echo "Connection Succesfull!\n";
  32.         return $connection;
  33.     }
  34. }
  35.  
  36.     // print the error if ther eis no connection
  37.     if (!$irc) {
  38.         echo "No connection\n";
  39.         echo $errstr." (".$errno.")<br />\n";
  40.     } else {
  41.         // write data through the socket to join the channel
  42.         fwrite($irc, "NICK ".$nick."\r\n");
  43.         fwrite($irc, "USER ".$ident." ".$host." bla :".$realname."\r\n");
  44.         fwrite($irc, "PRIVMSG nickserv :identify ******\r\n");
  45.          
  46.            while (!feof($irc)) {
  47.            
  48.             // Continue the rest of the script here
  49.             while($data = fgets($irc, 128)) {
  50.          
  51.                 echo $data."\n";
  52.                 flush();
  53.          
  54.                 // Separate all data
  55.                 $ex = explode(' ', $data);
  56.          
  57.                 // Send PONG back to the server
  58.                 if($ex[0] == "PING"){
  59.                     fputs($irc, "PONG ".$ex[1]."\n");
  60.                 }
  61.                
  62.                
  63.                 // DO something on the IRC server
  64.                 $command = str_replace(array(chr(10), chr(13),chr(58)), '', $ex[3]);
  65.                 if ($command == $cmdprefix."sterf")
  66.                 {
  67.                     fputs($irc, "QUIT Goodbye! \n");
  68.                 }
  69.                 elseif($command == $cmdprefix."join")
  70.                 {
  71.                     fputs($irc, "JOIN ".$ex[4]);
  72.                 }
  73.    
  74.          
  75.             }
  76.          
  77.         }
  78.    
  79.    
  80.     }
  81.  
  82.      
  83. ?>

Plain Code

<?php 
//(Re)Connect function need to be fixed!



// define your variables 
$host = "irc.ircworld.nl"; 
$port=6667; 
$nick="SanBot"; 
$ident="SanBot"; 
$chan="#ibot"; 
$readbuffer=""; 
$realname = "Sanbot"; 
$cmdprefix = ",";
$autoreconnect = 1;
$is_connected = 0;

$irc = connect($host, $port);

function connect($_host, $_port)
{
    echo "Conneting to: ".$_host.":".$_port."\n";
    
    // open a socket connection to the IRC server 
    $connection = fsockopen($_host, $_port, $erno, $errstr, 30);
    
    if (!$connection) { 
        echo "No connection\n";
        echo $errstr." (".$errno.")<br />\n"; 
    } else {
        echo "Connection Succesfull!\n";
        return $connection;
    }
}

    // print the error if ther eis no connection 
    if (!$irc) { 
        echo "No connection\n";
        echo $errstr." (".$errno.")<br />\n"; 
    } else { 
        // write data through the socket to join the channel 
        fwrite($irc, "NICK ".$nick."\r\n"); 
        fwrite($irc, "USER ".$ident." ".$host." bla :".$realname."\r\n"); 
        fwrite($irc, "PRIVMSG nickserv :identify ******\r\n");
         
           while (!feof($irc)) { 
            
            // Continue the rest of the script here
            while($data = fgets($irc, 128)) {
         
                echo $data."\n";
                flush();
         
                // Separate all data
                $ex = explode(' ', $data);
         
                // Send PONG back to the server
                if($ex[0] == "PING"){
                    fputs($irc, "PONG ".$ex[1]."\n");
                }
                
                
                // DO something on the IRC server
                $command = str_replace(array(chr(10), chr(13),chr(58)), '', $ex[3]);
                if ($command == $cmdprefix."sterf") 
                {
                    fputs($irc, "QUIT Goodbye! \n");
                }
                elseif($command == $cmdprefix."join")
                {
                    fputs($irc, "JOIN ".$ex[4]);
                }
    
         
            }
         
        }
    
    
    }

     
?> 

Permalink: http://codedumper.com/ifaqo