#!/usr/bin/perl # # favmame.pl David Mcanulty 5/21/03 # 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. # use Socket; use Getopt::Std; require "tcp.pl"; getopts ("sr"); $port = 7002; if ($opt_r) { print "\n-r (recieve) flag used"; # Check to see that user is root my $user = getpwuid $<; if ($user ne 'root') { print "Must be run as root\n"; exit; } my $proto = getprotobyname('tcp'); socket(F, PF_INET, SOCK_STREAM, $proto) || die $!; my $sin = sockaddr_in($port,INADDR_ANY); bind(F,$sin) || die $!; listen(F, $length) || die $!; while (1) { print "while\n"; accept(FH,F) || die $!; $game = ; chop($game); #get rid of any nastly control chars (^m) chomp($game); $game =~ s/.rom//ig; print "game = $game\n"; @database = `cat mame.map`; 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 "rom: $rom\n desc: $desc\n"; $output1 = $desc; $output2 = $rom; } } 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"; close LOG; close LASTGAME; close LASTROM; } else { print "rom $game wasn't found in my mame.map file, not logging.\n"; } } close(F); } if($opt_s) { print "\n-s (send) flag used\n"; # Get Hostname from command line or interactive if ($#ARGV+2) { $game = $ARGV[1]; chomp($game); $server=$ARGV[0]; if (open_TCP(F, "$server", $port) == undef) { print "error connecting to $server\n"; exit } print "sending: $game to port $port of $server\n"; print F "$game\n"; } else { print "missing input you must specify receiving server and game ie\n"; print "./favmame.pl -s www.hellspark.com %1 (%1 being the game.rom filename)"; exit; } close(F); exit; } print "\noptions:\n"; print "-s - send game (client) ie. ./favmame -s www.hellspark.com %1\n"; print "-r - recieve game (server) ie. ./favmame -r &\n"; exit;