]> ruin.nu Git - NDIRC.git/blob - Def.pm
b8dc386ba21f8d09fa48cd3c9e742a7f74026c30
[NDIRC.git] / Def.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
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.                                   *
8 #                                                                         *
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.                          *
13 #                                                                         *
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 #**************************************************************************/
19 package NDIRC::Def;
20 use strict;
21 use warnings;
22 use ND::DB;
23 use ND::Include;
24 use NDIRC::Access;
25 use NDIRC::Misc;
26 use CGI qw/:standard/;
27 require Exporter;
28
29 our @ISA = qw/Exporter/;
30
31 our @EXPORT = qw/showCall
32         setDefPrio/;
33
34 sub showCall {
35         my ($msg,$command) = @_;
36         my ($id);
37         if (defined $msg && $msg =~ /^(\d+)$/){
38                 $id = $1;
39         }else{
40                 $ND::server->command("notice $ND::nick Usage: $command callid");
41                 return;
42         }
43         if (dc()){
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')
46                 FROM incomings i
47                         JOIN calls c ON i.call = c.id
48                                 JOIN current_planet_stats p ON i.sender = p.id
49                                 WHERE i.call = ? 
50                                 ORDER BY p.x,p.y,p.z;
51 SQL
52 );
53                 $f->execute($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]");
57                 }
58         }
59 }
60
61 sub setDefPrio {
62         my ($msg,$command) = @_;
63         my ($min,$max);
64         if (defined $msg && $msg =~ /^(\d+)\D(\d+)$/){
65                 $min = $1;
66                 $max = $2;
67         }else{
68                 $ND::server->command("notice $ND::nick Usage: $command Min Max");
69                 return;
70         }
71         if (hc()){
72                 $ND::DBH->begin_work;
73                 my $update = $ND::DBH->prepare('UPDATE misc SET value = ? :: int WHERE id = ?');
74                 $update->execute($min,'DEFMIN');
75                 $update->execute($max,'DEFMAX');
76                 if ($ND::DBH->commit){
77                         $ND::server->command("msg $ND::target min def prio set to $ND::B$min$ND::B and max set to $ND::B$max");
78                 }else{
79                         $ND::server->command("msg $ND::target something went wrong");
80                 }
81         }
82 }
83
84 1;