X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=scripts%2Fscans.pl;h=e9795f7eba5e87e49b131481289fdc9671494fa4;hb=5b6c3c7d0003d636c1c3da6d25734e4aad5736a5;hp=654859a2508e9fffded65c509413ea2a6633dcce;hpb=9576a0ab8b41e013a7c184233f3bc28496647963;p=ndwebbie.git diff --git a/scripts/scans.pl b/scripts/scans.pl index 654859a..e9795f7 100755 --- a/scripts/scans.pl +++ b/scripts/scans.pl @@ -26,7 +26,7 @@ use CGI; use DBI; use DBD::Pg qw(:pg_types); use LWP::Simple; -use lib qw{/var/www/ndawn/}; +use lib qw{/var/www/ndawn/lib/}; use ND::DB; our $dbh = ND::DB::DB(); @@ -78,7 +78,11 @@ my $addpdata = $dbh->prepare(q{INSERT INTO planet_data (id,tick,scan,rid,amount) $dbh->begin_work or die 'No transaction'; $newscans->execute or die $dbh->errstr; $dbh->pg_savepoint('scans') or die "No savepoint"; + +my %production = (None => 0, Low => 35, Medium => 65, High => 100); while (my $scan = $newscans->fetchrow_hashref){ + $dbh->pg_release('scans') or die "Couldn't save"; + $dbh->pg_savepoint('scans') or die "Couldn't save"; my $file = get("http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}"); next unless defined $file; if ($file =~ /((?:\w| )*) (?:Scan|Probe) on (\d+):(\d+):(\d+) in tick (\d+)/){ @@ -90,14 +94,14 @@ while (my $scan = $newscans->fetchrow_hashref){ my $tick = $5; if($dbh->selectrow_array(q{SELECT * FROM scans WHERE scan_id = ? AND tick = ? AND id <> ?},undef,$scan->{scan_id},$tick,$scan->{id})){ - $dbh->rollback; + $dbh->pg_rollback_to('scans') or die "rollback didn't work"; $delscan->execute($scan->{id}); $addpoints->execute(-1,$scan->{uid}) if $scan->{uid} > 0; die "Duplicate scan: $scan->{id} http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}\n"; } my ($planet) = $dbh->selectrow_array($findplanet,undef,$x,$y,$z,$tick); unless ($planet){ - $dbh->rollback; + $dbh->pg_rollback_to('scans') or die "rollback didn't work"; next; } my $scantext = ""; @@ -106,14 +110,32 @@ while (my $scan = $newscans->fetchrow_hashref){ } if ($type eq 'Planet'){ $file =~ s/(\d),(\d)/$1$2/g; - while($file =~ m/"left">(Metal|Crystal|Eonium)\D+(\d+)\D+(\d+)/g){ + while($file =~ m/"center">(Metal|Crystal|Eonium)\D+(\d+)\D+([\d,]+)/g){ + my ($roids,$res) = ($2,$3); + $roids =~ s/,//g; $addpdata->execute($planet,$tick,$scan->{id} - ,'roid',$1, $2) or die $dbh->errstr; + ,'roid',$1, $roids) or die $dbh->errstr; + $res =~ s/,//g; + $addpdata->execute($planet,$tick,$scan->{id} + ,'resource',$1, $res) or die $dbh->errstr; + } + if($file =~ m{