Clean a bit - to be continued...
[seven-1.x.git] / include / channel.h
blobf300a7a679d167ebee6e12d7e78034c9092b5b40
1 /* irc-seven: Cows like it.
3 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
4 * Copyright (C) 1996-2002 Hybrid Development Team
5 * Copyright (C) 2002-2004 ircd-ratbox development team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to:
20 * Free Software Foundation, Inc.
21 * 51 Franklin St - Fifth Floor
22 * Boston, MA 02110-1301
23 * USA
25 * }}} */
27 #ifndef _SEVEN_CHANNEL_H
28 # define _SEVEN_CHANNEL_H
30 # include "config.h"
31 # include "ircd_defs.h"
32 # include "s_newconf.h"
34 # define MODEBUFLEN 200
36 /* Maximum mode changes allowed per client, per server is different */
37 #define MAXMODEPARAMS 4
38 #define MAXMODEPARAMSSERV 10
40 struct Client;
42 /* mode structure for channels */
43 struct Mode
45 unsigned int mode;
46 int limit;
47 char key[KEYLEN];
48 unsigned int join_num;
49 unsigned int join_time;
50 char forward[LOC_CHANNELLEN + 1];
51 int banlimit;
54 /* channel structure */
55 struct Channel
57 dlink_node node;
58 struct Mode mode;
59 char *topic;
60 char *topic_info;
61 time_t topic_time;
62 time_t users_last; /* when last user was in channel */
63 time_t last_knock; /* don't allow knock to flood */
65 dlink_list members; /* channel members */
66 dlink_list locmembers; /* local channel members */
68 dlink_list invites;
69 dlink_list banlist;
70 dlink_list exceptlist;
71 dlink_list invexlist;
72 dlink_list quietlist;
74 time_t first_received_message_time; /* channel flood control */
75 int received_number_of_privmsgs;
76 int flood_noticed;
78 unsigned int join_count; /* joins within delta */
79 unsigned int join_delta; /* last ts of join */
81 int num_mask; /* number of bans+exceptions+invite exceptions */
82 unsigned long bants;
83 time_t channelts;
84 char *chname;
87 struct membership
89 dlink_node channode;
90 dlink_node locchannode;
91 dlink_node usernode;
93 struct Channel *chptr;
94 struct Client *client_p;
95 unsigned int flags;
97 unsigned long bants;
100 #define BANLEN NICKLEN+USERLEN+HOSTLEN+6
101 struct Ban
103 char *banstr;
104 char *who;
105 time_t when;
106 dlink_node node;
109 struct ChModeChange
111 char letter;
112 const char *arg;
113 const char *id;
114 int dir;
115 int caps;
116 int nocaps;
117 int mems;
118 struct Client *client;
121 struct ChCapCombo
123 int count;
124 int cap_yes;
125 int cap_no;
128 struct ChannelMode
130 void (*set_func)(struct Client *source_p, struct Channel *chptr,
131 int alevel, int parc, int *parn, const char **parv,
132 int *errors, int dir, char c, long mode_type);
133 long mode_type;
136 typedef int (*ExtbanFunc)(const char *data, struct Client *client_p,
137 struct Channel *chptr, long mode_type);
139 struct mode_letter
141 const unsigned int mode;
142 const unsigned char letter;
145 /* can_send results */
146 #define CAN_SEND_NO 0
147 #define CAN_SEND_NONOP 1
148 #define CAN_SEND_OPV 2
150 /* channel status flags */
151 #define CHFL_PEON 0x0000 /* normal member of channel */
152 #define CHFL_CHANOP 0x0001 /* Channel operator */
153 #define CHFL_VOICE 0x0002 /* the power to speak */
154 #define CHFL_DEOPPED 0x0004 /* deopped on sjoin, bounce modes */
155 #define CHFL_BANNED 0x0008 /* cached as banned */
156 #define CHFL_QUIETED 0x0010 /* cached as being +q victim */
157 #define ONLY_SERVERS 0x0020
158 #define ALL_MEMBERS CHFL_PEON
159 #define ONLY_CHANOPS CHFL_CHANOP
160 #define ONLY_CHANOPSVOICED (CHFL_CHANOP|CHFL_VOICE)
162 #define is_chanop(x) ((x) && (((x)->flags & CHFL_CHANOP) || IsOverride((x)->client_p)))
163 #define is_real_chanop(x) ((x) && (x)->flags & CHFL_CHANOP)
164 #define is_voiced(x) ((x) && (x)->flags & CHFL_VOICE)
165 #define is_chanop_voiced(x) ((x) && (x)->flags & (CHFL_CHANOP|CHFL_VOICE))
166 #define is_deop(x) ((x) && (x)->flags & CHFL_DEOPPED)
167 #define can_send_banned(x) ((x) && (x)->flags & (CHFL_BANNED|CHFL_QUIETED))
169 /* channel modes ONLY */
170 #define MODE_PRIVATE 0x0001 /* paranoid channel, +p. */
171 #define MODE_SECRET 0x0002 /* secret channel (hidden from /list, etc). */
172 #define MODE_MODERATED 0x0004 /* moderated channel (requires voice/ops to speak). */
173 #define MODE_TOPICLIMIT 0x0008 /* require ops to change /topic. */
174 #define MODE_INVITEONLY 0x0010 /* must be invited/have +I to join. */
175 #define MODE_NOPRIVMSGS 0x0020 /* must be in channel to send to it. */
176 #define MODE_REGONLY 0x0040 /* must be registered to be able to join. */
177 #define MODE_NOCOLOR 0x0080 /* strip ansi/mirc colour codes. */
178 #define MODE_EXLIMIT 0x0100 /* exempt from list limits, +b/+e/+I/+q. */
179 #define MODE_PERMANENT 0x0200 /* permanant channel, +P. */
180 #define MODE_OPMODERATE 0x0400 /* send rejected messages to ops. */
181 #define MODE_FREEINVITE 0x0800 /* allow free use of /invite. */
182 #define MODE_FREETARGET 0x1000 /* can be forwarded to without authorization. */
183 #define MODE_DISFORWARD 0x2000 /* disable channel forwarding. */
184 #define MODE_QUIETUNID 0x4000 /* quiet unidentified. */
186 /* channel ban flags (hope we won't need any more...) */
187 #define CHFL_BAN 0x10000000 /* ban channel flag */
188 #define CHFL_EXCEPTION 0x20000000 /* exception to ban channel flag */
189 #define CHFL_INVEX 0x40000000
190 #define CHFL_QUIET 0x80000000
192 /* mode flags for direction indication */
193 #define MODE_QUERY 0
194 #define MODE_ADD 1
195 #define MODE_DEL -1
197 #define SecretChannel(x) ((x) && ((x)->mode.mode & MODE_SECRET))
198 #define HiddenChannel(x) ((x) && ((x)->mode.mode & MODE_PRIVATE))
199 #define PubChannel(x) \
200 ((!x) || ((x)->mode.mode & (MODE_PRIVATE | MODE_SECRET)) == 0)
202 /* channel visible */
203 #define ShowChannel(v,c) (PubChannel(c) || IsMember((v),(c)))
205 #define IsMember(who, chan) \
206 ((who && who->user && find_channel_membership(chan, who)) ? 1 : 0)
208 #define IsChannelName(name) ((name) && (*(name) == '#' || *(name) == '&'))
210 /* extban function results */
211 #define EXTBAN_INVALID -1 /* invalid mask, false even if negated */
212 #define EXTBAN_NOMATCH 0 /* valid mask, no match */
213 #define EXTBAN_MATCH 1 /* matches */
215 extern dlink_list global_channel_list;
216 void init_channels(void);
218 struct Channel *allocate_channel(const char *chname);
219 void free_channel(struct Channel *chptr);
220 struct Ban *allocate_ban(const char *, const char *);
221 void free_ban(struct Ban *bptr);
224 extern void destroy_channel(struct Channel *);
226 extern int can_send(struct Channel *chptr, struct Client *who,
227 struct membership *);
228 extern int is_banned(struct Channel *chptr, struct Client *who,
229 struct membership *msptr, const char *, const char *);
230 extern int is_quieted(struct Channel *chptr, struct Client *who,
231 struct membership *msptr, const char *, const char *);
232 extern int can_join(struct Client *source_p, struct Channel *chptr, char *key);
234 extern struct membership *find_channel_membership(struct Channel *, struct Client *);
235 extern const char *find_channel_status(struct membership *msptr, int combine);
236 extern void add_user_to_channel(struct Channel *, struct Client *, int flags);
237 extern void remove_user_from_channel(struct membership *);
238 extern void remove_user_from_channels(struct Client *);
239 extern void invalidate_bancache_user(struct Client *);
241 extern void free_channel_list(dlink_list *);
243 extern int check_channel_name(const char *name);
245 extern void channel_member_names(struct Channel *chptr, struct Client *,
246 int show_eon);
248 extern void del_invite(struct Channel *chptr, struct Client *who);
250 const char *channel_modes(struct Channel *chptr, struct Client *who);
252 extern struct Channel *find_bannickchange_channel(struct Client *client_p);
254 extern void check_spambot_warning(struct Client *source_p, const char *name);
256 extern void check_splitmode(void *);
258 void set_channel_topic(struct Channel *chptr, const char *topic,
259 const char *topic_info, time_t topicts);
261 extern void init_chcap_usage_counts(void);
262 extern void set_chcap_usage_counts(struct Client *serv_p);
263 extern void unset_chcap_usage_counts(struct Client *serv_p);
264 extern void send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
265 struct Channel *chptr, struct ChModeChange foo[], int);
267 extern void set_channel_mode(struct Client *client_p, struct Client *source_p,
268 struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]);
270 extern struct ChannelMode chmode_table[256];
272 extern int add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
273 dlink_list * list, long mode_type);
275 extern int del_id(struct Channel *chptr, const char *banid, dlink_list * list, long mode_type);
277 extern ExtbanFunc extban_table[256];
279 extern int match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type);
280 extern int valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type);
281 const char * get_extban_string(void);
284 * this is defined in src/channel.c but used in a few other places (namely
285 * modules/core/m_join.c and modules/core/m_sjoin.c).
287 extern const struct mode_letter channel_flags[];
289 #endif /* ! _SEVEN_CHANNEL_H */