]> ruin.nu Git - NDIRC.git/blobdiff - Intel.pm
recruit/ia access
[NDIRC.git] / Intel.pm
index 6012491e84a8dec1b468e442e34a35dc45563102..63c2ebdafab28c32815133d0f460ee808b42079e 100644 (file)
--- a/Intel.pm
+++ b/Intel.pm
 #   Free Software Foundation, Inc.,                                       *
 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 #**************************************************************************/
-package ND::IRC::Intel;
+package NDIRC::Intel;
 use strict;
 use warnings;
 use ND::DB;
-use ND::IRC::Access;
-use ND::IRC::Misc;
+use NDIRC::Access;
+use NDIRC::Misc;
+use ND::Include;
 require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/checkIntel setHostile findNick setNick setAlly setChannel/;
+our @EXPORT = qw/setHostile setNick setAlly setChannel/;
 
-sub checkIntel {
-       my ($x,$y,$z) = @_;
-       DB();
-       if (officer() || dc()){
-               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 = ?");
-               $f->execute($x,$y,$z);
-               while (my @row = $f->fetchrow()){
-                       @row = map (valuecolor(1),@row);
-                       $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] ");
-               }
+sub setHostile {
+       my ($msg, $command) = @_;
+       my ($x,$y,$z);
+       if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+)$/){
+               $x = $1;
+               $y = $2;
+               $z = $3;
        }else{
-               $ND::server->command("msg $ND::target Only officers are allowed to check that");
+               $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z");
+               return;
        }
-}
-
-sub setHostile {
-       my ($x,$y,$z) = @_;
-       DB();
-       if(dc()){
-               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);
+       if(my $user = dc()){
+               my $findid = $ND::DBH->prepare_cached(q{SELECT planetid(?,?,?,tick())});
+               my ($id) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
+               my $rv = $ND::DBH->do(q{UPDATE planets SET planet_status = 'Hostile' WHERE id = $1},undef,$id);
                if ($rv == 1){
                        $ND::server->command("msg $ND::target $x:$y:$z is now marked s hostile");
+                       intel_log $user->{uid},$id,"Set planet_status to: 'Hostile'";
                }
        }
 }
 
-sub findNick {
-       my ($nick) = @_;
-       DB();
-       if(officer()){
-               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");
-               $f->execute($nick);
-               $ND::server->command("notice $ND::target No such nick") if $f->rows == 0;
-               while (my @row = $f->fetchrow()){
-                       $ND::server->command("notice $ND::target $row[0] $row[1] OF $row[2] is $row[3]");
-               }
-       }
-}
 sub setNick {
-       my ($x,$y,$z,$nick) = @_;
-       DB();
-       if (officer()){
-               if ($ND::DBH->do("UPDATE planets SET nick = ? WHERE id = planetid(?,?,?,0)"
-                               ,undef,$nick,$x,$y,$z)){
-                       $ND::server->command("msg $ND::target $x:$y:$z has been updated");
+       my ($msg, $command) = @_;
+       my ($x,$y,$z,$nick);
+       if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
+               $x = $1;
+               $y = $2;
+               $z = $3;
+               $nick = $4;
+       }else{
+               $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z nick");
+               return;
+       }
+       if (my $user = officer){
+               my $findid = $ND::DBH->prepare_cached(q{SELECT nick, id FROM planets
+                       WHERE id = planetid(?,?,?,tick())});
+               my ($oldnick,$id) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
+               if ($ND::DBH->do('UPDATE planets SET nick = $1 WHERE id = $2'
+                               ,undef,$nick,$id)){
+                       unless (defined $oldnick){
+                               $ND::server->command("msg $ND::target $x:$y:$z nick has been set to $ND::B$nick");
+                       }else{
+                               $ND::server->command("msg $ND::target $x:$y:$z nick has been changed from $ND::B$oldnick$ND::B to $ND::B$nick");
+                       }
+                       intel_log $user->{uid},$id,"Set nick to: $nick";
                }
        }
 }
 
 sub setAlly {
-       my ($x,$y,$z,$ally) = @_;
-       DB();
-       if (officer()){
+       my ($msg, $command) = @_;
+       my ($x,$y,$z,$ally);
+       if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
+               $x = $1;
+               $y = $2;
+               $z = $3;
+               $ally = $4;
+       }else{
+               $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z ally | | % can be used for wildcards \%-crew\% will match [F-Crew]");
+               return;
+       }
+       if (my $user = officer){
                my $aid;
                if ($ally ne 'unknown'){
                        ($aid,$ally) = $ND::DBH->selectrow_array("SELECT id,name FROM alliances WHERE name ILIKE ?",undef,$ally);
                }
                if ($ally){
-                       $ND::DBH->do("UPDATE planets SET alliance_id = ? WHERE id = planetid(?,?,?,0)"
-                               ,undef,$aid,$x,$y,$z);
-                       $ND::server->command("msg $ND::target Setting $x:$y:$z as $ally");
+                       my $findid = $ND::DBH->prepare_cached(q{SELECT id,alliance FROM current_planet_stats 
+                               WHERE x = ? AND y = ? and z = ?});
+                       my ($id,$alliance) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
+                       if($id && $ND::DBH->do('UPDATE planets SET alliance_id = $1 WHERE id = $2'
+                               ,undef,$aid,$id)){
+                               if (defined $alliance){
+                                       $ND::server->command("msg $ND::target Changed $x:$y:$z from $ND::B$alliance$ND::B to $ND::B$ally");
+                               }else{
+                                       $ND::server->command("msg $ND::target Setting $x:$y:$z as $ND::B$ally");
+                               }
+                               intel_log $user->{uid},$id,"Set alliance_id to: $aid ($ally)";
+                       }else{
+                               $ND::server->command("msg $ND::target Couldn't find a planet at $x:$y:$z");
+                       }
                }else{
                        $ND::server->command("msg $ND::target Couldn't find such an alliance");
                }
@@ -96,12 +118,32 @@ sub setAlly {
 }
 
 sub setChannel {
-       my ($x,$y,$z,$channel) = @_;
-       DB();
-       if (officer()){
-               if ($ND::DBH->do("UPDATE planets SET channel = ? WHERE id = planetid(?,?,?,0)"
-                               ,undef,$channel,$x,$y,$z)){
-                       $ND::server->command("msg $ND::target $x:$y:$z relay channel has been set to: $channel");
+       my ($msg, $command) = @_;
+       my ($x,$y,$z,$channel);
+       if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+) (\S+)$/){
+               $x = $1;
+               $y = $2;
+               $z = $3;
+               $channel = $4;
+       }else{
+               $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z channel");
+               return;
+       }
+       if (my $user = officer()){
+               my $findid = $ND::DBH->prepare_cached(q{SELECT id,channel FROM current_planet_stats 
+                               WHERE x = ? AND y = ? and z = ?});
+               my ($id,$c) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z);
+               if ($ND::DBH->do('UPDATE planets SET channel = $1 WHERE id = $2'
+                               ,undef,$channel,$id)){
+
+                       if (defined $c){
+                               $ND::server->command("msg $ND::target Changed $x:$y:$z from $ND::B$c$ND::B to $ND::B$channel");
+                       }else{
+                               $ND::server->command("msg $ND::target Setting $x:$y:$z as $ND::B$channel");
+                       }
+                       intel_log $user->{uid},$id,"Set channel to: $channel";
+               }else{
+                       $ND::server->command("msg $ND::target Couldn't find a planet at $x:$y:$z");
                }
        }
 }