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/;
36 my $f = $ND::DBH->prepare(<<SQL
37 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')
39 JOIN calls c ON i.call = c.id
40 JOIN current_planet_stats p ON i.sender = p.id
46 while (my @row = $f->fetchrow()){
47 @row = map (valuecolor(0),@row);
48 $ND::server->command("msg $ND::target (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]");
54 my ($type,$id,$x,$y,$z) = @_;
59 SELECT i.id,call,shiptype, coords(x,y,z),c.landing_tick - tick() FROM incomings i
60 JOIN current_planet_stats p ON i.sender = p.id
61 JOIN calls c ON i.call = c.id
63 if (defined $x && $x eq 'call'){
64 $fleet = $ND::DBH->prepare(qq{
70 $fleet = $ND::DBH->prepare(qq{
72 WHERE i.call = ? AND p.id = planetid(?,?,?,0)
74 $fleet->execute($id,$x,$y,$z);
76 $fleet = $ND::DBH->prepare(qq{
82 while (my ($id,$call,$oldtype,$coords,$tick) = $fleet->fetchrow()){
83 if($ND::DBH->do(q{UPDATE incomings SET shiptype = ? WHERE id = ?},undef,$type,$id) == 1){
84 log_message $user->{uid}, "DC set fleet: $id to: $type";
85 $ND::server->command("msg $ND::target Set fleet from $coords on call $call to $type (previosly $oldtype)");
86 if ($tick < 0 && not (defined $x && $x eq 'call')){
87 $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.");
97 if ($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?) WHERE id = ?}
98 ,undef,$ND::address,$id) == 1){
99 $ND::server->command("msg $ND::target Updated the DC for call $id");
108 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = TRUE, open = FALSE WHERE id = ?}
109 ,undef,$ND::address,$id) == 1){
110 $ND::server->command("msg $ND::target Marked call $id as covered");
119 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = FALSE, open = FALSE WHERE id = ?}
120 ,undef,$ND::address,$id) == 1){
121 $ND::server->command("msg $ND::target Marked call $id as ignored");
127 my ($msg,$nick,$callnr) = @_;
132 my $st = $ND::DBH->prepare(q{
133 SELECT c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK'), concat(i.shiptype||'/') AS shiptype, p.x
135 JOIN incomings i ON i.call = c.id
136 LEFT OUTER JOIN users dc ON dc.uid = c.dc
137 JOIN users u ON u.uid = c.member
138 JOIN current_planet_stats p ON u.planet = p.id
139 WHERE not covered AND c.id = ?
140 GROUP BY c.id,c.landing_tick,p.x
141 ORDER BY c.landing_tick;
143 if (my @row = $ND::DBH->selectrow_array($st,undef,$callnr)){
145 $call = "(Anti $row[1] ETA: $row[0] Cluster: $row[2])"
148 $ND::server->command("notice $ND::memchan DEFENSE REQUIRED!! WAKE UP!!");
149 $ND::server->command("msg $ND::memchan DEFENSE REQUIRED $msg $call MSG $nick TO RESPOND");
154 my ($target,$msg) = @_;
156 $ND::server->command("msg $target ".chr(2).$msg);
157 $ND::server->command("msg $ND::target ".chr(3)."3$1 << $2");
166 $ND::DBH->begin_work;
167 my $update = $ND::DBH->prepare('UPDATE misc SET value = ? :: int WHERE id = ?');
168 $update->execute($min,'DEFMIN');
169 $update->execute($max,'DEFMAX');
170 if ($ND::DBH->commit){
171 $ND::server->command("msg $ND::target min def prio set to $min and max set to $max");
173 $ND::server->command("msg $ND::target something went wrong");