X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=scripts%2Fscans.pl;h=182fe088b47a0c07386269932b06a69c890f4500;hb=230e61ee1d992255138b56c50caf9cca52532c2b;hp=e9795f7eba5e87e49b131481289fdc9671494fa4;hpb=41646fbe70b05d4a96addcbdc71c2cc3b7bd8aa2;p=ndwebbie.git diff --git a/scripts/scans.pl b/scripts/scans.pl index e9795f7..182fe08 100755 --- a/scripts/scans.pl +++ b/scripts/scans.pl @@ -26,7 +26,10 @@ use CGI; use DBI; use DBD::Pg qw(:pg_types); use LWP::Simple; -use lib qw{/var/www/ndawn/lib/}; + +use FindBin; +use lib "$FindBin::Bin/../lib"; + use ND::DB; our $dbh = ND::DB::DB(); @@ -73,13 +76,23 @@ my $findcoords = $dbh->prepare(q{SELECT * FROM planetcoords(?,?)}); my $addfleet = $dbh->prepare(q{INSERT INTO fleets (name,mission,sender,target,tick,eta,back,amount,ingal,uid) VALUES(?,?,?,?,?,?,?,?,?,-1) RETURNING id}); my $fleetscan = $dbh->prepare(q{INSERT INTO fleet_scans (id,scan) VALUES(?,?)}); my $addships = $dbh->prepare(q{INSERT INTO fleet_ships (id,ship,amount) VALUES(?,?,?)}); -my $addpdata = $dbh->prepare(q{INSERT INTO planet_data (id,tick,scan,rid,amount) VALUES(?,?,?,(SELECT id FROM planet_data_types WHERE category = ? AND name = ?), ?)}); +my $addplanetscan = $dbh->prepare(q{INSERT INTO planet_scans + (id,tick,planet,metal_roids,metal,crystal_roids,crystal,eonium_roids,eonium + ,agents,guards,light,medium,heavy,hidden) + VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}); +my $adddevscan = $dbh->prepare(q{INSERT INTO development_scans + (id,tick,planet,light_fac,medium_fac,heavy_fac,amps,distorters + ,metal_ref,crystal_ref,eonium_ref,reslabs,fincents,seccents + ,travel,infra,hulls,waves,extraction,covert,mining,total) + VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + }); $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); +my $parsedscans = 0; + while (my $scan = $newscans->fetchrow_hashref){ $dbh->pg_release('scans') or die "Couldn't save"; $dbh->pg_savepoint('scans') or die "Couldn't save"; @@ -97,11 +110,16 @@ while (my $scan = $newscans->fetchrow_hashref){ $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"; + warn "Duplicate scan: $scan->{id} http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}\n"; + next; } my ($planet) = $dbh->selectrow_array($findplanet,undef,$x,$y,$z,$tick); unless ($planet){ $dbh->pg_rollback_to('scans') or die "rollback didn't work"; + if ( $x == 0 && $y == 0 && $z == 0 ){ + $delscan->execute($scan->{id}); + $addpoints->execute(-1,$scan->{uid}) if $scan->{uid} > 0; + } next; } my $scantext = ""; @@ -109,30 +127,23 @@ while (my $scan = $newscans->fetchrow_hashref){ #TODO: something about planet being closed? } if ($type eq 'Planet'){ + my @values = ($scan->{id},$tick,$planet); $file =~ s/(\d),(\d)/$1$2/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, $roids) or die $dbh->errstr; - $res =~ s/,//g; - $addpdata->execute($planet,$tick,$scan->{id} - ,'resource',$1, $res) or die $dbh->errstr; + 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]+)}){ - $addpdata->execute($planet,$tick,$scan->{id} - ,'planet','Light Usage', $production{$1}) or die $dbh->errstr; - $addpdata->execute($planet,$tick,$scan->{id} - ,'planet','Medium Usage', $production{$2}) or die $dbh->errstr; - $addpdata->execute($planet,$tick,$scan->{id} - ,'planet','Heavy Usage', $production{$3}) or die $dbh->errstr; + push @values,$1,$2,$3; } if($file =~ m{([\d,]+)}){ - my $res = $1; - $res =~ s/,//g; - $addpdata->execute($planet,$tick,$scan->{id} - ,'planet','Production', $res) or die $dbh->errstr; + push @values,$1; } + $addplanetscan->execute(@values); }elsif ($type eq 'Jumpgate'){ #print "$file\n"; while ($file =~ m{(\d+):(\d+):(\d+)\D+(Attack|Defend|Return)([^<]*)\D+(\d+)\D+(\d+)}g){ @@ -175,13 +186,15 @@ while (my $scan = $newscans->fetchrow_hashref){ $fleetscan->execute($id,$scan->{id}) or die $dbh->errstr; } } - } elsif($type eq 'Surface Analysis' || $type eq 'Technology Analysis'){ - my $cat = ($type eq 'Surface Analysis' ? 'struc' : 'tech'); + } elsif($type eq 'Development'){ + my @values = ($scan->{id},$tick,$planet); + my $total = 0; while($file =~ m{((?:[a-zA-Z]| )+)(\d+)}sg){ - $addpdata->execute($planet,$tick,$scan->{id} - ,$cat,$1, $2) or die $dbh->errstr; + push @values,$2; + $total += $2 if $#values <= 13; } - + push @values,$total; + $adddevscan->execute(@values); } elsif($type eq 'Unit' || $type eq 'Advanced Unit'){ my $id = addfleet($type,'Full fleet',$file,$planet,undef,$tick,undef,undef,undef); $fleetscan->execute($id,$scan->{id}) or die $dbh->errstr; @@ -195,6 +208,7 @@ while (my $scan = $newscans->fetchrow_hashref){ } $parsedscan->execute($tick,$type,$planet,$scan->{id}) or die $dbh->errstr; #$dbh->rollback; + ++$parsedscans; }; if ($@) { warn $@; @@ -209,6 +223,8 @@ while (my $scan = $newscans->fetchrow_hashref){ #$dbh->rollback; $dbh->commit; +system 'killall','-USR1', 'irssi' if $parsedscans; + sub addfleet { my ($name,$mission,$ships,$sender,$target,$tick,$eta,$back,$amount,$ingal) = @_;