#!/usr/bin/perl

#############################
## Temporal Vortex         ##
## Enter Message Engine    ##
## Version 1.0             ##
## By: Jeff Ledger         ##
#############################

#######################
# CONFIGURE VARIABLES #
#######################

my $user = $ARGV[0];

$path="/bbs/General";

##############################
## DISPLAY SCREEN FOR INPUT ##
##############################

if (open(MYFILE, "$path/intro.ans")) {
   while (<MYFILE>) {
       print ;
   }
}
   close(MYFILE);

## Get Subject and Address ##

print "    From: $user\n";
print "      To: ";
chomp($to = <STDIN>);
if($to eq '') { $to = 'All'; }
print " Subject: ";
chomp($subject = <STDIN>);
if($subject eq '') { $subject = 'General Chatter'; }
print "\n\n";




## Open the counter and find out what the last message was. ##

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

## Add one to the counter to establish this message number. ##
$count++;

## Write the new result to the counter. ##
open(FILE,">$path/number");
flock (FILE, 2);
print FILE "$count";
flock (FILE, 8);
close (FILE);


## Record message to this number. ##
open(FILE, ">$path/$count.msg");
flock (FILE, 2);

print FILE <<"END";

\033[1;36;40m    From: \033[1;37;40m$user
\033[1;36;40m      To: \033[1;37;40m$to
\033[1;36;40m Subject: \033[1;37;40m$subject
\033[1;33;40m

END

while(<STDIN>) {
    chomp($line = $_);
    if($line eq '/s') {
	close(FILE);
	exit;

    }
    else {
        # EMBED COLORS - DOESN'T WORK YET.
	###################################
 	$line =~ s/\~r/\e[1;31;40m/g;          # ~r = red
 	$line =~ s/\~g/\e[1;32;40m/g;          # ~g = green
 	$line =~ s/\~y/\e[1;33;40m/g;          # ~y = yellow
 	$line =~ s/\~b/\e[1;34;40m/g;          # ~b = light bl
 	$line =~ s/\~p/\e[1;35;40m/g;          # ~p = purple
 	$line =~ s/\~c/\e[1;36;40m/g;          # ~c = cyan
 	$line =~ s/\~w/\e[1;37;40m/g;          # ~w = white
       
        # FOUL WORD FILTER. 
	####################################
	$line =~ s/fuck/*censored*/g;
	$line =~ s/Fuck/*censored*/g;
	$line =~ s/cunt/*censored*/g;
	$line =~ s/Cunt/*censored*/g;
	$line =~ s/shit/*censored*/g;
	$line =~ s/Shit/*censored*/g;
	$line =~ s/bitch/*censored*/g;
	$line =~ s/Bitch/*censored*/g;
	$line =~ s/piss/*censored*/g;
	$line =~ s/Piss/*censored*/g;
	$line =~ s/Microsoft/Micro\$oft/g;
	$line =~ s/microsoft/micro\$oft/g;
#	$line =~ s/ass/*censored*/g;
#	$line =~ s/Ass /*censored* /g;
	
	print FILE " $line\n";
    }
}


