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