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