All pastes #979987 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-10 18:41 UTC
rendered paste body
<?
$bot = array();
$bot['nickname'] = "PHP^Bot";
$bot['realname'] = "Mr. PHP Bot";
$bot['ident'] = "php";
$bot['hostname'] = "0";
$bot['server'] = "irc.chattersweb.nl";
$bot['poort'] = "6667";
$bot['kanaal'] = "#Kletsroom";
?> 

<?

if (!$bot['socket']=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) { 
die("De socket kon niet worden aangemaakt.");
}
if (!@socket_bind($bot['socket'],$bot['hostname'])) {
  die("Kon de verbinding niet koppelen aan <b>".$bot['hostname']."</b>. Misschien fout?");
}
if (!@socket_connect($bot['socket'],$bot['server'],$bot['poort'])) {
  die("Kon geen verbinding maken met de server: <b>".$bot['server']."</b>. Misschien fout?");
}

?> 

<?

function sockwrite($data){
    global $bot;
    socket_write($bot['socket'],$data."\r\n");
}

sockwrite("USER ".$bot['ident']." ".$bot['hostname']." ".$bot['server']." :".$bot['realname']);
sockwrite("NICK ".$bot['nickname']);

$channel = 0; // Deze var komt later wel terug :)
while ($data=@socket_read($bot['socket'],65000,PHP_NORMAL_READ)) {
    if($data == "\n") continue;
// De data die we binnen krijgen, splitten we alvast op voor het makkelijk aanspreken.
    $edata = explode(" ",$data); 
    for($i=0; isset($edata[$i]); $i++) {
        $edata[$i]=trim($edata[$i]);
    }
// De variable $channel die net is geset, gaan we nou controleren.
    if ($channel == "0") { 
// De variable is nog 0, we moeten nog een kanaal in !
        sockwrite("JOIN ".$bot['kanaal']);
        $channel = 1;
    }
// Hier is er een PING binnengekomen. Deze gaan we antwoorden met PONG
    if($edata[0] == "PING") {
        sockwrite("PONG ".$edata[1]);
    }

// Hier komen alle scripts te staan.
    require('scripts.php'); 
}

?>