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(?,?,?,tick())
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 def_log $user->{uid}, $call , "Set fleet: [B] $id [/B] to: [B] $type [/B]";
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");
131 if (my $user = dc()){
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");
135 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
141 my ($msg,$command) = @_;
143 if (defined $msg && $msg =~ /^(\d+)$/){
146 $ND::server->command("notice $ND::nick Usage: $command callid");
149 if (my $user = dc()){
150 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = TRUE, open = FALSE WHERE id = ?}
151 ,undef,$ND::address,$id) == 1){
152 $ND::server->command("msg $ND::target Marked call $id as covered");
153 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
159 my ($msg,$command) = @_;
161 if (defined $msg && $msg =~ /^(\d+)$/){
164 $ND::server->command("notice $ND::nick Usage: $command callid");
167 if (my $user = dc()){
168 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = FALSE, open = FALSE WHERE id = ?}
169 ,undef,$ND::address,$id) == 1){
170 $ND::server->command("msg $ND::target Marked call $id as ignored");
171 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
177 my ($msg,$command) = @_;
178 my ($mess,$nick,$callnr) = @_;
179 if (defined $msg && $msg =~ /^(\d+)?(.*)$/){
183 $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");
189 my $st = $ND::DBH->prepare(q{
190 SELECT c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK'), concat(i.shiptype||'/') AS shiptype
192 JOIN incomings i ON i.call = c.id
193 LEFT OUTER JOIN users dc ON dc.uid = c.dc
194 JOIN users u ON u.uid = c.member
195 WHERE not covered AND c.id = ?
196 GROUP BY c.id,c.landing_tick
197 ORDER BY c.landing_tick;
199 if (my @row = $ND::DBH->selectrow_array($st,undef,$callnr)){
201 $call = "(Anti $row[1] ETA: $row[0])"
204 $ND::server->command("notice $ND::memchan DEFENSE REQUIRED!! WAKE UP!!");
205 $ND::server->command("msg $ND::memchan DEFENSE REQUIRED $mess $call MSG $ND::nick TO RESPOND");
210 my ($msg,$command) = @_;
212 if (defined $msg && $msg =~ /^(\S+) (.+)$/){
216 $ND::server->command("notice $ND::nick Usage: $command nick message");
220 $ND::server->command("msg $target ".chr(2).$mess);
221 $ND::server->command("msg $ND::target ".chr(3)."3$1 << $2");
227 my ($msg,$command) = @_;
229 if (defined $msg && $msg =~ /^(\d+)\D(\d+)$/){
233 $ND::server->command("notice $ND::nick Usage: $command Min Max");
237 $ND::DBH->begin_work;
238 my $update = $ND::DBH->prepare('UPDATE misc SET value = ? :: int WHERE id = ?');
239 $update->execute($min,'DEFMIN');
240 $update->execute($max,'DEFMAX');
241 if ($ND::DBH->commit){
242 $ND::server->command("msg $ND::target min def prio set to $ND::B$min$ND::B and max set to $ND::B$max");
244 $ND::server->command("msg $ND::target something went wrong");