X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=scripts%2Fscans.pl;h=e9795f7eba5e87e49b131481289fdc9671494fa4;hb=5b6c3c7d0003d636c1c3da6d25734e4aad5736a5;hp=fa27b0312fd1070fc4e76aea82f2b51bcdbc77e7;hpb=a333f6b98536c67510e7a633740bbc986f0981ef;p=ndwebbie.git
diff --git a/scripts/scans.pl b/scripts/scans.pl
index fa27b03..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+)/){
@@ -115,14 +119,14 @@ while (my $scan = $newscans->fetchrow_hashref){
$addpdata->execute($planet,$tick,$scan->{id}
,'resource',$1, $res) or die $dbh->errstr;
}
- #if($file =~ m{"center">([^<]+)
([^<]+) | ([^<]+) | }){
- # $addpdata->execute($planet,$tick,$scan->{id}
- # ,'planet','Light Usage', $1) or die $dbh->errstr;
- # $addpdata->execute($planet,$tick,$scan->{id}
- # ,'planet','Medium Usage', $2) or die $dbh->errstr;
- # $addpdata->execute($planet,$tick,$scan->{id}
- # ,'planet','Heavy Usage', $3) or die $dbh->errstr;
- #}
+ 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;
+ }
if($file =~ m{([\d,]+)}){
my $res = $1;
$res =~ s/,//g;
@@ -130,7 +134,8 @@ while (my $scan = $newscans->fetchrow_hashref){
,'planet','Production', $res) or die $dbh->errstr;
}
}elsif ($type eq 'Jumpgate'){
- while ($file =~ m/(\d+):(\d+):(\d+)\D+"left"\>(Attack|Defend|Return)<\/td>([^<]*)<\/td> | (\d+)\D+(\d+)/g){
+ #print "$file\n";
+ while ($file =~ m{(\d+):(\d+):(\d+)\D+(Attack|Defend|Return) | ([^<]*)\D+(\d+)\D+(\d+)}g){
my ($sender) = $dbh->selectrow_array($findplanet,undef,$1,$2,$3,$tick) or die $dbh->errstr;
($sender) = $dbh->selectrow_array($findoldplanet,undef,$1,$2,$3,$tick) if ((not defined $sender) && $4 eq 'Return');
@@ -189,8 +194,6 @@ while (my $scan = $newscans->fetchrow_hashref){
print "Something wrong with scan $scan->{id} type $type at tick $tick http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}";
}
$parsedscan->execute($tick,$type,$planet,$scan->{id}) or die $dbh->errstr;
- $dbh->pg_release('scans') or die "Couldn't save";
- $dbh->pg_savepoint('scans') or die "Couldn't save";
#$dbh->rollback;
};
if ($@) {
|