#!/usr/bin/perl

use IO::Socket;

$|=1;
$server_ip   = "10.0.0.2";
$server_port = "9000";
$local_ip    = "62.220.132.1";
$local_port  = "40000";
$vhost_ip    = "192.168.1.1";

$server = IO::Socket::INET->new(Proto=>'tcp',LocalAddr=>$local_ip,LocalPort=>$local_port,Listen=>'1',Reuse=>1);
while ($client = $server->accept()) {
	print $client "NOTICE AUTH :*** WELCOME TO EASY BOUNCE 1.0\n";
	$serv = IO::Socket::INET->new(PeerAddr=>$server_ip,PeerPort=>$server_port,Proto=>'tcp',LocalAddr=>$vhost_ip)||die "Unable to connect to IRC";
	vec($cdata2,fileno($client),1) = 1;
	vec($sdata2,fileno($serv),1) = 1;

	while(1) {
		$cdata = $cdata2;
		if ( select($cdata, undef, undef, 0.01) ) {
			if (vec($cdata, fileno($client), 1)) {
				$toserv = <$client>;
				print $serv $toserv;
				print "-> $toserv";
				if ( $toserv =~ /^quit /i ) { exit; }
			}
		}
		$sdata = $sdata2;
		if ( select($sdata, undef, undef, 0.01) ) {
			if (vec($sdata, fileno($serv), 1)) {
				$touser = <$serv>;
				print $client "$touser\n";
				print "<- $touser";
				if ( $touser =~ /^ERROR :Closing Link: /i ) { exit; }
			}
		}
	}
}
