]> ruin.nu Git - NDIRC.git/blobdiff - Usermgm.pm
changed addUser to use pnick
[NDIRC.git] / Usermgm.pm
index 8939b801e9fc2beb29498b4689c154521da7e55d..ae362319e86b2c09e404490754aeb631cdcb9a40 100644 (file)
@@ -28,30 +28,25 @@ our @ISA = qw/Exporter/;
 our @EXPORT = qw/addUser whois flags flag laston addPoints chattrG setHost deactivateUser/;
 
 sub addUser {
-       my ($nick,$host) = @_;
+       my ($nick,$pnick) = @_;
        DB();
        if (hc()){
-               unless (defined $host){
-                       my @nicks = $ND::server->nicks_get_same($nick);
-                       if (@nicks){
-                               $nicks[1]->{host} =~ /.*@(.*)/;
-                               $host = $1;
-                       }else{
-                               $host = "$nick.users.netgamers.org";
-                       }
-               }
-               my ($username,$hostname) = $ND::DBH->selectrow_array("SELECT username, hostmask FROM users WHERE username ILIKE ? OR hostmask ILIKE ?",undef,$nick,$host);
-               if ((not defined $username) && $ND::DBH->do("INSERT INTO users (username,hostmask,password) VALUES(?,?,'')"
-                               ,undef,$nick,$host)){
-                       $ND::server->command("msg $ND::target Added $ND::B$nick$ND::B with host: $ND::B$host$ND::B");
+               $pnick = $nick unless $pnick;
+               my $host = "$pnick.users.netgamers.org";
+               my ($username,$hostname,$p_nick) = $ND::DBH->selectrow_array(q{SELECT username, hostmask,pnick
+                       FROM users WHERE username ILIKE ? OR hostmask ILIKE ? OR pnick ILIKE ?}
+                       ,undef,$nick,$host,$pnick);
+               if ((not defined $username) && $ND::DBH->do("INSERT INTO users (username,hostmask,pnick,password) VALUES(?,?,?,'')"
+                               ,undef,$nick,$host,$pnick)){
+                       $ND::server->command("msg $ND::target Added $ND::B$nick(/$pnick)$ND::B with host: $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.");
+                       $ND::server->command("msg $ND::target $ND::B$username ($p_nick)$ND::B already exists with host: $ND::B$hostname$ND::B.");
 
                }else{
-                       $ND::server->command("msg $ND::target Something went wrong when trying to add $ND::B$nick$ND::B with host: $ND::B$host$ND::B, most likely duplicate user name");
+                       $ND::server->command("msg $ND::target Something went wrong when trying to add $ND::B$nick ($pnick)$ND::B with host: $ND::B$host$ND::B, ".$ND::DBH->errstr);
                }
        }else{
-               $ND::server->command("msg $ND::target Only HCs are allowed to check that");
+               $ND::server->command("msg $ND::target Only HCs are allowed to add users");
        }
 }
 sub whois {
@@ -96,13 +91,13 @@ sub flag {
 
        if (officer()|| ($ND::target eq $ND::scanchan && $flag eq 'S')){
                my $f = $ND::DBH->prepare(qq{
-SELECT TRIM(', ' FROM concat(username||', ')) FROM
+SELECT TRIM(', ' FROM concat(username||', ')),count(username) FROM
        (SELECT uid, username FROM users ORDER BY username) u NATURAL JOIN groupmembers gm 
        JOIN groups g ON g.gid = gm.gid
 WHERE flag = ?;
                        });
-               if (my ($users) = $ND::DBH->selectrow_array($f,undef,$flag)){
-                       $ND::server->command("msg $ND::target Users with flag $ND::B$flag$ND::B: $users");
+               if (my ($users,$count) = $ND::DBH->selectrow_array($f,undef,$flag)){
+                       $ND::server->command("msg $ND::target $ND::B$count$ND::B Users with flag $ND::B$flag$ND::B: $users");
                }
        }else{
                $ND::server->command("msg $ND::target Only officers are allowed to check that");
@@ -119,11 +114,13 @@ sub laston {
                $min = 0 unless defined $min;
                $f->execute($flag,$min);
                my $text;
+               my $i = 0;
                while (my $user = $f->fetchrow_hashref){
                        $user->{last} = '?' unless defined $user->{last};
                        $text .= "$user->{username}($user->{last}) ";
+                       $i++;
                }
-               $ND::server->command("msg $ND::target Users(days) with flag $ND::B$flag$ND::B: $text");
+               $ND::server->command("msg $ND::target $ND::B$i$ND::B Users(days) with flag $ND::B$flag$ND::B: $text");
        }else{
                $ND::server->command("msg $ND::target Only officers are allowed to check that");
        }