]> ruin.nu Git - NDIRC.git/blob - Def.pm
Converted .settype and .settypeall
[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 takeCall {
62         my ($msg,$command) = @_;
63         my ($id);
64         if (defined $msg && $msg =~ /^(\d+)$/){
65                 $id = $1;
66         }else{
67                 $ND::server->command("notice $ND::nick Usage: $command callid");
68                 return;
69         }
70         if (my $user = dc()){
71                 if ($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?) WHERE id = ?}
72                                 ,undef,$ND::address,$id) == 1){
73                         $ND::server->command("msg $ND::target Updated the DC for call $id");
74                         def_log $user->{uid}, $id , "Used: [B] $command [/B]";
75                 }
76         }
77 }
78
79 sub covCall {
80         my ($msg,$command) = @_;
81         my ($id);
82         if (defined $msg && $msg =~ /^(\d+)$/){
83                 $id = $1;
84         }else{
85                 $ND::server->command("notice $ND::nick Usage: $command callid");
86                 return;
87         }
88         if (my $user = dc()){
89                 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = TRUE, open = FALSE WHERE id = ?}
90                                 ,undef,$ND::address,$id) == 1){
91                         $ND::server->command("msg $ND::target Marked call $id as covered");
92                         def_log $user->{uid}, $id , "Used: [B] $command [/B]";
93                 }
94         }
95 }
96
97 sub ignoreCall {
98         my ($msg,$command) = @_;
99         my ($id);
100         if (defined $msg && $msg =~ /^(\d+)$/){
101                 $id = $1;
102         }else{
103                 $ND::server->command("notice $ND::nick Usage: $command callid");
104                 return;
105         }
106         if (my $user = dc()){
107                 if($ND::DBH->do(q{UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE ?), covered = FALSE, open = FALSE WHERE id = ?}
108                                 ,undef,$ND::address,$id) == 1){
109                         $ND::server->command("msg $ND::target Marked call $id as ignored");
110                         def_log $user->{uid}, $id , "Used: [B] $command [/B]";
111                 }
112         }
113 }
114
115 sub setCalc {
116         my ($msg,$command) = @_;
117         my ($id, $calc);
118         if (defined $msg && $msg =~ /^(\d+) (.+)$/){
119                 $id = $1;
120                 $calc = escapeHTML($2);
121         }else{
122                 $ND::server->command("notice $ND::nick Usage: $command callid calc");
123                 return;
124         }
125         if (my $user = dc()){
126                 if ($ND::DBH->do(q{UPDATE calls SET calc = $2 WHERE id = $1}
127                                 ,undef,$id, $calc) == 1){
128                         $ND::server->command("notice $ND::nick Updated calc call $ND::B$id$ND::O");
129                         def_log $user->{uid}, $id , 'Updated calc to: [URL]'
130                                 .$calc.'[/URL]';
131                 }
132         }
133 }
134
135 sub getCalc {
136         my ($msg,$command) = @_;
137         my ($id);
138         if (defined $msg && $msg =~ /^(\d+)$/){
139                 $id = $1;
140         }else{
141                 $ND::server->command("notice $ND::nick Usage: $command callid");
142                 return;
143         }
144         if (my $user = dc()){
145                 my $calc = $ND::DBH->selectrow_array(q{SELECT calc
146                         FROM calls WHERE id = $1}
147                         ,undef,$id);
148                 $ND::server->command("notice $ND::nick calc for call $ND::B$id$ND::O: $calc");
149         }
150 }
151
152 sub setDefPrio {
153         my ($msg,$command) = @_;
154         my ($min,$max);
155         if (defined $msg && $msg =~ /^(\d+)\D(\d+)$/){
156                 $min = $1;
157                 $max = $2;
158         }else{
159                 $ND::server->command("notice $ND::nick Usage: $command Min Max");
160                 return;
161         }
162         if (hc()){
163                 $ND::DBH->begin_work;
164                 my $update = $ND::DBH->prepare('UPDATE misc SET value = ? :: int WHERE id = ?');
165                 $update->execute($min,'DEFMIN');
166                 $update->execute($max,'DEFMAX');
167                 if ($ND::DBH->commit){
168                         $ND::server->command("msg $ND::target min def prio set to $ND::B$min$ND::B and max set to $ND::B$max");
169                 }else{
170                         $ND::server->command("msg $ND::target something went wrong");
171                 }
172         }
173 }
174
175 1;