]> ruin.nu Git - NDIRC.git/blob - Intel.pm
Converted the .gs command
[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 = intel){
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 ($id && $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                 }else{
79                         $ND::server->command("msg $ND::target Couldn't find any planet with coords $x:$y:$z");
80                 }
81         }
82 }
83
84 sub setAlly {
85         my ($msg, $command) = @_;
86         my ($x,$y,$z,$ally);
87         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
88                 $x = $1;
89                 $y = $2;
90                 $z = $3;
91                 $ally = $4;
92         }else{
93                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z ally | | % can be used for wildcards \%-crew\% will match [F-Crew]");
94                 return;
95         }
96         if (my $user = intel){
97                 my $aid;
98                 if ($ally ne 'unknown'){
99                         ($aid,$ally) = $ND::DBH->selectrow_array("SELECT id,name FROM alliances WHERE name ILIKE ?",undef,$ally);
100                 }
101                 if ($ally){
102                         my $findid = $ND::DBH->prepare(q{SELECT id,alliance FROM current_planet_stats 
103                                 WHERE x = ? AND y = ? and z = ?});
104                         my ($id,$alliance) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
105                         unless ($id){
106                                 $ND::server->command("msg $ND::target Couldn't find a planet at $x:$y:$z");
107                                 return;
108                         }
109                         if($ND::DBH->do('UPDATE planets SET alliance_id = $1 WHERE id = $2'
110                                 ,undef,$aid,$id)){
111                                 if (defined $alliance){
112                                         $ND::server->command("msg $ND::target Changed $x:$y:$z from $ND::B$alliance$ND::B to $ND::B$ally");
113                                 }else{
114                                         $ND::server->command("msg $ND::target Setting $x:$y:$z as $ND::B$ally");
115                                 }
116                                 intel_log $user->{uid},$id,"Set alliance_id to: $aid ($ally)";
117                         }else{
118                                 $ND::server->command("msg $ND::target Couldn't set alliance_id to: $aid");
119                         }
120                 }else{
121                         $ND::server->command("msg $ND::target Couldn't find such an alliance");
122                 }
123         }
124 }
125
126 sub setChannel {
127         my ($msg, $command) = @_;
128         my ($x,$y,$z,$channel);
129         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
130                 $x = $1;
131                 $y = $2;
132                 $z = $3;
133                 $channel = $4;
134         }else{
135                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z channel");
136                 return;
137         }
138         if (my $user = intel){
139                 my $findid = $ND::DBH->prepare_cached(q{SELECT id,channel FROM current_planet_stats 
140                                 WHERE x = ? AND y = ? and z = ?});
141                 my ($id,$c) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
142                 if ($ND::DBH->do('UPDATE planets SET channel = $1 WHERE id = $2'
143                                 ,undef,$channel,$id)){
144
145                         if (defined $c){
146                                 $ND::server->command("msg $ND::target Changed $x:$y:$z from $ND::B$c$ND::B to $ND::B$channel");
147                         }else{
148                                 $ND::server->command("msg $ND::target Setting $x:$y:$z as $ND::B$channel");
149                         }
150                         intel_log $user->{uid},$id,"Set channel to: $channel";
151                 }else{
152                         $ND::server->command("msg $ND::target Couldn't find a planet at $x:$y:$z");
153                 }
154         }
155 }
156
157 1;