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 #**************************************************************************/
26 use CGI qw/:standard/;
29 our @ISA = qw/Exporter/;
31 our @EXPORT = qw/showCall setType takeCall covCall ignoreCall defcall anon setDefPrio/;
34 my ($msg,$command) = @_;
36 if (defined $msg && $msg =~ /^(\d+)$/){
39 $ND::server->command("notice $ND::nick Usage: $command callid");
43 my $f = $ND::DBH->prepare(<<SQL
44 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')
46 JOIN calls c ON i.call = c.id
47 JOIN current_planet_stats p ON i.sender = p.id
53 while (my @row = $f->fetchrow()){
54 @row = map (valuecolor(0),@row);
55 $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]");
61 my ($msg,$command) = @_;
62 my ($type,$id,$x,$y,$z) = @_;
63 if ($command eq 'settypeall'){
64 if (defined $msg && $msg =~ /^(\d+) (.*)$/){
68 $ND::server->command("notice $ND::nick Usage: $command callId type");
72 if (defined $msg && $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/){
78 }elsif (defined $msg && $msg =~ /^(\d+) (.*)$/){
82 $ND::server->command("notice $ND::nick Usage: $command incId type | or: $command callId X:Y:Z type");
89 SELECT i.id,call,shiptype, coords(x,y,z),c.landing_tick - tick() FROM incomings i
90 JOIN current_planet_stats p ON i.sender = p.id
91 JOIN calls c ON i.call = c.id
93 if ($command eq 'settypeall'){
94 $fleet = $ND::DBH->prepare(qq{
100 $fleet = $ND::DBH->prepare(qq{
102 WHERE i.call = ? AND p.id = planetid(?,?,?,tick())
104 $fleet->execute($id,$x,$y,$z);
106 $fleet = $ND::DBH->prepare(qq{
110 $fleet->execute($id);
112 $type = escapeHTML($type);
113 while (my ($id,$call,$oldtype,$coords,$tick) = $fleet->fetchrow()){
114 if($ND::DBH->do(q{UPDATE incomings SET shiptype = ? WHERE id = ?},undef,$type,$id) == 1){
115 def_log $user->{uid}, $call , "Set fleet: [B] $id [/B] to: [B] $type [/B]";
116 $ND::server->command("msg $ND::target Set fleet from $coords on call $call to $type (previously $oldtype)");
117 if ($tick < 0 && not (defined $x && $x eq 'call')){
118 $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.");
125 my ($msg,$command) = @_;
127 if (defined $msg && $msg =~ /^(\d+)$/){
130 $ND::server->command("notice $ND::nick Usage: $command callid");
133 if (my $user = dc()){
134 if ($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?) WHERE id = ?}
135 ,undef,$ND::address,$id) == 1){
136 $ND::server->command("msg $ND::target Updated the DC for call $id");
137 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
143 my ($msg,$command) = @_;
145 if (defined $msg && $msg =~ /^(\d+)$/){
148 $ND::server->command("notice $ND::nick Usage: $command callid");
151 if (my $user = dc()){
152 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = TRUE, open = FALSE WHERE id = ?}
153 ,undef,$ND::address,$id) == 1){
154 $ND::server->command("msg $ND::target Marked call $id as covered");
155 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
161 my ($msg,$command) = @_;
163 if (defined $msg && $msg =~ /^(\d+)$/){
166 $ND::server->command("notice $ND::nick Usage: $command callid");
169 if (my $user = dc()){
170 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = FALSE, open = FALSE WHERE id = ?}
171 ,undef,$ND::address,$id) == 1){
172 $ND::server->command("msg $ND::target Marked call $id as ignored");
173 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
179 my ($msg,$command) = @_;
180 my ($mess,$nick,$callnr) = @_;
181 if (defined $msg && $msg =~ /^(\d+)?(.*)$/){
185 $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");
191 my $st = $ND::DBH->prepare(q{
192 SELECT c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK'), concat(i.shiptype||'/') AS shiptype
194 JOIN incomings i ON i.call = c.id
195 LEFT OUTER JOIN users dc ON dc.uid = c.dc
196 JOIN users u ON u.uid = c.member
197 WHERE not covered AND c.id = ?
198 GROUP BY c.id,c.landing_tick
199 ORDER BY c.landing_tick;
201 if (my @row = $ND::DBH->selectrow_array($st,undef,$callnr)){
203 $call = "(Anti $row[1] ETA: $row[0])"
206 $ND::server->command("notice $ND::memchan DEFENSE REQUIRED!! WAKE UP!!");
207 $ND::server->command("msg $ND::memchan DEFENSE REQUIRED $mess $call MSG $ND::nick TO RESPOND");
212 my ($msg,$command) = @_;
214 if (defined $msg && $msg =~ /^(\S+) (.+)$/){
218 $ND::server->command("notice $ND::nick Usage: $command nick message");
222 $ND::server->command("msg $target ".chr(2).$mess);
223 $ND::server->command("msg $ND::target ".chr(3)."3$1 << $2");
229 my ($msg,$command) = @_;
231 if (defined $msg && $msg =~ /^(\d+)\D(\d+)$/){
235 $ND::server->command("notice $ND::nick Usage: $command Min Max");
239 $ND::DBH->begin_work;
240 my $update = $ND::DBH->prepare('UPDATE misc SET value = ? :: int WHERE id = ?');
241 $update->execute($min,'DEFMIN');
242 $update->execute($max,'DEFMAX');
243 if ($ND::DBH->commit){
244 $ND::server->command("msg $ND::target min def prio set to $ND::B$min$ND::B and max set to $ND::B$max");
246 $ND::server->command("msg $ND::target something went wrong");