]> ruin.nu Git - NDIRC.git/blob - Def.pm
Converted .calltake, .callcov and .callignore
[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 takeCall covCall ignoreCall
32         setDefPrio setCalc getCalc/;
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 setCalc {
62         my ($msg,$command) = @_;
63         my ($id, $calc);
64         if (defined $msg && $msg =~ /^(\d+) (.+)$/){
65                 $id = $1;
66                 $calc = escapeHTML($2);
67         }else{
68                 $ND::server->command("notice $ND::nick Usage: $command callid calc");
69                 return;
70         }
71         if (my $user = dc()){
72                 if ($ND::DBH->do(q{UPDATE calls SET calc = $2 WHERE id = $1}
73                                 ,undef,$id, $calc) == 1){
74                         $ND::server->command("notice $ND::nick Updated calc call $ND::B$id$ND::O");
75                         def_log $user->{uid}, $id , 'Updated calc to: [URL]'
76                                 .$calc.'[/URL]';
77                 }
78         }
79 }
80
81 sub getCalc {
82         my ($msg,$command) = @_;
83         my ($id);
84         if (defined $msg && $msg =~ /^(\d+)$/){
85                 $id = $1;
86         }else{
87                 $ND::server->command("notice $ND::nick Usage: $command callid");
88                 return;
89         }
90         if (my $user = dc()){
91                 my $calc = $ND::DBH->selectrow_array(q{SELECT calc
92                         FROM calls WHERE id = $1}
93                         ,undef,$id);
94                 $ND::server->command("notice $ND::nick calc for call $ND::B$id$ND::O: $calc");
95         }
96 }
97
98 sub setDefPrio {
99         my ($msg,$command) = @_;
100         my ($min,$max);
101         if (defined $msg && $msg =~ /^(\d+)\D(\d+)$/){
102                 $min = $1;
103                 $max = $2;
104         }else{
105                 $ND::server->command("notice $ND::nick Usage: $command Min Max");
106                 return;
107         }
108         if (hc()){
109                 $ND::DBH->begin_work;
110                 my $update = $ND::DBH->prepare('UPDATE misc SET value = ? :: int WHERE id = ?');
111                 $update->execute($min,'DEFMIN');
112                 $update->execute($max,'DEFMAX');
113                 if ($ND::DBH->commit){
114                         $ND::server->command("msg $ND::target min def prio set to $ND::B$min$ND::B and max set to $ND::B$max");
115                 }else{
116                         $ND::server->command("msg $ND::target something went wrong");
117                 }
118         }
119 }
120
121 1;