]> jfr.im git - solanum.git/blob - include/channel.h
chmode: Make mode table manageable
[solanum.git] / include / channel.h
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * channel.h: The ircd channel header.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2004 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
24
25 #ifndef INCLUDED_channel_h
26 #define INCLUDED_channel_h
27
28 #define MODEBUFLEN 200
29
30 /* Maximum mode changes allowed per client, per server is different */
31 #define MAXMODEPARAMS 4
32 #define MAXMODEPARAMSSERV 10
33
34 #include <setup.h>
35
36 struct Client;
37
38 /* mode structure for channels */
39 struct Mode
40 {
41 unsigned int mode;
42 int limit;
43 char key[KEYLEN];
44 unsigned int join_num;
45 unsigned int join_time;
46 char forward[LOC_CHANNELLEN + 1];
47 };
48
49 /* channel structure */
50 struct Channel
51 {
52 rb_dlink_node node;
53 struct Mode mode;
54 char *mode_lock;
55 char *topic;
56 char *topic_info;
57 time_t topic_time;
58 time_t last_knock; /* don't allow knock to flood */
59
60 rb_dlink_list members; /* channel members */
61 rb_dlink_list locmembers; /* local channel members */
62
63 rb_dlink_list invites;
64 rb_dlink_list banlist;
65 rb_dlink_list exceptlist;
66 rb_dlink_list invexlist;
67 rb_dlink_list quietlist;
68
69 time_t first_received_message_time; /* channel flood control */
70 int received_number_of_privmsgs;
71 int flood_noticed;
72
73 unsigned int join_count; /* joins within delta */
74 unsigned int join_delta; /* last ts of join */
75
76 time_t bants;
77 time_t channelts;
78 char *chname;
79
80 struct Client *last_checked_client;
81 time_t last_checked_ts;
82 unsigned int last_checked_type;
83 int last_checked_result;
84 };
85
86 struct membership
87 {
88 rb_dlink_node channode;
89 rb_dlink_node locchannode;
90 rb_dlink_node usernode;
91
92 struct Channel *chptr;
93 struct Client *client_p;
94 unsigned int flags;
95
96 time_t bants;
97 };
98
99 #define BANLEN 195
100 struct Ban
101 {
102 char *banstr;
103 char *who;
104 time_t when;
105 char *forward;
106 rb_dlink_node node;
107 };
108
109 struct mode_letter
110 {
111 int mode;
112 char letter;
113 };
114
115 struct ChModeChange
116 {
117 char letter;
118 const char *arg;
119 const char *id;
120 int dir;
121 int mems;
122 };
123
124 typedef void (*ChannelModeFunc)(struct Client *source_p, struct Channel *chptr,
125 int alevel, int parc, int *parn,
126 const char **parv, int *errors, int dir, char c, long mode_type);
127
128 struct ChannelMode
129 {
130 ChannelModeFunc set_func;
131 long mode_type;
132 };
133
134 typedef int (*ExtbanFunc)(const char *data, struct Client *client_p,
135 struct Channel *chptr, long mode_type);
136
137 /* can_send results */
138 #define CAN_SEND_NO 0
139 #define CAN_SEND_NONOP 1
140 #define CAN_SEND_OPV 2
141
142 /* channel status flags */
143 #define CHFL_PEON 0x0000 /* normal member of channel */
144 #define CHFL_VOICE 0x0001 /* the power to speak */
145 #define CHFL_CHANOP 0x0002 /* Channel operator */
146
147 #define CHFL_BANNED 0x0008 /* cached as banned */
148 #define CHFL_QUIETED 0x0010 /* cached as being +q victim */
149 #define ONLY_SERVERS 0x0020
150 #define ONLY_OPERS 0x0040
151 #define ALL_MEMBERS CHFL_PEON
152 #define ONLY_CHANOPS CHFL_CHANOP
153 #define ONLY_CHANOPSVOICED (CHFL_CHANOP|CHFL_VOICE)
154
155 #define is_chanop(x) ((x) && (x)->flags & CHFL_CHANOP)
156 #define is_voiced(x) ((x) && (x)->flags & CHFL_VOICE)
157 #define is_chanop_voiced(x) ((x) && (x)->flags & (CHFL_CHANOP|CHFL_VOICE))
158 #define can_send_banned(x) ((x) && (x)->flags & (CHFL_BANNED|CHFL_QUIETED))
159
160 /* channel modes ONLY */
161 #define MODE_PRIVATE 0x0001
162 #define MODE_SECRET 0x0002
163 #define MODE_MODERATED 0x0004
164 #define MODE_TOPICLIMIT 0x0008
165 #define MODE_INVITEONLY 0x0010
166 #define MODE_NOPRIVMSGS 0x0020
167 #define MODE_REGONLY 0x0040
168 #define MODE_EXLIMIT 0x0100 /* exempt from list limits, +b/+e/+I/+q */
169 #define MODE_PERMANENT 0x0200 /* permanant channel, +P */
170 #define MODE_OPMODERATE 0x0400 /* send rejected messages to ops */
171 #define MODE_FREEINVITE 0x0800 /* allow free use of /invite */
172 #define MODE_FREETARGET 0x1000 /* can be forwarded to without authorization */
173 #define MODE_DISFORWARD 0x2000 /* disable channel forwarding */
174
175 #define CHFL_BAN 0x10000000 /* ban channel flag */
176 #define CHFL_EXCEPTION 0x20000000 /* exception to ban channel flag */
177 #define CHFL_INVEX 0x40000000
178 #define CHFL_QUIET 0x80000000
179
180 /* mode flags for direction indication */
181 #define MODE_QUERY 0
182 #define MODE_ADD 1
183 #define MODE_DEL -1
184
185 #define SecretChannel(x) ((x) && ((x)->mode.mode & MODE_SECRET))
186 #define HiddenChannel(x) ((x) && ((x)->mode.mode & MODE_PRIVATE))
187 #define PubChannel(x) ((!x) || ((x)->mode.mode &\
188 (MODE_PRIVATE | MODE_SECRET)) == 0)
189
190 /* channel visible */
191 #define ShowChannel(v,c) (PubChannel(c) || IsMember((v),(c)))
192
193 #define IsMember(who, chan) ((who && who->user && \
194 find_channel_membership(chan, who)) ? 1 : 0)
195
196 #define IsChannelName(name) ((name) && (IsChanPrefix(*(name))))
197
198 /* extban function results */
199 #define EXTBAN_INVALID -1 /* invalid mask, false even if negated */
200 #define EXTBAN_NOMATCH 0 /* valid mask, no match */
201 #define EXTBAN_MATCH 1 /* matches */
202
203 int iter_comm_channels_step(rb_dlink_node *pos1, rb_dlink_node *pos2,
204 struct membership **ms1, struct membership **ms2,
205 struct Channel **chptr);
206
207
208 /* Iterate two sorted linked lists of channels, with heads headN, in lockstep.
209 At each iteration, chptr will be a channel in at least one of the lists,
210 and each msN will be non-null iff the channel is in its corresponding list.
211
212 head1 and head2 must be linked list heads.
213 pos1, pos2, ms1, ms2 must be names of modifiable variables, and should not
214 be modified during iteration. It is safe to break or continue at any point
215 without any special cleanup.
216
217 rb_dlink_node_t *pos1, *pos2, *head1, *head2;
218 struct membership *ms1, *ms2;
219 struct Channel *chptr;
220 */
221 #define ITER_COMM_CHANNELS(pos1, pos2, head1, head2, ms1, ms2, chptr) \
222 for ((pos1) = (head1), (pos2) = (head2); \
223 iter_comm_channels_step((pos1), (pos2), &(ms1), &(ms2), &(chptr)); \
224 (ms1) && ((pos1) = (pos1)->next), (ms2) && ((pos2) = (pos2)->next))
225
226
227 extern rb_dlink_list global_channel_list;
228 void init_channels(void);
229
230 struct Channel *allocate_channel(const char *chname);
231 void free_channel(struct Channel *chptr);
232 struct Ban *allocate_ban(const char *, const char *, const char *);
233 void free_ban(struct Ban *bptr);
234
235
236 extern void destroy_channel(struct Channel *);
237
238 extern int can_send(struct Channel *chptr, struct Client *who,
239 struct membership *);
240 extern bool flood_attack_channel(int p_or_n, struct Client *source_p,
241 struct Channel *chptr, char *chname);
242 struct matchset;
243 extern int is_banned(struct Channel *chptr, struct Client *who,
244 struct membership *msptr, const struct matchset *ms,
245 const char **);
246 extern int is_quieted(struct Channel *chptr, struct Client *who,
247 struct membership *msptr, const struct matchset *ms);
248 extern int can_join(struct Client *source_p, struct Channel *chptr,
249 const char *key, const char **forward);
250
251 extern struct membership *find_channel_membership(struct Channel *, struct Client *);
252 extern const char *find_channel_status(struct membership *msptr, int combine);
253 extern void add_user_to_channel(struct Channel *, struct Client *, int flags);
254 extern void remove_user_from_channel(struct membership *);
255 extern void remove_user_from_channels(struct Client *);
256 extern void invalidate_bancache_user(struct Client *);
257
258 extern void free_channel_list(rb_dlink_list *);
259
260 extern bool check_channel_name(const char *name);
261
262 extern void channel_member_names(struct Channel *chptr, struct Client *,
263 int show_eon);
264
265 extern void del_invite(struct Channel *chptr, struct Client *who);
266
267 const char *channel_modes(struct Channel *chptr, struct Client *who);
268
269 extern struct Channel *find_bannickchange_channel(struct Client *client_p);
270
271 extern void check_spambot_warning(struct Client *source_p, const char *name);
272
273 extern void check_splitmode(void *);
274
275 void set_channel_topic(struct Channel *chptr, const char *topic,
276 const char *topic_info, time_t topicts);
277
278 extern void init_chcap_usage_counts(void);
279 extern void set_chcap_usage_counts(struct Client *serv_p);
280 extern void unset_chcap_usage_counts(struct Client *serv_p);
281 extern void send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
282 struct Channel *chptr, struct ChModeChange foo[], int);
283
284 void resv_chan_forcepart(const char *name, const char *reason, int temp_time);
285
286 extern void set_channel_mode(struct Client *client_p, struct Client *source_p,
287 struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]);
288 extern void set_channel_mlock(struct Client *client_p, struct Client *source_p,
289 struct Channel *chptr, const char *newmlock, bool propagate);
290
291 extern struct ChannelMode chmode_table[256];
292
293 extern bool add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
294 const char *forward, rb_dlink_list * list, long mode_type);
295
296 extern struct Ban * del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list,
297 long mode_type);
298
299 extern ExtbanFunc extban_table[256];
300
301 extern int match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type);
302 extern int valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type);
303 const char * get_extban_string(void);
304
305 extern int get_channel_access(struct Client *source_p, struct Channel *chptr, struct membership *msptr, int dir, const char *modestr);
306
307 extern void send_channel_join(struct Channel *chptr, struct Client *client_p);
308
309 #endif /* INCLUDED_channel_h */