#!/usr/bin/perl use XML::Parser; use Data::Dumper; use Mail::Sendmail; sub initmap; sub handle_start; sub handle_end; sub handle_char; sub groupstart; my $gamename; my $createTime; my $modifyTime; my @text; my @opentags; my $curcom; my $category; my $gid; my %groups; my $tag; my %start_map; my %end_map; my %char_map; my $root = $ENV{DOCUMENT_ROOT}; my $file = $ENV{PATH_INFO}; #my $addscript = "http://server1.megagames.com/megacheats/addcomment.cgi"; my $submitscript = "http://server1.megagames.com/megacheats/addcheat.cgi"; initmap(); $groupparse = new XML::Parser(Handlers => { Start => \&groupstart }, ProtocolEncoding => 'ISO-8859-1'); if ( -f "$root/megacheats/admin/groups.xml" ) { eval { $groupparse->parsefile("$root/megacheats/admin/groups.xml"); }; undef $groupparse; if ($@) { print "Content-type: text/plain\n\nUnable to parse groups.xml\n$@\nAdmin notified\n"; Apache->request->log_error("Groups parse error $@"); exit; } } else { print "Content-type: text/html\n\nUnable to find groups data file\n$root/megacheats/admin/groups.xml\n"; exit; } my $parser = new XML::Parser(Handlers => { Start => \&handle_start, End => \&handle_end, Char => \&handle_char }, ProtocolEncoding => 'ISO-8859-1'); unless (-f "$root/$file" ) { $root = "xml"; $file = "dc-196.xml"; } if (-f "$root/$file" ) { eval { $parser->parsefile("$root/$file"); }; Apache->request->log_error("$file parse error: $@") if ($@); undef $parser; } else { print "Content-type: text/html\n\nUnable to find cheat data file\n"; exit; } ################################################################### print "Content-type: text/html\n"; print "\n"; if ($ENV{QUERY_STRING} =~ /printer/i) { print "

Send to Printer

\n"; } print "

$gamename

\n"; print "

\n"; print @text, "\n"; print "

\n"; unless ($ENV{QUERY_STRING} =~ /printer/i) { print "

Printer Friendly View

\n"; if ($params{'message'}) { print '' . $params{'message'} . '
\n'; } print "Submit a new cheat for " . $gamename . ":
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
Name:
Email:
\n"; print "
Cheat:
\n"; } #unless ($ENV{QUERY_STRING} =~ /printer/i) { # print "

Printer Friendly View\n"; # print "

There are ", scalar @comments, " comments:

\n"; # print "Add a new comment:
\n"; # print "
\n"; # print "\n"; # print "\n"; # print "\n"; # print "\n"; # print "\n"; # print "
Name:
Email:
\n"; # print "
Comment:
\n"; # # foreach (@comments) { # print "

Comment from $_->{name} ($_->{email}):
@{$_->{text}}

\n"; # } # # print "

\n"; #} print "\n"; print "

\n"; foreach (@{$groups{category}}) { if ($category eq $_->{catName}) { print "Platform: $_->{displayName}
\n"; last; } } print " \n"; print "\n" if ($createTime); print "Modified: ", scalar localtime $modifyTime, "
\n" if ($modifyTime); print "

MegaGames - The Hardcore Gaming Experience\n";
print "            http://www.megagames.com
\n"; print "

\n"; exit; ################################################################### sub handle_start { my $object = shift; $tag = shift; push @opentags, $tag; my $funcname; foreach (@opentags) { $funcname .= "$_-"; } chop $funcname; if (exists $start_map{$funcname}) { &{$start_map{$funcname}}(@_); } } sub handle_end { my $object = shift; $tag = shift; my $funcname; foreach (@opentags) { $funcname .= "$_-"; } chop $funcname; pop @opentags; $tag = $opentags[$#opentags]; if (exists $end_map{$funcname}) { &{$end_map{$funcname}}(@_); } } sub handle_char { my $object = shift; my $funcname; foreach (@opentags) { $funcname .= "$_-"; } my @array; chop $funcname; @array = map { /[^\s\r\n]/ ? $_ : () } @_; foreach (@array) { if (exists $char_map{$funcname}) { &{$char_map{$funcname}}($_); } else { #print "Didn't find function for $funcname ($char_map{$funcname})\n"; } } } sub initmap { %start_map = ( 'cheat' => sub { $createTime = $gid = $gamename = $category = ''; undef $modifyTime; @text = (); }, 'cheat-comment' => sub { $curcom = { @_ }; push @comments, $curcom; } ); %end_map = ( 'cheat-comment' => sub { undef $curcom; } ); %char_map = ( 'cheat-name' => sub { $gamename .= shift; }, 'cheat-cat' => sub { $category .= shift; }, 'cheat-gid' => sub { $gid .= shift; }, 'cheat-modifyTime' => sub { $modifyTime .= shift; }, 'cheat-createTime' => sub { $createTime .= shift; }, 'cheat-text' => sub { push @text, @_; }, 'cheat-comment' => sub { @{$curcom->{text}} = @_; } ); } sub groupstart { my $object = shift; my $name = shift; push @{$groups{$name}}, { @_ }; }