All pastes #273423 Raw Edit

Untitled

public text v1 · immutable
·published 2006-12-09 22:10 UTC
rendered paste body
<?php

$bot = array();
$bot['nickname'] = 'UberBot';
$bot['realname'] = 'Mr. UberBot';
$bot['ident']    = 'uberbot';
$bot['hostname'] = '0.0.0.0';
$bot['server']   = 'irc.rizon.net';
$bot['port']     = 6667;
$bot['chan']     = '#Manekian';

if (!$bot['socket']=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) {
  die("Could not create the socket. " .
  socket_strerror(socket_last_error($bot['socket'])));
}
if (!socket_connect($bot['socket'],$bot['server'],$bot['port'])) {
  die("Could not connect to the server: ".$bot['server'].". " .
  socket_strerror(socket_last_error($bot['socket'])));
}

echo "Connected...\n";

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']);

echo "Identified...\n";
echo $data;

$channel = 0; // Deze var komt later wel terug :)
while (($data = socket_read($bot['socket'], 65000, PHP_NORMAL_READ)) !== false) {
    echo "While1...\n";
    if($data == "\n") continue;
    echo "While2...\n";
// 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['chan']);
        $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');
}
echo $data;

?>