#!/usr/bin/perl # Michael Tartaglia # This program is responsible for getting quote inputs, and assigning # each user to a random color, which is displayed along with the username # in the chatroom's board use CGI ':standard'; my $color = param("color"); my $user = param("user"); my $mesg = param("mesg"); my ($sec,$min,$hr,$md,$mon,$yr,$wd,$yd,$isdst) = localtime(); my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); $yr += 1900; $min = "0" . $min if ($min < 10); $sec = "0" . $sec if ($sec < 10); my $time = "$md $months[$mon] $yr, $hr:$min:$sec"; my $cgi = 'http://storm.cis.fordham.edu/~tartagli/cgi-bin/chat/input.cgi'; $color = getColor() if ($color eq ""); # set session color if none exists already $mesg =~ s/\t//; # take out tabs $mesg =~ s/<.*?>//g; # remove html tags # PRINT QUERY BOX, WITH USER NAME, AND COLOR ID print <
Message: Your ID is \u$user.
EndOfHTML print "\n"; if (param('color') ne "") { # if this isn't the first loading open(CHAT, "; close(CHAT); # add current line to front unshift(@lines, "$user\t$color\t$mesg\t$time\n"); my $max = scalar(@lines) - 1; $max-- if ($max > 40); open(CHAT, ">chat.txt"); # save maximum of 40 lines flock(CHAT, 2); print CHAT $lines[$_] foreach (0 .. $max); close(CHAT); } # RETURNS A RANDOM HEXIDECIMAL COLOR sub getColor { my $hex = ""; my $cursor; my @letters = qw(0 1 2 3 4 5 6 7 8 9 a b c d); foreach (1 .. 6) { srand(); $cursor = int(rand(1) * 14); $hex .= $letters[$cursor]; } return "#\U$hex\E"; }