#!/usr/bin/perl # # favmame.pl David Mcanulty 10/08/04 # perl program that sends your rom name to a webserver so others can see # what the current/last game you played was. You could also chomp data on # server and make a top 10 favorites, etc, etc. # $debug=1; #html header print "Content-type: text/html\n\n"; # Get game from html form use CGI; $query=new CGI; my $game=$query->param('game'); if (! defined $game) { print "Game not specified, aborting\n"; exit 1; } chomp($game); $game =~ s/.rom//ig; print "($game)\n" if $debug; $match=0; @database = `cat mame.map`; SearchDatabase($game); $gameimage=$game; while (SearchImages($gameimage)) { chop($gameimage); if ($gameimage eq "") { print "gameimage was chop'd to empty\n" if $debug; exit; } } if (($output1) && ($output2)) { open(LASTGAME,">favmame.html") || die "Couldn't open favmame.html for output: $!"; open(LASTROM,">favmame.rom") || die "Couldn't open favmame.html for output: $!" open(LOG,">>favmame.log") || die "Couldn't open favmame.log for output: $!"; chomp($output1); print LASTGAME "$output1\n"; #chomp($output2); #print LASTROM "$output2"; #print LOG "$output1 $output2\n"; chomp($gameimage); print LASTROM "$gameimage"; print LOG "$output1 $gameimage\n"; close LOG; close LASTGAME; close LASTROM; } else { print "rom $game wasn't found in my mame.map file, not logging.\n"; } close database; sub SearchDatabase() { my $game=shift; print "Attempting Database match on: $game\n" if $debug; foreach $line (@database) { $line =~ s/\(//ig; #get rid of revision info from rom desc, who cares $line =~ s/\)//ig; #get rid of revision info from rom desc, who cares ($rom, $desc) = split(/ /, $line, 2); chomp($rom); chomp($desc); if ($game eq $rom) { print "MATCHED!! rom: $rom\n desc: $desc\n" if $debug; $output1 = $desc; $output2 = $rom; return(1); } } } sub SearchImages() { my $gameimage=shift; print "Attempting Image match on: $gameimage\n" if $debug; foreach $line (`ls -1 /snaps/png/`) { chomp($line); $line =~ s/.png//ig; if ($gameimage eq $line) { print "FOUND IMAGE: $gameimage matched to $line\n" if $debug; return(0); } } return(1); }