]> ruin.nu Git - NDIRC.git/blob - Intel.pm
7594c09ac75bb9282d71add33718c6aaba96ae4e
[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/setNick setAlly setChannel/;
31
32 sub setNick {
33         my ($msg, $command) = @_;
34         my ($x,$y,$z,$nick);
35         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
36                 $x = $1;
37                 $y = $2;
38                 $z = $3;
39                 $nick = $4;
40         }else{
41                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z nick");
42                 return;
43         }
44         if (my $user = intel){
45                 my $findid = $ND::DBH->prepare_cached(q{SELECT nick, id FROM planets
46                         WHERE id = planetid(?,?,?,tick())});
47                 my ($oldnick,$id) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
48                 if ($id && $ND::DBH->do('UPDATE planets SET nick = $1 WHERE id = $2'
49                                 ,undef,$nick,$id)){
50                         unless (defined $oldnick){
51                                 $ND::server->command("msg $ND::target $x:$y:$z nick has been set to $ND::B$nick");
52                         }else{
53                                 $ND::server->command("msg $ND::target $x:$y:$z nick has been changed from $ND::B$oldnick$ND::B to $ND::B$nick");
54                         }
55                         intel_log $user->{uid},$id,"Set nick to: $nick";
56                 }else{
57                         $ND::server->command("msg $ND::target Couldn't find any planet with coords $x:$y:$z");
58                 }
59         }
60 }
61
62 sub setAlly {
63         my ($msg, $command) = @_;
64         my ($x,$y,$z,$ally);
65         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
66                 $x = $1;
67                 $y = $2;
68                 $z = $3;
69                 $ally = $4;
70         }else{
71                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z ally | | % can be used for wildcards \%-crew\% will match [F-Crew]");
72                 return;
73         }
74         if (my $user = intel){
75                 my $aid;
76                 if ($ally ne 'unknown'){
77                         ($aid,$ally) = $ND::DBH->selectrow_array("SELECT id,name FROM alliances WHERE name ILIKE ?",undef,$ally);
78                 }
79                 if ($ally){
80                         my $findid = $ND::DBH->prepare(q{SELECT id,alliance FROM current_planet_stats 
81                                 WHERE x = ? AND y = ? and z = ?});
82                         my ($id,$alliance) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
83                         unless ($id){
84                                 $ND::server->command("msg $ND::target Couldn't find a planet at $x:$y:$z");
85                                 return;
86                         }
87                         if($ND::DBH->do('UPDATE planets SET alliance_id = $1 WHERE id = $2'
88                                 ,undef,$aid,$id)){
89                                 if (defined $alliance){
90                                         $ND::server->command("msg $ND::target Changed $x:$y:$z from $ND::B$alliance$ND::B to $ND::B$ally");
91                                 }else{
92                                         $ND::server->command("msg $ND::target Setting $x:$y:$z as $ND::B$ally");
93                                 }
94                                 intel_log $user->{uid},$id,"Set alliance_id to: $aid ($ally)";
95                         }else{
96                                 $ND::server->command("msg $ND::target Couldn't set alliance_id to: $aid");
97                         }
98                 }else{
99                         $ND::server->command("msg $ND::target Couldn't find such an alliance");
100                 }
101         }
102 }
103
104 sub setChannel {
105         my ($msg, $command) = @_;
106         my ($x,$y,$z,$channel);
107         if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
108                 $x = $1;
109                 $y = $2;
110                 $z = $3;
111                 $channel = $4;
112         }else{
113                 $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z channel");
114                 return;
115         }
116         if (my $user = intel){
117                 my $findid = $ND::DBH->prepare_cached(q{SELECT id,channel FROM current_planet_stats 
118                                 WHERE x = ? AND y = ? and z = ?});
119                 my ($id,$c) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
120                 if ($ND::DBH->do('UPDATE planets SET channel = $1 WHERE id = $2'
121                                 ,undef,$channel,$id)){
122
123                         if (defined $c){
124                                 $ND::server->command("msg $ND::target Changed $x:$y:$z from $ND::B$c$ND::B to $ND::B$channel");
125                         }else{
126                                 $ND::server->command("msg $ND::target Setting $x:$y:$z as $ND::B$channel");
127                         }
128                         intel_log $user->{uid},$id,"Set channel to: $channel";
129                 }else{
130                         $ND::server->command("msg $ND::target Couldn't find a planet at $x:$y:$z");
131                 }
132         }
133 }
134
135 1;