1 #**************************************************************************
2 # Copyright (C) 2006 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 #**************************************************************************/
28 our @ISA = qw/Exporter/;
30 our @EXPORT = qw/showCall setType takeCall covCall ignoreCall defcall anon setDefPrio/;
33 my ($msg,$command) = @_;
35 if (defined $msg && $msg =~ /^(\d+)$/){
38 $ND::server->command("notice $ND::nick Usage: $command callid");
42 my $f = $ND::DBH->prepare(<<SQL
43 SELECT i.id,coords(p.x,p.y,p.z), p.planet_status,p.nick, p.alliance, p.race,i.eta,i.amount,i.fleet,i.shiptype,p.relationship,c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK')
45 JOIN calls c ON i.call = c.id
46 JOIN current_planet_stats p ON i.sender = p.id
52 while (my @row = $f->fetchrow()){
53 @row = map (valuecolor(0),@row);
54 $ND::server->command("notice $ND::nick (CALL $id) $row[0]: $row[1], $row[3] ($row[2]), $row[4] ($row[10]), $row[5], ETA: $row[11](/$row[6]), Amount: $row[7], $row[8], Type: $row[9]");
60 my ($msg,$command) = @_;
61 my ($type,$id,$x,$y,$z) = @_;
62 if ($command eq 'settypeall'){
63 if (defined $msg && $msg =~ /^(\d+) (.*)$/){
67 $ND::server->command("notice $ND::nick Usage: $command callId type");
71 if (defined $msg && $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/){
77 }elsif (defined $msg && $msg =~ /^(\d+) (.*)$/){
81 $ND::server->command("notice $ND::nick Usage: $command incId type | or: $command callId X:Y:Z type");
88 SELECT i.id,call,shiptype, coords(x,y,z),c.landing_tick - tick() FROM incomings i
89 JOIN current_planet_stats p ON i.sender = p.id
90 JOIN calls c ON i.call = c.id
92 if ($command eq 'settypeall'){
93 $fleet = $ND::DBH->prepare(qq{
99 $fleet = $ND::DBH->prepare(qq{
101 WHERE i.call = ? AND p.id = planetid(?,?,?,0)
103 $fleet->execute($id,$x,$y,$z);
105 $fleet = $ND::DBH->prepare(qq{
109 $fleet->execute($id);
111 while (my ($id,$call,$oldtype,$coords,$tick) = $fleet->fetchrow()){
112 if($ND::DBH->do(q{UPDATE incomings SET shiptype = ? WHERE id = ?},undef,$type,$id) == 1){
113 log_message $user->{uid}, "DC set fleet: $id to: $type";
114 $ND::server->command("msg $ND::target Set fleet from $coords on call $call to $type (previously $oldtype)");
115 if ($tick < 0 && not (defined $x && $x eq 'call')){
116 $ND::server->command("msg $ND::target 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.");
123 my ($msg,$command) = @_;
125 if (defined $msg && $msg =~ /^(\d+)$/){
128 $ND::server->command("notice $ND::nick Usage: $command callid");
132 if ($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?) WHERE id = ?}
133 ,undef,$ND::address,$id) == 1){
134 $ND::server->command("msg $ND::target Updated the DC for call $id");
140 my ($msg,$command) = @_;
142 if (defined $msg && $msg =~ /^(\d+)$/){
145 $ND::server->command("notice $ND::nick Usage: $command callid");
149 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = TRUE, open = FALSE WHERE id = ?}
150 ,undef,$ND::address,$id) == 1){
151 $ND::server->command("msg $ND::target Marked call $id as covered");
157 my ($msg,$command) = @_;
159 if (defined $msg && $msg =~ /^(\d+)$/){
162 $ND::server->command("notice $ND::nick Usage: $command callid");
166 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = FALSE, open = FALSE WHERE id = ?}
167 ,undef,$ND::address,$id) == 1){
168 $ND::server->command("msg $ND::target Marked call $id as ignored");
174 my ($msg,$command) = @_;
175 my ($mess,$nick,$callnr) = @_;
176 if (defined $msg && $msg =~ /^(\d+)?(.*)$/){
180 $ND::server->command("notice $ND::nick Usage: $command [callid] message | if a call id is given, then shiptypes and eta will be fetched from the database and added to the message");
186 my $st = $ND::DBH->prepare(q{
187 SELECT c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK'), concat(i.shiptype||'/') AS shiptype
189 JOIN incomings i ON i.call = c.id
190 LEFT OUTER JOIN users dc ON dc.uid = c.dc
191 JOIN users u ON u.uid = c.member
192 WHERE not covered AND c.id = ?
193 GROUP BY c.id,c.landing_tick
194 ORDER BY c.landing_tick;
196 if (my @row = $ND::DBH->selectrow_array($st,undef,$callnr)){
198 $call = "(Anti $row[1] ETA: $row[0])"
201 $ND::server->command("notice $ND::memchan DEFENSE REQUIRED!! WAKE UP!!");
202 $ND::server->command("msg $ND::memchan DEFENSE REQUIRED $mess $call MSG $ND::nick TO RESPOND");
207 my ($msg,$command) = @_;
209 if (defined $msg && $msg =~ /^(\S+) (.+)$/){
213 $ND::server->command("notice $ND::nick Usage: $command nick message");
217 $ND::server->command("msg $target ".chr(2).$mess);
218 $ND::server->command("msg $ND::target ".chr(3)."3$1 << $2");
224 my ($msg,$command) = @_;
226 if (defined $msg && $msg =~ /^(\d+)\D(\d+)$/){
230 $ND::server->command("notice $ND::nick Usage: $command Min Max");
234 $ND::DBH->begin_work;
235 my $update = $ND::DBH->prepare('UPDATE misc SET value = ? :: int WHERE id = ?');
236 $update->execute($min,'DEFMIN');
237 $update->execute($max,'DEFMAX');
238 if ($ND::DBH->commit){
239 $ND::server->command("msg $ND::target min def prio set to $ND::B$min$ND::B and max set to $ND::B$max");
241 $ND::server->command("msg $ND::target something went wrong");