our @ISA = qw/Exporter/;
-our @EXPORT = qw/addScan addScanGroup sendScan reqScan scanReqs/;
+our @EXPORT = qw/addScan addScanGroup sendScan reqScan scanReqs getScan/;
sub addScan {
- my ($id,$verbose, $quiet) = @_;
+ my ($id,$verbose) = @_;
if (1){
- unless ($ND::DBH->selectrow_array(q{SELECT scan_id FROM scans WHERE NOT groupscan AND scan_id = ? AND tick >= tick() - 168},undef,$id)){
+ unless ($ND::DBH->selectrow_array(q{SELECT scan_id FROM scans WHERE NOT groupscan AND scan_id = LOWER(?) AND tick >= tick() - 168},undef,$id)){
my @user = $ND::DBH->selectrow_array(q{SELECT uid,username, scan_points, tick()
FROM users WHERE hostmask ILIKE ? },undef,$ND::address);
- if ($ND::DBH->do(q{INSERT INTO scans (scan_id,tick,uid) VALUES (?,tick(),COALESCE(?,-1))},
+ if ($ND::DBH->do(q{INSERT INTO scans (scan_id,tick,uid) VALUES (LOWER(?),tick(),COALESCE(?,-1))},
undef,$id,$user[0]) == 1){
if (@user){
$ND::DBH->do('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ',undef,$user[0]);
$user[2] += 1;
- if ($quiet){
- $ND::server->command("msg $ND::target Added scan, points now $user[2]");
- }
- else{
- $ND::server->command("msg $ND::target Added scan, at tick $user[3]. $user[1] points now $user[2]");
- }
+ $ND::server->command("notice $ND::nick Added scan, points now $user[2]");
}elsif ($verbose){
$ND::server->command("msg $ND::target Added scan, but unknown user, no points");
}
sub addScanGroup {
my ($id,$verbose) = @_;
if (1){
- unless ($ND::DBH->selectrow_array("SELECT scan_id FROM scans WHERE groupscan AND scan_id = ? AND tick >= tick() - 168",undef,$id)){
+ unless ($ND::DBH->selectrow_array(q{SELECT scan_id FROM scans WHERE groupscan AND scan_id = LOWER(?) AND tick >= tick() - 168},undef,$id)){
my @user = $ND::DBH->selectrow_array(q{SELECT uid,username, scan_points, tick()
FROM users WHERE hostmask ILIKE ? },undef,$ND::address);
- if ($ND::DBH->do(q{INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (?,tick(),true,COALESCE(?,-1))},
+ if ($ND::DBH->do(q{INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (LOWER(?),tick(),true,COALESCE(?,-1))},
undef,$id,$user[0]) == 1){
if (@user){
- $ND::server->command("msg $ND::target Added scan group, at tick $user[3]. Points will be added after parsing");
+ $ND::server->command("notice $ND::nick Added scan group. Points will be added after parsing.");
}elsif ($verbose){
$ND::server->command("msg $ND::target Added scan, but unknown user, no points");
}
}
}
-our %scanid = (p => 1, s => 2, t => 3, u => 4, n => 5, j => 7, a => 8);
+our %scanid = (p => 1, l => 2, d => 3, u => 4, n => 5, j => 7, a => 8);
-our @scantypes = ('Planet','Surface Analysis', 'Technology Analysis'
+our @scantypes = ('Planet','Landing', 'Development'
,'Unit', 'News', 'Incoming', 'Jumpgate', 'Advanced Unit');
sub reqScan {
my ($msg, $command) = @_;
my ($x, $y, $z, $type, $typeid);
- if (defined $msg && $msg =~ /^([pstunja]) (\d+)\D+(\d+)\D+(\d+) (\S.*)/){
+ if (defined $msg && $msg =~ /^([pdunja]) (\d+)\D+(\d+)\D+(\d+) (\S.*)/){
$typeid = $scanid{$1};
$type = $scantypes[$typeid-1];
($x,$y,$z) = ($2,$3,$4);
$msg = $5;
}else{
$ND::server->command("notice $ND::nick syntax: $command type X:Y:Z message"
- . " | type is the first character in the scan name, like p for planet scan, message is a message to scanners, message is a message to scanners, like plz or thanks like plz or thanks");
+ . " | type is the first character in the scan name, like p for planet scan, message is a message to scanners, like plz or thanks like plz or thanks");
return;
}
if (scanner()){
+ my @notype;
+ if ($msg && $msg =~ /-([pdunja]+)/){
+ for (split //, $1){
+ push @notype, $scantypes[$scanid{$_}-1];
+ }
+ }
+
my $reqs = $ND::DBH->prepare(q{SELECT min(sr.id) AS id, x,y,z,type
FROM scan_requests sr
JOIN current_planet_stats p ON p.id = sr.planet
AND type = sr.type
AND tick >= sr.tick
)
+ AND type <> ALL($1)
GROUP BY x,y,z,type
ORDER BY id
});
- $reqs->execute;
+ $reqs->execute(\@notype);
my $text = '';
while (my $req = $reqs->fetchrow_hashref){
$text .= "$ND::B$req->{id}$ND::O http://game.planetarion.com/waves.pl?id=$scantypes{$req->{type}}&x=$req->{x}&y=$req->{y}&z=$req->{z} "
}
- $text = 'No unhandled reqests.' unless $text;
+ $text = 'No unhandled requests.' unless $text;
$ND::server->command("notice $ND::nick $text");
}
}
+sub getScan {
+ my ($msg, $command) = @_;
+
+ my ($t, $x, $y, $z, $type, $tick);
+ if (defined $msg && $msg =~ /^([pdunja]) (\d+)\D+(\d+)\D+(\d+)(?: (\d+))?/){
+ $t = $1;
+ $type =$scantypes[$scanid{$1}-1];
+ ($x,$y,$z) = ($2,$3,$4);
+ $tick = $5;
+ }else{
+ $ND::server->command("notice $ND::nick syntax: $command type X:Y:Z [tick]"
+ . " | type is the first character in the scan name, like p for planet scan."
+ . " Specify a tick if you want scans older than the specified tick."
+ );
+ return;
+ }
+
+ if (my $user = member){
+ my $scan = $ND::DBH->selectrow_hashref(q{
+SELECT id, scan_id, tick FROM scans
+WHERE type = $1 AND planet = planetid($2,$3,$4,0) AND COALESCE(tick < $5,TRUE)
+ORDER BY tick DESC LIMIT 1
+ },undef,$type,$x,$y,$z,$tick);
+ unless ($scan->{id}){
+ $ND::server->command("notice $ND::nick No such scan");
+ }
+ my $text = '|';
+ if ($t =~ /[uja]/){
+ my $fid = $ND::DBH->selectrow_array(q{
+SELECT fid FROM fleet_scans WHERE id = $1
+ },undef,$scan->{id});
+ my $ships = $ND::DBH->prepare(q{
+SELECT ship,amount FROM fleet_ships WHERE fid = $1 ORDER BY num
+ });
+ $ships->execute($fid);
+ while (my $ship = $ships->fetchrow_hashref){
+ $text .= " $ship->{ship} $ship->{amount} |"
+ }
+ }else{
+ $text = "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}";
+ }
+ $ND::server->command("notice $ND::nick $ND::B$type$ND::O scan of $x:$y:$z "
+ . "($scan->{scan_id} pt: $ND::B$scan->{tick}$ND::O) $text");
+ }
+}
+
+
1;