]> ruin.nu Git - NDIRC.git/commitdiff
Introduce a uid member for the context and use it intead of the host in commands
authorMichael Andreen <harv@ruin.nu>
Sun, 23 Aug 2009 16:12:15 +0000 (18:12 +0200)
committerMichael Andreen <harv@ruin.nu>
Sun, 23 Aug 2009 16:12:15 +0000 (18:12 +0200)
Commands/Channel.pm
Commands/Def.pm
Commands/Members.pm
Commands/PA.pm
Commands/Quotes.pm
Commands/SMS.pm
Commands/Scans.pm
Commands/Usermgm.pm
Context.pm

index 9207b0c4cadf71645339da18cab0eaec2756c1bc..f83969ea8f4594f69b3f790e015412c608672329 100644 (file)
@@ -47,12 +47,12 @@ SELECT DISTINCT LOWER(flag) FROM users u
        JOIN groupmembers g USING (uid)
        JOIN channel_group_flags gf USING (gid)
        JOIN channel_flags f USING (flag)
-WHERE u.hostmask ILIKE $1 AND channel = $2 AND f.name = ANY($3);
+WHERE uid = $1 AND channel = $2 AND f.name = ANY($3);
                };
        if ($c->check_user_roles(qw/irc_masterop/)){
                $mode = substr $access[0], 0,1;
        }else{
-               ($mode) = $c->model->selectrow_array($mode,undef,$c->host,$c->channel,\@access);
+               ($mode) = $c->model->selectrow_array($mode,undef,$c->uid,$c->channel,\@access);
        }
        if ($mode){
                $c->command(mode => $c->channel, "$mod$mode", $msg);
@@ -73,17 +73,16 @@ sub invite
        if ($channel && $c->check_user_roles('irc_masterinvite')){
                push @channels,$channel;
        }else{
-               my @access = ('auto_invite');
-               push @access, 'invite' if $channel;
+               my @access = ('i');
+               push @access, 'I' if $channel;
                my $channels = $c->model->prepare(q{
 SELECT DISTINCT channel FROM users u
        JOIN groupmembers g USING (uid)
        JOIN channel_group_flags gf USING (gid)
-       JOIN channel_flags f USING (flag)
-WHERE u.hostmask ILIKE $1 AND COALESCE(channel = $2,TRUE)
-       AND (f.name = ANY($3) )
+WHERE uid = $1 AND COALESCE(channel = $2,TRUE)
+       AND (flag = ANY($3) )
                });
-               $channels->execute($c->host,$channel,\@access);
+               $channels->execute($c->uid,$channel,\@access);
                while (my ($channel) = $channels->fetchrow()){
                        push @channels,$channel;
                }
@@ -131,8 +130,8 @@ sub getpass
        my $password = generate_random_string 10;
        my $update = $dbh->do(q{
 UPDATE users SET password = MD5( ? )
-WHERE hostmask ILIKE ? AND password =''
-               },undef,$password,$c->host);
+WHERE uid  ? AND password =''
+               },undef,$password,$c->uid);
        if ($update > 0){
                $c->reply("Password set to: $password (you can change it on webbie)");
        }else{
index d7862a364fdbe6d1ddda62cfeda6a0f34e4e6096..7c57099bdd8fd506208f96ad68b30dc9aa8b87ef 100644 (file)
@@ -172,10 +172,10 @@ sub calltake
 
        $dbh->begin_work;
        my $rows = $dbh->do(q{
-UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE $1)
+UPDATE calls SET dc = $1
        ,status = $3
 WHERE call = $2
-               },undef,$c->host,$id,$status);
+               },undef,$c->uid,$id,$status);
        if ($rows == 1){
                $c->reply("Setting status on call $id to $status");
                $c->def_log($id , "Changed status: [B]$status [/B]");
index b1f4da9a998bf8aa083a829063810a8c1ff1d18a..960728904c05feea288bba004d1757a5c0a231ec 100644 (file)
@@ -80,7 +80,7 @@ sub points
 {
        my ($self,$c,$msg) = @_;
        my $f;
-       my $nick = $c->host;
+       my $nick = $c->uid;
        if ($msg =~ /(\S+)/ && $c->check_user_roles(qw/irc_points_others/)){
                $nick = $1;
                $f = $c->model->prepare(q{
@@ -90,7 +90,7 @@ FROM users WHERE username ILIKE ? LIMIT 5
        }else{
                $f = $c->model->prepare(q{
 SELECT username, attack_points, defense_points, scan_points, humor_points
-FROM users WHERE hostmask ILIKE ?
+FROM users WHERE uid = ?
                });
        }
        $f->execute($nick);
@@ -138,8 +138,8 @@ SELECT uid,username FROM users WHERE username ILIKE ?
                }, undef, $1);
        }else{
                $user = $dbh->selectrow_hashref(q{
-SELECT uid,username FROM users WHERE hostmask ILIKE ?
-               }, undef, $c->host);
+SELECT uid,username FROM users WHERE uid = ?
+               }, undef, $c->uid);
        }
        if ($user){
                my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
index 2dcb00671d0c90ccc3355f138606ffd50ce7100d..52fb3a007a1241c3cdc9e234f3c244cc3defde45 100644 (file)
@@ -126,8 +126,8 @@ sub xp
 
        my ($avalue,$ascore) = $c->model->selectrow_array(q{
 SELECT value,score FROM current_planet_stats
-WHERE pid = (SELECT pid FROM users WHERE hostmask ILIKE ?)
-               }, undef, $c->host);
+WHERE pid = (SELECT pid FROM users WHERE uid = ?)
+               }, undef, $c->uid);
        my ($tvalue,$tscore,$tsize) = $c->model->selectrow_array(q{
 SELECT value,score,size FROM current_planet_stats
 WHERE x = ? AND y = ? and z = ?
@@ -167,8 +167,8 @@ sub fco
 
        my ($value,$score) = $c->model->selectrow_array(q{
 SELECT value,score FROM planet_stats WHERE tick = $2 AND
-       pid = (SELECT pid FROM users WHERE hostmask ILIKE $1)
-               }, undef, $c->host,$tick);
+       pid = (SELECT pid FROM users WHERE uid = $1)
+               }, undef, $c->uid,$tick);
        unless ($value){
                $c->reply("You don't have a planet registered.");
                return;
index 7d18819eb61f038160163571bae522994256c499..608832f9d38094c40173c8d92c0800105acf7d10 100644 (file)
@@ -108,8 +108,8 @@ sub delquote
        $n = $n-1;
        if (exists $FILE[$n]){
                my ($uid,$username) = $c->model->selectrow_array(q{
-SELECT uid,username FROM users where hostmask ILIKE ?
-                       },undef,$c->host);
+SELECT uid,username FROM users where uid = ?
+                       },undef,$c->uid);
 
                my $text = $FILE[$n];
                push @OLDFILE,"Removed by $username ($uid): $text";
index bc0200c08403007300dfccfcc4adb6cda19a59af..eba2d650b72d79919f99a67cd83b1830a2d30e5d 100644 (file)
@@ -57,10 +57,10 @@ SELECT sms FROM users WHERE username ilike $1
        }
        my $sms = $dbh->prepare(q{
 INSERT INTO sms (uid,number,message)
-VALUES((SELECT uid FROM users WHERE hostmask ilike $1),$2,$3)
+VALUES($1,$2,$3)
 RETURNING id
                });
-       $sms->execute($c->host,$number,$message);
+       $sms->execute($c->uid,$number,$message);
        my ($id) = $sms->fetchrow_array;
        $c->reply("Message added to queue, you can see the status with: .smsstatus $id");
 }
index 315903190c6ddf5b5e15e57f4d5c9cf9c3ed10a6..ffc8e184023a0b31d09ce894de92346ae103cff3 100644 (file)
@@ -70,10 +70,10 @@ sub gs
        }else{
                my $req = $c->model->prepare(q{
 SELECT * FROM scan_requests
-WHERE uid = (SELECT uid FROM users WHERE hostmask ILIKE $1)
+WHERE uid = $1
        AND pid = $2 AND type = $3 AND NOT sent
                });
-               $req->execute($c->host,$planet,$type);
+               $req->execute($c->uid,$planet,$type);
 
                my $id;
                if(my $scan = $req->fetchrow_hashref){
@@ -86,14 +86,14 @@ WHERE id = $2
                }else{
                        $req = $c->model->prepare(q{
 INSERT INTO scan_requests (uid,nick,pid,type)
-VALUES((SELECT uid FROM users WHERE hostmask ILIKE $1),$2,$3,$4) RETURNING (id)
+VALUES($1,$2,$3,$4) RETURNING (id)
                        });
-                       $req->execute($c->host,$c->nick,$planet,$type);
+                       $req->execute($c->uid,$c->nick,$planet,$type);
                        $id = $req->fetchrow;
                }
 
                if ($id){
-                       $c->message(privmsg =>$c->disp->targets->{scans}
+                       $c->message(privmsg => $c->disp->targets->{scan}
                                ,"<b>$id</b> http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z"
                                . " ($x:$y:$z $type) | <".$c->nick."> $msg"
                        );
@@ -217,7 +217,7 @@ WHERE groupscan = $1 AND scan_id = LOWER($2) AND tick >= tick() - 168
 INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (LOWER($1),tick(),$2,COALESCE($3,-1))
                });
        my $user = $dbh->selectrow_hashref(q{SELECT uid,username, scan_points, tick()
-               FROM users WHERE hostmask ILIKE ? },undef,$c->host);
+               FROM users WHERE uid = ? },undef,$c->uid);
        my $groupscans = 0;
        my $scans = 0;
        eval {
index 78c02b81d24431a0a9cf7b6d3156d72c59017fb8..adda73f80de3eb170aa75e834198967ab70f7891 100644 (file)
@@ -40,7 +40,7 @@ sub adduser
        my $host = "$pnick.users.netgamers.org";
        my ($username,$hostname,$p_nick) = $dbh->selectrow_array(q{
 SELECT username, hostmask,pnick
-FROM users WHERE username ILIKE ? OR hostmask ILIKE ? OR pnick ILIKE ?
+FROM users WHERE username = $1 OR hostmask = $2 OR pnick = $3
                },undef,$nick,$host,$pnick);
 
        if (defined $username){
@@ -351,7 +351,7 @@ SELECT uid,username,pnick,hostmask FROM users WHERE username ILIKE ?
                if($@){
                        if ($@ =~ /duplicate key value violates unique constraint/){
                                my ($username, $hostname) = $dbh->selectrow_array(q{
-SELECT username,hostmask FROM users WHERE hostmask ILIKE $1
+SELECT username,hostmask FROM users WHERE hostmask = $1
                                },undef,$host);
                                $c->reply("<c04>Problem</c>, <b>$username</b> already uses host <b>$hostname</b>.");
                        }else{
@@ -387,7 +387,7 @@ sub setpnick
                if($@){
                        if ($@ =~ /duplicate key value violates unique constraint/){
                                my ($username, $hostname, $pnick) = $dbh->selectrow_array(q{
-SELECT username,hostmask,pnick FROM users WHERE hostmask ILIKE $1 OR pnick ILIKE $2
+SELECT username,hostmask,pnick FROM users WHERE hostmask = $1 OR pnick = $2
                                },undef,$hostname, $pnick);
                                $c->reply("<c04>Problem</c>, <b>$username</b> already uses host <b>$hostname</b> and pnick <b>$pnick</b>.");
                        }else{
index 8a0a911a3b2abbaca49a0e8995dc853540c8b19d..8c16a95a65cdacc507cb06299e434f0727cb417d 100644 (file)
@@ -50,6 +50,12 @@ has roles => (
        lazy_build => 1
 );
 
+has uid => (
+       is => 'ro',
+       isa => 'Int',
+       lazy_build => 1
+);
+
 has disp => (
        is => 'ro',
        isa => 'Object',
@@ -143,21 +149,18 @@ sub intel_log {
        my ($c,$planet, $message) = @_;
        my $log = $c->model->prepare_cached(q{
 INSERT INTO forum_posts (ftid,uid,message) VALUES(
-       (SELECT ftid FROM planets WHERE pid = $3)
-       ,(SELECT uid FROM users WHERE hostmask ILIKE $1)
-       ,$2)
+       (SELECT ftid FROM planets WHERE pid = $3),$1,$2)
                });
-       $log->execute($c->host,$message,$planet);
+       $log->execute($c->uid,$message,$planet);
 }
 
 sub def_log {
        my ($c,$call, $message) = @_;
        my $log = $c->model->prepare(q{
 INSERT INTO forum_posts (ftid,uid,message) VALUES(
-       (SELECT ftid FROM calls WHERE call = $3)
-       ,(SELECT uid FROM users WHERE hostmask ILIKE $1),$2)
+       (SELECT ftid FROM calls WHERE call = $3),$1,$2)
                });
-       $log->execute($c->host,$message,$call);
+       $log->execute($c->uid,$message,$call);
 }
 
 sub _build_roles {
@@ -166,7 +169,7 @@ sub _build_roles {
        my $query = $self->model->prepare(q{
 SELECT role FROM group_roles
 WHERE gid IN (SELECT gid FROM groupmembers JOIN users USING (uid)
-       WHERE hostmask ILIKE $1)
+       WHERE hostmask = $1)
                });
        $query->execute($self->host);
 
@@ -177,5 +180,20 @@ WHERE gid IN (SELECT gid FROM groupmembers JOIN users USING (uid)
        return Set::Object->new(@roles);
 }
 
+sub _build_uid {
+       my ($self) = @_;
+
+       my $query = $self->model->prepare(q{
+SELECT uid FROM users
+WHERE hostmask = $1
+               });
+       $query->execute($self->host);
+
+       if (my ($uid) = $query->fetchrow_array){
+               $query->finish;
+               return $uid;
+       }
+       return -4;
+}
 
 1;