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
32 defcall setDefPrio setCalc getCalc/;
35 my ($msg,$command) = @_;
37 if (defined $msg && $msg =~ /^(\d+)$/){
40 $ND::server->command("notice $ND::nick Usage: $command callid");
44 my $f = $ND::DBH->prepare(<<SQL
45 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')
47 JOIN calls c ON i.call = c.id
48 JOIN current_planet_stats p ON i.sender = p.id
54 while (my @row = $f->fetchrow()){
55 @row = map (valuecolor(0),@row);
56 $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]");
62 my ($msg,$command) = @_;
63 my ($type,$id,$x,$y,$z) = @_;
64 if ($command eq 'settypeall'){
65 if (defined $msg && $msg =~ /^(\d+) (.*)$/){
69 $ND::server->command("notice $ND::nick Usage: $command callId type");
73 if (defined $msg && $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/){
79 }elsif (defined $msg && $msg =~ /^(\d+) (.*)$/){
83 $ND::server->command("notice $ND::nick Usage: $command incId type | or: $command callId X:Y:Z type");
90 SELECT i.id,call,shiptype, coords(x,y,z),c.landing_tick - tick() FROM incomings i
91 JOIN current_planet_stats p ON i.sender = p.id
92 JOIN calls c ON i.call = c.id
94 if ($command eq 'settypeall'){
95 $fleet = $ND::DBH->prepare(qq{
101 $fleet = $ND::DBH->prepare(qq{
103 WHERE i.call = ? AND p.id = planetid(?,?,?,tick())
105 $fleet->execute($id,$x,$y,$z);
107 $fleet = $ND::DBH->prepare(qq{
111 $fleet->execute($id);
113 $type = escapeHTML($type);
114 while (my ($id,$call,$oldtype,$coords,$tick) = $fleet->fetchrow()){
115 if($ND::DBH->do(q{UPDATE incomings SET shiptype = ? WHERE id = ?},undef,$type,$id) == 1){
116 def_log $user->{uid}, $call , "Set fleet: [B] $id [/B] to: [B] $type [/B]";
117 $ND::server->command("msg $ND::target Set fleet from $coords on call $call to $type (previously $oldtype)");
118 if ($tick < 0 && not (defined $x && $x eq 'call')){
119 $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.");
126 my ($msg,$command) = @_;
128 if (defined $msg && $msg =~ /^(\d+)$/){
131 $ND::server->command("notice $ND::nick Usage: $command callid");
134 if (my $user = dc()){
135 if ($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?) WHERE id = ?}
136 ,undef,$ND::address,$id) == 1){
137 $ND::server->command("msg $ND::target Updated the DC for call $id");
138 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
144 my ($msg,$command) = @_;
146 if (defined $msg && $msg =~ /^(\d+)$/){
149 $ND::server->command("notice $ND::nick Usage: $command callid");
152 if (my $user = dc()){
153 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = TRUE, open = FALSE WHERE id = ?}
154 ,undef,$ND::address,$id) == 1){
155 $ND::server->command("msg $ND::target Marked call $id as covered");
156 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
162 my ($msg,$command) = @_;
164 if (defined $msg && $msg =~ /^(\d+)$/){
167 $ND::server->command("notice $ND::nick Usage: $command callid");
170 if (my $user = dc()){
171 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = FALSE, open = FALSE WHERE id = ?}
172 ,undef,$ND::address,$id) == 1){
173 $ND::server->command("msg $ND::target Marked call $id as ignored");
174 def_log $user->{uid}, $id , "Used: [B] $command [/B]";
180 my ($msg,$command) = @_;
181 my ($mess,$nick,$callnr) = @_;
182 if (defined $msg && $msg =~ /^(\d+)?(.*)$/){
186 $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");
192 my $st = $ND::DBH->prepare(q{
193 SELECT c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK'), concat(i.shiptype||'/') AS shiptype
195 JOIN incomings i ON i.call = c.id
196 LEFT OUTER JOIN users dc ON dc.uid = c.dc
197 JOIN users u ON u.uid = c.member
198 WHERE not covered AND c.id = ?
199 GROUP BY c.id,c.landing_tick
200 ORDER BY c.landing_tick;
202 if (my @row = $ND::DBH->selectrow_array($st,undef,$callnr)){
204 $call = "(Anti $row[1] ETA: $row[0])"
207 $ND::server->command("notice $ND::memchan DEFENSE REQUIRED!! WAKE UP!!");
208 $ND::server->command("msg $ND::memchan DEFENSE REQUIRED $mess $call MSG $ND::nick TO RESPOND");
213 my ($msg,$command) = @_;
215 if (defined $msg && $msg =~ /^(\d+) (.+)$/){
217 $calc = escapeHTML($2);
219 $ND::server->command("notice $ND::nick Usage: $command callid calc");
222 if (my $user = dc()){
223 if ($ND::DBH->do(q{UPDATE calls SET calc = $2 WHERE id = $1}
224 ,undef,$id, $calc) == 1){
225 $ND::server->command("notice $ND::nick Updated calc call $ND::B$id$ND::O");
226 def_log $user->{uid}, $id , 'Updated calc to: [URL]'
233 my ($msg,$command) = @_;
235 if (defined $msg && $msg =~ /^(\d+)$/){
238 $ND::server->command("notice $ND::nick Usage: $command callid");
241 if (my $user = dc()){
242 my $calc = $ND::DBH->selectrow_array(q{SELECT calc
243 FROM calls WHERE id = $1}
245 $ND::server->command("notice $ND::nick calc for call $ND::B$id$ND::O: $calc");
250 my ($msg,$command) = @_;
252 if (defined $msg && $msg =~ /^(\d+)\D(\d+)$/){
256 $ND::server->command("notice $ND::nick Usage: $command Min Max");
260 $ND::DBH->begin_work;
261 my $update = $ND::DBH->prepare('UPDATE misc SET value = ? :: int WHERE id = ?');
262 $update->execute($min,'DEFMIN');
263 $update->execute($max,'DEFMAX');
264 if ($ND::DBH->commit){
265 $ND::server->command("msg $ND::target min def prio set to $ND::B$min$ND::B and max set to $ND::B$max");
267 $ND::server->command("msg $ND::target something went wrong");