]> ruin.nu Git - NDIRC.git/blob - Intel.pm
modules
[NDIRC.git] / Intel.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 ND::IRC::Intel;
20 use strict;
21 use warnings;
22 use ND::DB;
23 use ND::IRC::Access;
24 use ND::IRC::Misc;
25 require Exporter;
26
27 our @ISA = qw/Exporter/;
28
29 our @EXPORT = qw/checkIntel setHostile findNick setNick setAlly setChannel/;
30
31 sub checkIntel {
32         my ($x,$y,$z) = @_;
33         DB();
34         if (officer() || dc()){
35                 my $f = $ND::DBH->prepare("SELECT nick,alliance,coords(x,y,z),ruler,planet,hit_us,race,score,size,value,planet_status,relationship FROM current_planet_stats WHERE x = ? AND y = ? and z = ?");
36                 $f->execute($x,$y,$z);
37                 while (my @row = $f->fetchrow()){
38                         @row = map (valuecolor(1),@row);
39                         $ND::server->command("notice $ND::target $row[2] - $row[3] OF $row[4], Alliance=$row[1] ($row[11]), Nick=$row[0] ($row[10]), Hostile Count=$row[5], Race=$row[6], Score=$row[7], Size=$row[8], Value=$row[9] ");
40                 }
41         }else{
42                 $ND::server->command("msg $ND::target Only officers are allowed to check that");
43         }
44 }
45
46 sub setHostile {
47         my ($x,$y,$z) = @_;
48         DB();
49         if(dc()){
50                 my $rv = $ND::DBH->do("UPDATE planets SET planet_status = 'Hostile' WHERE id = (SELECT id FROM current_planet_stats WHERE x = ? AND y = ? and z = ?)",undef,$x,$y,$z);
51                 if ($rv == 1){
52                         $ND::server->command("msg $ND::target $x:$y:$z is now marked s hostile");
53                 }
54         }
55 }
56
57 sub findNick {
58         my ($nick) = @_;
59         DB();
60         if(officer()){
61                 my $f = $ND::DBH->prepare("SELECT coords(x,y,z), ruler,planet,nick FROM current_planet_stats WHERE nick ILIKE ? ORDER BY x,y,z");
62                 $f->execute($nick);
63                 $ND::server->command("notice $ND::target No such nick") if $f->rows == 0;
64                 while (my @row = $f->fetchrow()){
65                         $ND::server->command("notice $ND::target $row[0] $row[1] OF $row[2] is $row[3]");
66                 }
67         }
68 }
69 sub setNick {
70         my ($x,$y,$z,$nick) = @_;
71         DB();
72         if (officer()){
73                 if ($ND::DBH->do("UPDATE planets SET nick = ? WHERE id = planetid(?,?,?,0)"
74                                 ,undef,$nick,$x,$y,$z)){
75                         $ND::server->command("msg $ND::target $x:$y:$z has been updated");
76                 }
77         }
78 }
79
80 sub setAlly {
81         my ($x,$y,$z,$ally) = @_;
82         DB();
83         if (officer()){
84                 my $aid;
85                 if ($ally ne 'unknown'){
86                         ($aid,$ally) = $ND::DBH->selectrow_array("SELECT id,name FROM alliances WHERE name ILIKE ?",undef,$ally);
87                 }
88                 if ($ally){
89                         $ND::DBH->do("UPDATE planets SET alliance_id = ? WHERE id = planetid(?,?,?,0)"
90                                 ,undef,$aid,$x,$y,$z);
91                         $ND::server->command("msg $ND::target Setting $x:$y:$z as $ally");
92                 }else{
93                         $ND::server->command("msg $ND::target Couldn't find such an alliance");
94                 }
95         }
96 }
97
98 sub setChannel {
99         my ($x,$y,$z,$channel) = @_;
100         DB();
101         if (officer()){
102                 if ($ND::DBH->do("UPDATE planets SET channel = ? WHERE id = planetid(?,?,?,0)"
103                                 ,undef,$channel,$x,$y,$z)){
104                         $ND::server->command("msg $ND::target $x:$y:$z relay channel has been set to: $channel");
105                 }
106         }
107 }
108
109 1;