1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package NDIRC::Commands::Def;
29 use MooseX::MethodAttributes;
32 : Help(syntax: .anon nick message)
36 my ($self,$c,$msg) = @_;
38 my ($target,$mess) = $msg =~ /^(\S+) (.*)$/ or die 'ARGS';
40 $c->message("msg $target", "<b>$mess</b>");
41 $c->message("msg ".$c->channel, "<c03>$target << $mess</c>");
45 : 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)
49 my ($self,$c,$msg) = @_;
50 my ($callnr,$mess) = $msg =~ /^(\d+)?(.*)$/ or die 'ARGS';
55 my $st = $dbh->prepare(q{
57 ,c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK') AS eta
58 ,concat(i.shiptype||'/') AS shiptype
60 JOIN incomings i ON i.call = c.id
61 LEFT OUTER JOIN users dc ON dc.uid = c.dc
62 JOIN users u ON u.uid = c.member
64 GROUP BY c.id,c.landing_tick,c.covered
65 ORDER BY c.landing_tick;
67 my $call = $dbh->selectrow_hashref($st,undef,$callnr);
68 unless (defined $call->{covered}){
69 $c->reply("No call with id: $callnr");
72 chop($call->{shiptype});
73 $callinfo = "(Anti $call->{shiptype} ETA: $call->{eta})";
75 $c->reply("Call <b>$callnr</b> $callinfo is covered.");
79 $c->message("notice $ND::memchan", "DEFENSE REQUIRED!! WAKE UP!!");
80 $c->message("msg $ND::memchan", "DEFENSE REQUIRED $mess $callinfo MSG "
81 .$c->nick." TO RESPOND");
85 : Help(Usage: .settype incId type | or: .settyp callId X:Y:Z type | or: .settypeall callId type)
90 my ($self,$c,$msg) = @_;
94 SELECT i.id,call,shiptype, coords(x,y,z),c.landing_tick - tick() AS eta
96 JOIN current_planet_stats p ON i.sender = p.id
97 JOIN calls c ON i.call = c.id
103 if ($self->name eq 'settypeall'){
104 ($call,$type) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS';
106 $fleets = $dbh->prepare($query . q{
109 $fleets->execute($call);
111 my ($id,$x,$y,$z,$t) = $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/;
113 $fleets = $dbh->prepare($query . q{
114 WHERE i.call = ? AND p.id = planetid(?,?,?,tick())
116 $fleets->execute($id,$x,$y,$z);
118 ($id,$t) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS';
119 $fleets = $dbh->prepare($query . q{
122 $fleets->execute($id);
127 $type = CGI::escapeHTML($type);
130 my $settype = $dbh->prepare(q{UPDATE incomings SET shiptype = ? WHERE id = ?});
131 while (my $inc = $fleets->fetchrow_hashref){
132 $call //= $inc->{call};
133 if ($inc->{eta} < 0){
134 $c->reply("This call is old. Did you use the call id instead of inc id by"
135 ." accident? You can use .settypeall callid to set the type on all incs"
136 ." in a call. Or use webbie if you really want to update this old call.");
140 $settype->execute($type,$inc->{id});
141 $deflog .= "Set fleet: [B]$inc->{id} [/B] to: [B]$type [/B]\n";
142 $c->reply("Set fleet $inc->{id} from $inc->{coords} on call $call to $type (previously $inc->{shiptype})");
144 if ($fleets->rows == 0){
145 $c->reply("No matching fleets");
148 $c->def_log($call,$deflog);