X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FDef.pm;h=e8067dd7a50b27ad147526a8bdf66acf51688914;hb=9e077e0aeb51cfd1eeeb12f2362fc11ac6d6b38a;hp=7931033e2f6ddd1ba1cf1b04372dff5bb5fbaef0;hpb=565ece6e27fa54253934518cc8c69ecfac9487e4;p=NDIRC.git diff --git a/Commands/Def.pm b/Commands/Def.pm index 7931033..e8067dd 100644 --- a/Commands/Def.pm +++ b/Commands/Def.pm @@ -23,6 +23,8 @@ use strict; use warnings; use feature ':5.10'; +use CGI; + use Moose; use MooseX::MethodAttributes; @@ -39,5 +41,114 @@ sub anon $c->message("msg ".$c->channel, "$target << $mess"); } +sub defcall + : Help(syntax: .defcall [callid] | if a call id is given, then shiptypes and eta will be fetched from the database and added to the message) + : Type(def) + : ACL(irc_defcall) +{ + my ($self,$c,$msg) = @_; + my ($callnr,$mess) = $msg =~ /^(\d+)?(.*)$/ or die 'ARGS'; + my $dbh = $c->model; + + my $callinfo = ""; + if ($callnr){ + my $st = $dbh->prepare(q{ +SELECT covered + ,c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK') AS eta + ,concat(i.shiptype||'/') AS shiptype +FROM calls c + JOIN incomings i ON i.call = c.id + 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 +ORDER BY c.landing_tick; + }); + my $call = $dbh->selectrow_hashref($st,undef,$callnr); + unless (defined $call->{covered}){ + $c->reply("No call with id: $callnr"); + return; + } + chop($call->{shiptype}); + $callinfo = "(Anti $call->{shiptype} ETA: $call->{eta})"; + if($call->{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"); +} + +sub settype + : Help(Usage: .settype incId type | or: .settyp callId X:Y:Z type | or: .settypeall callId type) + : Type(def) + : ACL(irc_settype) + : Alias(settypeall) +{ + my ($self,$c,$msg) = @_; + my $dbh = $c->model; + + my $query = q{ +SELECT i.id,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 + }; + my $fleets; + my $type; + my $call; + + if ($self->name eq 'settypeall'){ + ($call,$type) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS'; + + $fleets = $dbh->prepare($query . q{ +WHERE i.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()) + }); + $fleets->execute($id,$x,$y,$z); + }else{ + ($id,$t) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS'; + $fleets = $dbh->prepare($query . q{ +WHERE i.id = ? + }); + $fleets->execute($id); + } + $type = $t; + } + + $type = CGI::escapeHTML($type); + $dbh->begin_work; + my $deflog = ''; + my $settype = $dbh->prepare(q{UPDATE incomings SET shiptype = ? WHERE id = ?}); + while (my $inc = $fleets->fetchrow_hashref){ + $call //= $inc->{call}; + if ($inc->{eta} < 0){ + $c->reply("This call is old. Did you use the call id instead of inc id by" + ." accident? You can use .settypeall callid to set the type on all incs" + ." in a call. Or use webbie if you really want to update this old call."); + $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})"); + } + if ($fleets->rows == 0){ + $c->reply("No matching fleets"); + $dbh->rollback; + }else{ + $c->def_log($call,$deflog); + $dbh->commit; + } +} + 1;