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

http://codedumper.com/ucuge (16-Aug @ 17:50)

Syntax Highlighted Code

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

Plain Code

<?php 






// define your variables 
$host = "irc.ircworld.nl"; 
$port=6667; 


$nick="SanBot"; 
$ident="SanBot"; 
$chan="#ibot"; 

$readbuffer=""; 
$realname = "Sanbot"; 
$cmdprefix = ",";

$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"); 
        fwrite($irc, "JOIN :".$chan."\r\n"); 
         
           while (!feof($irc)) { 
            
            // Continue the rest of the script here
            while(trim($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(chr(58), '', $ex[3]);
                if ($command == $cmdprefix."sterf") 
                {
                    echo  "QUIT :Goodbye!\r\n";
                    fputs($irc, "QUIT :Goodbye!\r\n");
                }
                elseif($command == $cmdprefix."dood")
                {
                    echo  "QUIT :Goodbye!\r\n";
                    fputs($irc, "QUIT :Goodbye!\r\n");
                }
                elseif($command == $cmdprefix."join")
                {
                    echo "JOIN ".$ex[4]."\r\n";
                    fputs($irc, "JOIN ".$ex[4]."\r\n");
                }
                elseif($command == $cmdprefix."part")
                {
                    echo "PART ".$ex[4]."\r\n";
                    fputs($irc, "PART ".$ex[4]."\r\n");
                }
                elseif($command == $cmdprefix."say")
                {
                    echo "PRIVMSG ".$ex[4]." :".$ex[5]." ".$ex[6]."\r\n";
                    fputs($irc, "PRIVMSG ".$ex[4]." :".$ex[5]." ".$ex[6]."\r\n");
                }
         
            }
         
        }
    
    
    }

     
?> 

Permalink: http://codedumper.com/ucuge