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(privmsg => $target, "<b>$mess</b>");
41 $c->message(privmsg => $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 ,array_to_string(array_agg(i.shiptype),'/') AS shiptype
60 JOIN incomings i USING (call)
61 LEFT OUTER JOIN users dc ON dc.uid = c.dc
63 GROUP BY c.call,c.landing_tick,c.status
64 ORDER BY c.landing_tick;
66 my $call = $dbh->selectrow_hashref($st,undef,$callnr);
67 unless (defined $call->{status}){
68 $c->reply("No call with id: $callnr");
71 $callinfo = "(Anti $call->{shiptype} ETA: $call->{eta})";
72 if($call->{status} eq 'Covered'){
73 $c->reply("Call <b>$callnr</b> $callinfo is covered.");
77 $c->message(notice => $ND::memchan, "DEFENSE REQUIRED!! WAKE UP!!");
78 $c->message(privmsg => $ND::memchan, "DEFENSE REQUIRED $mess $callinfo MSG "
79 .$c->nick." TO RESPOND");
83 : Help(Usage: .settype incId type | or: .settyp callId X:Y:Z type | or: .settypeall callId type)
88 my ($self,$c,$msg) = @_;
92 SELECT inc,call,shiptype, coords(x,y,z),c.landing_tick - tick() AS eta
94 JOIN current_planet_stats p USING (pid)
95 JOIN calls c USING (call)
101 if ($self->name eq 'settypeall'){
102 ($call,$type) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS';
104 $fleets = $dbh->prepare($query . q{
107 $fleets->execute($call);
109 my ($id,$x,$y,$z,$t) = $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/;
111 $fleets = $dbh->prepare($query . q{
112 WHERE call = ? AND pid = planetid(?,?,?,tick())
114 $fleets->execute($id,$x,$y,$z);
116 ($id,$t) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS';
117 $fleets = $dbh->prepare($query . q{
120 $fleets->execute($id);
125 $type = CGI::escapeHTML($type);
128 my $settype = $dbh->prepare(q{UPDATE incomings SET shiptype = ? WHERE inc = ?});
129 while (my $inc = $fleets->fetchrow_hashref){
130 $call //= $inc->{call};
131 if ($inc->{eta} < 0){
132 $c->reply("This call is old. Did you use the call id instead of inc id by"
133 ." accident? You can use .settypeall callid to set the type on all incs"
134 ." in a call. Or use webbie if you really want to update this old call.");
138 $settype->execute($type,$inc->{inc});
139 $deflog .= "Set fleet: [B]$inc->{inc} [/B] to: [B]$type [/B]\n";
140 $c->reply("Set fleet $inc->{inc} from $inc->{coords} on call $call to $type (previously $inc->{shiptype})");
142 if ($fleets->rows == 0){
143 $c->reply("No matching fleets");
146 $c->def_log($call,$deflog);
152 : Help(Usage: .calltake callid | sets the dc. also markes as covered/ignored with .callcov and .callignore)
155 : Alias(qw/callcov callignore/)
157 my ($self,$c,$msg) = @_;
158 my ($id) = $msg =~ /^(\d+)$/ or die 'ARGS';
163 given ($self->{name}){
173 my $rows = $dbh->do(q{
174 UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE $1)
177 },undef,$c->host,$id,$status);
179 $c->reply("Setting status on call $id to $status");
180 $c->def_log($id , "Changed status: [B]$status [/B]");
183 $c->reply("$id is not a valid call");
189 : Help(Usage: .setcalc callId calc | sets the calc for the given call.)
193 my ($self,$c,$msg) = @_;
194 my ($id,$calc) = $msg =~ /^(\d+) (.+)$/ or die 'ARGS';
198 my $rows = $dbh->do(q{UPDATE calls SET calc = $2 WHERE id = $1}
201 $c->reply("Updated calc call <b>$id</b>");
202 $calc = CGI::escapeHTML($calc);
203 $c->def_log($id , 'Updated calc to: [URL]'.$calc.'[/URL]');
206 $c->reply("$id is not a valid call");
212 : Help(Usage: .getcalc callId | receives the calc for the given call)
216 my ($self,$c,$msg) = @_;
217 my ($id) = $msg =~ /^(\d+)$/ or die 'ARGS';
220 my $calc = $dbh->selectrow_array(q{
221 SELECT calc FROM calls WHERE id = $1}
223 $calc //= "Bad call id, there is no such call.";
224 $c->reply("Calc for call <b>$id</b>: $calc");