#!/usr/bin/perl -w

use strict;
use IO::Socket::INET;

my $host = "irc.example.com";
my $port = "6667";
my $server = "jupe.irc.example.com";
my $serverpass = "xxx";

my $conn = IO::Socket::INET->new("$host:$port");
$conn->autoflush(1);
$| = 1;

print $conn "PASS $serverpass :TS\n";
print $conn "SERVER $server 1 :Jupe server\n";

sub pr {
    print "--> "; print @_;
    print $conn @_;
}

while (<$conn>) {
    s/[\n\r]+$//;

    print "<-- "; print; print "\n";

    if (/^PING (.*)$/i) {
	pr "PONG $1\n";
    } elsif (/^:(\S+) CONNECT (\S+) (\S+) :(.*)$/i) {
	if ($2 =~ /[*?]/) {
	    pr "NOTICE $1 :Jupe cannot contain wildcards\s";
	} else {
	    pr "SERVER $2 2 :Juped by $1\n";
	    pr "NOTICE $1 :$2 juped\n";
	}
    } elsif (/^:(\S+) STATS (.) :(.*)$/i) {
	pr ":$3 219 $1 :End of /STATS report\n";
    }
}
close($conn);
