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 #**************************************************************************/
26 use NDIRC::Dispatcher;
29 help => q(syntax: .defcall [callid] | if a call id is given, then shiptypes and eta will be fetched from the database and added to the message),
31 acl => q(irc_defcall),
32 }, class extends NDIRC::Command {
33 method execute($c,$msg) {
34 my ($callnr,$mess) = $msg =~ /^(\d+)?(.*)$/ or die 'ARGS';
39 my $st = $dbh->prepare(q{
41 ,c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK') AS eta
42 ,array_to_string(array_agg(i.shiptype),'/') AS shiptype
44 JOIN incomings i USING (call)
45 LEFT OUTER JOIN users dc ON dc.uid = c.dc
47 GROUP BY c.call,c.landing_tick,c.status
48 ORDER BY c.landing_tick;
50 my $call = $dbh->selectrow_hashref($st,undef,$callnr);
51 unless (defined $call->{status}){
52 $c->reply("No call with id: $callnr");
55 $callinfo = "(Anti $call->{shiptype} ETA: $call->{eta})";
56 if($call->{status} eq 'Covered'){
57 $c->reply("Call <b>$callnr</b> $callinfo is covered.");
61 $c->message(notice => $c->disp->targets->{members}, "DEFENSE REQUIRED!! WAKE UP!!");
62 $c->message(privmsg => $c->disp->targets->{members}, "DEFENSE REQUIRED "
63 ."$mess $callinfo MSG ".$c->nick." TO RESPOND");
68 help => q(Usage: .settype incId type | or: .settyp callId X:Y:Z type | or: .settypeall callId type),
70 acl => q(irc_settype),
71 alias => q(settypeall),
72 }, class extends NDIRC::Command {
74 method execute($c,$msg) {
78 SELECT inc,call,shiptype, coords(x,y,z),c.landing_tick - tick() AS eta
80 JOIN current_planet_stats p USING (pid)
81 JOIN calls c USING (call)
87 if ($self->name eq 'settypeall'){
88 ($call,$type) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS';
90 $fleets = $dbh->prepare($query . q{
93 $fleets->execute($call);
95 my ($id,$x,$y,$z,$t) = $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/;
97 $fleets = $dbh->prepare($query . q{
98 WHERE call = ? AND pid = planetid(?,?,?,tick())
100 $fleets->execute($id,$x,$y,$z);
102 ($id,$t) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS';
103 $fleets = $dbh->prepare($query . q{
106 $fleets->execute($id);
111 $type = CGI::escapeHTML($type);
114 my $settype = $dbh->prepare(q{UPDATE incomings SET shiptype = ? WHERE inc = ?});
115 while (my $inc = $fleets->fetchrow_hashref){
116 $call //= $inc->{call};
117 if ($inc->{eta} < 0){
118 $c->reply("This call is old. Did you use the call id instead of inc id by"
119 ." accident? You can use .settypeall callid to set the type on all incs"
120 ." in a call. Or use webbie if you really want to update this old call.");
124 $settype->execute($type,$inc->{inc});
125 $deflog .= "Set fleet: [B]$inc->{inc} [/B] to: [B]$type [/B]\n";
126 $c->reply("Set fleet $inc->{inc} from $inc->{coords} on call $call to $type (previously $inc->{shiptype})");
128 if ($fleets->rows == 0){
129 $c->reply("No matching fleets");
132 $c->def_log($call,$deflog);
138 command calltake => {
139 help => q(Usage: .calltake callid | sets the dc. also markes as covered/ignored with .callcov and .callignore),
141 acl => q(irc_calltake),
142 alias => [qw/callcov callignore/],
143 }, class extends NDIRC::Command {
144 method execute($c,$msg) {
145 my ($id) = $msg =~ /^(\d+)$/ or die 'ARGS';
150 given ($self->{name}){
160 my $rows = $dbh->do(q{
161 UPDATE calls SET dc = $1
164 },undef,$c->uid,$id,$status);
166 $c->reply("Setting status on call $id to $status");
167 $c->def_log($id , "Changed status: [B]$status [/B]");
170 $c->reply("$id is not a valid call");
177 help => q(Usage: .setcalc callId calc | sets the calc for the given call.),
179 acl => q(irc_setcalc),
180 }, class extends NDIRC::Command {
182 method execute($c,$msg) {
183 my ($id,$calc) = $msg =~ /^(\d+) (.+)$/ or die 'ARGS';
187 my $rows = $dbh->do(q{UPDATE calls SET calc = $2 WHERE call = $1}
190 $c->reply("Updated calc call <b>$id</b>");
191 $calc = CGI::escapeHTML($calc);
192 $c->def_log($id , 'Updated calc to: [URL]'.$calc.'[/URL]');
195 $c->reply("$id is not a valid call");
202 help => q(Usage: .getcalc callId | receives the calc for the given call),
204 acl => q(irc_getcalc),
205 }, class extends NDIRC::Command {
206 method execute($c,$msg) {
207 my ($id) = $msg =~ /^(\d+)$/ or die 'ARGS';
210 my $calc = $dbh->selectrow_array(q{
211 SELECT calc FROM calls WHERE call = $1}
213 $calc //= "Bad call id, there is no such call.";
214 $c->reply("Calc for call <b>$id</b>: $calc");
218 command report_incs => {
219 help => q(Used to report incs, same as pasting in pm. Use ~ prefix to send output to channel),
221 }, class extends NDIRC::Command {
222 method execute($c,$msg) {
224 $msg =~ /(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\s+([^:]*\S+)\s+(?:Ter|Cat|Xan|Zik|Etd)\s+([\d,]+)\s+Attack\s+(\d+)/
225 || $msg =~ /(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)\s+\((?:Ter|Cat|Xan|Zik|Etd)\)\s+([^,]*\S+)\s+([\d,]+)\s+(\d+)\s+\(\d+\)/
233 my $st = $dbh->prepare(q{
234 SELECT username, uid, pid, defprio
236 WHERE pid = planetid($1,$2,$3,tick())
237 AND uid IN (SELECT uid FROM groupmembers WHERE gid = 'M')
239 if (my $user = $dbh->selectrow_hashref($st,undef,$1,$2,$3)){
241 $st = $dbh->prepare(q{
242 SELECT nick,alliance,pid,planet_status,relationship
243 FROM current_planet_stats WHERE x = ? AND y = ? AND z = ?
245 if (my @attacker = $dbh->selectrow_array($st,undef,$4,$5,$6)){
247 my $landing_tick = $dbh->selectrow_array(q{SELECT tick() + ?},undef,$9);
248 my @call = $dbh->selectrow_array(q{
249 SELECT call,status,calc
250 FROM calls WHERE uid = ? AND landing_tick = ?
251 },undef,$user->{uid},$landing_tick);
252 my $threefleeter = $dbh->selectrow_array(q{
253 SELECT COALESCE(gid = 'X',false)
254 FROM groupmembers WHERE uid = ? AND gid = 'X'
255 },undef,$user->{uid});
256 unless (@call){ #call doesn't exists, create a new one
257 @call = $dbh->selectrow_array(q{
258 INSERT INTO calls (uid,landing_tick,info) VALUES(?,?,'') RETURNING call,status,calc
259 },undef,$user->{uid},$landing_tick);
261 $dbh->do(q{UPDATE calls SET status = 'Ignored' WHERE call = $1},undef,$call[0]);
262 $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.');
263 $call[1] = 'Ignored';
267 my $pointlimits = $dbh->prepare(q{SELECT value :: float FROM misc WHERE id = ?});
268 my ($minpoints) = $dbh->selectrow_array($pointlimits,undef,'DEFMINPRIO');
269 my ($maxpoints) = $dbh->selectrow_array($pointlimits,undef,'DEFMAXPRIO');
271 if ($user->{defprio} < $minpoints){
273 }elsif ($user->{defprio} < $maxpoints){
276 $user->{defprio} = "<c0$color>$user->{defprio}</c>";
277 $st = $dbh->prepare(q{SELECT pid FROM incomings WHERE pid = ? AND amount = ? and fleet = ? AND call = ?});
278 unless (my @inc = $dbh->selectrow_array($st,undef,$attacker[2],$amount,$7,$call[0])){
279 my $incid = $dbh->selectrow_array(q{
280 INSERT INTO incomings (call,pid,eta,amount,fleet) VALUES(?,?,?,?,?) RETURNING inc
281 },undef,$call[0],$attacker[2],$9,$amount,$7);
282 @attacker = map ($c->valuecolor(0),@attacker);
283 if (! $threefleeter || $call[1] ne 'Ignored'){
284 $c->reply("<b>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]</b>");
286 $c->reply("<b>Do not cover</b>, NoDef member is under attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4]) https://nd.ruin.nu/calls/edit/$call[0]");
288 $dbh->do(q{UPDATE planets SET hit_us = hit_us + 1 WHERE pid = ?},undef,$attacker[2]);
289 if ($call[1] eq 'Covered'){
290 $dbh->do(q{UPDATE calls SET status = 'Open' WHERE call = ?},undef,$call[0]);
291 $c->reply("<b>Call is likely not covered anymore, please recalc! calc: $call[2]</b>");
294 @attacker = map ($c->valuecolor(0),@attacker);
295 $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");
298 my ($fleetcatch) = $dbh->selectrow_array(q{
299 SELECT count(*) FROM launch_confirmations WHERE uid = ? AND back = ?
300 },undef,$user->{uid},$landing_tick);
301 if ($fleetcatch > 0){
302 $c->reply("<c04>THIS IS A POSSIBLE FLEETCATCH!</c>");
307 $c->reply("<c04>Didn't find any planet with coordinates $4:$5:$6 at this tick</c>");
310 $c->reply("<c04>No member registered with coordinates $1:$2:$3</c>");