DAN ZEN EXPO - CODE EXHIBIT -
GORGOLON
#!/usr/bin/perl
# roots removed for exhibit
$game = "gorgolon";
$headertype = "b";
$footertype = "bf";
&ReadParse;
#data: 0-first name; 1-last name; 2-fingers; 3-flying; 4-start time; 5-wrong check; 6-rank
$command = $in{'command'};
$transmit = $in{'transmit'};
$origin5 = $in{'origin5'};
$gorgolonian = $in{'gorgolonian'};
$gorg = $gorgolonian; $gorg =~ s/ /+/g;
$message = $in{'message'};
#print &PrintHeader; print &random(2); exit;
sub random{local($a)=@_; srand(time|$$); int(rand($a))+1;} #int((substr(time|$$,-1,1))/10.00*$a+1);}
$file = $logroot."gorgolon.txt";
$flagfile = $logroot."flagfile.txt";
$flagfire = $logroot."flagfire.txt";
$log = $logroot."origin5log.txt";
$firelog = $logroot."firelog.txt";
$palm = $logroot."palm.txt";
$saucerfile = $logroot."saucers.txt";
$fireduration = 2; #minutes
$solveduration = 1; #minutes
$channelmax = 8; #including Origin 5
$lordlevel = 100; #change on philosophy if change
&checkflag;
&checkfire;
&checklife;
if ($command eq "start") {
&start;
} elsif ($command eq "stop") {
&stopflying;
} elsif ($command eq "status") {
&status;
} elsif ($command eq "logs") {
&logs;
} elsif ($command eq "transmit") {
&transmit;
} elsif ($command eq "lock") {
if ($gorgolonian eq "" || $flyingcheck != 1) {&checkflying;}
&lock;
} elsif ($command eq "startfire") {
&startfire;
} elsif ($command eq "stopfire") {
&stopfire;
} else {
&load($origin5);
}
#-----------------below are html output subroutines---------------------
sub load {
#print html with $signal in Origin 5 box and nothing in Gorgolonian box
local($signal) = @_;
$title = " | Gorgolon";
&header;
print "<!-- $hourtoday - $oldflagcheck - $yeartoday - $yearflag - $ydaytoday - $ydayflag flag -->";
print "<br><br><br>
<form action=".$cgiroot."gorgolon method=post>
<INPUT TYPE=hidden NAME=command value=transmit>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td></td><td><img src=".$dataroot."gorgolon/gorgolon1.gif></td><td></td></tr>
<tr><td><img src=".$dataroot."gorgolon/gorgolon2a.gif></td><td bgcolor=99cc33 align=center>
<table cellspacing=6>
<tr><td>
<a href=".$cgiroot."gorgolon?gorgolonian=".$gorg."\&command=start><img src=".$dataroot."gorgolon/start.gif border=0></a>
</td><th><textarea name=origin5 cols=36 rows=4 wrap>";
print $signal;
print "</textarea></th><td>
<a href=".$cgiroot."gorgolon?gorgolonian=".$gorg."\&command=status><img src=".$dataroot."gorgolon/status.gif border=0></a>
</td></tr></table>
</td><td align=left><img src=".$dataroot."gorgolon/gorgolon3a.gif></td></tr>
<tr><td><img src=".$dataroot."gorgolon/gorgolon2b.gif></td><td bgcolor=99cc33 align=center>
<table cellspacing=6>
<tr><td>
<a href=".$cgiroot."gorgolon?gorgolonian=".$gorg."\&command=stop><img src=".$dataroot."gorgolon/stop.gif border=0></a>
</td><th><textarea name=transmit cols=36 rows=4 wrap></textarea></th><td>
<a href=".$cgiroot."gorgolon?gorgolonian=".$gorg."\&command=logs><img src=".$dataroot."gorgolon/logs.gif border=0></a>
</td></tr></table>
</td><td align=left><img src=".$dataroot."gorgolon/gorgolon3b.gif></td></tr>
<tr><td></td><td><img src=".$dataroot."gorgolon/bottom1.gif border=0><INPUT TYPE=image NAME=button SRC=".$dataroot."gorgolon/bottom2.gif border=0><img src=".$dataroot."gorgolon/bottom3.gif border=0>
</td><td></td></tr>
</table>";
print "<input type=hidden name=gorgolonian value=\"".$gorgolonian."\">\n";
print "<input type=hidden name=message value=\"".$messagenumber."\">\n";
print '
</form><br><br>
';
&footer;
}
sub loadchannels {
#print html with channels in @scrambledchannels
$title = " | Gorgolon | Firestorm";
&header;
print "
<br><br>
<form action=/cgi-bin/gorgolon method=post>
<INPUT TYPE=hidden NAME=command value=transmit>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td></td><td><img src=".$dataroot."gorgolon/gorgolon1.gif></td><td></td></tr>
<tr><td><img src=".$dataroot."gorgolon/gorgolon2a.gif></td><td bgcolor=99cc33 align=center>
<table cellspacing=6>
<tr><td><img hspace=17 src=".$dataroot."gorgolon/1.gif>
</td><th><textarea name=channel1 cols=36 rows=4 wrap>";
print $scrambledchannels[0];
print "</textarea></th><td><img hspace=16 src=".$dataroot."gorgolon/1.gif>
</td></tr></table>
</td><td align=left><img src=".$dataroot."gorgolon/gorgolon3a.gif></td></tr>";
for ($i=1; $i<=$#scrambledchannels; $i++) {
$ii = $i + 1;
print "
<tr><td><img src=".$dataroot."gorgolon/gorgolon2c.gif></td><td bgcolor=99cc33 align=center>
<table cellspacing=6>
<tr><td><img hspace=17 src=".$dataroot."gorgolon/".$ii.".gif>
</td><th><textarea name=channel".$ii." cols=36 rows=4 wrap>";
print $scrambledchannels[$i];
print "</textarea></th><td><img hspace=16 src=".$dataroot."gorgolon/".$ii.".gif>
</td></tr></table>
</td><td align=left><img src=".$dataroot."gorgolon/gorgolon3c.gif></td></tr>";
}
print "<tr><td><img src=".$dataroot."gorgolon/gorgolon2b.gif></td><td bgcolor=99cc33 align=center>
<table cellspacing=6>
<tr><td>
</td><th><textarea name=transmit cols=36 rows=4 wrap></textarea></th><td>
</td></tr></table>
</td><td align=left><img src=".$dataroot."gorgolon/gorgolon3b.gif></td></tr>
<tr><td></td><td><img src=".$dataroot."gorgolon/bottom1.gif border=0><INPUT TYPE=image NAME=button SRC=".$dataroot."gorgolon/bottom2.gif border=0><img src=".$dataroot."gorgolon/bottom3.gif border=0>
</td><td></td></tr>
</table>";
print "<input type=hidden name=gorgolonian value=\"".$gorgolonian."\">\n";
print '</form><br><br>';
&footer;
}
sub loadlock {
#print html with black channels and lock buttons
$title = " | Gorgolon | Firestorm";
&header;
print "
<br><br>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td></td><td><img src=".$dataroot."gorgolon/gorgolon1.gif></td><td></td></tr>
<tr><td><img height=200 width=57 src=".$dataroot."gorgolon/gorgolon2a.gif></td><td bgcolor=99cc33 align=center>
<table cellspacing=6 width=100\%>
<tr align=center><td><img hspace=16 src=".$dataroot."gorgolon/1.gif>
</td><td><table border=2 cellspacing=0 cellpadding=10 width=312><tr><td bgcolor=black>
<font color=gray>";
print $lastchannels[0];
print "</td></tr></table>
</td><form action=/cgi-bin/gorgolon method=post>
<INPUT TYPE=hidden name=gorgolonian value=\"".$gorgolonian."\">
<INPUT TYPE=hidden NAME=command value=lock>
<INPUT TYPE=hidden NAME=lock value=1><td><INPUT TYPE=image NAME=button value=lock SRC=".$dataroot."gorgolon/lock.gif border=0>
</td></form></tr></table>
</td><td align=left><img height=200 width=57 src=".$dataroot."gorgolon/gorgolon3a.gif></td></tr>";
for ($i=1; $i<=$#scrambledchannels; $i++) {
$ii = $i + 1;
print "<tr><td><img height=200 width=57 src=".$dataroot."gorgolon/gorgolon2c.gif></td><td bgcolor=99cc33 align=center>
<table cellspacing=6 width=100\%>
<tr align=center><td><img hspace=16 src=".$dataroot."gorgolon/".$ii.".gif>
</td><td><table border=2 cellspacing=0 cellpadding=10 width=312><tr><td bgcolor=black>
<font color=gray>";
print $lastchannels[$i];
print "</td></tr></table>
</td><form action=/cgi-bin/gorgolon method=post>
<INPUT TYPE=hidden name=gorgolonian value=\"".$gorgolonian."\">
<INPUT TYPE=hidden NAME=command value=lock>
<INPUT TYPE=hidden NAME=lock value=".$ii."><td><INPUT TYPE=image NAME=button value=lock SRC=".$dataroot."gorgolon/lock.gif border=0>
</td></form></tr></table>
</td><td align=left><img height=200 width=57 src=".$dataroot."gorgolon/gorgolon3c.gif></td></tr>";
}
print "<tr><td><img src=".$dataroot."gorgolon/gorgolon2b.gif></td><td bgcolor=99cc33 align=center>
<table cellspacing=6>
<tr><td>
</td><th><textarea name=transmit cols=36 rows=4 wrap></textarea></th><td>
</td></tr></table>
</td><td align=left><img src=".$dataroot."gorgolon/gorgolon3b.gif></td></tr>
<tr><td></td><td><img src=".$dataroot."gorgolon/bottom1.gif border=0><img SRC=".$dataroot."gorgolon/bottom2.gif border=0><img src=".$dataroot."gorgolon/bottom3.gif border=0>
</td><td></td></tr>
</table>";
&footer;
}
sub loadcrash {
local($fingers) = @_;
#print html with crash
$title = " | Gorgolon | Crash";
&header;
print "<br><br><br><h1><Font color=ff0000><blink>Crash!</blink></font></h1>";
if ($fingers == 1) {
print "<font color=lime>you have $fingers finger left after this crash";
} else {
print "<font color=lime>you have $fingers fingers left after this crash";
}
if ($fingers > 0) {
print "<p><a href=$dataroot"."gorgolon/index.html>fly again</a><br><br><br>";
} else {
print "<p><a href=$dataroot"."gorgolon/gorgolon.html>fly again</a><br><br><br>";
}
&footer;
}
#-----------------below are functions-------------------
sub firewatch {
($sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst) = localtime(time);
#print &PrintHeader; print $hour."here"; exit;
if ($hour == 12 && $min < ($fireduration + 1)) {
$minleft = $fireduration + $solveduration - $min - 1;
$secleft = 60 - $sec;
$firestorm = 1;
return "Saucer recording: You cannot start saucer controls during a fire storm. There is $minleft MIN $secleft SEC until end of storm.\n";
} elsif ($hour == 12 && $min < ($fireduration + 1 + $solveduration)) {
#see if channels will lock or if started flying just after storm finished
open (GORGOLON, $file);
while(<GORGOLON>) {
@line = split(/,/);
if ($line[0]." ".$line[1] eq $gorgolonian) {
close (GORGOLON);
if ($line[3] == 1) {
$firestorm = 2;
return "";
} else {
$firestorm = 1;
$minleft = $fireduration + $solveduration - $min - 1;
$secleft = 60 - $sec;
return "Saucer recording: You cannot start saucer controls during a fire storm. There is $minleft MIN $secleft SEC until end of storm.\n";
}
last;
}
}
} else {
$firestorm = 0;
if ($hour >= 12) {
$hourleft = 35 - $hour;
} else {
$hourleft = 11 - $hour;
}
$minleft = 60 - $min;
$secleft = 60 - $sec;
return "Warning: fire storm will occur in $hourleft HR $minleft MIN $secleft SEC\n";
}
}
sub message {
#return message from database not during firestorm
@messages = ("Saucer to ring 6 tube 3 dome 4. What is happening in the subcity jungle?","Saucer to molton glass mine 9. What are the deliveries for this hour?","Saucer to council 2. What are the requirements for the ring?","Saucer to council 7. What are the complaints?","Saucer to Lord window. Are there any requests from the Lords?","Saucer to Furnace 7. How is worker morale?","Saucer to Furnace 3. What items are the lower level recycling?","Saucer to Furnace 8. What are the artists making?","Saucer to Subcity Jungle ring 2, tube 1, dome 6. What report have you on the tenders' revolt?","Saucer to The Palm's platform. What is his command on the vegetarian riot?","Saucer to aquarium 2. What is the status of the Vegetarian revolt?","Saucer to molton chromium mine. What is the progress on finding new supplies beneath bed 3?","Saucer to Verti 6. What is the situation with the water-lift to air-drop seal?","Saucer to Verti 7. Explain how the air-drop tube of the transport bubble filled with water.","Saucer to Verti 2. What are the reports on drop sickness due to fire ivy darkness?","Saucer to Lord level. What are the tourist trends?","Saucer to The Palm's platform. Report the mood of the Lords on the Tourism of that level.","Saucer to Molton Glass Mine. What are their findings on depth of the Chrome tubes versus the cooling rate of the molton glass?","Retrieve molton ball from Furnace 6. Extrude from Exhale Ring 6 to Jungle 5, tube 3 at diameter 40. What Bennefits will the tunnel have?","Describe why we can not get rid of the fire storm.","Describe what the Fire Ivy looks like.","Describe what the Gorgolon looks like.","Describe the inside of the Verti pods.","Describe travelling on the transport tunnel as you slide down.","Describe floating up through the transport tunnels.","Describe the mushroom jungala.","Describe the dome chambers in which you live.","Describe the dome city in which you live.","Describe what you see outside.","Origin 5 Survey asks if you have transparent floors and why.","Origin 5 Survey asks if you have transparent walls and why.","Origin 5 Survey asks if you have transparent ceilings and why.","Origin 5 Survey asks what you recycle the most and why.","Origin 5 Survey asks what you have never recycled and why.","Describe how Gorgolonians are using mirrored glass.","Describe what a Gorgolonian Finger looks like.","Describe the current fashion of the Gorgolonians.","Describe the current gossip amongst the Gorgolonians.","Describe the latest sport of the Gorgolonians.","Describe the Gorgolonian language.","Describe a Gorgolonian vacation.
","Describe the outside of the Red Chrome Saucers.","Describe the latest Gorgolonian Artwork.");
$messagenumber = &random($#messages);
#print &PrintHeader; print $messagenumber; exit;
return $messages[$messagenumber];
}
sub origin5fire {
#gets unscrambled origin 5 signal (with echo maybe) during storm
local($i);
if (&random(4)==1) {return "";}
#random echo from logs
$random = &random(200);
open (LOG, $log);
while (<LOG>) {
$i++;
if ($i == $random) {
@line = split(/\t/);
chop ($line[2]);
$response = $line[2];
last;
}
}
close (LOG);
#random echo from recent responses
$random = &random(8+4);
$response = $lastchannels[$random].$response;
#random Origin 5 signal
$random = &random($#messages*3);
$response = $response.$messages[$random];
#chop and mix
return $response;
}
sub scramble {
#take input then output to first chosen code filter
local($input) = @_;
@filter =
(3,7,9,11,12,14,17,19,20,22,23,25,26,30,32,34,35,37,41,42,43,45,46,48,50,51,54,55,57,59,62,63,65,69,70,71,75,77,78,79,85,89,90,91,92,95,96,97,98,99,1,4,7,9,10,12,15,6,19,20,21,24,25,31,32,35,36,39,41,42,43,45,49,50,51,52,56,58,60,62,63,65,66,69,70,72,73,75,81,82,84,85,87,90,91,92,93,97,99,100,5,6,8,10,11,12,13,18,20,21,22,23,28,30,34,36,38,40,41,45,47,48,50,51,52,53,55,56,57,62,63,65,67,69,70,72,78,79,80,81,83,85,86,87,90,91,92,95,97,98,1,5,7,8,11,15,16,17,21,22,23,29,30,35,36,38,39,40,44,45,46,47,49,50,51,53,55,57,59,61,64,67,68,70,71,72,73,74,78,80,83,84,85,89,90,92,93,94,95,99);
$frequency = &random(72/18)-1;
@frequency = @filter[($frequency*50-1)..(($frequency*50-1)+50)];
@bits = split(/ /,$input);
return join(" ", @bits[@frequency]);
}
#----------------below are subroutines called by buttons-----------------
sub logs {
#if gorgolonian is the Palm or a Lord then they can view origin5logs.txt
open (STATUS, $file);
@palms=();
@lords=();
$highest=0;
while (<STATUS>) {
@line = split (/,/,$_);
if ($line[6] >= $lordlevel) {push (@lords, "$line[0] $line[1]");}
if ($line[6] > $highest) {
$highest = $line[6];
@palms=("$line[0] $line[1]");
} elsif ($line[6] == $highest) {
push (@palms, "$line[0] $line[1]");
}
}
close (STATUS);
foreach $a (@palms) {
if ($gorgolonian eq $a) {
$accesscheck = 1;
last;
}
}
foreach $a (@lords) {
if ($gorgolonian eq $a) {
$accesscheck = 1;
last;
}
}
$message = &message; #gets message list
if ($accesscheck > 0) {
$title = " | Gorgolon";
&header;
print "<br><br><table width=500 border=1 cellpadding=8 cellspacing=2>";
open (LOGS, $log);
while (<LOGS>) {
@line = split (/\t/,$_);
print "<tr><td><font color=white><b> $messages[$line[0]] </b><p> Reply from Gorgolonian <b>$line[1]</b>:<p> $line[2]</font></td></tr>\n";
}
close (LOGS);
print "</table><br><br><br>";
&footer;
} else {
if ($gorgolonian ne "") {
$signal = "Only Lords and the Palm of Gorgolon can access Origin 5 Logs\n".&firewatch.$message;
} else {
$signal = "Only Lords and the Palm of Gorgolon can access Origin 5 Logs\n"."Activate saucer controls by transmiting full Gorgolonian name - see help below if you are new";
}
&load($signal);
}
}
sub lock {
#response from one of the lock choices
#get origin 5 channel from saucers.txt
#if they select Origin 5 channel they win - change flying start time to past storm.
#if flying = 0 or wrong = 0 then give crash message - too long to decide
#data: 0-first name; 1-last name; 2-fingers; 3-flying; 4-start time; 5-wrong check; 6-rank
$lock = $in{'lock'};
@temp = ();
open (GORGOLON, $file);
while(<GORGOLON>) {push (@temp, $_);}
close (GORGOLON);
#calculate which set you are in and what the origin5number translates to
&sets;
if ($origin5channel > $position) {$lock++;}
if ($lock == $origin5channel) {
#right
#set wrong = 0
while (open (GORGOLON, "> $file") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(3);
}
}
foreach $a (@temp) {
@line = split (/,/,$a);
if ($line[0]." ".$line[1] eq $gorgolonian) {
if (($hourtoday+($mintoday/60.00)) > (12.00 + ($fireduration+$solveduration)/60.00) && ($hourtoday+($mintoday/60.00)) < (12.00 + $fireduration/60.00)) {
$fingers = $line[2];
$timeout = 1; #using lock outside of locktime
} else {#within lock time
$line[4] = time;
$line[6]++;
}
$new = join(",", @line);
print GORGOLON $new;
} else {
print GORGOLON $a;
}
}
close (GORGOLON);
if ($timeout == 1) {
$signal = "Gorgolonian, $gorg[0], your saucer controls are now unlocked\n".&firewatch;
&loadcrash ($fingers);
}
@gorg = split(/ /,$gorgolonian);
$signal = "Gorgolonian, $gorg[0], you have progressed one rank\n".&firewatch;
&load($signal);
} else {
#wrong set fingers - 1 and reset rest then load crash
while (open (GORGOLON, "> $file") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(3);
}
}
#Mandolin,Strings,7,0,880221630,0,0,718494
foreach $a (@temp) {
@line = split(/,/,$a);
if ($line[0]." ".$line[1] eq $gorgolonian) {
$fingers = 0;
if ($line[3] == 1) {
if ($line[2] - 1 > 0) {
$line[2] = $line[2]-1; #fingers left
$fingers = $line[2];
$line[5] = 0; #Wrong guess
$line[3] = 0; #flying
$line[4] = 0; #start time
$new = join(",", @line);
print GORGOLON $new;
}
} else { #already reduced by stopfire
print GORGOLON $a;
}
} else {
print GORGOLON $a;
}
}
close (GORGOLON);
&loadcrash ($fingers);
}
}
sub start {
if ($gorgolonian ne "" && $flyingcheck == 1) {
$signal = &firewatch."Gorgolonian, The saucer is flying. Origin 5 is recording your log.\n".&message;
} else {
$signal = "Activate saucer controls by transmiting full Gorgolonian name - see help below if you are new";
}
&load($signal);
}
sub status {
$title = " | Gorgolon | Status";
&header;
print "<br><br><font color=ff0000 size=+3><b>Gorgolon</b></font><p><table width=300 border=0><tr><td align=center>";
if ($gorgolonian ne "") {
open (STATUS, $file);
@palms=();
@lords=();
$highest=0;
while (<STATUS>) {
@line = split (/,/,$_);
if ($line[6] >= $lordlevel) {push (@lords, "$line[0]^^$line[2]^^$line[6]");}
if ($line[6] > $highest) {
$highest = $line[6];
@palms=("$line[0]^^$line[2]^^$line[6]");
} elsif ($line[6] == $highest) {
push (@palms, "$line[0]^^$line[2]^^$line[6]");
}
if ($line[0]." ".$line[1] eq $gorgolonian) {
if ($line[6] != 1) {
if ($line[2] != 1) {
$signal = "Gorgolonian $line[0], you have lived through $line[6] fire storms and have $line[2] Fingers.";
} else {
$signal = "Gorgolonian $line[0], you have lived through $line[6] fire storms and have 1 Finger.";
}
} else {
if ($line[2] != 1) {
$signal = "Gorgolonian $line[0], you have lived through 1 fire storm and have $line[2] Fingers.";
} else {
$signal = "Gorgolonian $line[0], you have lived through 1 fire storm and have 1 Finger.";
}
}
}
}
close (STATUS);
print "<font color=lime>$signal</font><p>";
} else {
open (STATUS, $file);
@palms=();
@lords=();
$highest=0;
while (<STATUS>) {
@line = split (/,/,$_);
if ($line[6] >= $lordlevel) {push (@lords, "$line[0]^^$line[2]^^$line[6]");}
if ($line[6] > $highest) {
$highest = $line[6];
@palms=("$line[0]^^$line[2]^^$line[6]");
} elsif ($line[6] == $highest) {
push (@palms, "$line[0]^^$line[2]^^$line[6]");
}
}
close (STATUS);
}
print "<font color=ff0000 size=+2><b>The Palm</b></font><p>
<table cellpadding=6 border=1>
<tr><td align=right><b><font color=lime>Gorgolonian</font></b></td><td><b><font color=lime>Fingers</font></b></td><td><b><font color=lime>Fire Storms</font></b></td></tr>";
foreach $a (@palms) {
@line=split (/\^\^/,$a);
print "<tr><td align=right><font color=lime>$line[0]</font></td><td align=center><font color=lime>$line[1]</font></td><td align=center><font color=lime>$line[2]</font></td></tr>";
}
print "</table><br><br><font color=ff0000 size=+2><b>Lords</b></font><p>";
if ($#lords > 0) {
print "<table cellpadding=6 border=1>
<tr><td align=right><b><font color=lime>Gorgolonian</font></b></td><td><b><font color=lime>Fingers</font></b></td><td><b><font color=lime>Fire Storms</font></b></td></tr>";
foreach $a (@palms) {
@line=split (/\^\^/,$a);
print "<tr><td align=right><font color=lime>$line[0]</font></td><td align=center><font color=lime>$line[1]</font></td><td align=center><font color=lime>$line[2]</font></td></tr>";
}
} else {
print "<font color=lime>There are no living Lords of Gorgolon</font>";
}
print "</td></tr></table><br>";
&footer;
}
sub flying {
@temp=();
open (FLY, $file) || &error(1);
while (<FLY>) {push(@temp,$_);}
close (FLY);
while (open (FLY, "> $file") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(1);
}
}
foreach $a (@temp) {
@line = split (/,/,$a);
if ($line[0]." ".$line[1] eq $gorgolonian) {
if ($line[3] == 1) {
$alreadyflying = 1;
} else {
$line[3] = 1;
$line[4] = time;
}
$new = join(",", @line);
print FLY $new;
} else {
print FLY $a;
}
}
close (FLY);
if ($alreadyflying == 1) {
$signal = "You are already flying.\n".&firewatch.&message;
&load($signal);
}
}
sub stopflying {
@temp = ();
open (FLY, $file) || &error(1);
while (<FLY>) {push (@temp, $_);}
close (FLY);
foreach $a (@temp) {
@line = split (/,/,$a);
if ($line[0]." ".$line[1] eq $gorgolonian) {
if ($line[3] == 0) {
$signal = "Saucer recording: The saucer is not activated. Select Start";
&load($signal);
} else {
($sec1, $min1, $hour1, $mday1, $month1, $year1, $wday1, $yday1, $isdst1) = localtime(time);
($sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst) = localtime($line[4]);
$timeinsaucer = ($sec1+$min1*60+$hour1*60*60)-($sec+$min*60+$hour*60*60);
$timebeforestorm = (12*60*60)-($sec1+$min1*60+$hour1*60*60);
if ($hour1 < 12 && $timeinsaucer > $timebeforestorm && $timeinsaucer < 60*60) { #too long in Saucer to stop
$signal = "Alert: you cannot dock in time\n".&firewatch.&message;
&load($signal);
} else {
while (open (FLY, "> $file") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(1);
}
}
foreach $a (@temp) {
@line = split (/,/,$a);
if ($line[0]." ".$line[1] eq $gorgolonian) {
$line[3] = 0;
$new = join(",", @line);
print FLY $new;
} else {
print FLY $a;
}
}
close (FLY);
}
$signal = "You have succesfully landed.\nFinal signal Origin 5";
$gorgolonian = "";
$gorg = "";
&load($signal);
}
}
}
$signal = "Gorgolonian, please register for flight by selecting the help circle at top then reading on.";
&load($signal);
}
sub transmit {
$line1 = &firewatch; #sets firestorm = 0, 1, or 2 and returns appropriate storm warning message
#print &PrintHeader; print "g=$gorgolonian<p>t=$transmit"; exit;
if ($gorgolonian eq "" || $flyingcheck != 1) { #has not logged in
if ($transmit ne "") {
if ($firestorm == 0) { #not during storm
open (DATA, $file) || &error(1);
while (<DATA>) {
@line = split (/,/);
if ($line[0]." ".$line[1] eq $transmit) {
close (DATA);
$gorgolonian = $transmit;
$gorg = $gorgolonian;
$gorg =~ s/ /+/g;
$g = $line[0];
&checklife;
if ($line[3] == 0) {&flying;}
$signal = "Welcome Gorgolonian, ".$g.".\n".&firewatch.&message;
&load($signal);
}
}
} else {
&load($line1);
}
}
&start;
} else {
#we are in the game already
#record transmission send back signal
if ($firestorm > 0) {
&firestorm;
} else {
@origin5 = split (/\n/,$origin5);
if ($transmit eq "" || length($transmit) < 6) {
$signal = $line1."Please illuminate...\n$origin5[$#origin5]";
} else {
@firstname = split (/ /,$gorgolonian);
while (open (LOG, ">> $log") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(1);
}
}
$transmit =~ s/\s\n/\<br\>/gi;
print LOG $message."\t".$firstname[0]."\t".$transmit."\n";
close (LOG);
$signal = "Thank you.\n$line1".&message;
}
&load($signal);
}
}
}
#------------------below are other subroutines--------------------
sub error {
local($error) = @_;
if ($error == 1) {
$signal = "Sorry, the Origin 5 Saucer logs are temporarily out of order.";
&load($signal);
} elsif ($error ==2) {
$signal = "Sorry, Origin 5 cannot access the Palm of Gorgolon file at the moment. Try back later.";
&load($signal);
} elsif ($error ==3) {
$signal = "One second please, then try again.";
&load($signal);
} else {
$signal = "Sorry, something is wrong with Origin 5. Try flying later.";
&load($signal);
}
}
sub firestorm {
#load up to 8 scrambled signals in expanded saucer screen
#calculate which set you are in and what the origin5number translates to
&sets;
#now write to your file $logroot."channels/".$location.".txt"
#read from channels in @set except yours - this makes 7
#insert Origin 5 channel at location $origin5channel in output
#prepare your transmission
$transmit =~ s/\n/ /g; #get rid of returns
$transmit =~ s/\s?\n\s?/ /gi; #funny stuff
$transmit =~ s/\^\^/\~\~/g; #just in case code is fudged
$transmit =~ s/\^\~\^/\~\~/g;
#write $transmit to your saucer log
open (SAUCER, ">> $logroot"."channels/".$position.".txt");
print SAUCER $transmit," ";
close (SAUCER);
#read other nearby saucers into @channels
foreach $a (@set) {
if ($a != $position) {
open (SAUCER, $logroot."channels/".$a.".txt");
while (<SAUCER>) {unless($_ eq ""){$saucersignal = $_;}} #no returns so it should be 1 line - the last line
close (SAUCER);
#save your codes
$saucersignal =~ s/\^\^$position/\^\~\^$position/g;
#delete other codes
$saucersignal =~ s/\^\^.//g;
#filter the signal
#hack words larger than 8 characters
#get rid of not letters
#get rid of saucer
#write some to eccho pool
if ($saucersignal eq "") {
push (@channels, " ");
} else {
@saucersignal = split (/\^\~\^$position/,$saucersignal);
if ($#saucersignal < 0 || $saucersignal[$#saucersignal] eq "") {
push (@channels, " ");
} else {
push (@channels, $saucersignal[$#saucersignal]);
}
}
open (SAUCER, ">> ".$logroot."channels/".$a.".txt");
#append your code
print SAUCER "^^".$position;
close (SAUCER);
}
}
#put new signals in channels
push (@lastchannels, $in{'channel1'});
push (@lastchannels, $in{'channel2'});
push (@lastchannels, $in{'channel3'});
push (@lastchannels, $in{'channel4'});
push (@lastchannels, $in{'channel5'});
push (@lastchannels, $in{'channel6'});
push (@lastchannels, $in{'channel7'});
push (@lastchannels, $in{'channel8'}); #not necessarily the right number
open (FILE, ">> $logroot"."channelscheck.txt");
foreach $a (@lastchannels) {
print FILE $a."\n";
}
close (FILE);
$past = 0; $i = 0; $check = 0;
if ($origin5channel > $position) {$addone = 1;} else {$addone = 0;}
for ($i=0; $i<=$#channels+1; $i++) { #+1 for origin 5
if ($origin5channel == $i+1+$addone) { #origin 5 channel
#print "origin5channel=$i<p>";
$past = 1;
$origin5fire = &origin5fire; #gets origin 5 signal
if ($origin5fire ne "") {
push (@scrambledchannels, &scramble($origin5fire));
} else {
if ($lastchannels[$i] eq "") {$lastchannels[$i] = " ";}
push (@scrambledchannels, $lastchannels[$i]);
}
} else {
if ($past == 0) { #if origin 5 channel not reached yet
#print "beforeorigin5=$i<p>";
$_ = $channels[$i];
#if (/\w/) {
push (@scrambledchannels, &scramble($channels[$i]));
#} else {
# $_ = $lastchannels[$i];
#if (/\W/) {$lastchannels[$i] = " ";}
#push (@scrambledchannels, $lastchannels[$i]);
#}
} else {
#print "afterorigin5=$i<p>";
$_ = $channels[$i+1];
#if (/\w/) {
push (@scrambledchannels, &scramble($channels[$i+1]));
#} else {
# $_ = $lastchannels[$i+1];
# if (/\W/) {$lastchannels[$i+1] = " ";}
# push (@scrambledchannels, $lastchannels[$i+1]);
#}
}
}
}
if ($firestorm == 1) {
&loadchannels; #firestorm still on
} else {
&loadlock; #trying to transmit after firestorm just over
}
}
sub sets {
if (-e $saucerfile) {
open (SAUCERS, $saucerfile);
$i = -1;
while (<SAUCERS>) {
$i++;
if ($i == 0) { #get channel of Origin 5
chop($origin5channel = $_);
} else {
@gorgolonian = split (/ /,$gorgolonian);
$who = $_;
$who =~ s/\n//gi;
if ($who eq $gorgolonian[0]) {$position =$i;}
push(@saucers, $who);
}
}
close (SAUCERS);
$total = $i;
if ($position <= 0) {&start;}
} else {
&start;
}
#Determine the set of saucers which are in your vicinity.
$division = $channelmax * 1.0000 - 1; #no Origin 5
#find number of full sets that fit total (less last)
$full = int($total/$division-.1);
$mod = $total % $division; #how many left over after full sets
if ($mod == 0) {$mod = $division;}
#print "<p>$origin5channel - $division - $full - $mod<p>";
if ($full > 0) { #more than 1 set
$penultimate = ($full-1)*$division;
unless ($position > $penultimate) { #in an earlier set than last 2
$set = int($position/$division-.1); #which set we are in starting at 0
for ($i=$set*$division+1; $i<=($set+1)*$division; $i++) {
push (@set, $i); # will read these saucer transmits
}
$setposition = $position - ($set * $division); #ie. we are number 4 in this set
} else {#in last 2 sets affected by splitting
$last2total = $mod + $division; #total of last 2 sets to divide
$last2division = int($last2total / 2.00 + .499); #gets number in first set
$last2position = $position - $penultimate; #your number relative to last sets
if ($last2position <= $last2division) { #then in first set of last 2
for ($i=$penultimate+1; $i<=$penultimate+$last2division; $i++) {
push (@set, $i);
}
$setposition = $position - ($penultimate);
} else {
for ($i=$penultimate+1+$last2division; $i<=$total; $i++) {
push (@set, $i);
}
$setposition = $position - ($penultimate + $last2division);
}
}
} else { #only one set of $mod saucers
for ($i=1; $i<=$mod; $i++) {
push (@set, $i);
}
$setposition = $position;
}
$origin5channel = int($origin5channel/$channelmax*($#set+2)+.99);
}
sub checkflying {
if ($gorgolonian eq "" || $flyingcheck != 1) {
$signal = "Your Saucer is not flying. Activate saucer controls by transmiting full Gorgolonian name - see help below if you are new";
&load($signal);
}
}
sub checklife {
#if line7[5] is 1 then gorgolonian had been flying but did not answer during a firestorm
#line7[5] is set to 1 and the fingers reduced by sub update which runs just after the firsestorm
$crashcheck = 0;
@temp = ();
open (GORGOLON, $file);
while(<GORGOLON>) {
push (@temp, $_);
@line7 = split(/,/);
if ($line7[0]." ".$line7[1] eq $gorgolonian) {
if ($line7[3] == 1) {$flyingcheck = 1;}
if ($line7[5] == 1) {$crashcheck = 1;}
}
}
close (GORGOLON);
if ($crashcheck == 1) {
while (open (GORGOLON, "> $file") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(3);
}
}
foreach $a (@temp) {
@line7 = split(/,/,$a);
if ($line7[0]." ".$line7[1] eq $gorgolonian) {
$line7[5] = 0;
$fingers = $line7[2];
if ($fingers > 0) {
$new = join(",", @line7);
print GORGOLON $new;
}
} else {
print GORGOLON $a;
}
}
close (GORGOLON);
&loadcrash ($fingers);
}
}
sub checkflag {
if (-e $flagfile) {
open (FLAG, $flagfile);
while(<FLAG>) {$date = $_; last;}
close (FLAG);
$date =~ s/\n//g;
($secflag, $minflag, $hourflag, $mdayflag, $monthflag, $yearflag, $wdayflag, $ydayflag, $isdst) = localtime($date);
($sectoday, $mintoday, $hourtoday, $mdaytoday, $monthtoday, $yeartoday, $wdaytoday, $ydaytoday, $isdst) = localtime(time);
if ($yeartoday - $yearflag > 0) {
&oldflag;
} else {
if ($ydaytoday - $ydayflag > 1) {
&oldflag;
} else {
if (($hourtoday+($mintoday/60.00)) > (12.00 + ($fireduration+$solveduration)/60.00)) { #afternoon
if ($ydaytoday - $ydayflag > 0) { #yesterday
&oldflag;
} else { #today
unless (($hourflag + ($minuteflag/60.00)) > (12.00 + ($fireduration+$solveduration)/60.00)) { #this afternoon
&oldflag;
}
}
} else { #morning
if ($ydaytoday - $ydayflag > 0) {
if ($hourflag < 12) {#previous morning
&oldflag;
}
}
}
}
}
} else {
&oldflag;
}
}
sub oldflag {
$oldflagcheck = 1;
while (open (FLAG, "> $flagfile") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(3);
}
}
print FLAG time;
close (FLAG);
&update;
}
sub update {
#if this is the first hit after a firestorm we have to take anybody whose time is old and are flying
#and reduce their fingers and set their wrongcheck line[5] = 1 which is read by sub checklife
#by the way, the time of teh saucer is set to during the lock period if they were correct
@temp = ();
$check = 0;
open (GORGOLON, $file) || &error(3);
while (<GORGOLON>) {
@line = split (",",$_);
if ($line[3] == 1) { #flying
if ($line[4] < 0) {$line[4] = 0;}
if ($hourtoday < 12 && (($hourtoday + $mintoday/60.00 + $sectoday/60.00/60.00) < (time - $line[4])/60.00/60.00)) {
$line[3] = 0;
$line[4] = 0;
$line[5] = 1;
if ($line[2] > 0) {$line[2] = $line[2]-1;}
$new = join(",", @line);
push (@temp, $new);
} elsif (($hourtoday+($mintoday/60.00)) > (12+($fireduration+$solveduration)/60.00) && (($hourtoday + $mintoday/60.00 + $sectoday/60.00/60.00 - 12.00) < (time - $line[4])/60.00/60.00)) {
$line[3] = 0;
$line[4] = 0;
$line[5] = 1;
if ($line[2] > 0) {$line[2] = $line[2]-1;}
$new = join(",", @line);
push (@temp, $new);
} else {
push (@temp, $_);
}
} else {
push (@temp, $_);
}
}
close (GORGOLON);
while (open (GORGOLON, "> $file") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(3);
}
}
foreach $a (@temp) {print GORGOLON $a;}
close (GORGOLON);
}
sub checkfire {
if ($hourtoday >= 12 && ($hourtoday + ($mintoday/60.00) + ($sectoday/60.00/60.00) < (12 + ($fireduration+$solveduration)/60.00))) { #within firestorm
if (-e $flagfire) {
open (FLAG, $flagfire);
while(<FLAG>) {$date = $_; last;}
close (FLAG);
$date =~ s/\n//g;
if ((time - $date)/60.00 > ($fireduration+$solveduration)*1.00) { #need to start fire
&startfire;
}
} else {
&startfire;
}
}
}
sub startfire {
#set flagfire
while (open (FLAG, "> $flagfire") != 1) {
sleep(2);
$counter++;
if ($counter > 90) {# 3 minutes
&error(3);
}
}
print FLAG time;
close (FLAG);
#data: 0-first name; 1-last name; 2-fingers; 3-flying; 4-start time; 5-wrong check; 6-rank; 7-ordernumber
#save and delete any old saucer files
open (LOG, ">> $firelog");
opendir(DIR, $logroot."channels");
while ($a = readdir(DIR)) {
open (CHANNEL, $logroot."channels/".$a);
while (<CHANNEL>) {
$line = $_;
$line =~ s/\^\^.//g;
print LOG $line;
}
close (CHANNEL);
print LOG "\n";
unlink $logroot."channels/".$a;
}
closedir(DIR);
unlink $logroot."saucers.txt";
#Create new saucer files
@temp = ();
open (DATA, "$file");
while(<DATA>) {push (@temp, $_);}
close (DATA);
open (SAUCERS, "> $saucerfile");
print SAUCERS &random($channelmax)."\n";
$i = 0;
foreach $a (@temp) {
@line = split(/,/,$a);
if ($line[3] == 1) {
print SAUCERS $line[0]."\n";
$i++;
open (CHANNEL, "> ".$logroot."channels/".$i.".txt");
close (CHANNEL);
}
}
close (SAUCERS);
}
sub ReadParse {
#Stefan Powell version
if (@_) {
local (*in) = @_;
}
local ($i, $loc, $key, $val);
# Read in text
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
$in .= getc;
}
}
@in = split(/&/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Convert %XX from hex numbers to alphanumeric
$in[$i] =~ s/%(..)/pack("c",hex($1))/ge;
# Split into key and value.
$loc = index($in[$i],"=");
$key = substr($in[$i],0,$loc);
$val = substr($in[$i],$loc+1);
$in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
return 1; # just for fun
}