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-2005 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
22  *  USA
23  *
24  *  $Id: channel.h 26094 2008-09-19 15:33:46Z androsyn $
25  */
26 
27 #ifndef INCLUDED_channel_h
28 #define INCLUDED_channel_h
29 
30 #define MODEBUFLEN      200
31 
32 /* Maximum mode changes allowed per client, per server is different */
33 #define MAXMODEPARAMS   4
34 #define MAXMODEPARAMSSERV 10
35 
36 extern struct ev_entry *checksplit_ev;
37 struct Client;
38 
39 /* mode structure for channels */
40 struct Mode
41 {
42 	unsigned int mode;
43 	int limit;
44 	char key[KEYLEN];
45 };
46 
47 struct topic_info
48 {
49 	char *topic;
50 	char topic_info[USERHOST_REPLYLEN];
51 	time_t topic_time;
52 };
53 
54 /* channel structure */
55 struct Channel
56 {
57 	rb_dlink_node node;
58 	struct Mode mode;
59 	struct topic_info *topic;
60 	time_t last_knock;	/* don't allow knock to flood */
61 
62 	rb_dlink_list members;	/* channel members */
63 	rb_dlink_list locmembers;	/* local channel members */
64 
65 	rb_dlink_list invites;
66 	rb_dlink_list banlist;
67 	rb_dlink_list exceptlist;
68 	rb_dlink_list invexlist;
69 
70 	time_t first_received_message_time;	/* channel flood control */
71 	int received_number_of_privmsgs;
72 	int flood_noticed;
73 
74 	uint32_t ban_serial;
75 	time_t channelts;
76 	char *chname;
77 };
78 
79 struct membership
80 {
81 	rb_dlink_node channode;
82 	rb_dlink_node locchannode;
83 	rb_dlink_node usernode;
84 
85 	struct Channel *chptr;
86 	struct Client *client_p;
87 	uint8_t flags;
88 
89 	uint32_t ban_serial;
90 };
91 
92 #define BANLEN NICKLEN+USERLEN+HOSTLEN+6
93 struct Ban
94 {
95 	char *banstr;
96 	char *who;
97 	time_t when;
98 	rb_dlink_node node;
99 };
100 
101 struct ChModeChange
102 {
103 	char letter;
104 	const char *arg;
105 	const char *id;
106 	int dir;
107 	int caps;
108 	int nocaps;
109 	int mems;
110 	struct Client *client;
111 };
112 
113 struct ChCapCombo
114 {
115 	int count;
116 	int cap_yes;
117 	int cap_no;
118 };
119 
120 /* can_send results */
121 #define CAN_SEND_NO	0
122 #define CAN_SEND_NONOP  1
123 #define CAN_SEND_OPV	2
124 
125 /* channel status flags */
126 #define CHFL_PEON		0x0000	/* normal member of channel */
127 #define CHFL_CHANOP     	0x0001	/* Channel operator */
128 #define CHFL_VOICE      	0x0002	/* the power to speak */
129 #define CHFL_DEOPPED    	0x0004	/* deopped on sjoin, bounce modes */
130 #define CHFL_BANNED		0x0008	/* cached as banned */
131 #define ONLY_SERVERS		0x0010
132 #define ALL_MEMBERS		CHFL_PEON
133 #define ONLY_CHANOPS		CHFL_CHANOP
134 #define ONLY_CHANOPSVOICED	(CHFL_CHANOP|CHFL_VOICE)
135 
136 #define is_chanop(x)	((x) && (x)->flags & CHFL_CHANOP)
137 #define is_voiced(x)	((x) && (x)->flags & CHFL_VOICE)
138 #define is_chanop_voiced(x) ((x) && (x)->flags & (CHFL_CHANOP|CHFL_VOICE))
139 #define is_deop(x)	((x) && (x)->flags & CHFL_DEOPPED)
140 #define can_send_banned(x) ((x) && (x)->flags & CHFL_BANNED)
141 
142 /* channel modes ONLY */
143 #define MODE_PRIVATE    0x0001
144 #define MODE_SECRET     0x0002
145 #define MODE_MODERATED  0x0004
146 #define MODE_TOPICLIMIT 0x0008
147 #define MODE_INVITEONLY 0x0010
148 #define MODE_NOPRIVMSGS 0x0020
149 #define MODE_REGONLY	0x0040
150 #define MODE_SSLONLY	0x0080
151 #define CHFL_BAN        0x0100	/* ban channel flag */
152 #define CHFL_EXCEPTION  0x0200	/* exception to ban channel flag */
153 #define CHFL_INVEX      0x0400
154 
155 /* mode flags for direction indication */
156 #define MODE_QUERY     0
157 #define MODE_ADD       1
158 #define MODE_DEL       -1
159 
160 #define SecretChannel(x)        ((x) && ((x)->mode.mode & MODE_SECRET))
161 #define HiddenChannel(x)        ((x) && ((x)->mode.mode & MODE_PRIVATE))
162 #define PubChannel(x)           ((!x) || ((x)->mode.mode &\
163 				 (MODE_PRIVATE | MODE_SECRET)) == 0)
164 
165 /* channel visible */
166 #define ShowChannel(v,c)        (PubChannel(c) || IsMember((v),(c)))
167 
168 #define IsMember(who, chan) ((who && who->user && \
169 		find_channel_membership(chan, who)) ? 1 : 0)
170 
171 #define IsChannelName(name) ((name) && (*(name) == '#' || *(name) == '&'))
172 
173 extern rb_dlink_list global_channel_list;
174 void init_channels(void);
175 
176 struct Channel *allocate_channel(const char *chname);
177 void free_channel(struct Channel *chptr);
178 struct Ban *allocate_ban(const char *, const char *);
179 void free_ban(struct Ban *bptr);
180 
181 
182 void destroy_channel(struct Channel *);
183 
184 int can_send(struct Channel *chptr, struct Client *who, struct membership *);
185 int is_banned(struct Channel *chptr, struct Client *who,
186 	      struct membership *msptr, const char *, const char *);
187 
188 struct membership *find_channel_membership(struct Channel *, struct Client *);
189 const char *find_channel_status(struct membership *msptr, int combine);
190 void add_user_to_channel(struct Channel *, struct Client *, int flags);
191 void remove_user_from_channel(struct membership *);
192 void remove_user_from_channels(struct Client *);
193 void invalidate_bancache_user(struct Client *);
194 
195 void free_channel_list(rb_dlink_list *);
196 
197 int check_channel_name(const char *name);
198 
199 void channel_member_names(struct Channel *chptr, struct Client *, int show_eon);
200 
201 void del_invite(struct Channel *chptr, struct Client *who);
202 
203 const char *channel_modes(struct Channel *chptr, struct Client *who);
204 
205 void check_spambot_warning(struct Client *source_p, const char *name);
206 
207 void check_splitmode(void *);
208 
209 void set_channel_topic(struct Channel *chptr, const char *topic,
210 		       const char *topic_info, time_t topicts);
211 
212 void init_chcap_usage_counts(void);
213 void set_chcap_usage_counts(struct Client *serv_p);
214 void unset_chcap_usage_counts(struct Client *serv_p);
215 void send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
216 			   struct Channel *chptr, struct ChModeChange foo[], int);
217 
218 
219 #endif /* INCLUDED_channel_h */
220