X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FUsermgm.pm;h=27864b94955dfca62de7bba9bad86f7982f4d58c;hb=e053b73d5ae0ca68e4f40463450fe2fae0ae737a;hp=21fe6375322b36bf0a4beb09e39b80339d704181;hpb=04c0624b174ff51ccd6f1847d342e79a98bfa29b;p=NDIRC.git
diff --git a/Commands/Usermgm.pm b/Commands/Usermgm.pm
index 21fe637..27864b9 100644
--- a/Commands/Usermgm.pm
+++ b/Commands/Usermgm.pm
@@ -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 $user->{username}'s host to: $host");
+ };
+ 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("Problem, $username already uses host $hostname.");
+ }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;