]> ruin.nu Git - NDIRC.git/blob - Intel.pm
recruit/ia access
[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 NDIRC::Intel;
20 use strict;
21 use warnings;
22 use ND::DB;
23 use NDIRC::Access;
24 use NDIRC::Misc;
25 use ND::Include;
26 require Exporter;
27
28 our @ISA = qw/Exporter/;
29
30 our @EXPORT = qw/setHostile setNick setAlly setChannel/;
31
32 sub setHostile {
33         my ($msg, $command) = @_;
34         my ($x,$y,$z);
35         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+)$/){
36                 $x = $1;
37                 $y = $2;
38                 $z = $3;
39         }else{
40                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z");
41                 return;
42         }
43         if(my $user = dc()){
44                 my $findid = $ND::DBH->prepare_cached(q{SELECT planetid(?,?,?,tick())});
45                 my ($id) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
46                 my $rv = $ND::DBH->do(q{UPDATE planets SET planet_status = 'Hostile' WHERE id = $1},undef,$id);
47                 if ($rv == 1){
48                         $ND::server->command("msg $ND::target $x:$y:$z is now marked s hostile");
49                         intel_log $user->{uid},$id,"Set planet_status to: 'Hostile'";
50                 }
51         }
52 }
53
54 sub setNick {
55         my ($msg, $command) = @_;
56         my ($x,$y,$z,$nick);
57         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
58                 $x = $1;
59                 $y = $2;
60                 $z = $3;
61                 $nick = $4;
62         }else{
63                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z nick");
64                 return;
65         }
66         if (my $user = officer){
67                 my $findid = $ND::DBH->prepare_cached(q{SELECT nick, id FROM planets
68                         WHERE id = planetid(?,?,?,tick())});
69                 my ($oldnick,$id) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
70                 if ($ND::DBH->do('UPDATE planets SET nick = $1 WHERE id = $2'
71                                 ,undef,$nick,$id)){
72                         unless (defined $oldnick){
73                                 $ND::server->command("msg $ND::target $x:$y:$z nick has been set to $ND::B$nick");
74                         }else{
75                                 $ND::server->command("msg $ND::target $x:$y:$z nick has been changed from $ND::B$oldnick$ND::B to $ND::B$nick");
76                         }
77                         intel_log $user->{uid},$id,"Set nick to: $nick";
78                 }
79         }
80 }
81
82 sub setAlly {
83         my ($msg, $command) = @_;
84         my ($x,$y,$z,$ally);
85         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
86                 $x = $1;
87                 $y = $2;
88                 $z = $3;
89                 $ally = $4;
90         }else{
91                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z ally | | % can be used for wildcards \%-crew\% will match [F-Crew]");
92                 return;
93         }
94         if (my $user = officer){
95                 my $aid;
96                 if ($ally ne 'unknown'){
97                         ($aid,$ally) = $ND::DBH->selectrow_array("SELECT id,name FROM alliances WHERE name ILIKE ?",undef,$ally);
98                 }
99                 if ($ally){
100                         my $findid = $ND::DBH->prepare_cached(q{SELECT id,alliance FROM current_planet_stats 
101                                 WHERE x = ? AND y = ? and z = ?});
102                         my ($id,$alliance) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
103                         if($id && $ND::DBH->do('UPDATE planets SET alliance_id = $1 WHERE id = $2'
104                                 ,undef,$aid,$id)){
105                                 if (defined $alliance){
106                                         $ND::server->command("msg $ND::target Changed $x:$y:$z from $ND::B$alliance$ND::B to $ND::B$ally");
107                                 }else{
108                                         $ND::server->command("msg $ND::target Setting $x:$y:$z as $ND::B$ally");
109                                 }
110                                 intel_log $user->{uid},$id,"Set alliance_id to: $aid ($ally)";
111                         }else{
112                                 $ND::server->command("msg $ND::target Couldn't find a planet at $x:$y:$z");
113                         }
114                 }else{
115                         $ND::server->command("msg $ND::target Couldn't find such an alliance");
116                 }
117         }
118 }
119
120 sub setChannel {
121         my ($msg, $command) = @_;
122         my ($x,$y,$z,$channel);
123         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
124                 $x = $1;
125                 $y = $2;
126                 $z = $3;
127                 $channel = $4;
128         }else{
129                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z channel");
130                 return;
131         }
132         if (my $user = officer()){
133                 my $findid = $ND::DBH->prepare_cached(q{SELECT id,channel FROM current_planet_stats 
134                                 WHERE x = ? AND y = ? and z = ?});
135                 my ($id,$c) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
136                 if ($ND::DBH->do('UPDATE planets SET channel = $1 WHERE id = $2'
137                                 ,undef,$channel,$id)){
138
139                         if (defined $c){
140                                 $ND::server->command("msg $ND::target Changed $x:$y:$z from $ND::B$c$ND::B to $ND::B$channel");
141                         }else{
142                                 $ND::server->command("msg $ND::target Setting $x:$y:$z as $ND::B$channel");
143                         }
144                         intel_log $user->{uid},$id,"Set channel to: $channel";
145                 }else{
146                         $ND::server->command("msg $ND::target Couldn't find a planet at $x:$y:$z");
147                 }
148         }
149 }
150
151 1;