#!/usr/bin/perl
#----------------------------------------------------------------------
#
# Copyright (c) Craig Ferguson, 2000. All rights reserved.
#
# Note that this code implements Richard Bartle's "Waving Hands" game,
# which is itself copyright.
#
#----------------------------------------------------------------------
#
# The contents of this file are subject to the FM Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# ftp://ftp.gamerz.net/pub/fm/LICENSE
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is challenges.pl.
#
# The Initial Developer of the Original Code is Craig Ferguson.
#
# Portions of the Original Code are based on users.pl, by Martin
# Gregory
#
#----------------------------------------------------------------------
#
# This code presents the output of a CHALLENGES command as an HTML
# page.
#
#----------------------------------------------------------------------
$Revision .= ' L1.00';
# The description of an opponent's state in a Game Status report...
# (any states not in this hash will appear unchanged in the report)
sub ReportErrorAndExit
{
my $Error = shift;
print "Content-type: text/html\n\n";
print "
Error in challenges.pl\n";
print "\n";
print "$Error\n";
print "\n";
exit;
}
sub OpenChallenges
{
print "Challenges open for anyone to accept:
\n";
print "Game | \n";
print "Challenger | No. acc. | \n";
print "Limit | Spell Book | \n";
print "Comments | \n";
print "
\n";
foreach $row (0..$#OpenChallenges)
{
print "$OpenChallenges[$row]{'Game'} | \n";
print "$OpenChallenges[$row]{'Challenger'} | \n";
print "$OpenChallenges[$row]{'NoAcc'} | \n";
print "$OpenChallenges[$row]{'Limit'} | \n";
print "$OpenChallenges[$row]{'Spell Book'} | \n";
print "$OpenChallenges[$row]{'Comment'} | \n";
print "
\n";
}
print "
\n";
}
sub ClosedChallenges
{
print "Closed Challenges:
\n";
print "Game | \n";
print "Challenger | No. acc. | \n";
print "Limit | Spell Book | \n";
print "Comments | \n";
print "
\n";
foreach $row (0..$#ClosedChallenges)
{
print "$ClosedChallenges[$row]{'Game'} | \n";
print "$ClosedChallenges[$row]{'Challenger'} | \n";
print "$ClosedChallenges[$row]{'NoAcc'} | \n";
print "$ClosedChallenges[$row]{'Limit'} | \n";
print "$ClosedChallenges[$row]{'Spell Book'} | \n";
print "$ClosedChallenges[$row]{'Comment'} | \n";
print "
\n";
}
print "
\n";
}
$version = "";
$version = "Test" if ($ENV{SCRIPT_FILENAME} =~ m#/Test/#);
$version = "Main" if ($ENV{SCRIPT_FILENAME} =~ m#/Main/#);
$gamedir = "/home/FM/fm/\L$version\E/saves";
open (WIZARDS, "<$gamedir/wizards.dat") || ReportErrorAndExit("Error opening wizards file ($gamedir/wizards.dat): " . $!);
@WizardInfo = ;
close WIZARDS;
eval "@WizardInfo";
opendir (SAVEDIR,$gamedir) || ReportErrorAndExit("Error opening save directory ($gamedir): " . $!);
@NewGames = grep(/\.ngm$/, readdir(SAVEDIR));
closedir (SAVEDIR);
print "Content-type: text/html\n\n";
print "Firetop Mountain Challenges ($version Server)\n";
print "\n";
print "Challenges to battle on Firetop Mountain
\n";
@OpenChallenges = ();
@ClosedChallenges = ();
# Indices into OpenChallenges and CloseChallenges arrays
$orow = 0;
$crow = 0;
foreach $NewGame (@NewGames)
{
$ng = $NewGame;
$ng =~ s/\.ngm$//;
if (!open (NEWGAME, "<$gamedir/$NewGame"))
{
print "Error opening newgame file $NewGame: $!\n";
}
else
{
@GameInfo = ;
close NEWGAME;
eval "@GameInfo";
@Challenged = grep(defined($Wizard{$_}), @Challenged);
if ($Open)
{
$OpenChallenges[$orow]{'Game'} = $ng;
$OpenChallenges[$orow]{'Challenger'} = "$Challenger ($Wizard{$Challenger}{'User'})";
$OpenChallenges[$orow]{'NoAcc'} = (keys %Accepted)-1;
$OpenChallenges[$orow]{'Limit'} = $Limit?$Limit:'none';
$OpenChallenges[$orow]{'Spell Book'} = "\u$SpellBook";
$OpenChallenges[$orow]{'Comment'} = $Comment;
$orow++;
}
else
{
$NumAcc = (keys %Accepted)-1;
$NumChl = @Challenged;
$ClosedChallenges[$crow]{'Game'} = $ng;
$ClosedChallenges[$crow]{'Challenger'} = "$Challenger ($Wizard{$Challenger}{'User'})";
$ClosedChallenges[$crow]{'NoAcc'} = "$NumAcc / $NumChl";
$ClosedChallenges[$crow]{'Limit'} = $Limit?$Limit:'none';
$ClosedChallenges[$crow]{'Spell Book'} = "\u$SpellBook";
$ClosedChallenges[$crow]{'Comment'} = $Comment;
$crow++;
}
}
}
OpenChallenges;
ClosedChallenges;