X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FChannel.pm;h=d309ce00ae1ac4e533f08f66f90101db2fe28159;hb=1ccb344994c1b517c662da9f236cf1c640780177;hp=c30c632650d0b17ffd43a430f66f1d7bc002428e;hpb=fd3b4651fa4a5957ff4abc2e75075497f58e857f;p=NDIRC.git diff --git a/Commands/Channel.pm b/Commands/Channel.pm index c30c632..d309ce0 100644 --- a/Commands/Channel.pm +++ b/Commands/Channel.pm @@ -33,26 +33,25 @@ sub op { my ($self,$c,$msg) = @_; - my ($access) = $self->name =~ /(op|voice)/; + $self->name =~ /(op|voice)/; + my @access = ($1); - my $where = ""; if ($msg =~ /^\s*$/){ $msg = $c->nick; - $where = "OR f.name = 'auto_$access'"; + push @access, "auto_$access[0]"; } - my $mode = qq{ -SELECT DISTINCT c.name FROM users u - JOIN groupmembers g ON g.uid = u.uid - JOIN channel_group_flags gf ON g.gid = gf.group - JOIN channels c ON gf.channel = c.id - JOIN channel_flags f ON f.id = gf.flag -WHERE u.hostmask ILIKE ? AND c.name = ? AND (f.name = '$access' $where); + my $mode = 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 channel = $2 AND f.name = ANY($3); }; if ($c->check_user_roles(qw/irc_masterop/)){ $mode = 1; }else{ - ($mode) = $c->model->selectrow_array($mode,undef,$c->host,$c->channel); + ($mode) = $c->model->selectrow_array($mode,undef,$c->host,$c->channel,\@access); } if ($mode){ $c->server->command($self->name . " " . $c->channel . " $msg"); @@ -76,12 +75,11 @@ sub invite my @access = ('auto_invite'); push @access, 'invite' if $channel; my $channels = $c->model->prepare(q{ -SELECT DISTINCT c.name FROM users u - JOIN groupmembers g ON g.uid = u.uid - JOIN channel_group_flags gf ON g.gid = gf.group - JOIN channels c ON gf.channel = c.id - JOIN channel_flags f ON f.id = gf.flag -WHERE u.hostmask ILIKE $1 AND COALESCE(c.name = $2,TRUE) +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) ) }); $channels->execute($c->host,$channel,\@access); @@ -102,4 +100,43 @@ sub hostname $c->reply('Your hostname is: '.$c->host); } +########################################################### +# Written by Guy Malachi http://guymal.com +# 18 August, 2002 +########################################################### +sub generate_random_string +{ + my $length_of_randomstring=shift;# the length of + # the random string to generate + + my @chars=('a'..'z','A'..'Z','0'..'9','_'); + my $random_string; + foreach (1..$length_of_randomstring) + { + # rand @chars will generate a random + # number between 0 and scalar @chars + $random_string .= $chars[rand @chars]; + } + return $random_string; +} + +sub getpass + : Help(Gives new users a random password.) + : Type(pm) +{ + my ($self,$c,$msg) = @_; + my $dbh = $c->model; + + 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); + if ($update > 0){ + $c->reply("Password set to: $password (you can change it on webbie)"); + }else{ + $c->reply("Couldn't set password. Either it has already been set or you don't have an account"); + } +} + 1;