#!/usr/bin/perl -w
$base="General";

my $user = $ARGV[0];
$olpath="/bbs/oneliners";
$mspath="/bbs/$base";

while(1) {

######################
## RECORD THIS USER ##
######################
system("touch /bbs/ramdrive/$user");

##########################
## GET LAST LOGIN STATS ##
##########################
open(FILE,"lastlogin");
flock (FILE, 2);
$lastuser = <FILE>;
flock (FILE, 8);
close (FILE);

############################
## GET MESSAGE BASE STATS ##
############################
open(FILE,"/bbs/$base/number");
flock (FILE, 2);
$messmax = <FILE>;
flock (FILE, 8);
close (FILE);

open(FILE,"/bbs/$base/first");
flock (FILE, 2);
$messfirst = <FILE>;
flock (FILE, 8);
close (FILE);
chomp($messfirst);


#############################
## GET AND PRINT ONELINERS ##
#############################

open(FILE,"$olpath/number");
flock (FILE, 2);
$count = <FILE>;
flock (FILE, 8);
close (FILE);

$count++;
if ($count eq '9' || $count eq '0') { $count="1"; }

open (FILE,">$olpath/number");
flock (FILE, 2);
print FILE "$count";
flock (FILE, 8);
close (FILE);

open (FILE,"$olpath/$count.ol");
flock (FILE, 2);
$oneliner = <FILE>;
flock (FILE, 8);
close (FILE);
chomp($oneliner);

###################
## END ONELINERS ##
###################

	if (open(MYFILE, "mainmenu.ans")) {
		while(<MYFILE>) {
			print;
		}
	}
	close(MYFILE);
        print " \033[0m         Message Area: \033[1;37;40m$base\n";
	print " \033[0m        Message Stats: \033[1;37;40m$messfirst\033[0m-\033[1;37;40m$messmax\033[0m";
	print "\n \033[0m   Last User to Login: \033[1;37;40m$lastuser\033[0m";
	print "\n\n  \033[1;36;40m$oneliner";
	print "\n\n \033[0m $user, Enter Command -> ";
	chomp($command = <STDIN>);

	if ($command eq 'g' || $command eq 'G') { 
	system "echo -e '$user is logging out...' > /dev/console";
	print "\n\n\n Goodbye!\n";
	exit;
	 }

if ($command eq 'c' || $command eq 'C') { system "./chat $user"; }
if ($command eq 'f' || $command eq 'F') { system "./feedback $user"; }
if ($command eq 'd' || $command eq 'D') { system "./download"; } 
if ($command eq 'u' || $command eq 'U') { system "./upload"; }
if ($command eq 'l' || $command eq 'L') { system "./filelist"; }
if ($command eq 'p' || $command eq 'P') { system "/bbs/$base/./post $user"; }
if ($command eq 'r' || $command eq 'R') { system "/bbs/$base/./read $user"; }
if ($command eq 'e' || $command eq 'E') { system "/bbs/oneliners/./oneliner"; }
if ($command eq '*' || $command eq '*') { system "./doors"; }
if ($command eq 'w' || $command eq 'W') { system "./who"; }
if ($command eq '1' ) { $base="General"; }


    }
