X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;ds=sidebyside;f=Commands%2FScans.pm;h=ed0def8dc5af3bd3adfafe4c23497ac377b41ea2;hb=5f3e2c69d303e9196a76dd10607b595cac6658a8;hp=2747acbb2abc5700770692bbe35c42f3acba48a3;hpb=df43148278c85c28726accbec2421688260661b7;p=NDIRC.git
diff --git a/Commands/Scans.pm b/Commands/Scans.pm
index 2747acb..ed0def8 100644
--- a/Commands/Scans.pm
+++ b/Commands/Scans.pm
@@ -54,6 +54,10 @@ sub gs
my $planet = $c->model->selectrow_array(q{SELECT planetid($1,$2,$3,tick())}
,undef,$x,$y,$z);
+ unless ($planet){
+ $c->reply("There is no planet with coords $x:$y:$z, try again after the tick.");
+ return;
+ }
my $query = $c->model->prepare(q{SELECT scan_id
FROM scans
@@ -194,8 +198,54 @@ sub anon
my ($self, $c, $msg) = @_;
my ($target,$mess) = $msg =~ /^(\S+) (.*)$/ or die 'ARGS';
- $c->message("msg $target", "$mess (reply with /msg $ND::scanchan)");
- $c->message("msg $ND::scanchan", "$target << $mess");
+ $c->message("msg $target", "$mess (reply with /msg "
+ .$c->channel.")");
+ $c->message("msg ".$c->channel, "$target << $mess");
+}
+
+sub addscan
+ : Help(syntax: .addscan list of scans)
+{
+ my ($self, $c, $msg) = @_;
+ my $dbh = $c->model;
+
+ my $oldscan = $dbh->prepare(q{
+SELECT scan_id FROM scans
+WHERE groupscan = $1 AND scan_id = LOWER($2) AND tick >= tick() - 168
+ });
+ my $addscan = $dbh->prepare(q{
+INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (LOWER($1),tick(),$2,COALESCE($3,-1))
+ });
+ my $user = $dbh->selectrow_hashref(q{SELECT uid,username, scan_points, tick()
+ FROM users WHERE hostmask ILIKE ? },undef,$c->host);
+ my $groupscans = 0;
+ my $scans = 0;
+ eval {
+ $dbh->begin_work;
+ while ($msg =~ m{/.+?scan(_id|_grp)?=(\w+)}g){
+ my $id = $2;
+ my $group = ($1 ~~ /_grp/ || 0);
+ unless($dbh->selectrow_array($oldscan,undef,$group,$id)){
+ $addscan->execute($id,$group,$user->{uid});
+ if ($group){
+ $groupscans++;
+ }else{
+ $scans++;
+ }
+ }
+ }
+ if ($user->{uid} && ($scans || $groupscans)){
+ $dbh->do(q{UPDATE users SET scan_points = scan_points + $2 WHERE uid = $1}
+ ,undef,$user->{uid},$scans);
+ my $points = $user->{scan_points} + $scans;
+ $c->reply("Added $scans scans and $groupscans groupscans, $points in total.");
+ }
+ $dbh->commit;
+ };
+ if ($@){
+ $dbh->rollback;
+ die $@;
+ }
}
1;