]> jfr.im git - irc/SurrealServices/srsv.git/blame - branches/0.4.3/SrSv/ChanReg/Flags.pm
/cs set noclones; prevents clones from joining channels. Appears to work. Help files...
[irc/SurrealServices/srsv.git] / branches / 0.4.3 / SrSv / ChanReg / Flags.pm
CommitLineData
7b261bb8 1# This file is part of SurrealServices.
2#
3# SurrealServices is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# SurrealServices is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with SurrealServices; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17package SrSv::ChanReg::Flags;
18
19=head1 NAME
20
21SrSv::ChanReg::Flags - Manage flags of registered channels.
22
23=cut
24
25use strict;
26
27use Exporter 'import';
28
29BEGIN {
30 my %constants = (
31 #current chanreg.flags definition limits us to 16 of these. or 32768 as last flag
32 CRF_OPGUARD => 1,
33 CRF_LEAVEOP => 2,
34 CRF_VERBOSE => 4,
35 CRF_HOLD => 8,
36 CRF_FREEZE => 16,
37 CRF_BOTSTAY => 32,
38 CRF_CLOSE => 64,
39 CRF_DRONE => 128,
40 CRF_SPLITOPS => 256,
41 CRF_LOG => 512,
42 CRF_AUTOVOICE => 1024,
43 CRF_WELCOMEINCHAN => 2048,
44 CRF_NEVEROP => 4096,
0b380dbc 45 CRF_NOCLONES => 8192,
7b261bb8 46 );
47
48 our @EXPORT = (qw(cr_chk_flag cr_set_flag), keys(%constants));
49
50 require constant; import constant (\%constants);
51}
52
53use SrSv::MySQL '$dbh';
54use SrSv::Process::Init;
55
56our ($set_flags, $get_flags, $set_flag, $unset_flag);
57
58proc_init {
59 $set_flags = $dbh->prepare("UPDATE chanreg SET flags=? WHERE chan=?");
60 $get_flags = $dbh->prepare("SELECT flags FROM chanreg WHERE chan=?");
61 $set_flag = $dbh->prepare("UPDATE chanreg SET flags=(flags | (?)) WHERE chan=?");
62 $unset_flag = $dbh->prepare("UPDATE chanreg SET flags=(flags & ~(?)) WHERE chan=?");
63
64};
65
66sub cr_set_flag($$$) {
67 my ($chan, $flag, $sign) = @_;
68 my $cn = $chan->{CHAN};
69
70 if($sign >= 1) {
71 $chan->{FLAGS} = ( ( defined $chan->{FLAGS} ? $chan->{FLAGS} : 0 ) | $flag );
72 $set_flag->execute($flag, $cn);
73 } else {
74 $chan->{FLAGS} = ( ( defined $chan->{FLAGS} ? $chan->{FLAGS} : 0 ) & ~($flag) );
75 $unset_flag->execute($flag, $cn);
76 }
77}
78
79sub cr_chk_flag($$;$) {
80 my ($chan, $flag, $sign) = @_;
81 my $cn = $chan->{CHAN};
82 $sign = 1 unless defined($sign);
83
84 my $flags;
85 unless (exists($chan->{FLAGS})) {
86 $get_flags->execute($cn);
87 ($chan->{FLAGS}) = $get_flags->fetchrow_array;
88 $get_flags->finish();
89 }
90 $flags = $chan->{FLAGS};
91
92 return ($sign ? ($flags & $flag) : !($flags & $flag));
93}
94
951;