]> jfr.im git - irc/SurrealServices/srsv.git/blob - branches/erry-devel/SrSv/ChanReg/Flags.pm
initial commit of erry's Insp work.
[irc/SurrealServices/srsv.git] / branches / erry-devel / SrSv / ChanReg / Flags.pm
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
17 package SrSv::ChanReg::Flags;
18
19 =head1 NAME
20
21 SrSv::ChanReg::Flags - Manage flags of registered channels.
22
23 =cut
24
25 use strict;
26
27 use Exporter 'import';
28
29 BEGIN {
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,
45 );
46
47 our @EXPORT = (qw(cr_chk_flag cr_set_flag), keys(%constants));
48
49 require constant; import constant (\%constants);
50 }
51
52 use SrSv::MySQL '$dbh';
53 use SrSv::Process::Init;
54
55 our ($set_flags, $get_flags, $set_flag, $unset_flag);
56
57 proc_init {
58 $set_flags = $dbh->prepare("UPDATE chanreg SET flags=? WHERE chan=?");
59 $get_flags = $dbh->prepare("SELECT flags FROM chanreg WHERE chan=?");
60 $set_flag = $dbh->prepare("UPDATE chanreg SET flags=(flags | (?)) WHERE chan=?");
61 $unset_flag = $dbh->prepare("UPDATE chanreg SET flags=(flags & ~(?)) WHERE chan=?");
62
63 };
64
65 sub cr_set_flag($$$) {
66 my ($chan, $flag, $sign) = @_;
67 my $cn = $chan->{CHAN};
68
69 if($sign >= 1) {
70 $chan->{FLAGS} = ( ( defined $chan->{FLAGS} ? $chan->{FLAGS} : 0 ) | $flag );
71 $set_flag->execute($flag, $cn);
72 } else {
73 $chan->{FLAGS} = ( ( defined $chan->{FLAGS} ? $chan->{FLAGS} : 0 ) & ~($flag) );
74 $unset_flag->execute($flag, $cn);
75 }
76 }
77
78 sub cr_chk_flag($$;$) {
79 my ($chan, $flag, $sign) = @_;
80 my $cn = $chan->{CHAN};
81 $sign = 1 unless defined($sign);
82
83 my $flags;
84 unless (exists($chan->{FLAGS})) {
85 $get_flags->execute($cn);
86 ($chan->{FLAGS}) = $get_flags->fetchrow_array;
87 $get_flags->finish();
88 }
89 $flags = $chan->{FLAGS};
90
91 return ($sign ? ($flags & $flag) : !($flags & $flag));
92 }
93
94 1;