#/usr/bin/perl -w

require 5.002;

use Socket;

$uplink = "hub.server.tld"; # Uplink to connect to
$port = 6667;
$pass = "password";

$jupename = "bad.server.tld";
$jupecomment = "Juped - Reason";

start: 
$iaddr = inet_aton($uplink) || die "no host: $uplink";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect(SOCK, $paddr) || die "connect: $!";

select SOCK; $| = 1;
select STDOUT;

# NOTE:  You must adjust this to the IRCD that you are using
# This first one is for most Dreamforge derivatives
#print SOCK "PASS $pass\n";

# This is for Hybrid and probably Bahamut as well
#print SOCK "PASS $pass :TS\n";

# This is for IRCnet 2.10.x
#print SOCK "PASS $pass :0210\n";

# Hybrid 6 can use the QS CAPAB in order to save a heap of bandwidth and
# CPU time.  We don't have to process anything except PING, why send it
# anything extra?
print SOCK "PASS $pass :TS\nCAPAB :QS\n";

# Dreamforge has a similar option using PROTOCTL but I don't know 
# it offhand and don't have any means of testing it

# Don't touch this unless you have a REAL screwy server
print SOCK "SERVER $jupename 1 :$jupecomment\n";

while (<SOCK>)
{
        chomp;

        if (  /^PING (.*)/  )
        {
                print SOCK "PONG $1\n";
        }
}
close (SOCK) || die "close: $!";

# Don't flood out opers if a C/N is wrong
sleep 3;

goto start;

exit;
