#!/usr/bin/perl
my $input = 0;

if($ARGV[0] eq "")
{
    die "** You must supply a port number.  Example: ./hlConsole 27015\n\n";
}
elsif($ARGV[0] eq "-h")
{
    print "** hlConsole usage:\n\n";
    print "\t./hlConsole portNo [lines]\n\n";
    print "** portNo is the port of the halflife server <required>\n";
    die "** lines is the number of lines to display from thec onsole [optional]\n\n";
}

if($ARGV[1] eq "")
{
    $num = 5;
}
else
{
    $num = $ARGV[1];
}

system("clear");

while($input ne "q" && $input ne "Q" && $input ne "quit")
{
    print "\n\nEnter the command to send to the console (or quit): ";
    chomp($input = <STDIN>);
    
    if($input ne "q" && $input ne "Q" && $input ne "quit")
    {
	system("echo \"$input\" >> in.$ARGV[0]");
	sleep 3;
	print "\n\n** Last $num lines of the console **\n\n";
	system("tail -$num out.$ARGV[0]");
    }
}

print "\n\n** Quitting\n\n";
