X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FDef.pm;h=e13758d4797964e6bdd0d8293c8f101c1a0717b8;hb=e8c94cdebefdc428ea92fde6db63f18d3e8399b2;hp=89ceeee3f7ce30b34ec41e6d2e8df654e2a09466;hpb=5e02deb33fbdb994d72da23e8de85e633ec6654c;p=NDIRC.git diff --git a/Commands/Def.pm b/Commands/Def.pm index 89ceeee..e13758d 100644 --- a/Commands/Def.pm +++ b/Commands/Def.pm @@ -37,8 +37,8 @@ sub anon my ($target,$mess) = $msg =~ /^(\S+) (.*)$/ or die 'ARGS'; - $c->message("msg $target", "$mess"); - $c->message("msg ".$c->channel, "$target << $mess"); + $c->message(privmsg => $target, "$mess"); + $c->message(privmsg => $c->channel, "$target << $mess"); } sub defcall @@ -53,31 +53,29 @@ sub defcall my $callinfo = ""; if ($callnr){ my $st = $dbh->prepare(q{ -SELECT covered +SELECT status ,c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK') AS eta - ,concat(i.shiptype||'/') AS shiptype + ,array_to_string(array_agg(i.shiptype),'/') AS shiptype FROM calls c - JOIN incomings i ON i.call = c.id + JOIN incomings i USING (call) LEFT OUTER JOIN users dc ON dc.uid = c.dc - JOIN users u ON u.uid = c.member -WHERE c.id = ? -GROUP BY c.id,c.landing_tick,c.covered +WHERE c.call = ? +GROUP BY c.call,c.landing_tick,c.status ORDER BY c.landing_tick; }); my $call = $dbh->selectrow_hashref($st,undef,$callnr); - unless (defined $call->{covered}){ + unless (defined $call->{status}){ $c->reply("No call with id: $callnr"); return; } - chop($call->{shiptype}); $callinfo = "(Anti $call->{shiptype} ETA: $call->{eta})"; - if($call->{covered}){ + if($call->{status} eq 'Covered'){ $c->reply("Call $callnr $callinfo is covered."); return; } } - $c->message("notice $ND::memchan", "DEFENSE REQUIRED!! WAKE UP!!"); - $c->message("msg $ND::memchan", "DEFENSE REQUIRED $mess $callinfo MSG " + $c->message(notice => $ND::memchan, "DEFENSE REQUIRED!! WAKE UP!!"); + $c->message(privmsg => $ND::memchan, "DEFENSE REQUIRED $mess $callinfo MSG " .$c->nick." TO RESPOND"); } @@ -91,10 +89,10 @@ sub settype my $dbh = $c->model; my $query = q{ -SELECT i.id,call,shiptype, coords(x,y,z),c.landing_tick - tick() AS eta +SELECT inc,call,shiptype, coords(x,y,z),c.landing_tick - tick() AS eta FROM incomings i - JOIN current_planet_stats p ON i.sender = p.id - JOIN calls c ON i.call = c.id + JOIN current_planet_stats p USING (pid) + JOIN calls c USING (call) }; my $fleets; my $type; @@ -104,20 +102,20 @@ FROM incomings i ($call,$type) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS'; $fleets = $dbh->prepare($query . q{ -WHERE i.call = ? +WHERE call = ? }); $fleets->execute($call); }else{ my ($id,$x,$y,$z,$t) = $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/; if (defined $id){ $fleets = $dbh->prepare($query . q{ -WHERE i.call = ? AND p.id = planetid(?,?,?,tick()) +WHERE call = ? AND pid = planetid(?,?,?,tick()) }); $fleets->execute($id,$x,$y,$z); }else{ ($id,$t) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS'; $fleets = $dbh->prepare($query . q{ -WHERE i.id = ? +WHERE inc = ? }); $fleets->execute($id); } @@ -127,7 +125,7 @@ WHERE i.id = ? $type = CGI::escapeHTML($type); $dbh->begin_work; my $deflog = ''; - my $settype = $dbh->prepare(q{UPDATE incomings SET shiptype = ? WHERE id = ?}); + my $settype = $dbh->prepare(q{UPDATE incomings SET shiptype = ? WHERE inc = ?}); while (my $inc = $fleets->fetchrow_hashref){ $call //= $inc->{call}; if ($inc->{eta} < 0){ @@ -137,9 +135,9 @@ WHERE i.id = ? $dbh->rollback; return; } - $settype->execute($type,$inc->{id}); - $deflog .= "Set fleet: [B]$inc->{id} [/B] to: [B]$type [/B]\n"; - $c->reply("Set fleet $inc->{id} from $inc->{coords} on call $call to $type (previously $inc->{shiptype})"); + $settype->execute($type,$inc->{inc}); + $deflog .= "Set fleet: [B]$inc->{inc} [/B] to: [B]$type [/B]\n"; + $c->reply("Set fleet $inc->{inc} from $inc->{coords} on call $call to $type (previously $inc->{shiptype})"); } if ($fleets->rows == 0){ $c->reply("No matching fleets"); @@ -160,26 +158,26 @@ sub calltake my ($id) = $msg =~ /^(\d+)$/ or die 'ARGS'; my $dbh = $c->model; - my $extra = ''; + my $status = 'Open'; given ($self->{name}){ when('callignore'){ - $extra = ',covered = FALSE, open = FALSE' + $status = 'Ignored'; } when('callcov'){ - $extra = ',covered = TRUE, open = FALSE' + $status = 'Covered'; } } $dbh->begin_work; my $rows = $dbh->do(q{ UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE $1) - }. $extra .q{ -WHERE id = $2 - },undef,$c->host,$id); + ,status = $3 +WHERE call = $2 + },undef,$c->host,$id,$status); if ($rows == 1){ - $c->reply("Marked call $id with ".$self->name); - $c->def_log($id , "Used: [B]".$self->name."[/B]"); + $c->reply("Setting status on call $id to $status"); + $c->def_log($id , "Changed status: [B]$status [/B]"); $dbh->commit; }else{ $c->reply("$id is not a valid call"); @@ -187,5 +185,45 @@ WHERE id = $2 } } +sub setcalc + : Help(Usage: .setcalc callId calc | sets the calc for the given call.) + : Type(def) + : ACL(irc_setcalc) +{ + my ($self,$c,$msg) = @_; + my ($id,$calc) = $msg =~ /^(\d+) (.+)$/ or die 'ARGS'; + my $dbh = $c->model; + + $dbh->begin_work; + my $rows = $dbh->do(q{UPDATE calls SET calc = $2 WHERE id = $1} + ,undef,$id, $calc); + if ($rows == 1){ + $c->reply("Updated calc call $id"); + $calc = CGI::escapeHTML($calc); + $c->def_log($id , 'Updated calc to: [URL]'.$calc.'[/URL]'); + $dbh->commit; + }else{ + $c->reply("$id is not a valid call"); + $dbh->rollback; + } +} + +sub getcalc + : Help(Usage: .getcalc callId | receives the calc for the given call) + : Type(def) + : ACL(irc_getcalc) +{ + my ($self,$c,$msg) = @_; + my ($id) = $msg =~ /^(\d+)$/ or die 'ARGS'; + my $dbh = $c->model; + + my $calc = $dbh->selectrow_array(q{ +SELECT calc FROM calls WHERE id = $1} + ,undef,$id); + $calc //= "Bad call id, there is no such call."; + $c->reply("Calc for call $id: $calc"); +} + + 1;