1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
5346 |
* Copyright (c) 1997-2015 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
michael |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
/*! \file channel.c |
23 |
|
|
* \brief Responsible for managing channels, members, bans and topics |
24 |
knight |
31 |
* \version $Id$ |
25 |
adx |
30 |
*/ |
26 |
|
|
|
27 |
|
|
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "channel.h" |
30 |
|
|
#include "channel_mode.h" |
31 |
|
|
#include "client.h" |
32 |
|
|
#include "hash.h" |
33 |
michael |
1632 |
#include "conf.h" |
34 |
michael |
371 |
#include "hostmask.h" |
35 |
adx |
30 |
#include "irc_string.h" |
36 |
|
|
#include "ircd.h" |
37 |
|
|
#include "numeric.h" |
38 |
michael |
3347 |
#include "server.h" |
39 |
adx |
30 |
#include "send.h" |
40 |
|
|
#include "event.h" |
41 |
|
|
#include "memory.h" |
42 |
michael |
1654 |
#include "mempool.h" |
43 |
michael |
3347 |
#include "misc.h" |
44 |
michael |
1826 |
#include "resv.h" |
45 |
adx |
30 |
|
46 |
michael |
3235 |
|
47 |
michael |
3945 |
dlink_list channel_list; |
48 |
michael |
1654 |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
49 |
adx |
30 |
|
50 |
michael |
3250 |
static mp_pool_t *member_pool, *channel_pool; |
51 |
adx |
30 |
|
52 |
|
|
|
53 |
|
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
54 |
|
|
*/ |
55 |
|
|
void |
56 |
michael |
1798 |
channel_init(void) |
57 |
adx |
30 |
{ |
58 |
michael |
6353 |
add_capability("EX", CAPAB_EX); |
59 |
|
|
add_capability("IE", CAPAB_IE); |
60 |
adx |
30 |
|
61 |
michael |
1654 |
channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL); |
62 |
|
|
ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN); |
63 |
|
|
member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER); |
64 |
adx |
30 |
} |
65 |
|
|
|
66 |
michael |
3308 |
/*! \brief Adds a user to a channel by adding another link to the |
67 |
adx |
30 |
* channels member chain. |
68 |
michael |
3308 |
* \param chptr Pointer to channel to add client to |
69 |
|
|
* \param who Pointer to client (who) to add |
70 |
|
|
* \param flags Flags for chanops etc |
71 |
|
|
* \param flood_ctrl Whether to count this join in flood calculations |
72 |
adx |
30 |
*/ |
73 |
|
|
void |
74 |
|
|
add_user_to_channel(struct Channel *chptr, struct Client *who, |
75 |
|
|
unsigned int flags, int flood_ctrl) |
76 |
|
|
{ |
77 |
michael |
4816 |
struct Membership *member = NULL; |
78 |
adx |
30 |
|
79 |
michael |
5591 |
assert(IsClient(who)); |
80 |
|
|
|
81 |
adx |
30 |
if (GlobalSetOptions.joinfloodtime > 0) |
82 |
|
|
{ |
83 |
|
|
if (flood_ctrl) |
84 |
michael |
3250 |
++chptr->number_joined; |
85 |
adx |
30 |
|
86 |
|
|
chptr->number_joined -= (CurrentTime - chptr->last_join_time) * |
87 |
|
|
(((float)GlobalSetOptions.joinfloodcount) / |
88 |
|
|
(float)GlobalSetOptions.joinfloodtime); |
89 |
|
|
|
90 |
|
|
if (chptr->number_joined <= 0) |
91 |
|
|
{ |
92 |
|
|
chptr->number_joined = 0; |
93 |
|
|
ClearJoinFloodNoticed(chptr); |
94 |
|
|
} |
95 |
|
|
else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount) |
96 |
|
|
{ |
97 |
|
|
chptr->number_joined = GlobalSetOptions.joinfloodcount; |
98 |
|
|
|
99 |
|
|
if (!IsSetJoinFloodNoticed(chptr)) |
100 |
|
|
{ |
101 |
|
|
SetJoinFloodNoticed(chptr); |
102 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
103 |
adx |
30 |
"Possible Join Flooder %s on %s target: %s", |
104 |
|
|
get_client_name(who, HIDE_IP), |
105 |
michael |
4617 |
who->servptr->name, chptr->name); |
106 |
adx |
30 |
} |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
chptr->last_join_time = CurrentTime; |
110 |
|
|
} |
111 |
|
|
|
112 |
michael |
4816 |
member = mp_pool_get(member_pool); |
113 |
|
|
member->client_p = who; |
114 |
|
|
member->chptr = chptr; |
115 |
|
|
member->flags = flags; |
116 |
adx |
30 |
|
117 |
michael |
4816 |
dlinkAdd(member, &member->channode, &chptr->members); |
118 |
michael |
4171 |
|
119 |
|
|
if (MyConnect(who)) |
120 |
michael |
4816 |
dlinkAdd(member, &member->locchannode, &chptr->locmembers); |
121 |
michael |
4171 |
|
122 |
michael |
4816 |
dlinkAdd(member, &member->usernode, &who->channel); |
123 |
adx |
30 |
} |
124 |
|
|
|
125 |
michael |
3308 |
/*! \brief Deletes an user from a channel by removing a link in the |
126 |
adx |
30 |
* channels member chain. |
127 |
michael |
3308 |
* \param member Pointer to Membership struct |
128 |
adx |
30 |
*/ |
129 |
|
|
void |
130 |
|
|
remove_user_from_channel(struct Membership *member) |
131 |
|
|
{ |
132 |
michael |
4976 |
struct Client *const client_p = member->client_p; |
133 |
|
|
struct Channel *const chptr = member->chptr; |
134 |
adx |
30 |
|
135 |
|
|
dlinkDelete(&member->channode, &chptr->members); |
136 |
michael |
4171 |
|
137 |
|
|
if (MyConnect(client_p)) |
138 |
|
|
dlinkDelete(&member->locchannode, &chptr->locmembers); |
139 |
|
|
|
140 |
adx |
30 |
dlinkDelete(&member->usernode, &client_p->channel); |
141 |
|
|
|
142 |
michael |
1654 |
mp_pool_release(member); |
143 |
adx |
30 |
|
144 |
michael |
1011 |
if (chptr->members.head == NULL) |
145 |
michael |
6374 |
channel_free(chptr); |
146 |
adx |
30 |
} |
147 |
|
|
|
148 |
michael |
6374 |
/* channel_send_members() |
149 |
adx |
30 |
* |
150 |
|
|
* inputs - |
151 |
|
|
* output - NONE |
152 |
|
|
* side effects - |
153 |
|
|
*/ |
154 |
|
|
static void |
155 |
michael |
6374 |
channel_send_members(struct Client *client_p, const struct Channel *chptr, |
156 |
|
|
char *modebuf, char *parabuf) |
157 |
adx |
30 |
{ |
158 |
michael |
4389 |
char buf[IRCD_BUFSIZE] = ""; |
159 |
michael |
4801 |
const dlink_node *node = NULL; |
160 |
adx |
30 |
int tlen; /* length of text to append */ |
161 |
|
|
char *t, *start; /* temp char pointer */ |
162 |
|
|
|
163 |
michael |
1847 |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:", |
164 |
michael |
4817 |
me.id, (unsigned long)chptr->creationtime, |
165 |
michael |
4617 |
chptr->name, modebuf, parabuf); |
166 |
adx |
30 |
|
167 |
michael |
4801 |
DLINK_FOREACH(node, chptr->members.head) |
168 |
adx |
30 |
{ |
169 |
michael |
4816 |
const struct Membership *member = node->data; |
170 |
adx |
30 |
|
171 |
michael |
4816 |
tlen = strlen(member->client_p->id) + 1; /* +1 for space */ |
172 |
adx |
30 |
|
173 |
michael |
4816 |
if (member->flags & CHFL_CHANOP) |
174 |
michael |
3250 |
++tlen; |
175 |
michael |
4816 |
if (member->flags & CHFL_HALFOP) |
176 |
michael |
3250 |
++tlen; |
177 |
michael |
4816 |
if (member->flags & CHFL_VOICE) |
178 |
michael |
3250 |
++tlen; |
179 |
adx |
30 |
|
180 |
michael |
3250 |
/* |
181 |
|
|
* Space will be converted into CR, but we also need space for LF.. |
182 |
michael |
3783 |
* That's why we use '- 1' here -adx |
183 |
michael |
3250 |
*/ |
184 |
michael |
1330 |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
185 |
adx |
30 |
{ |
186 |
michael |
3250 |
*(t - 1) = '\0'; /* Kill the space and terminate the string */ |
187 |
adx |
30 |
sendto_one(client_p, "%s", buf); |
188 |
|
|
t = start; |
189 |
|
|
} |
190 |
|
|
|
191 |
michael |
4816 |
if (member->flags & CHFL_CHANOP) |
192 |
michael |
3140 |
*t++ = '@'; |
193 |
michael |
4816 |
if (member->flags & CHFL_HALFOP) |
194 |
michael |
3140 |
*t++ = '%'; |
195 |
michael |
4816 |
if (member->flags & CHFL_VOICE) |
196 |
adx |
356 |
*t++ = '+'; |
197 |
adx |
30 |
|
198 |
michael |
4816 |
strcpy(t, member->client_p->id); |
199 |
michael |
3135 |
|
200 |
adx |
30 |
t += strlen(t); |
201 |
|
|
*t++ = ' '; |
202 |
|
|
} |
203 |
|
|
|
204 |
michael |
3250 |
/* Should always be non-NULL unless we have a kind of persistent channels */ |
205 |
michael |
3235 |
if (chptr->members.head) |
206 |
michael |
3250 |
t--; /* Take the space out */ |
207 |
adx |
30 |
*t = '\0'; |
208 |
|
|
sendto_one(client_p, "%s", buf); |
209 |
|
|
} |
210 |
|
|
|
211 |
michael |
3308 |
/*! \brief Sends +b/+e/+I |
212 |
|
|
* \param client_p Client pointer to server |
213 |
|
|
* \param chptr Pointer to channel |
214 |
michael |
3998 |
* \param list Pointer to list of modes to send |
215 |
michael |
3308 |
* \param flag Char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
216 |
adx |
30 |
*/ |
217 |
|
|
static void |
218 |
michael |
6374 |
channel_send_mask_list(struct Client *client_p, const struct Channel *chptr, |
219 |
|
|
const dlink_list *list, const char flag) |
220 |
adx |
30 |
{ |
221 |
michael |
4801 |
const dlink_node *node = NULL; |
222 |
michael |
4389 |
char mbuf[IRCD_BUFSIZE] = ""; |
223 |
michael |
3215 |
char pbuf[IRCD_BUFSIZE] = ""; |
224 |
michael |
3524 |
int tlen, mlen, cur_len; |
225 |
michael |
3144 |
char *pp = pbuf; |
226 |
adx |
30 |
|
227 |
michael |
4976 |
if (!list->length) |
228 |
adx |
30 |
return; |
229 |
|
|
|
230 |
michael |
4389 |
mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %lu %s %c :", me.id, |
231 |
michael |
4817 |
(unsigned long)chptr->creationtime, chptr->name, flag); |
232 |
michael |
3135 |
cur_len = mlen; |
233 |
adx |
30 |
|
234 |
michael |
4801 |
DLINK_FOREACH(node, list->head) |
235 |
adx |
30 |
{ |
236 |
michael |
4816 |
const struct Ban *ban = node->data; |
237 |
adx |
30 |
|
238 |
michael |
4816 |
tlen = ban->len + 3; /* +3 for ! + @ + space */ |
239 |
adx |
30 |
|
240 |
|
|
/* |
241 |
michael |
3995 |
* Send buffer and start over if we cannot fit another ban |
242 |
adx |
30 |
*/ |
243 |
michael |
3135 |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
244 |
adx |
30 |
{ |
245 |
michael |
3250 |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
246 |
michael |
4389 |
sendto_one(client_p, "%s%s", mbuf, pbuf); |
247 |
adx |
30 |
|
248 |
michael |
3135 |
cur_len = mlen; |
249 |
adx |
30 |
pp = pbuf; |
250 |
|
|
} |
251 |
|
|
|
252 |
michael |
4816 |
pp += sprintf(pp, "%s!%s@%s ", ban->name, ban->user, ban->host); |
253 |
adx |
30 |
cur_len += tlen; |
254 |
|
|
} |
255 |
|
|
|
256 |
michael |
3250 |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
257 |
michael |
4389 |
sendto_one(client_p, "%s%s", mbuf, pbuf); |
258 |
adx |
30 |
} |
259 |
|
|
|
260 |
michael |
3308 |
/*! \brief Send "client_p" a full list of the modes for channel chptr |
261 |
|
|
* \param client_p Pointer to client client_p |
262 |
|
|
* \param chptr Pointer to channel pointer |
263 |
adx |
30 |
*/ |
264 |
|
|
void |
265 |
michael |
6374 |
channel_send_modes(struct Client *client_p, struct Channel *chptr) |
266 |
adx |
30 |
{ |
267 |
michael |
3145 |
char modebuf[MODEBUFLEN] = ""; |
268 |
|
|
char parabuf[MODEBUFLEN] = ""; |
269 |
|
|
|
270 |
adx |
30 |
channel_modes(chptr, client_p, modebuf, parabuf); |
271 |
michael |
6374 |
channel_send_members(client_p, chptr, modebuf, parabuf); |
272 |
adx |
30 |
|
273 |
michael |
6374 |
channel_send_mask_list(client_p, chptr, &chptr->banlist, 'b'); |
274 |
|
|
channel_send_mask_list(client_p, chptr, &chptr->exceptlist, 'e'); |
275 |
|
|
channel_send_mask_list(client_p, chptr, &chptr->invexlist, 'I'); |
276 |
adx |
30 |
} |
277 |
|
|
|
278 |
michael |
3308 |
/*! \brief Check channel name for invalid characters |
279 |
|
|
* \param name Pointer to channel name string |
280 |
|
|
* \param local Indicates whether it's a local or remote creation |
281 |
michael |
632 |
* \return 0 if invalid, 1 otherwise |
282 |
adx |
30 |
*/ |
283 |
|
|
int |
284 |
michael |
6374 |
channel_check_name(const char *name, const int local) |
285 |
adx |
30 |
{ |
286 |
michael |
632 |
const char *p = name; |
287 |
michael |
3422 |
|
288 |
michael |
5591 |
assert(!EmptyString(p)); |
289 |
adx |
30 |
|
290 |
michael |
632 |
if (!IsChanPrefix(*p)) |
291 |
|
|
return 0; |
292 |
adx |
30 |
|
293 |
db |
633 |
if (!local || !ConfigChannel.disable_fake_channels) |
294 |
michael |
632 |
{ |
295 |
|
|
while (*++p) |
296 |
db |
634 |
if (!IsChanChar(*p)) |
297 |
michael |
632 |
return 0; |
298 |
|
|
} |
299 |
|
|
else |
300 |
|
|
{ |
301 |
|
|
while (*++p) |
302 |
db |
634 |
if (!IsVisibleChanChar(*p)) |
303 |
michael |
632 |
return 0; |
304 |
|
|
} |
305 |
|
|
|
306 |
michael |
3422 |
return p - name <= CHANNELLEN; |
307 |
adx |
30 |
} |
308 |
|
|
|
309 |
|
|
void |
310 |
michael |
4816 |
remove_ban(struct Ban *ban, dlink_list *list) |
311 |
adx |
30 |
{ |
312 |
michael |
4816 |
dlinkDelete(&ban->node, list); |
313 |
|
|
mp_pool_release(ban); |
314 |
adx |
30 |
} |
315 |
|
|
|
316 |
michael |
6374 |
/* channel_free_mask_list() |
317 |
adx |
30 |
* |
318 |
|
|
* inputs - pointer to dlink_list |
319 |
|
|
* output - NONE |
320 |
|
|
* side effects - |
321 |
|
|
*/ |
322 |
michael |
6374 |
static void |
323 |
|
|
channel_free_mask_list(dlink_list *list) |
324 |
adx |
30 |
{ |
325 |
michael |
4801 |
dlink_node *node = NULL, *node_next = NULL; |
326 |
adx |
30 |
|
327 |
michael |
4801 |
DLINK_FOREACH_SAFE(node, node_next, list->head) |
328 |
|
|
remove_ban(node->data, list); |
329 |
adx |
30 |
} |
330 |
|
|
|
331 |
michael |
4617 |
/*! \brief Get Channel block for name (and allocate a new channel |
332 |
adx |
30 |
* block, if it didn't exist before) |
333 |
michael |
4617 |
* \param name Channel name |
334 |
michael |
3308 |
* \return Channel block |
335 |
adx |
30 |
*/ |
336 |
|
|
struct Channel * |
337 |
michael |
6374 |
channel_make(const char *name) |
338 |
adx |
30 |
{ |
339 |
|
|
struct Channel *chptr = NULL; |
340 |
|
|
|
341 |
michael |
4617 |
assert(!EmptyString(name)); |
342 |
adx |
30 |
|
343 |
michael |
1654 |
chptr = mp_pool_get(channel_pool); |
344 |
adx |
30 |
|
345 |
michael |
3308 |
/* Doesn't hurt to set it here */ |
346 |
michael |
4817 |
chptr->creationtime = CurrentTime; |
347 |
michael |
632 |
chptr->last_join_time = CurrentTime; |
348 |
adx |
30 |
|
349 |
michael |
4617 |
strlcpy(chptr->name, name, sizeof(chptr->name)); |
350 |
michael |
3945 |
dlinkAdd(chptr, &chptr->node, &channel_list); |
351 |
adx |
30 |
|
352 |
|
|
hash_add_channel(chptr); |
353 |
|
|
|
354 |
|
|
return chptr; |
355 |
|
|
} |
356 |
|
|
|
357 |
michael |
3308 |
/*! \brief Walk through this channel, and destroy it. |
358 |
|
|
* \param chptr Channel pointer |
359 |
adx |
30 |
*/ |
360 |
|
|
void |
361 |
michael |
6374 |
channel_free(struct Channel *chptr) |
362 |
adx |
30 |
{ |
363 |
michael |
5851 |
clear_invites_channel(chptr); |
364 |
adx |
30 |
|
365 |
michael |
3308 |
/* Free ban/exception/invex lists */ |
366 |
michael |
6374 |
channel_free_mask_list(&chptr->banlist); |
367 |
|
|
channel_free_mask_list(&chptr->exceptlist); |
368 |
|
|
channel_free_mask_list(&chptr->invexlist); |
369 |
adx |
30 |
|
370 |
michael |
3945 |
dlinkDelete(&chptr->node, &channel_list); |
371 |
adx |
30 |
hash_del_channel(chptr); |
372 |
|
|
|
373 |
michael |
1654 |
mp_pool_release(chptr); |
374 |
adx |
30 |
} |
375 |
|
|
|
376 |
|
|
/*! |
377 |
michael |
3308 |
* \param chptr Pointer to channel |
378 |
|
|
* \return String pointer "=" if public, "@" if secret else "*" |
379 |
adx |
30 |
*/ |
380 |
|
|
static const char * |
381 |
michael |
1013 |
channel_pub_or_secret(const struct Channel *chptr) |
382 |
adx |
30 |
{ |
383 |
|
|
if (SecretChannel(chptr)) |
384 |
|
|
return "@"; |
385 |
|
|
if (PrivateChannel(chptr)) |
386 |
|
|
return "*"; |
387 |
|
|
return "="; |
388 |
|
|
} |
389 |
|
|
|
390 |
|
|
/*! \brief lists all names on given channel |
391 |
michael |
3308 |
* \param source_p Pointer to client struct requesting names |
392 |
|
|
* \param chptr Pointer to channel block |
393 |
|
|
* \param show_eon Show RPL_ENDOFNAMES numeric or not |
394 |
adx |
30 |
* (don't want it with /names with no params) |
395 |
|
|
*/ |
396 |
|
|
void |
397 |
|
|
channel_member_names(struct Client *source_p, struct Channel *chptr, |
398 |
|
|
int show_eon) |
399 |
|
|
{ |
400 |
michael |
4801 |
const dlink_node *node = NULL; |
401 |
michael |
4389 |
char buf[IRCD_BUFSIZE + 1] = ""; |
402 |
adx |
30 |
char *t = NULL, *start = NULL; |
403 |
|
|
int tlen = 0; |
404 |
michael |
4834 |
const int is_member = IsMember(source_p, chptr); |
405 |
|
|
const int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0; |
406 |
|
|
const int uhnames = HasCap(source_p, CAP_UHNAMES) != 0; |
407 |
adx |
30 |
|
408 |
michael |
5591 |
assert(IsClient(source_p)); |
409 |
|
|
|
410 |
adx |
30 |
if (PubChannel(chptr) || is_member) |
411 |
|
|
{ |
412 |
michael |
4389 |
t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY), |
413 |
|
|
me.name, source_p->name, |
414 |
michael |
4617 |
channel_pub_or_secret(chptr), chptr->name); |
415 |
adx |
30 |
start = t; |
416 |
|
|
|
417 |
michael |
4801 |
DLINK_FOREACH(node, chptr->members.head) |
418 |
adx |
30 |
{ |
419 |
michael |
4816 |
const struct Membership *member = node->data; |
420 |
adx |
30 |
|
421 |
michael |
4816 |
if (HasUMode(member->client_p, UMODE_INVISIBLE) && !is_member) |
422 |
adx |
30 |
continue; |
423 |
|
|
|
424 |
michael |
2910 |
if (!uhnames) |
425 |
michael |
4816 |
tlen = strlen(member->client_p->name) + 1; /* +1 for space */ |
426 |
michael |
2910 |
else |
427 |
michael |
4816 |
tlen = strlen(member->client_p->name) + strlen(member->client_p->username) + |
428 |
|
|
strlen(member->client_p->host) + 3; /* +3 for ! + @ + space */ |
429 |
adx |
30 |
|
430 |
michael |
506 |
if (!multi_prefix) |
431 |
|
|
{ |
432 |
michael |
4816 |
if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
433 |
michael |
506 |
++tlen; |
434 |
|
|
} |
435 |
|
|
else |
436 |
|
|
{ |
437 |
michael |
4816 |
if (member->flags & CHFL_CHANOP) |
438 |
michael |
506 |
++tlen; |
439 |
michael |
4816 |
if (member->flags & CHFL_HALFOP) |
440 |
michael |
506 |
++tlen; |
441 |
michael |
4816 |
if (member->flags & CHFL_VOICE) |
442 |
michael |
506 |
++tlen; |
443 |
|
|
} |
444 |
|
|
|
445 |
michael |
4389 |
if (t + tlen - buf > IRCD_BUFSIZE - 2) |
446 |
adx |
30 |
{ |
447 |
|
|
*(t - 1) = '\0'; |
448 |
michael |
4389 |
sendto_one(source_p, "%s", buf); |
449 |
adx |
30 |
t = start; |
450 |
|
|
} |
451 |
|
|
|
452 |
michael |
2910 |
if (!uhnames) |
453 |
michael |
4816 |
t += sprintf(t, "%s%s ", get_member_status(member, multi_prefix), |
454 |
|
|
member->client_p->name); |
455 |
michael |
2910 |
else |
456 |
michael |
4816 |
t += sprintf(t, "%s%s!%s@%s ", get_member_status(member, multi_prefix), |
457 |
|
|
member->client_p->name, member->client_p->username, |
458 |
|
|
member->client_p->host); |
459 |
adx |
30 |
} |
460 |
|
|
|
461 |
michael |
3215 |
if (tlen) |
462 |
adx |
30 |
{ |
463 |
|
|
*(t - 1) = '\0'; |
464 |
michael |
4389 |
sendto_one(source_p, "%s", buf); |
465 |
adx |
30 |
} |
466 |
|
|
} |
467 |
|
|
|
468 |
|
|
if (show_eon) |
469 |
michael |
4617 |
sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->name); |
470 |
adx |
30 |
} |
471 |
|
|
|
472 |
michael |
3308 |
/*! \brief Adds client to invite list |
473 |
|
|
* \param chptr Pointer to channel block |
474 |
|
|
* \param who Pointer to client to add invite to |
475 |
adx |
30 |
*/ |
476 |
|
|
void |
477 |
|
|
add_invite(struct Channel *chptr, struct Client *who) |
478 |
|
|
{ |
479 |
michael |
5591 |
assert(IsClient(who)); |
480 |
|
|
|
481 |
adx |
30 |
del_invite(chptr, who); |
482 |
|
|
|
483 |
|
|
/* |
484 |
michael |
3308 |
* Delete last link in chain if the list is max length |
485 |
adx |
30 |
*/ |
486 |
michael |
4589 |
if (dlink_list_length(&who->connection->invited) >= |
487 |
michael |
3934 |
ConfigChannel.max_channels) |
488 |
michael |
4589 |
del_invite(who->connection->invited.tail->data, who); |
489 |
adx |
30 |
|
490 |
michael |
3308 |
/* Add client to channel invite list */ |
491 |
adx |
30 |
dlinkAdd(who, make_dlink_node(), &chptr->invites); |
492 |
|
|
|
493 |
michael |
3308 |
/* Add channel to the end of the client invite list */ |
494 |
michael |
4589 |
dlinkAdd(chptr, make_dlink_node(), &who->connection->invited); |
495 |
adx |
30 |
} |
496 |
|
|
|
497 |
|
|
/*! \brief Delete Invite block from channel invite list |
498 |
|
|
* and client invite list |
499 |
michael |
3308 |
* \param chptr Pointer to Channel struct |
500 |
|
|
* \param who Pointer to client to remove invites from |
501 |
adx |
30 |
*/ |
502 |
|
|
void |
503 |
|
|
del_invite(struct Channel *chptr, struct Client *who) |
504 |
|
|
{ |
505 |
michael |
4801 |
dlink_node *node = NULL; |
506 |
adx |
30 |
|
507 |
michael |
4801 |
if ((node = dlinkFindDelete(&who->connection->invited, chptr))) |
508 |
|
|
free_dlink_node(node); |
509 |
adx |
30 |
|
510 |
michael |
4801 |
if ((node = dlinkFindDelete(&chptr->invites, who))) |
511 |
|
|
free_dlink_node(node); |
512 |
adx |
30 |
} |
513 |
|
|
|
514 |
michael |
4812 |
/*! \brief Removes all invites of a specific channel |
515 |
|
|
* \param chptr Pointer to Channel struct |
516 |
|
|
*/ |
517 |
|
|
void |
518 |
michael |
5851 |
clear_invites_channel(struct Channel *chptr) |
519 |
michael |
4812 |
{ |
520 |
|
|
dlink_node *node = NULL, *node_next = NULL; |
521 |
|
|
|
522 |
|
|
DLINK_FOREACH_SAFE(node, node_next, chptr->invites.head) |
523 |
|
|
del_invite(chptr, node->data); |
524 |
|
|
} |
525 |
|
|
|
526 |
michael |
5854 |
/*! \brief Removes all invites of a specific client |
527 |
|
|
* \param source_p Pointer to Client struct |
528 |
|
|
*/ |
529 |
michael |
5851 |
void |
530 |
|
|
clear_invites_client(struct Client *source_p) |
531 |
|
|
{ |
532 |
|
|
dlink_node *node = NULL, *node_next = NULL; |
533 |
|
|
|
534 |
|
|
DLINK_FOREACH_SAFE(node, node_next, source_p->connection->invited.head) |
535 |
|
|
del_invite(node->data, source_p); |
536 |
|
|
} |
537 |
|
|
|
538 |
adx |
30 |
/* get_member_status() |
539 |
|
|
* |
540 |
|
|
* inputs - pointer to struct Membership |
541 |
|
|
* - YES if we can combine different flags |
542 |
|
|
* output - string either @, +, % or "" depending on whether |
543 |
|
|
* chanop, voiced or user |
544 |
|
|
* side effects - |
545 |
|
|
* |
546 |
|
|
* NOTE: Returned string is usually a static buffer |
547 |
|
|
* (like in get_client_name) |
548 |
|
|
*/ |
549 |
|
|
const char * |
550 |
michael |
4816 |
get_member_status(const struct Membership *member, const int combine) |
551 |
adx |
30 |
{ |
552 |
michael |
4046 |
static char buffer[4]; /* 4 for @%+\0 */ |
553 |
michael |
1902 |
char *p = buffer; |
554 |
adx |
30 |
|
555 |
michael |
4816 |
if (member->flags & CHFL_CHANOP) |
556 |
adx |
30 |
{ |
557 |
|
|
if (!combine) |
558 |
|
|
return "@"; |
559 |
|
|
*p++ = '@'; |
560 |
|
|
} |
561 |
|
|
|
562 |
michael |
4816 |
if (member->flags & CHFL_HALFOP) |
563 |
adx |
30 |
{ |
564 |
|
|
if (!combine) |
565 |
|
|
return "%"; |
566 |
|
|
*p++ = '%'; |
567 |
|
|
} |
568 |
|
|
|
569 |
michael |
4816 |
if (member->flags & CHFL_VOICE) |
570 |
adx |
30 |
*p++ = '+'; |
571 |
|
|
*p = '\0'; |
572 |
|
|
|
573 |
|
|
return buffer; |
574 |
|
|
} |
575 |
|
|
|
576 |
|
|
/*! |
577 |
michael |
3308 |
* \param who Pointer to Client to check |
578 |
|
|
* \param list Pointer to ban list to search |
579 |
adx |
30 |
* \return 1 if ban found for given n!u\@h mask, 0 otherwise |
580 |
|
|
*/ |
581 |
|
|
static int |
582 |
|
|
find_bmask(const struct Client *who, const dlink_list *const list) |
583 |
|
|
{ |
584 |
michael |
4801 |
const dlink_node *node = NULL; |
585 |
adx |
30 |
|
586 |
michael |
4801 |
DLINK_FOREACH(node, list->head) |
587 |
adx |
30 |
{ |
588 |
michael |
4816 |
const struct Ban *ban = node->data; |
589 |
adx |
30 |
|
590 |
michael |
4816 |
if (!match(ban->name, who->name) && !match(ban->user, who->username)) |
591 |
michael |
371 |
{ |
592 |
michael |
4816 |
switch (ban->type) |
593 |
michael |
371 |
{ |
594 |
|
|
case HM_HOST: |
595 |
michael |
4816 |
if (!match(ban->host, who->host) || !match(ban->host, who->sockhost)) |
596 |
michael |
371 |
return 1; |
597 |
|
|
break; |
598 |
|
|
case HM_IPV4: |
599 |
michael |
4589 |
if (who->connection->aftype == AF_INET) |
600 |
michael |
4816 |
if (match_ipv4(&who->connection->ip, &ban->addr, ban->bits)) |
601 |
michael |
371 |
return 1; |
602 |
|
|
break; |
603 |
|
|
case HM_IPV6: |
604 |
michael |
4589 |
if (who->connection->aftype == AF_INET6) |
605 |
michael |
4816 |
if (match_ipv6(&who->connection->ip, &ban->addr, ban->bits)) |
606 |
michael |
371 |
return 1; |
607 |
|
|
break; |
608 |
|
|
default: |
609 |
|
|
assert(0); |
610 |
|
|
} |
611 |
|
|
} |
612 |
adx |
30 |
} |
613 |
|
|
|
614 |
|
|
return 0; |
615 |
|
|
} |
616 |
|
|
|
617 |
|
|
/*! |
618 |
michael |
3308 |
* \param chptr Pointer to channel block |
619 |
|
|
* \param who Pointer to client to check access fo |
620 |
adx |
30 |
* \return 0 if not banned, 1 otherwise |
621 |
|
|
*/ |
622 |
|
|
int |
623 |
michael |
1013 |
is_banned(const struct Channel *chptr, const struct Client *who) |
624 |
adx |
30 |
{ |
625 |
michael |
632 |
if (find_bmask(who, &chptr->banlist)) |
626 |
michael |
1495 |
if (!find_bmask(who, &chptr->exceptlist)) |
627 |
michael |
632 |
return 1; |
628 |
adx |
30 |
|
629 |
michael |
632 |
return 0; |
630 |
adx |
30 |
} |
631 |
|
|
|
632 |
michael |
3308 |
/*! Tests if a client can join a certain channel |
633 |
|
|
* \param source_p Pointer to client attempting to join |
634 |
|
|
* \param chptr Pointer to channel |
635 |
|
|
* \param key Key sent by client attempting to join if present |
636 |
adx |
30 |
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
637 |
|
|
* or 0 if allowed to join. |
638 |
|
|
*/ |
639 |
michael |
1834 |
int |
640 |
michael |
4784 |
can_join(struct Client *source_p, const struct Channel *chptr, const char *key) |
641 |
adx |
30 |
{ |
642 |
michael |
2246 |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
643 |
michael |
1150 |
return ERR_SSLONLYCHAN; |
644 |
|
|
|
645 |
michael |
1173 |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
646 |
|
|
return ERR_NEEDREGGEDNICK; |
647 |
|
|
|
648 |
michael |
1219 |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER)) |
649 |
michael |
1150 |
return ERR_OPERONLYCHAN; |
650 |
|
|
|
651 |
adx |
30 |
if (chptr->mode.mode & MODE_INVITEONLY) |
652 |
michael |
4589 |
if (!dlinkFind(&source_p->connection->invited, chptr)) |
653 |
michael |
1495 |
if (!find_bmask(source_p, &chptr->invexlist)) |
654 |
adx |
30 |
return ERR_INVITEONLYCHAN; |
655 |
|
|
|
656 |
michael |
1430 |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
657 |
adx |
30 |
return ERR_BADCHANNELKEY; |
658 |
|
|
|
659 |
|
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
660 |
|
|
chptr->mode.limit) |
661 |
|
|
return ERR_CHANNELISFULL; |
662 |
|
|
|
663 |
michael |
2208 |
if (is_banned(chptr, source_p)) |
664 |
|
|
return ERR_BANNEDFROMCHAN; |
665 |
|
|
|
666 |
michael |
1834 |
return 0; |
667 |
adx |
30 |
} |
668 |
|
|
|
669 |
|
|
int |
670 |
michael |
4816 |
has_member_flags(const struct Membership *member, const unsigned int flags) |
671 |
adx |
30 |
{ |
672 |
michael |
4816 |
return member && (member->flags & flags); |
673 |
adx |
30 |
} |
674 |
|
|
|
675 |
|
|
struct Membership * |
676 |
|
|
find_channel_link(struct Client *client_p, struct Channel *chptr) |
677 |
|
|
{ |
678 |
michael |
4801 |
dlink_node *node = NULL; |
679 |
adx |
30 |
|
680 |
|
|
if (!IsClient(client_p)) |
681 |
|
|
return NULL; |
682 |
|
|
|
683 |
michael |
2567 |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
684 |
|
|
{ |
685 |
michael |
4801 |
DLINK_FOREACH(node, chptr->members.head) |
686 |
|
|
if (((struct Membership *)node->data)->client_p == client_p) |
687 |
|
|
return node->data; |
688 |
michael |
2567 |
} |
689 |
|
|
else |
690 |
|
|
{ |
691 |
michael |
4801 |
DLINK_FOREACH(node, client_p->channel.head) |
692 |
|
|
if (((struct Membership *)node->data)->chptr == chptr) |
693 |
|
|
return node->data; |
694 |
michael |
2567 |
} |
695 |
adx |
30 |
|
696 |
|
|
return NULL; |
697 |
|
|
} |
698 |
|
|
|
699 |
michael |
4782 |
/*! Checks if a message contains control codes |
700 |
michael |
3889 |
* \param message The actual message string the client wants to send |
701 |
|
|
* \return 1 if the message does contain any control codes, 0 otherwise |
702 |
michael |
1937 |
*/ |
703 |
|
|
static int |
704 |
|
|
msg_has_ctrls(const char *message) |
705 |
|
|
{ |
706 |
|
|
const unsigned char *p = (const unsigned char *)message; |
707 |
|
|
|
708 |
|
|
for (; *p; ++p) |
709 |
|
|
{ |
710 |
|
|
if (*p > 31 || *p == 1) |
711 |
michael |
3953 |
continue; /* No control code or CTCP */ |
712 |
michael |
1937 |
|
713 |
michael |
3889 |
if (*p == 27) /* Escape */ |
714 |
michael |
1937 |
{ |
715 |
michael |
3889 |
/* ISO 2022 charset shift sequence */ |
716 |
michael |
1937 |
if (*(p + 1) == '$' || |
717 |
|
|
*(p + 1) == '(') |
718 |
|
|
{ |
719 |
|
|
++p; |
720 |
|
|
continue; |
721 |
|
|
} |
722 |
|
|
} |
723 |
|
|
|
724 |
michael |
3889 |
return 1; /* Control code */ |
725 |
michael |
1937 |
} |
726 |
|
|
|
727 |
michael |
4782 |
return 0; /* No control code found */ |
728 |
michael |
1937 |
} |
729 |
|
|
|
730 |
michael |
3308 |
/*! Tests if a client can send to a channel |
731 |
|
|
* \param chptr Pointer to Channel struct |
732 |
|
|
* \param source_p Pointer to Client struct |
733 |
michael |
4816 |
* \param member Pointer to Membership struct (can be NULL) |
734 |
michael |
3308 |
* \param message The actual message string the client wants to send |
735 |
adx |
30 |
* \return CAN_SEND_OPV if op or voiced on channel\n |
736 |
|
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
737 |
michael |
1173 |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
738 |
adx |
30 |
*/ |
739 |
|
|
int |
740 |
michael |
1937 |
can_send(struct Channel *chptr, struct Client *source_p, |
741 |
michael |
4816 |
struct Membership *member, const char *message) |
742 |
adx |
30 |
{ |
743 |
michael |
4784 |
const struct MaskItem *conf = NULL; |
744 |
michael |
1858 |
|
745 |
michael |
1219 |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
746 |
adx |
30 |
return CAN_SEND_OPV; |
747 |
|
|
|
748 |
michael |
6314 |
if (MyClient(source_p) && !HasFlag(source_p, FLAGS_EXEMPTRESV)) |
749 |
michael |
6448 |
if (!(HasUMode(source_p, UMODE_OPER) && HasOFlag(source_p, OPER_FLAG_JOIN_RESV))) |
750 |
michael |
4617 |
if ((conf = match_find_resv(chptr->name)) && !resv_find_exempt(source_p, conf)) |
751 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
752 |
adx |
30 |
|
753 |
michael |
1944 |
if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message)) |
754 |
|
|
return ERR_NOCTRLSONCHAN; |
755 |
michael |
4883 |
|
756 |
michael |
5463 |
if (chptr->mode.mode & MODE_NOCTCP) |
757 |
michael |
5466 |
if (*message == '\001' && strncmp(message + 1, "ACTION ", 7)) |
758 |
michael |
5463 |
return ERR_NOCTCP; |
759 |
|
|
|
760 |
michael |
4816 |
if (member || (member = find_channel_link(source_p, chptr))) |
761 |
michael |
5582 |
if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
762 |
adx |
30 |
return CAN_SEND_OPV; |
763 |
michael |
4883 |
|
764 |
michael |
4816 |
if (!member && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
765 |
michael |
2441 |
return ERR_CANNOTSENDTOCHAN; |
766 |
michael |
4883 |
|
767 |
michael |
1944 |
if (chptr->mode.mode & MODE_MODERATED) |
768 |
|
|
return ERR_CANNOTSENDTOCHAN; |
769 |
michael |
4883 |
|
770 |
michael |
1954 |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
771 |
michael |
1944 |
return ERR_NEEDREGGEDNICK; |
772 |
adx |
30 |
|
773 |
michael |
3308 |
/* Cache can send if banned */ |
774 |
michael |
1944 |
if (MyClient(source_p)) |
775 |
|
|
{ |
776 |
michael |
4816 |
if (member) |
777 |
adx |
30 |
{ |
778 |
michael |
4816 |
if (member->flags & CHFL_BAN_SILENCED) |
779 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
780 |
adx |
30 |
|
781 |
michael |
4816 |
if (!(member->flags & CHFL_BAN_CHECKED)) |
782 |
adx |
30 |
{ |
783 |
|
|
if (is_banned(chptr, source_p)) |
784 |
|
|
{ |
785 |
michael |
5582 |
member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED); |
786 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
787 |
adx |
30 |
} |
788 |
|
|
|
789 |
michael |
4816 |
member->flags |= CHFL_BAN_CHECKED; |
790 |
adx |
30 |
} |
791 |
|
|
} |
792 |
michael |
1944 |
else if (is_banned(chptr, source_p)) |
793 |
michael |
1941 |
return ERR_CANNOTSENDTOCHAN; |
794 |
|
|
} |
795 |
adx |
30 |
|
796 |
|
|
return CAN_SEND_NONOP; |
797 |
|
|
} |
798 |
|
|
|
799 |
|
|
/*! \brief Updates the client's oper_warn_count_down, warns the |
800 |
|
|
* IRC operators if necessary, and updates |
801 |
|
|
* join_leave_countdown as needed. |
802 |
michael |
3308 |
* \param source_p Pointer to struct Client to check |
803 |
|
|
* \param name Channel name or NULL if this is a part. |
804 |
adx |
30 |
*/ |
805 |
|
|
void |
806 |
|
|
check_spambot_warning(struct Client *source_p, const char *name) |
807 |
|
|
{ |
808 |
|
|
int t_delta = 0; |
809 |
|
|
int decrement_count = 0; |
810 |
|
|
|
811 |
|
|
if ((GlobalSetOptions.spam_num && |
812 |
michael |
4589 |
(source_p->connection->join_leave_count >= |
813 |
adx |
30 |
GlobalSetOptions.spam_num))) |
814 |
|
|
{ |
815 |
michael |
4589 |
if (source_p->connection->oper_warn_count_down > 0) |
816 |
|
|
source_p->connection->oper_warn_count_down--; |
817 |
adx |
30 |
else |
818 |
michael |
4589 |
source_p->connection->oper_warn_count_down = 0; |
819 |
adx |
30 |
|
820 |
michael |
4589 |
if (source_p->connection->oper_warn_count_down == 0) |
821 |
adx |
30 |
{ |
822 |
michael |
3308 |
/* It's already known as a possible spambot */ |
823 |
michael |
3235 |
if (name) |
824 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
825 |
adx |
30 |
"User %s (%s@%s) trying to join %s is a possible spambot", |
826 |
|
|
source_p->name, source_p->username, |
827 |
|
|
source_p->host, name); |
828 |
|
|
else |
829 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
830 |
adx |
30 |
"User %s (%s@%s) is a possible spambot", |
831 |
|
|
source_p->name, source_p->username, |
832 |
|
|
source_p->host); |
833 |
michael |
4589 |
source_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN; |
834 |
adx |
30 |
} |
835 |
|
|
} |
836 |
|
|
else |
837 |
|
|
{ |
838 |
michael |
4589 |
if ((t_delta = (CurrentTime - source_p->connection->last_leave_time)) > |
839 |
adx |
30 |
JOIN_LEAVE_COUNT_EXPIRE_TIME) |
840 |
|
|
{ |
841 |
|
|
decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); |
842 |
michael |
4883 |
|
843 |
michael |
4589 |
if (decrement_count > source_p->connection->join_leave_count) |
844 |
|
|
source_p->connection->join_leave_count = 0; |
845 |
adx |
30 |
else |
846 |
michael |
4589 |
source_p->connection->join_leave_count -= decrement_count; |
847 |
adx |
30 |
} |
848 |
|
|
else |
849 |
|
|
{ |
850 |
michael |
4589 |
if ((CurrentTime - (source_p->connection->last_join_time)) < |
851 |
adx |
30 |
GlobalSetOptions.spam_time) |
852 |
michael |
4589 |
source_p->connection->join_leave_count++; /* It's a possible spambot */ |
853 |
adx |
30 |
} |
854 |
|
|
|
855 |
michael |
3215 |
if (name) |
856 |
michael |
4589 |
source_p->connection->last_join_time = CurrentTime; |
857 |
adx |
30 |
else |
858 |
michael |
4589 |
source_p->connection->last_leave_time = CurrentTime; |
859 |
adx |
30 |
} |
860 |
|
|
} |
861 |
|
|
|
862 |
michael |
3308 |
/*! \brief Sets the channel topic for a certain channel |
863 |
adx |
30 |
* \param chptr Pointer to struct Channel |
864 |
|
|
* \param topic The topic string |
865 |
|
|
* \param topic_info n!u\@h formatted string of the topic setter |
866 |
michael |
3308 |
* \param topicts Timestamp on the topic |
867 |
|
|
* \param local Whether the topic is set by a local client |
868 |
adx |
30 |
*/ |
869 |
|
|
void |
870 |
michael |
3940 |
channel_set_topic(struct Channel *chptr, const char *topic, |
871 |
michael |
1751 |
const char *topic_info, time_t topicts, int local) |
872 |
adx |
30 |
{ |
873 |
michael |
1751 |
if (local) |
874 |
michael |
4341 |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1)); |
875 |
michael |
1751 |
else |
876 |
|
|
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
877 |
|
|
|
878 |
michael |
1203 |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
879 |
michael |
2345 |
chptr->topic_time = topicts; |
880 |
adx |
30 |
} |
881 |
michael |
3913 |
|
882 |
|
|
/* do_join_0() |
883 |
|
|
* |
884 |
|
|
* inputs - pointer to client doing join 0 |
885 |
|
|
* output - NONE |
886 |
|
|
* side effects - Use has decided to join 0. This is legacy |
887 |
|
|
* from the days when channels were numbers not names. *sigh* |
888 |
|
|
* There is a bunch of evilness necessary here due to |
889 |
|
|
* anti spambot code. |
890 |
|
|
*/ |
891 |
|
|
void |
892 |
|
|
channel_do_join_0(struct Client *source_p) |
893 |
|
|
{ |
894 |
michael |
4801 |
dlink_node *node = NULL, *node_next = NULL; |
895 |
michael |
3913 |
|
896 |
|
|
if (source_p->channel.head) |
897 |
|
|
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
898 |
|
|
check_spambot_warning(source_p, NULL); |
899 |
|
|
|
900 |
michael |
4801 |
DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head) |
901 |
michael |
3913 |
{ |
902 |
michael |
4801 |
struct Channel *chptr = ((struct Membership *)node->data)->chptr; |
903 |
michael |
3913 |
|
904 |
michael |
4963 |
sendto_server(source_p, 0, 0, ":%s PART %s", |
905 |
michael |
4617 |
source_p->id, chptr->name); |
906 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s!%s@%s PART %s", |
907 |
michael |
3913 |
source_p->name, source_p->username, |
908 |
michael |
4617 |
source_p->host, chptr->name); |
909 |
michael |
3913 |
|
910 |
michael |
4801 |
remove_user_from_channel(node->data); |
911 |
michael |
3913 |
} |
912 |
|
|
} |
913 |
|
|
|
914 |
|
|
static char * |
915 |
|
|
channel_find_last0(struct Client *source_p, char *chanlist) |
916 |
|
|
{ |
917 |
|
|
int join0 = 0; |
918 |
|
|
|
919 |
|
|
for (char *p = chanlist; *p; ++p) /* Find last "JOIN 0" */ |
920 |
|
|
{ |
921 |
|
|
if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0')) |
922 |
|
|
{ |
923 |
michael |
4757 |
if (*(p + 1) == ',') |
924 |
michael |
3913 |
++p; |
925 |
|
|
|
926 |
|
|
chanlist = p + 1; |
927 |
|
|
join0 = 1; |
928 |
|
|
} |
929 |
|
|
else |
930 |
|
|
{ |
931 |
|
|
while (*p != ',' && *p != '\0') /* Skip past channel name */ |
932 |
|
|
++p; |
933 |
|
|
|
934 |
|
|
if (*p == '\0') /* Hit the end */ |
935 |
|
|
break; |
936 |
|
|
} |
937 |
|
|
} |
938 |
|
|
|
939 |
|
|
if (join0) |
940 |
|
|
channel_do_join_0(source_p); |
941 |
|
|
|
942 |
|
|
return chanlist; |
943 |
|
|
} |
944 |
|
|
|
945 |
|
|
void |
946 |
michael |
3936 |
channel_do_join(struct Client *source_p, char *channel, char *key_list) |
947 |
michael |
3913 |
{ |
948 |
|
|
char *p = NULL; |
949 |
michael |
3936 |
char *chan = NULL; |
950 |
michael |
3913 |
char *chan_list = NULL; |
951 |
|
|
struct Channel *chptr = NULL; |
952 |
|
|
struct MaskItem *conf = NULL; |
953 |
michael |
4784 |
const struct ClassItem *const class = get_class_ptr(&source_p->connection->confs); |
954 |
michael |
3913 |
int i = 0; |
955 |
|
|
unsigned int flags = 0; |
956 |
|
|
|
957 |
michael |
5591 |
assert(IsClient(source_p)); |
958 |
|
|
|
959 |
michael |
3936 |
chan_list = channel_find_last0(source_p, channel); |
960 |
michael |
3913 |
|
961 |
|
|
for (chan = strtoken(&p, chan_list, ","); chan; |
962 |
|
|
chan = strtoken(&p, NULL, ",")) |
963 |
|
|
{ |
964 |
|
|
const char *key = NULL; |
965 |
|
|
|
966 |
|
|
/* If we have any more keys, take the first for this channel. */ |
967 |
|
|
if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ','))) |
968 |
|
|
*key_list++ = '\0'; |
969 |
|
|
|
970 |
|
|
/* Empty keys are the same as no keys. */ |
971 |
|
|
if (key && *key == '\0') |
972 |
|
|
key = NULL; |
973 |
|
|
|
974 |
michael |
6374 |
if (!channel_check_name(chan, 1)) |
975 |
michael |
3913 |
{ |
976 |
|
|
sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan); |
977 |
|
|
continue; |
978 |
|
|
} |
979 |
|
|
|
980 |
michael |
6314 |
if (!HasFlag(source_p, FLAGS_EXEMPTRESV) && |
981 |
michael |
6448 |
!(HasUMode(source_p, UMODE_OPER) && HasOFlag(source_p, OPER_FLAG_JOIN_RESV)) && |
982 |
michael |
3913 |
((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf))) |
983 |
|
|
{ |
984 |
|
|
++conf->count; |
985 |
michael |
5982 |
sendto_one_numeric(source_p, &me, ERR_CHANBANREASON, chan, conf->reason); |
986 |
michael |
4152 |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
987 |
michael |
3913 |
"Forbidding reserved channel %s from user %s", |
988 |
|
|
chan, get_client_name(source_p, HIDE_IP)); |
989 |
|
|
continue; |
990 |
|
|
} |
991 |
|
|
|
992 |
|
|
if (dlink_list_length(&source_p->channel) >= |
993 |
michael |
3934 |
((class->max_channels) ? class->max_channels : ConfigChannel.max_channels)) |
994 |
michael |
3913 |
{ |
995 |
|
|
sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan); |
996 |
|
|
break; |
997 |
|
|
} |
998 |
|
|
|
999 |
|
|
if ((chptr = hash_find_channel(chan))) |
1000 |
|
|
{ |
1001 |
|
|
if (IsMember(source_p, chptr)) |
1002 |
|
|
continue; |
1003 |
|
|
|
1004 |
|
|
/* |
1005 |
|
|
* can_join checks for +i key, bans. |
1006 |
|
|
*/ |
1007 |
|
|
if ((i = can_join(source_p, chptr, key))) |
1008 |
|
|
{ |
1009 |
michael |
4617 |
sendto_one_numeric(source_p, &me, i, chptr->name); |
1010 |
michael |
3913 |
continue; |
1011 |
|
|
} |
1012 |
|
|
|
1013 |
|
|
/* |
1014 |
|
|
* This should never be the case unless there is some sort of |
1015 |
|
|
* persistant channels. |
1016 |
|
|
*/ |
1017 |
michael |
4976 |
if (!dlink_list_length(&chptr->members)) |
1018 |
michael |
3913 |
flags = CHFL_CHANOP; |
1019 |
|
|
else |
1020 |
|
|
flags = 0; |
1021 |
|
|
} |
1022 |
|
|
else |
1023 |
|
|
{ |
1024 |
|
|
flags = CHFL_CHANOP; |
1025 |
michael |
6374 |
chptr = channel_make(chan); |
1026 |
michael |
3913 |
} |
1027 |
|
|
|
1028 |
|
|
if (!HasUMode(source_p, UMODE_OPER)) |
1029 |
michael |
4617 |
check_spambot_warning(source_p, chptr->name); |
1030 |
michael |
3913 |
|
1031 |
|
|
add_user_to_channel(chptr, source_p, flags, 1); |
1032 |
|
|
|
1033 |
|
|
/* |
1034 |
michael |
5546 |
* Set timestamp if appropriate, and propagate |
1035 |
michael |
3913 |
*/ |
1036 |
|
|
if (flags == CHFL_CHANOP) |
1037 |
|
|
{ |
1038 |
michael |
4817 |
chptr->creationtime = CurrentTime; |
1039 |
michael |
3913 |
chptr->mode.mode |= MODE_TOPICLIMIT; |
1040 |
|
|
chptr->mode.mode |= MODE_NOPRIVMSGS; |
1041 |
|
|
|
1042 |
michael |
4963 |
sendto_server(source_p, 0, 0, ":%s SJOIN %lu %s +nt :@%s", |
1043 |
michael |
4817 |
me.id, (unsigned long)chptr->creationtime, |
1044 |
michael |
4617 |
chptr->name, source_p->id); |
1045 |
michael |
3913 |
|
1046 |
|
|
/* |
1047 |
|
|
* Notify all other users on the new channel |
1048 |
|
|
*/ |
1049 |
michael |
4793 |
sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s", |
1050 |
|
|
source_p->name, source_p->username, |
1051 |
|
|
source_p->host, chptr->name, |
1052 |
michael |
4820 |
(!IsDigit(source_p->account[0]) && source_p->account[0] != '*') ? source_p->account : "*", |
1053 |
michael |
4793 |
source_p->info); |
1054 |
|
|
sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s", |
1055 |
|
|
source_p->name, source_p->username, |
1056 |
|
|
source_p->host, chptr->name); |
1057 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s MODE %s +nt", |
1058 |
michael |
4617 |
me.name, chptr->name); |
1059 |
michael |
3913 |
|
1060 |
|
|
if (source_p->away[0]) |
1061 |
michael |
4793 |
sendto_channel_local_butone(source_p, CAP_AWAY_NOTIFY, 0, chptr, |
1062 |
michael |
3913 |
":%s!%s@%s AWAY :%s", |
1063 |
|
|
source_p->name, source_p->username, |
1064 |
|
|
source_p->host, source_p->away); |
1065 |
|
|
} |
1066 |
|
|
else |
1067 |
|
|
{ |
1068 |
michael |
4963 |
sendto_server(source_p, 0, 0, ":%s JOIN %lu %s +", |
1069 |
michael |
4817 |
source_p->id, (unsigned long)chptr->creationtime, |
1070 |
michael |
4617 |
chptr->name); |
1071 |
michael |
3913 |
|
1072 |
michael |
4793 |
sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s", |
1073 |
|
|
source_p->name, source_p->username, |
1074 |
|
|
source_p->host, chptr->name, |
1075 |
michael |
4820 |
(!IsDigit(source_p->account[0]) && source_p->account[0] != '*') ? source_p->account : "*", |
1076 |
michael |
4793 |
source_p->info); |
1077 |
|
|
sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s", |
1078 |
|
|
source_p->name, source_p->username, |
1079 |
|
|
source_p->host, chptr->name); |
1080 |
|
|
|
1081 |
michael |
3913 |
if (source_p->away[0]) |
1082 |
michael |
4793 |
sendto_channel_local_butone(source_p, CAP_AWAY_NOTIFY, 0, chptr, |
1083 |
michael |
3913 |
":%s!%s@%s AWAY :%s", |
1084 |
|
|
source_p->name, source_p->username, |
1085 |
|
|
source_p->host, source_p->away); |
1086 |
|
|
} |
1087 |
|
|
|
1088 |
|
|
del_invite(chptr, source_p); |
1089 |
|
|
|
1090 |
|
|
if (chptr->topic[0]) |
1091 |
|
|
{ |
1092 |
michael |
4617 |
sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->name, chptr->topic); |
1093 |
|
|
sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->name, |
1094 |
michael |
3913 |
chptr->topic_info, chptr->topic_time); |
1095 |
|
|
} |
1096 |
|
|
|
1097 |
|
|
channel_member_names(source_p, chptr, 1); |
1098 |
|
|
|
1099 |
michael |
4589 |
source_p->connection->last_join_time = CurrentTime; |
1100 |
michael |
3913 |
} |
1101 |
|
|
} |
1102 |
|
|
|
1103 |
|
|
/*! \brief Removes a client from a specific channel |
1104 |
|
|
* \param source_p Pointer to source client to remove |
1105 |
|
|
* \param name Name of channel to remove from |
1106 |
|
|
* \param reason Part reason to show |
1107 |
|
|
*/ |
1108 |
|
|
static void |
1109 |
|
|
channel_part_one_client(struct Client *source_p, const char *name, const char *reason) |
1110 |
|
|
{ |
1111 |
|
|
struct Channel *chptr = NULL; |
1112 |
michael |
4816 |
struct Membership *member = NULL; |
1113 |
michael |
3913 |
|
1114 |
|
|
if ((chptr = hash_find_channel(name)) == NULL) |
1115 |
|
|
{ |
1116 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name); |
1117 |
|
|
return; |
1118 |
|
|
} |
1119 |
|
|
|
1120 |
michael |
4816 |
if ((member = find_channel_link(source_p, chptr)) == NULL) |
1121 |
michael |
3913 |
{ |
1122 |
michael |
4617 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name); |
1123 |
michael |
3913 |
return; |
1124 |
|
|
} |
1125 |
|
|
|
1126 |
|
|
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
1127 |
|
|
check_spambot_warning(source_p, NULL); |
1128 |
|
|
|
1129 |
|
|
/* |
1130 |
|
|
* Remove user from the old channel (if any) |
1131 |
|
|
* only allow /part reasons in -m chans |
1132 |
|
|
*/ |
1133 |
|
|
if (*reason && (!MyConnect(source_p) || |
1134 |
michael |
4816 |
((can_send(chptr, source_p, member, reason) && |
1135 |
michael |
4589 |
(source_p->connection->firsttime + ConfigGeneral.anti_spam_exit_message_time) |
1136 |
michael |
3913 |
< CurrentTime)))) |
1137 |
|
|
{ |
1138 |
michael |
4963 |
sendto_server(source_p, 0, 0, ":%s PART %s :%s", |
1139 |
michael |
4617 |
source_p->id, chptr->name, reason); |
1140 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s!%s@%s PART %s :%s", |
1141 |
michael |
3913 |
source_p->name, source_p->username, |
1142 |
michael |
4617 |
source_p->host, chptr->name, reason); |
1143 |
michael |
3913 |
} |
1144 |
|
|
else |
1145 |
|
|
{ |
1146 |
michael |
4963 |
sendto_server(source_p, 0, 0, ":%s PART %s", |
1147 |
michael |
4617 |
source_p->id, chptr->name); |
1148 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s!%s@%s PART %s", |
1149 |
michael |
3913 |
source_p->name, source_p->username, |
1150 |
michael |
4617 |
source_p->host, chptr->name); |
1151 |
michael |
3913 |
} |
1152 |
|
|
|
1153 |
michael |
4816 |
remove_user_from_channel(member); |
1154 |
michael |
3913 |
} |
1155 |
|
|
|
1156 |
|
|
void |
1157 |
michael |
4784 |
channel_do_part(struct Client *source_p, char *channel, const char *reason) |
1158 |
michael |
3913 |
{ |
1159 |
|
|
char *p = NULL, *name = NULL; |
1160 |
michael |
4784 |
char buf[KICKLEN + 1] = ""; |
1161 |
michael |
3913 |
|
1162 |
michael |
5591 |
assert(IsClient(source_p)); |
1163 |
|
|
|
1164 |
michael |
3936 |
if (!EmptyString(reason)) |
1165 |
michael |
4784 |
strlcpy(buf, reason, sizeof(buf)); |
1166 |
michael |
3913 |
|
1167 |
michael |
3936 |
for (name = strtoken(&p, channel, ","); name; |
1168 |
michael |
3913 |
name = strtoken(&p, NULL, ",")) |
1169 |
michael |
4784 |
channel_part_one_client(source_p, name, buf); |
1170 |
michael |
3913 |
} |