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();
$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+)/){
$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 = "";
$addpdata->execute($planet,$tick,$scan->{id}
,'resource',$1, $res) or die $dbh->errstr;
}
- #if($file =~ m{"center">([^<]+)</td><td class="center">([^<]+)</td><td class="center">([^<]+)</td>}){
- # $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{<td class="center">([A-Z][a-z]+)</td><td class="center">([A-Z][a-z]+)</td><td class="center">([A-Z][a-z]+)</td>}){
+ $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{<span class="superhighlight">([\d,]+)</span>}){
my $res = $1;
$res =~ s/,//g;
,'planet','Production', $res) or die $dbh->errstr;
}
}elsif ($type eq 'Jumpgate'){
- while ($file =~ m/(\d+):(\d+):(\d+)\D+"left"\>(Attack|Defend|Return)<\/td><td>([^<]*)<\/td><td>(\d+)\D+(\d+)/g){
+ #print "$file\n";
+ while ($file =~ m{(\d+):(\d+):(\d+)\D+(Attack|Defend|Return)</td><td class="left">([^<]*)\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');
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 ($@) {