Initial import (again)
[srvx.git] / src / chanserv.h
1 /* chanserv.h - Channel service bot
2  * Copyright 2000-2004 srvx Development Team
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.  Important limitations are
8  * listed in the COPYING file that accompanies this software.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, email srvx-maintainers@srvx.net.
17  */
18
19 #ifndef _chanserv_h
20 #define _chanserv_h
21
22 #include "nickserv.h"
23
24 enum UL_ALIASES {
25     UL_PEON = 100,
26     UL_OP = 200,
27     UL_MASTER = 300,
28     UL_PRESENT = UL_MASTER,
29     UL_COOWNER = 400,
30     UL_OWNER = 500,
31     UL_HELPER = 600,
32 };
33
34 enum levelOption {
35     lvlGiveOps,
36     lvlEnfOps,
37     lvlEnfModes,
38     lvlEnfTopic,
39     lvlPubCmd,
40     lvlSetters,
41     lvlCTCPUsers,
42     NUM_LEVEL_OPTIONS
43 };
44
45 enum charOption {
46     chProtect,
47     chToys,
48     chTopicRefresh,
49     chCTCPReaction,
50     NUM_CHAR_OPTIONS
51 };
52
53 #define CHANNEL_NODELETE        0x00000001 /* (1 << 0) */
54 #define CHANNEL_SUSPENDED       0x00000002 /* (1 << 1) */
55 #define CHANNEL_INFO_LINES      0x00000004 /* (1 << 2) */
56 #define CHANNEL_VOICE_ALL       0x00000008 /* (1 << 3) */
57 /* No longer used. */                      /* (1 << 4) */
58 #define CHANNEL_DYNAMIC_LIMIT   0x00000020 /* (1 << 5) */
59 #define CHANNEL_TOPIC_SNARF     0x00000040 /* (1 << 6) */
60 #define CHANNEL_PEON_INVITE     0x00000080 /* (1 << 7) */
61 /* Flags with values over 0x20000000 or (1 << 29) will not work
62  * because chanData.flags is a 30-bit field.
63  */
64
65 #define IsProtected(x)          ((x)->flags & CHANNEL_NODELETE)
66 #define IsSuspended(x)          ((x)->flags & CHANNEL_SUSPENDED)
67
68 struct chanData
69 {
70     struct chanNode     *channel;
71     struct mod_chanmode modes;
72
73     time_t              registered;
74     time_t              visited;
75     time_t              limitAdjusted;
76
77     char                *topic;
78     char                *greeting;
79     char                *user_greeting;
80     char                *registrar;
81     char                *topic_mask;
82
83     unsigned int        flags : 30;
84     unsigned int        may_opchan : 1;
85     unsigned int        max;
86     unsigned int        last_refresh;
87     unsigned short      banCount;
88     unsigned short      userCount;
89     unsigned short      lvlOpts[NUM_LEVEL_OPTIONS];
90     unsigned char       chOpts[NUM_CHAR_OPTIONS];
91
92     struct userData     *users;
93     struct banData      *bans;
94     struct dict         *notes;
95     struct suspended    *suspended;
96     struct chanData     *prev;
97     struct chanData     *next;
98 };
99
100 #define USER_AUTO_OP            0x00000001
101 #define USER_SUSPENDED          0x00000002
102 #define USER_AUTO_INVITE        0x00000004
103 #define USER_FLAGS_SIZE         7
104
105 #define IsUserAutoOp(USER)      (!((USER)->flags & USER_AUTO_OP))
106 #define IsUserSuspended(USER)   ((USER)->flags & USER_SUSPENDED)
107 #define IsUserAutoInvite(USER)  ((USER)->flags & USER_AUTO_INVITE)
108
109 struct userData
110 {
111     struct handle_info  *handle;
112     struct chanData     *channel;
113
114     char                *info;
115     time_t              seen;
116     unsigned short      access;
117     unsigned int        present : 1;
118     unsigned int        flags : USER_FLAGS_SIZE;
119
120     /* linked list of userDatas for a chanData */
121     struct userData     *prev;
122     struct userData     *next;
123     /* linked list of userDatas for a handle_info */
124     struct userData     *u_prev;
125     struct userData     *u_next;
126 };
127
128 struct banData
129 {
130     char                mask[NICKLEN + USERLEN + HOSTLEN + 3];
131     char                owner[NICKLEN+1];
132     struct chanData     *channel;
133
134     time_t              set;
135     time_t              triggered;
136     time_t              expires;
137
138     char                *reason;
139
140     struct banData      *prev;
141     struct banData      *next;
142 };
143
144 struct suspended
145 {
146     struct chanData     *cData;
147     char                *suspender;
148     char                *reason;
149     time_t              issued, expires, revoked;
150     struct suspended    *previous;
151 };
152
153 struct do_not_register
154 {
155     char   chan_name[CHANNELLEN+1];
156     char   setter[NICKSERV_HANDLE_LEN+1];
157     time_t set; 
158     char   reason[1];
159 };
160
161 void init_chanserv(const char *nick);
162 void del_channel_user(struct userData *user, int do_gc);
163 struct channelList *chanserv_support_channels(void);
164 unsigned short user_level_from_name(const char *name, unsigned short clamp_level);
165 struct do_not_register *chanserv_is_dnr(const char *chan_name, struct handle_info *handle);
166 int check_user_level(struct chanNode *channel, struct userNode *user, enum levelOption opt, int allow_override, int exempt_owner);
167
168 #endif