X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FScans.pm;h=87a43d183f4cb70d55cf9782898b0654a034f294;hb=refs%2Fheads%2Fmaster;hp=bb05e99408d6bbe1cb69aea55b30a29f220f4df4;hpb=0000c72e6700ef1af5dd4ef608d6a9f00b30442d;p=ndwebbie.git diff --git a/lib/NDWeb/Scans.pm b/lib/NDWeb/Scans.pm index bb05e99..87a43d1 100644 --- a/lib/NDWeb/Scans.pm +++ b/lib/NDWeb/Scans.pm @@ -24,7 +24,7 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/parseMilScan doMilScan/; +our @EXPORT = qw/parseMilScan doMilScan doPlanetScan/; my %classes = (Fighter => 'Fi', Corvette => 'Co', Frigate => 'Fr', Destroyer => 'De', Cruiser => 'Cr', Battleship => 'Bs', Structure => 'St', Roids => 'Ro', Resources => 'Re', '-' => '-'); @@ -33,26 +33,36 @@ sub parseMilScan ($) { my @fleets; while ($file =~ m{([^<]+)}g) { - push @fleets, {name => $1, ships => []}; + push @fleets, {name => $1, mission => 'Military', ships => []}; } + push @fleets, {name => 'Military', mission => 'Full fleet', ships => []}; + my $total = 0; while ($file =~ m{([^<]+)(.+?)}g) { my $ship = $1; - next if $ship eq 'Total Ships'; + next if $ship eq 'Total Visible Ships'; my $amounts = $2; + my $tot_amount = 0; my $i = 0; while ($amounts =~ m{([\d,]+)}g) { my $fleet = $fleets[$i]; my $amount = $1; $amount =~ s/,//g; - if ($ship eq 'Total Visible Ships') { + if ($ship eq 'Total Ships') { $fleet->{amount} = $amount; } elsif ($amount > 0) { + $tot_amount += $amount; + $total += $amount; push @{$fleet->{ships}}, {ship => $ship, amount => $amount}; } ++$i; } + + if ($tot_amount > 0) { + push @{$fleets[4]->{ships}}, {ship => $ship, amount => $tot_amount}; + } } + $fleets[4]->{amount} = $total; return @fleets; } @@ -70,8 +80,8 @@ sub doMilScan ($$$) { my @fleets = parseMilScan($file); for my $fleet (@fleets) { - next if $fleet->{amount} == 0; - $addfleet->execute($fleet->{name},$scan->{type},$scan->{pid} + next if $fleet->{amount} == 0 && $fleet->{mission} eq 'Military'; + $addfleet->execute($fleet->{name},$fleet->{mission},$scan->{pid} ,$scan->{tick}, $fleet->{amount}); my ($id) = $addfleet->fetchrow_array; $fleetscan->execute($id,$scan->{id}) or die $dbh->errstr; @@ -81,4 +91,32 @@ sub doMilScan ($$$) { } } +my $addplanetscan_sql = q{INSERT INTO planet_scans + (id,tick,pid,metal_roids,metal,crystal_roids,crystal,eonium_roids,eonium + ,agents,guards,light,medium,heavy,hidden) + VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}; + +sub doPlanetScan ($$$) { + my ($dbh, $scan,$file) = @_; + + my $addplanetscan = $dbh->prepare_cached($addplanetscan_sql); + + my @values = ($scan->{id},$scan->{tick},$scan->{pid}); + $file =~ s/(\d),(\d)/$1$2/g; + + while($file =~ m{"center">(Metal|Crystal|Eonium)\D+(\d+)\D+([\d,]+)}g){ + push @values,$2,$3; + } + if($file =~ m{Security\ Guards .+? "center">(\d+) + .+? "center">(\d+)}sx){ + push @values,$1,$2; + } + if($file =~ m{([A-Z][a-z]+)([A-Z][a-z]+)([A-Z][a-z]+)}){ + push @values,$1,$2,$3; + } + if($file =~ m{([\d,]+)}){ + push @values,$1; + } + $addplanetscan->execute(@values); +}