All pastes #179069 Raw Edit

Someone

public text v1 · immutable
#179069 ·published 2006-09-21 21:48 UTC
rendered paste body
<?php
/* Variables that determine server, channel, etc */
$CONFIG = array();
$CONFIG['server'] = 'hydra.fl.us.SwiftIRC.net'; // server (i.e. irc.gamesurge.net)
$CONFIG['nick'] = 'kvnphpBot'; // nick (i.e. demonbot)
$CONFIG['port'] = 6667; // port (standard: 6667)
$CONFIG['channel'] = '#mIRC'; // channel  (i.e. #php)
$CONFIG['name'] = 'man'; // bot name (i.e. demonbot) 
?>
<?php
	function send($command)
	{
		/* Send the command. Think of it as writing to a file. */
		fputs($con['socket'], $command."\n\r");
	}
/* Connect to the irc server */
$con['socket'] = fsockopen($CONFIG['server'], $CONFIG['port']);

/* Check that we have connected */
if (!$con['socket']) {
    print ("Could not connect to: ". $CONFIG['server'] ." on port ". $CONFIG['port']);
} else {
    /* Send the username and nick */
    send("USER ". $CONFIG['nick'] ." codedemons.net codedemons.net :". $CONFIG['name']);
    send("NICK ". $CONFIG['nick'] ." codedemons.net");
?>
<?php
/* Here is the loop. Read the incoming data (from the socket connection) */
while (!feof($con['socket']))
{
    /* Think of $con['buffer']['all'] as a line of chat messages.
    We are getting a 'line' and getting rid of whitespace around it. */
    $con['buffer']['all'] = trim(fgets($con['socket'], 4096));

    /* Print the line/buffer to the console
    I used <- to identify incoming data, -> for outgoing. This is so that
    you can identify messages that appear in the console. */
    print date("[d/m @ H:i]")."<- ".$con['buffer']['all'] ."n";

    /* If the server is PINGing, then PONG. This is to tell the server that
    we are still here, and have not lost the connection */
    if(substr($con['buffer']['all'], 0, 6) == 'PING :') {
        /* PONG : is followed by the line that the server
        sent us when PINGing */
        send('PONG :'.substr($con['buffer']['all'], 6));
        /* If this is the first time we have reached this point,
        then JOIN the channel */
        if ($firstTime == true){
            send("JOIN ". $CONFIG['channel']);
            /* The next time we get here, it will NOT be the firstTime */
            $firstTime = false;
        }
        /* Make sure that we have a NEW line of chats to analyse. If we don't,
        there is no need to parse the data again */
    } elseif ($old_buffer != $con['buffer']['all']) {

    /* This is where you would analyze the data, and act accordingly. */
    }
} 
}
?>