]>
jfr.im git - irc/SurrealServices/srsv.git/blob - tags/0.4.3.1-pre2/SrSv/ChanReg/Flags.pm
1 # This file is part of SurrealServices.
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.
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.
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
17 package SrSv
::ChanReg
::Flags
;
21 SrSv::ChanReg::Flags - Manage flags of registered channels.
27 use Exporter
'import';
31 #current chanreg.flags definition limits us to 16 of these. or 32768 as last flag
42 CRF_AUTOVOICE
=> 1024,
43 CRF_WELCOMEINCHAN
=> 2048,
48 our @EXPORT = (qw(cr_chk_flag cr_set_flag), keys(%constants));
50 require constant; import
constant (\
%constants);
53 use SrSv
::MySQL
'$dbh';
54 use SrSv
::Process
::Init
;
56 our ($set_flags, $get_flags, $set_flag, $unset_flag);
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=?");
66 sub cr_set_flag
($$$) {
67 my ($chan, $flag, $sign) = @_;
68 my $cn = $chan->{CHAN
};
71 $chan->{FLAGS
} = ( ( defined $chan->{FLAGS
} ? $chan->{FLAGS
} : 0 ) | $flag );
72 $set_flag->execute($flag, $cn);
74 $chan->{FLAGS
} = ( ( defined $chan->{FLAGS
} ? $chan->{FLAGS
} : 0 ) & ~($flag) );
75 $unset_flag->execute($flag, $cn);
79 sub cr_chk_flag
($$;$) {
80 my ($chan, $flag, $sign) = @_;
81 my $cn = $chan->{CHAN
};
82 $sign = 1 unless defined($sign);
85 unless (exists($chan->{FLAGS
})) {
86 $get_flags->execute($cn);
87 ($chan->{FLAGS
}) = $get_flags->fetchrow_array;
90 $flags = $chan->{FLAGS
};
92 return ($sign ? ($flags & $flag) : !($flags & $flag));