]> ruin.nu Git - NDIRC.git/commitdiff
Converted .sethost
authorMichael Andreen <harv@ruin.nu>
Sat, 16 May 2009 19:12:16 +0000 (21:12 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 16 May 2009 19:12:16 +0000 (21:12 +0200)
Commands/Usermgm.pm
Usermgm.pm
database/roles.sql

index 21fe6375322b36bf0a4beb09e39b80339d704181..27864b94955dfca62de7bba9bad86f7982f4d58c 100644 (file)
@@ -329,4 +329,42 @@ ORDER BY num
        }
 }
 
+sub sethost
+       : Help(Usage: .sethost username [host] | if host isn't given then it resets to netgamers host)
+       : ACL(irc_sethost)
+{
+       my ($self,$c,$msg) = @_;
+       my ($nick,$host) = $msg =~ /^(\S+)(?: (\S+))?$/ or die 'ARGS';
+       my $dbh = $c->model;
+
+       my $f = $dbh->prepare(q{
+SELECT uid,username,pnick,hostmask FROM users WHERE username ILIKE ?
+               });
+       $f->execute($nick);
+       my $user = $f->fetchrow_hashref;
+       if ($f->rows == 1){
+               $host //= "$user->{pnick}.users.netgamers.org";
+               eval{
+                       $dbh->do(q{UPDATE users SET hostmask = ? WHERE uid = ?}
+                               ,undef,$host,$user->{uid});
+                       $c->reply("Updated <b>$user->{username}</b>'s host to: <b>$host</b>");
+               };
+               if($@){
+                       if ($@ =~ /duplicate key value violates unique constraint/){
+                               my ($username, $hostname) = $dbh->selectrow_array(q{
+SELECT username,hostmask FROM users WHERE hostmask ILIKE $1
+                               },undef,$host);
+                               $c->reply("<c04>Problem</c>, <b>$username</b> already uses host <b>$hostname</b>.");
+                       }else{
+                               die $@;
+                       }
+               }
+       }elsif ($f->rows == 0){
+               $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
+       }else{
+               $c->reply("More than 1 user matched, please refine the search");
+       }
+       $f->finish;
+}
+
 1;
index 16a45285243016c4d52d92d9fd832d6c87424d85..a38e595b77fba09411b5811b82c9f27112b3426a 100644 (file)
@@ -25,7 +25,7 @@ require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/addPoints setHost setPNick/;
+our @EXPORT = qw/addPoints setPNick/;
 
 sub addPoints {
        my ($msg, $t) = @_;
@@ -75,39 +75,6 @@ sub addPoints {
        }
 }
 
-sub setHost {
-       my ($msg, $command) = @_;
-
-       my ($nick, $host);
-       if(defined $msg && $msg =~ /^(\S+) (\S+)$/){
-               $nick = $1;
-               $host = $2;
-       }else{
-               $ND::server->command("notice $ND::nick syntax: .sethost nick host | % can be used for wildcards \%arro% will match barrow");
-               return;
-       }
-       if (hc()){
-               my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
-               $f->execute($nick);
-               my ($uid,$nick) = $f->fetchrow();
-               if ($f->rows == 1){
-                       my ($username,$hostname) = $ND::DBH->selectrow_array("SELECT username, hostmask FROM users WHERE hostmask ILIKE ? AND NOT (username ILIKE ?)",undef,$host,$nick);
-                       if ((not defined $username) && $ND::DBH->do("UPDATE users SET hostmask = ? WHERE uid = ?",undef,$host,$uid) > 0){
-                               $ND::server->command("msg $ND::target Updated $ND::B$nick${ND::B}'s host to: $ND::B$host$ND::B");
-                       }elsif(defined $username){
-                               $ND::server->command("msg $ND::target $ND::B$username$ND::B already exists with host: $ND::B$hostname$ND::B.");
-                       }else{
-                               $ND::server->command("msg $ND::target Couldn't update $ND::B$username${ND::B}'s host");
-                       }
-               }elsif ($f->rows == 0){
-                       $ND::server->command("msg $ND::target No hit, maybe spelling mistake, or add % as wildcard");
-               }else{
-                       $ND::server->command("msg $ND::target More than 1 user matched, please refine the search");
-               }
-               $f->finish;
-       }
-}
-
 sub setPNick {
        my ($msg, $command) = @_;
 
index 91493a3caa3d5e98b40bcd94c7214a7b335ae0bc..1c6232d85269229d6b304c849ed1ec1f94c83d59 100644 (file)
@@ -18,6 +18,7 @@ INSERT INTO roles VALUES('irc_laston');
 INSERT INTO roles VALUES('irc_lastseen');
 INSERT INTO roles VALUES('irc_getships');
 INSERT INTO roles VALUES('irc_getfleet');
+INSERT INTO roles VALUES('irc_sethost');
 
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
@@ -37,6 +38,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_laston');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_lastseen');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_getships');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_getfleet');
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_sethost');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs');
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan');
@@ -58,6 +60,7 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_laston');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_lastseen');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_getships');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_getfleet');
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_sethost');
 
 INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others');