X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FDef.pm;h=c49405c96b5b8bf140bbc840fe47b4cc72422075;hb=6815b7a875e95937693864b76a028f92ee2cbf35;hp=1731689e12689e673d06cec3e0d1543e9acbb80c;hpb=ae37bc6b64270f8c65298a36fce1f4bad761231f;p=NDIRC.git
diff --git a/Commands/Def.pm b/Commands/Def.pm
index 1731689..c49405c 100644
--- a/Commands/Def.pm
+++ b/Commands/Def.pm
@@ -27,6 +27,7 @@ use CGI;
use Moose;
use MooseX::MethodAttributes;
+use NDIRC::Misc;
sub anon
: Help(syntax: .anon nick message)
@@ -37,8 +38,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
@@ -55,7 +56,7 @@ sub defcall
my $st = $dbh->prepare(q{
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 USING (call)
LEFT OUTER JOIN users dc ON dc.uid = c.dc
@@ -68,16 +69,15 @@ ORDER BY c.landing_tick;
$c->reply("No call with id: $callnr");
return;
}
- chop($call->{shiptype});
$callinfo = "(Anti $call->{shiptype} ETA: $call->{eta})";
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->nick." TO RESPOND");
+ $c->message(notice => $c->disp->targets->{members}, "DEFENSE REQUIRED!! WAKE UP!!");
+ $c->message(privmsg => $c->disp->targets->{members}, "DEFENSE REQUIRED "
+ ."$mess $callinfo MSG ".$c->nick." TO RESPOND");
}
sub settype
@@ -172,10 +172,10 @@ sub calltake
$dbh->begin_work;
my $rows = $dbh->do(q{
-UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE $1)
+UPDATE calls SET dc = $1
,status = $3
WHERE call = $2
- },undef,$c->host,$id,$status);
+ },undef,$c->uid,$id,$status);
if ($rows == 1){
$c->reply("Setting status on call $id to $status");
$c->def_log($id , "Changed status: [B]$status [/B]");
@@ -196,7 +196,7 @@ sub setcalc
my $dbh = $c->model;
$dbh->begin_work;
- my $rows = $dbh->do(q{UPDATE calls SET calc = $2 WHERE id = $1}
+ my $rows = $dbh->do(q{UPDATE calls SET calc = $2 WHERE call = $1}
,undef,$id, $calc);
if ($rows == 1){
$c->reply("Updated calc call $id");
@@ -219,12 +219,108 @@ sub getcalc
my $dbh = $c->model;
my $calc = $dbh->selectrow_array(q{
-SELECT calc FROM calls WHERE id = $1}
+SELECT calc FROM calls WHERE call = $1}
,undef,$id);
$calc //= "Bad call id, there is no such call.";
$c->reply("Calc for call $id: $calc");
}
+sub report_incs
+ : Help(Used to report incs, same as pasting in pm. Use ~ prefix to send output to channel)
+ : Type(def)
+{
+ my ($self,$c,$msg) = @_;
+
+ if ($msg =~ /(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\s+([^:]*\S+)\s+(?:Ter|Cat|Xan|Zik|Etd)\s+([\d,]+)\s+Attack\s+(\d+)/
+ || $msg =~ /(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)\s+\((?:Ter|Cat|Xan|Zik|Etd)\)\s+([^,]*\S+)\s+([\d,]+)\s+(\d+)\s+\(\d+\)/){
+ my $dbh = $c->model;
+ my $amount = $8;
+ {
+ $amount =~ s/,//g;
+ }
+
+ my $st = $dbh->prepare(q{
+SELECT username, uid, pid, defprio
+FROM users_defprio u
+WHERE pid = planetid($1,$2,$3,tick())
+ AND uid IN (SELECT uid FROM groupmembers WHERE gid = 'M')
+ });
+ if (my $user = $dbh->selectrow_hashref($st,undef,$1,$2,$3)){
+
+ $st = $dbh->prepare(q{
+SELECT nick,alliance,pid,planet_status,relationship
+FROM current_planet_stats WHERE x = ? AND y = ? AND z = ?
+ });
+ if (my @attacker = $dbh->selectrow_array($st,undef,$4,$5,$6)){
+ $dbh->begin_work;
+ my $landing_tick = $dbh->selectrow_array(q{SELECT tick() + ?},undef,$9);
+ my @call = $dbh->selectrow_array(q{
+SELECT call,status,calc
+FROM calls WHERE uid = ? AND landing_tick = ?
+ },undef,$user->{uid},$landing_tick);
+ my $threefleeter = $dbh->selectrow_array(q{
+SELECT COALESCE(gid = 'X',false)
+FROM groupmembers WHERE uid = ? AND gid = 'X'
+ },undef,$user->{uid});
+ unless (@call){ #call doesn't exists, create a new one
+ @call = $dbh->selectrow_array(q{
+INSERT INTO calls (uid,landing_tick,info) VALUES(?,?,'') RETURNING call,status,calc
+ },undef,$user->{uid},$landing_tick);
+ if ($threefleeter){
+ $dbh->do(q{UPDATE calls SET status = 'Ignored' WHERE call = $1},undef,$call[0]);
+ $c->def_log($call[0], 'This member has been marked as [B]NoDef[/B], do [B]not cover[/B] unless you have a good reaon.');
+ $call[1] = 'Ignored';
+ }
+ }
+ if (@call){
+ my $pointlimits = $dbh->prepare(q{SELECT value :: float FROM misc WHERE id = ?});
+ my ($minpoints) = $dbh->selectrow_array($pointlimits,undef,'DEFMINPRIO');
+ my ($maxpoints) = $dbh->selectrow_array($pointlimits,undef,'DEFMAXPRIO');
+ my $color = 3;
+ if ($user->{defprio} < $minpoints){
+ $color = 5;
+ }elsif ($user->{defprio} < $maxpoints){
+ $color = 8;
+ }
+ $user->{defprio} = "$user->{defprio}";
+ $st = $dbh->prepare(q{SELECT pid FROM incomings WHERE pid = ? AND amount = ? and fleet = ? AND call = ?});
+ unless (my @inc = $dbh->selectrow_array($st,undef,$attacker[2],$amount,$7,$call[0])){
+ my $incid = $dbh->selectrow_array(q{
+INSERT INTO incomings (call,pid,eta,amount,fleet) VALUES(?,?,?,?,?) RETURNING inc
+ },undef,$call[0],$attacker[2],$9,$amount,$7);
+ @attacker = map (valuecolor(0),@attacker);
+ if (! $threefleeter || $call[1] ne 'Ignored'){
+ $c->reply("New incoming: CallId: $call[0], IncId: $incid $1:$2:$3 ($user->{defprio}) is under Attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4]) https://nd.ruin.nu/calls/edit/$call[0]");
+ }else{
+ $c->reply("Do not cover, NoDef member is under attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4]) https://nd.ruin.nu/calls/edit/$call[0]");
+ }
+ $dbh->do(q{UPDATE planets SET hit_us = hit_us + 1 WHERE pid = ?},undef,$attacker[2]);
+ if ($call[1] eq 'Covered'){
+ $dbh->do(q{UPDATE calls SET status = 'Open' WHERE call = ?},undef,$call[0]);
+ $c->reply("Call is likely not covered anymore, please recalc! calc: $call[2]");
+ }
+ }else{
+ @attacker = map (valuecolor(0),@attacker);
+ $c->reply("Duplicate call: Callid: $call[0], Status: $call[1] $1:$2:$3 ($user->{defprio}) is under Attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4]), landing tick: $landing_tick");
+ }
+
+ my ($fleetcatch) = $dbh->selectrow_array(q{
+SELECT count(*) FROM launch_confirmations WHERE uid = ? AND back = ?
+ },undef,$user->{uid},$landing_tick);
+ if ($fleetcatch > 0){
+ $c->reply("THIS IS A POSSIBLE FLEETCATCH!");
+ }
+ }
+ $dbh->commit;
+ }else{
+ $c->reply("Didn't find any planet with coordinates $4:$5:$6 at this tick");
+ }
+ }else{
+ $c->reply("No member registered with coordinates $1:$2:$3");
+ }
+ }
+
+}
1;