1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
7006 |
* 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 |
4565 |
* 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 |
3944 |
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 |
6354 |
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 |
6681 |
* \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 |
6681 |
add_user_to_channel(struct Channel *chptr, struct Client *client_p, |
75 |
adx |
30 |
unsigned int flags, int flood_ctrl) |
76 |
|
|
{ |
77 |
michael |
6681 |
assert(IsClient(client_p)); |
78 |
michael |
5590 |
|
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 |
6681 |
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 |
7076 |
struct Membership *member = mp_pool_get(member_pool); |
111 |
michael |
6681 |
member->client_p = client_p; |
112 |
michael |
4815 |
member->chptr = chptr; |
113 |
|
|
member->flags = flags; |
114 |
adx |
30 |
|
115 |
michael |
4815 |
dlinkAdd(member, &member->channode, &chptr->members); |
116 |
michael |
4170 |
|
117 |
michael |
6681 |
if (MyConnect(client_p)) |
118 |
michael |
4815 |
dlinkAdd(member, &member->locchannode, &chptr->locmembers); |
119 |
michael |
4170 |
|
120 |
michael |
6681 |
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 |
4977 |
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 |
4170 |
|
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 |
6373 |
channel_free(chptr); |
144 |
adx |
30 |
} |
145 |
|
|
|
146 |
michael |
6373 |
/* channel_send_members() |
147 |
adx |
30 |
* |
148 |
|
|
* inputs - |
149 |
|
|
* output - NONE |
150 |
|
|
* side effects - |
151 |
|
|
*/ |
152 |
|
|
static void |
153 |
michael |
6373 |
channel_send_members(struct Client *client_p, const struct Channel *chptr, |
154 |
|
|
char *modebuf, char *parabuf) |
155 |
adx |
30 |
{ |
156 |
michael |
4388 |
char buf[IRCD_BUFSIZE] = ""; |
157 |
michael |
4800 |
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 |
6782 |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %ju %s %s %s:", |
162 |
|
|
me.id, chptr->creationtime, |
163 |
michael |
4618 |
chptr->name, modebuf, parabuf); |
164 |
adx |
30 |
|
165 |
michael |
4800 |
DLINK_FOREACH(node, chptr->members.head) |
166 |
adx |
30 |
{ |
167 |
michael |
4815 |
const struct Membership *member = node->data; |
168 |
adx |
30 |
|
169 |
michael |
4815 |
tlen = strlen(member->client_p->id) + 1; /* +1 for space */ |
170 |
adx |
30 |
|
171 |
michael |
4815 |
if (member->flags & CHFL_CHANOP) |
172 |
michael |
3250 |
++tlen; |
173 |
michael |
4815 |
if (member->flags & CHFL_HALFOP) |
174 |
michael |
3250 |
++tlen; |
175 |
michael |
4815 |
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 |
3782 |
* 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 |
4815 |
if (member->flags & CHFL_CHANOP) |
190 |
michael |
3140 |
*t++ = '@'; |
191 |
michael |
4815 |
if (member->flags & CHFL_HALFOP) |
192 |
michael |
3140 |
*t++ = '%'; |
193 |
michael |
4815 |
if (member->flags & CHFL_VOICE) |
194 |
adx |
356 |
*t++ = '+'; |
195 |
adx |
30 |
|
196 |
michael |
4815 |
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 |
3997 |
* \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 |
6373 |
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 |
4800 |
const dlink_node *node = NULL; |
220 |
michael |
4388 |
char mbuf[IRCD_BUFSIZE] = ""; |
221 |
michael |
3215 |
char pbuf[IRCD_BUFSIZE] = ""; |
222 |
michael |
3523 |
int tlen, mlen, cur_len; |
223 |
michael |
3144 |
char *pp = pbuf; |
224 |
adx |
30 |
|
225 |
michael |
7012 |
if (!dlink_list_length(list)) |
226 |
adx |
30 |
return; |
227 |
|
|
|
228 |
michael |
6782 |
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 |
4800 |
DLINK_FOREACH(node, list->head) |
233 |
adx |
30 |
{ |
234 |
michael |
4815 |
const struct Ban *ban = node->data; |
235 |
adx |
30 |
|
236 |
michael |
4815 |
tlen = ban->len + 3; /* +3 for ! + @ + space */ |
237 |
adx |
30 |
|
238 |
|
|
/* |
239 |
michael |
3996 |
* 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 |
4388 |
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 |
4815 |
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 |
4388 |
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 |
6373 |
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 |
6373 |
channel_send_members(client_p, chptr, modebuf, parabuf); |
270 |
adx |
30 |
|
271 |
michael |
6373 |
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 |
6373 |
channel_check_name(const char *name, const int local) |
283 |
adx |
30 |
{ |
284 |
michael |
632 |
const char *p = name; |
285 |
michael |
3421 |
|
286 |
michael |
5590 |
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 |
3421 |
return p - name <= CHANNELLEN; |
305 |
adx |
30 |
} |
306 |
|
|
|
307 |
|
|
void |
308 |
michael |
4815 |
remove_ban(struct Ban *ban, dlink_list *list) |
309 |
adx |
30 |
{ |
310 |
michael |
4815 |
dlinkDelete(&ban->node, list); |
311 |
|
|
mp_pool_release(ban); |
312 |
adx |
30 |
} |
313 |
|
|
|
314 |
michael |
6373 |
/* channel_free_mask_list() |
315 |
adx |
30 |
* |
316 |
|
|
* inputs - pointer to dlink_list |
317 |
|
|
* output - NONE |
318 |
|
|
* side effects - |
319 |
|
|
*/ |
320 |
michael |
6373 |
static void |
321 |
|
|
channel_free_mask_list(dlink_list *list) |
322 |
adx |
30 |
{ |
323 |
michael |
4800 |
dlink_node *node = NULL, *node_next = NULL; |
324 |
adx |
30 |
|
325 |
michael |
4800 |
DLINK_FOREACH_SAFE(node, node_next, list->head) |
326 |
|
|
remove_ban(node->data, list); |
327 |
adx |
30 |
} |
328 |
|
|
|
329 |
michael |
4618 |
/*! \brief Get Channel block for name (and allocate a new channel |
330 |
adx |
30 |
* block, if it didn't exist before) |
331 |
michael |
4618 |
* \param name Channel name |
332 |
michael |
3308 |
* \return Channel block |
333 |
adx |
30 |
*/ |
334 |
|
|
struct Channel * |
335 |
michael |
6373 |
channel_make(const char *name) |
336 |
adx |
30 |
{ |
337 |
|
|
struct Channel *chptr = NULL; |
338 |
|
|
|
339 |
michael |
4618 |
assert(!EmptyString(name)); |
340 |
adx |
30 |
|
341 |
michael |
1654 |
chptr = mp_pool_get(channel_pool); |
342 |
adx |
30 |
|
343 |
michael |
3308 |
/* Doesn't hurt to set it here */ |
344 |
michael |
4818 |
chptr->creationtime = CurrentTime; |
345 |
michael |
632 |
chptr->last_join_time = CurrentTime; |
346 |
adx |
30 |
|
347 |
michael |
6982 |
chptr->name_len = strlcpy(chptr->name, name, sizeof(chptr->name)); |
348 |
|
|
if (chptr->name_len >= sizeof(chptr->name)) |
349 |
|
|
chptr->name_len = sizeof(chptr->name) - 1; |
350 |
michael |
6990 |
|
351 |
michael |
3944 |
dlinkAdd(chptr, &chptr->node, &channel_list); |
352 |
adx |
30 |
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 |
6373 |
channel_free(struct Channel *chptr) |
362 |
adx |
30 |
{ |
363 |
michael |
5852 |
clear_invites_channel(chptr); |
364 |
adx |
30 |
|
365 |
michael |
3308 |
/* Free ban/exception/invex lists */ |
366 |
michael |
6373 |
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 |
3944 |
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 |
6681 |
* \param client_p Pointer to client struct requesting names |
392 |
michael |
3308 |
* \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 |
michael |
6681 |
channel_member_names(struct Client *client_p, struct Channel *chptr, |
398 |
adx |
30 |
int show_eon) |
399 |
|
|
{ |
400 |
michael |
4800 |
const dlink_node *node = NULL; |
401 |
michael |
4388 |
char buf[IRCD_BUFSIZE + 1] = ""; |
402 |
adx |
30 |
char *t = NULL, *start = NULL; |
403 |
|
|
int tlen = 0; |
404 |
michael |
6681 |
const int is_member = IsMember(client_p, chptr); |
405 |
|
|
const int multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0; |
406 |
|
|
const int uhnames = HasCap(client_p, CAP_UHNAMES) != 0; |
407 |
adx |
30 |
|
408 |
michael |
6681 |
assert(IsClient(client_p)); |
409 |
michael |
5590 |
|
410 |
adx |
30 |
if (PubChannel(chptr) || is_member) |
411 |
|
|
{ |
412 |
michael |
4388 |
t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY), |
413 |
michael |
6681 |
me.name, client_p->name, |
414 |
michael |
4618 |
channel_pub_or_secret(chptr), chptr->name); |
415 |
adx |
30 |
start = t; |
416 |
|
|
|
417 |
michael |
4800 |
DLINK_FOREACH(node, chptr->members.head) |
418 |
adx |
30 |
{ |
419 |
michael |
4815 |
const struct Membership *member = node->data; |
420 |
adx |
30 |
|
421 |
michael |
4815 |
if (HasUMode(member->client_p, UMODE_INVISIBLE) && !is_member) |
422 |
adx |
30 |
continue; |
423 |
|
|
|
424 |
michael |
2910 |
if (!uhnames) |
425 |
michael |
4815 |
tlen = strlen(member->client_p->name) + 1; /* +1 for space */ |
426 |
michael |
2910 |
else |
427 |
michael |
4815 |
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 |
4815 |
if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
433 |
michael |
506 |
++tlen; |
434 |
|
|
} |
435 |
|
|
else |
436 |
|
|
{ |
437 |
michael |
4815 |
if (member->flags & CHFL_CHANOP) |
438 |
michael |
506 |
++tlen; |
439 |
michael |
4815 |
if (member->flags & CHFL_HALFOP) |
440 |
michael |
506 |
++tlen; |
441 |
michael |
4815 |
if (member->flags & CHFL_VOICE) |
442 |
michael |
506 |
++tlen; |
443 |
|
|
} |
444 |
|
|
|
445 |
michael |
4388 |
if (t + tlen - buf > IRCD_BUFSIZE - 2) |
446 |
adx |
30 |
{ |
447 |
|
|
*(t - 1) = '\0'; |
448 |
michael |
6681 |
sendto_one(client_p, "%s", buf); |
449 |
adx |
30 |
t = start; |
450 |
|
|
} |
451 |
|
|
|
452 |
michael |
2910 |
if (!uhnames) |
453 |
michael |
4815 |
t += sprintf(t, "%s%s ", get_member_status(member, multi_prefix), |
454 |
|
|
member->client_p->name); |
455 |
michael |
2910 |
else |
456 |
michael |
4815 |
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 |
6681 |
sendto_one(client_p, "%s", buf); |
465 |
adx |
30 |
} |
466 |
|
|
} |
467 |
|
|
|
468 |
|
|
if (show_eon) |
469 |
michael |
6681 |
sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, chptr->name); |
470 |
adx |
30 |
} |
471 |
|
|
|
472 |
michael |
3308 |
/*! \brief Adds client to invite list |
473 |
michael |
6681 |
* \param chptr Pointer to channel block |
474 |
|
|
* \param client_p Pointer to client to add invite to |
475 |
adx |
30 |
*/ |
476 |
|
|
void |
477 |
michael |
6681 |
add_invite(struct Channel *chptr, struct Client *client_p) |
478 |
adx |
30 |
{ |
479 |
michael |
6681 |
assert(IsClient(client_p)); |
480 |
michael |
5590 |
|
481 |
michael |
6681 |
del_invite(chptr, client_p); |
482 |
adx |
30 |
|
483 |
|
|
/* |
484 |
michael |
3308 |
* Delete last link in chain if the list is max length |
485 |
adx |
30 |
*/ |
486 |
michael |
6681 |
if (dlink_list_length(&client_p->connection->invited) >= |
487 |
michael |
3933 |
ConfigChannel.max_channels) |
488 |
michael |
6681 |
del_invite(client_p->connection->invited.tail->data, client_p); |
489 |
adx |
30 |
|
490 |
michael |
3308 |
/* Add client to channel invite list */ |
491 |
michael |
6681 |
dlinkAdd(client_p, make_dlink_node(), &chptr->invites); |
492 |
adx |
30 |
|
493 |
michael |
3308 |
/* Add channel to the end of the client invite list */ |
494 |
michael |
6681 |
dlinkAdd(chptr, make_dlink_node(), &client_p->connection->invited); |
495 |
adx |
30 |
} |
496 |
|
|
|
497 |
|
|
/*! \brief Delete Invite block from channel invite list |
498 |
|
|
* and client invite list |
499 |
michael |
6681 |
* \param chptr Pointer to Channel struct |
500 |
|
|
* \param client_p Pointer to client to remove invites from |
501 |
adx |
30 |
*/ |
502 |
|
|
void |
503 |
michael |
6681 |
del_invite(struct Channel *chptr, struct Client *client_p) |
504 |
adx |
30 |
{ |
505 |
michael |
4800 |
dlink_node *node = NULL; |
506 |
adx |
30 |
|
507 |
michael |
6681 |
if ((node = dlinkFindDelete(&client_p->connection->invited, chptr))) |
508 |
michael |
4800 |
free_dlink_node(node); |
509 |
adx |
30 |
|
510 |
michael |
6681 |
if ((node = dlinkFindDelete(&chptr->invites, client_p))) |
511 |
michael |
4800 |
free_dlink_node(node); |
512 |
adx |
30 |
} |
513 |
|
|
|
514 |
michael |
4811 |
/*! \brief Removes all invites of a specific channel |
515 |
|
|
* \param chptr Pointer to Channel struct |
516 |
|
|
*/ |
517 |
|
|
void |
518 |
michael |
5852 |
clear_invites_channel(struct Channel *chptr) |
519 |
michael |
4811 |
{ |
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 |
5853 |
/*! \brief Removes all invites of a specific client |
527 |
michael |
6681 |
* \param client_p Pointer to Client struct |
528 |
michael |
5853 |
*/ |
529 |
michael |
5852 |
void |
530 |
michael |
6681 |
clear_invites_client(struct Client *client_p) |
531 |
michael |
5852 |
{ |
532 |
|
|
dlink_node *node = NULL, *node_next = NULL; |
533 |
|
|
|
534 |
michael |
6681 |
DLINK_FOREACH_SAFE(node, node_next, client_p->connection->invited.head) |
535 |
|
|
del_invite(node->data, client_p); |
536 |
michael |
5852 |
} |
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 |
4815 |
get_member_status(const struct Membership *member, const int combine) |
551 |
adx |
30 |
{ |
552 |
michael |
6904 |
static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1]; /* +1 for \0 */ |
553 |
michael |
1902 |
char *p = buffer; |
554 |
adx |
30 |
|
555 |
michael |
4815 |
if (member->flags & CHFL_CHANOP) |
556 |
adx |
30 |
{ |
557 |
|
|
if (!combine) |
558 |
|
|
return "@"; |
559 |
|
|
*p++ = '@'; |
560 |
|
|
} |
561 |
|
|
|
562 |
michael |
4815 |
if (member->flags & CHFL_HALFOP) |
563 |
adx |
30 |
{ |
564 |
|
|
if (!combine) |
565 |
|
|
return "%"; |
566 |
|
|
*p++ = '%'; |
567 |
|
|
} |
568 |
|
|
|
569 |
michael |
4815 |
if (member->flags & CHFL_VOICE) |
570 |
adx |
30 |
*p++ = '+'; |
571 |
|
|
*p = '\0'; |
572 |
|
|
|
573 |
|
|
return buffer; |
574 |
|
|
} |
575 |
|
|
|
576 |
|
|
/*! |
577 |
michael |
6681 |
* \param client_p 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 |
michael |
6681 |
find_bmask(const struct Client *client_p, const dlink_list *const list) |
583 |
adx |
30 |
{ |
584 |
michael |
4800 |
const dlink_node *node = NULL; |
585 |
adx |
30 |
|
586 |
michael |
4800 |
DLINK_FOREACH(node, list->head) |
587 |
adx |
30 |
{ |
588 |
michael |
4815 |
const struct Ban *ban = node->data; |
589 |
adx |
30 |
|
590 |
michael |
6681 |
if (!match(ban->name, client_p->name) && !match(ban->user, client_p->username)) |
591 |
michael |
371 |
{ |
592 |
michael |
4815 |
switch (ban->type) |
593 |
michael |
371 |
{ |
594 |
|
|
case HM_HOST: |
595 |
michael |
6681 |
if (!match(ban->host, client_p->host) || !match(ban->host, client_p->sockhost)) |
596 |
michael |
371 |
return 1; |
597 |
|
|
break; |
598 |
|
|
case HM_IPV4: |
599 |
michael |
6681 |
if (client_p->connection->aftype == AF_INET) |
600 |
|
|
if (match_ipv4(&client_p->connection->ip, &ban->addr, ban->bits)) |
601 |
michael |
371 |
return 1; |
602 |
|
|
break; |
603 |
|
|
case HM_IPV6: |
604 |
michael |
6681 |
if (client_p->connection->aftype == AF_INET6) |
605 |
|
|
if (match_ipv6(&client_p->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 |
6681 |
* \param chptr Pointer to channel block |
619 |
|
|
* \param client_p Pointer to client to check access fo |
620 |
adx |
30 |
* \return 0 if not banned, 1 otherwise |
621 |
|
|
*/ |
622 |
|
|
int |
623 |
michael |
6681 |
is_banned(const struct Channel *chptr, const struct Client *client_p) |
624 |
adx |
30 |
{ |
625 |
michael |
6681 |
if (find_bmask(client_p, &chptr->banlist)) |
626 |
|
|
if (!find_bmask(client_p, &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 |
michael |
6681 |
* \param client_p Pointer to client attempting to join |
634 |
michael |
3308 |
* \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 |
6881 |
static int |
640 |
michael |
6681 |
can_join(struct Client *client_p, const struct Channel *chptr, const char *key) |
641 |
adx |
30 |
{ |
642 |
michael |
6681 |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(client_p, UMODE_SSL)) |
643 |
michael |
1150 |
return ERR_SSLONLYCHAN; |
644 |
|
|
|
645 |
michael |
6681 |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED)) |
646 |
michael |
1173 |
return ERR_NEEDREGGEDNICK; |
647 |
|
|
|
648 |
michael |
6681 |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER)) |
649 |
michael |
1150 |
return ERR_OPERONLYCHAN; |
650 |
|
|
|
651 |
adx |
30 |
if (chptr->mode.mode & MODE_INVITEONLY) |
652 |
michael |
6681 |
if (!dlinkFind(&client_p->connection->invited, chptr)) |
653 |
|
|
if (!find_bmask(client_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 |
6681 |
if (is_banned(chptr, client_p)) |
664 |
michael |
2208 |
return ERR_BANNEDFROMCHAN; |
665 |
|
|
|
666 |
michael |
1834 |
return 0; |
667 |
adx |
30 |
} |
668 |
|
|
|
669 |
|
|
int |
670 |
michael |
4815 |
has_member_flags(const struct Membership *member, const unsigned int flags) |
671 |
adx |
30 |
{ |
672 |
michael |
4815 |
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 |
4800 |
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 |
4800 |
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 |
4800 |
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 |
4783 |
/*! Checks if a message contains control codes |
700 |
michael |
3888 |
* \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 |
3952 |
continue; /* No control code or CTCP */ |
712 |
michael |
1937 |
|
713 |
michael |
3888 |
if (*p == 27) /* Escape */ |
714 |
michael |
1937 |
{ |
715 |
michael |
3888 |
/* ISO 2022 charset shift sequence */ |
716 |
michael |
1937 |
if (*(p + 1) == '$' || |
717 |
|
|
*(p + 1) == '(') |
718 |
|
|
{ |
719 |
|
|
++p; |
720 |
|
|
continue; |
721 |
|
|
} |
722 |
|
|
} |
723 |
|
|
|
724 |
michael |
3888 |
return 1; /* Control code */ |
725 |
michael |
1937 |
} |
726 |
|
|
|
727 |
michael |
4783 |
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 |
michael |
6681 |
* \param client_p Pointer to Client struct |
733 |
michael |
4815 |
* \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 |
6681 |
can_send(struct Channel *chptr, struct Client *client_p, |
741 |
michael |
6858 |
struct Membership *member, const char *message, int notice) |
742 |
adx |
30 |
{ |
743 |
michael |
4785 |
const struct MaskItem *conf = NULL; |
744 |
michael |
1858 |
|
745 |
michael |
6681 |
if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE)) |
746 |
adx |
30 |
return CAN_SEND_OPV; |
747 |
|
|
|
748 |
michael |
7054 |
if (MyConnect(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV)) |
749 |
michael |
6681 |
if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV))) |
750 |
|
|
if ((conf = match_find_resv(chptr->name)) && !resv_find_exempt(client_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 |
4884 |
|
756 |
michael |
5464 |
if (chptr->mode.mode & MODE_NOCTCP) |
757 |
michael |
5465 |
if (*message == '\001' && strncmp(message + 1, "ACTION ", 7)) |
758 |
michael |
5464 |
return ERR_NOCTCP; |
759 |
|
|
|
760 |
michael |
6681 |
if (member || (member = find_channel_link(client_p, chptr))) |
761 |
michael |
5583 |
if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
762 |
adx |
30 |
return CAN_SEND_OPV; |
763 |
michael |
4884 |
|
764 |
michael |
4815 |
if (!member && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
765 |
michael |
2441 |
return ERR_CANNOTSENDTOCHAN; |
766 |
michael |
4884 |
|
767 |
michael |
1944 |
if (chptr->mode.mode & MODE_MODERATED) |
768 |
|
|
return ERR_CANNOTSENDTOCHAN; |
769 |
michael |
4884 |
|
770 |
michael |
6681 |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED)) |
771 |
michael |
1944 |
return ERR_NEEDREGGEDNICK; |
772 |
adx |
30 |
|
773 |
michael |
6858 |
if ((chptr->mode.mode & MODE_NONOTICE) && notice) |
774 |
|
|
return ERR_CANNOTSENDTOCHAN; |
775 |
|
|
|
776 |
michael |
3308 |
/* Cache can send if banned */ |
777 |
michael |
7054 |
if (MyConnect(client_p)) |
778 |
michael |
1944 |
{ |
779 |
michael |
4815 |
if (member) |
780 |
adx |
30 |
{ |
781 |
michael |
4815 |
if (member->flags & CHFL_BAN_SILENCED) |
782 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
783 |
adx |
30 |
|
784 |
michael |
4815 |
if (!(member->flags & CHFL_BAN_CHECKED)) |
785 |
adx |
30 |
{ |
786 |
michael |
6681 |
if (is_banned(chptr, client_p)) |
787 |
adx |
30 |
{ |
788 |
michael |
5583 |
member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED); |
789 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
790 |
adx |
30 |
} |
791 |
|
|
|
792 |
michael |
4815 |
member->flags |= CHFL_BAN_CHECKED; |
793 |
adx |
30 |
} |
794 |
|
|
} |
795 |
michael |
6681 |
else if (is_banned(chptr, client_p)) |
796 |
michael |
1941 |
return ERR_CANNOTSENDTOCHAN; |
797 |
|
|
} |
798 |
adx |
30 |
|
799 |
|
|
return CAN_SEND_NONOP; |
800 |
|
|
} |
801 |
|
|
|
802 |
|
|
/*! \brief Updates the client's oper_warn_count_down, warns the |
803 |
|
|
* IRC operators if necessary, and updates |
804 |
|
|
* join_leave_countdown as needed. |
805 |
michael |
6682 |
* \param client_p Pointer to struct Client to check |
806 |
michael |
3308 |
* \param name Channel name or NULL if this is a part. |
807 |
adx |
30 |
*/ |
808 |
|
|
void |
809 |
michael |
6682 |
check_spambot_warning(struct Client *client_p, const char *name) |
810 |
adx |
30 |
{ |
811 |
|
|
int t_delta = 0; |
812 |
|
|
int decrement_count = 0; |
813 |
|
|
|
814 |
|
|
if ((GlobalSetOptions.spam_num && |
815 |
michael |
6682 |
(client_p->connection->join_leave_count >= |
816 |
adx |
30 |
GlobalSetOptions.spam_num))) |
817 |
|
|
{ |
818 |
michael |
6682 |
if (client_p->connection->oper_warn_count_down > 0) |
819 |
|
|
client_p->connection->oper_warn_count_down--; |
820 |
adx |
30 |
else |
821 |
michael |
6682 |
client_p->connection->oper_warn_count_down = 0; |
822 |
adx |
30 |
|
823 |
michael |
6682 |
if (client_p->connection->oper_warn_count_down == 0) |
824 |
adx |
30 |
{ |
825 |
michael |
3308 |
/* It's already known as a possible spambot */ |
826 |
michael |
3235 |
if (name) |
827 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
828 |
adx |
30 |
"User %s (%s@%s) trying to join %s is a possible spambot", |
829 |
michael |
6682 |
client_p->name, client_p->username, |
830 |
|
|
client_p->host, name); |
831 |
adx |
30 |
else |
832 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
833 |
adx |
30 |
"User %s (%s@%s) is a possible spambot", |
834 |
michael |
6682 |
client_p->name, client_p->username, |
835 |
|
|
client_p->host); |
836 |
|
|
client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN; |
837 |
adx |
30 |
} |
838 |
|
|
} |
839 |
|
|
else |
840 |
|
|
{ |
841 |
michael |
6682 |
if ((t_delta = (CurrentTime - client_p->connection->last_leave_time)) > |
842 |
adx |
30 |
JOIN_LEAVE_COUNT_EXPIRE_TIME) |
843 |
|
|
{ |
844 |
|
|
decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); |
845 |
michael |
4884 |
|
846 |
michael |
6682 |
if (decrement_count > client_p->connection->join_leave_count) |
847 |
|
|
client_p->connection->join_leave_count = 0; |
848 |
adx |
30 |
else |
849 |
michael |
6682 |
client_p->connection->join_leave_count -= decrement_count; |
850 |
adx |
30 |
} |
851 |
|
|
else |
852 |
|
|
{ |
853 |
michael |
6682 |
if ((CurrentTime - (client_p->connection->last_join_time)) < |
854 |
adx |
30 |
GlobalSetOptions.spam_time) |
855 |
michael |
6682 |
client_p->connection->join_leave_count++; /* It's a possible spambot */ |
856 |
adx |
30 |
} |
857 |
|
|
|
858 |
michael |
3215 |
if (name) |
859 |
michael |
6682 |
client_p->connection->last_join_time = CurrentTime; |
860 |
adx |
30 |
else |
861 |
michael |
6682 |
client_p->connection->last_leave_time = CurrentTime; |
862 |
adx |
30 |
} |
863 |
|
|
} |
864 |
|
|
|
865 |
michael |
3308 |
/*! \brief Sets the channel topic for a certain channel |
866 |
adx |
30 |
* \param chptr Pointer to struct Channel |
867 |
|
|
* \param topic The topic string |
868 |
|
|
* \param topic_info n!u\@h formatted string of the topic setter |
869 |
michael |
3308 |
* \param topicts Timestamp on the topic |
870 |
|
|
* \param local Whether the topic is set by a local client |
871 |
adx |
30 |
*/ |
872 |
|
|
void |
873 |
michael |
3941 |
channel_set_topic(struct Channel *chptr, const char *topic, |
874 |
michael |
1751 |
const char *topic_info, time_t topicts, int local) |
875 |
adx |
30 |
{ |
876 |
michael |
1751 |
if (local) |
877 |
michael |
4340 |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1)); |
878 |
michael |
1751 |
else |
879 |
|
|
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
880 |
|
|
|
881 |
michael |
1203 |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
882 |
michael |
2345 |
chptr->topic_time = topicts; |
883 |
adx |
30 |
} |
884 |
michael |
3912 |
|
885 |
|
|
/* do_join_0() |
886 |
|
|
* |
887 |
|
|
* inputs - pointer to client doing join 0 |
888 |
|
|
* output - NONE |
889 |
|
|
* side effects - Use has decided to join 0. This is legacy |
890 |
|
|
* from the days when channels were numbers not names. *sigh* |
891 |
|
|
* There is a bunch of evilness necessary here due to |
892 |
|
|
* anti spambot code. |
893 |
|
|
*/ |
894 |
|
|
void |
895 |
michael |
6682 |
channel_do_join_0(struct Client *client_p) |
896 |
michael |
3912 |
{ |
897 |
michael |
4800 |
dlink_node *node = NULL, *node_next = NULL; |
898 |
michael |
3912 |
|
899 |
michael |
6682 |
if (client_p->channel.head) |
900 |
|
|
if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER)) |
901 |
|
|
check_spambot_warning(client_p, NULL); |
902 |
michael |
3912 |
|
903 |
michael |
6682 |
DLINK_FOREACH_SAFE(node, node_next, client_p->channel.head) |
904 |
michael |
3912 |
{ |
905 |
michael |
4800 |
struct Channel *chptr = ((struct Membership *)node->data)->chptr; |
906 |
michael |
3912 |
|
907 |
michael |
6682 |
sendto_server(client_p, 0, 0, ":%s PART %s", |
908 |
|
|
client_p->id, chptr->name); |
909 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s", |
910 |
michael |
6682 |
client_p->name, client_p->username, |
911 |
|
|
client_p->host, chptr->name); |
912 |
michael |
3912 |
|
913 |
michael |
4800 |
remove_user_from_channel(node->data); |
914 |
michael |
3912 |
} |
915 |
|
|
} |
916 |
|
|
|
917 |
|
|
static char * |
918 |
michael |
6682 |
channel_find_last0(struct Client *client_p, char *chanlist) |
919 |
michael |
3912 |
{ |
920 |
|
|
int join0 = 0; |
921 |
|
|
|
922 |
|
|
for (char *p = chanlist; *p; ++p) /* Find last "JOIN 0" */ |
923 |
|
|
{ |
924 |
|
|
if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0')) |
925 |
|
|
{ |
926 |
michael |
4756 |
if (*(p + 1) == ',') |
927 |
michael |
3912 |
++p; |
928 |
|
|
|
929 |
|
|
chanlist = p + 1; |
930 |
|
|
join0 = 1; |
931 |
|
|
} |
932 |
|
|
else |
933 |
|
|
{ |
934 |
|
|
while (*p != ',' && *p != '\0') /* Skip past channel name */ |
935 |
|
|
++p; |
936 |
|
|
|
937 |
|
|
if (*p == '\0') /* Hit the end */ |
938 |
|
|
break; |
939 |
|
|
} |
940 |
|
|
} |
941 |
|
|
|
942 |
|
|
if (join0) |
943 |
michael |
6682 |
channel_do_join_0(client_p); |
944 |
michael |
3912 |
|
945 |
|
|
return chanlist; |
946 |
|
|
} |
947 |
|
|
|
948 |
|
|
void |
949 |
michael |
6682 |
channel_do_join(struct Client *client_p, char *channel, char *key_list) |
950 |
michael |
3912 |
{ |
951 |
|
|
char *p = NULL; |
952 |
michael |
3937 |
char *chan = NULL; |
953 |
michael |
3912 |
char *chan_list = NULL; |
954 |
|
|
struct Channel *chptr = NULL; |
955 |
|
|
struct MaskItem *conf = NULL; |
956 |
michael |
6682 |
const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs); |
957 |
michael |
3912 |
int i = 0; |
958 |
|
|
unsigned int flags = 0; |
959 |
|
|
|
960 |
michael |
6682 |
assert(IsClient(client_p)); |
961 |
michael |
5590 |
|
962 |
michael |
6682 |
chan_list = channel_find_last0(client_p, channel); |
963 |
michael |
3912 |
|
964 |
michael |
6546 |
for (chan = strtok_r(chan_list, ",", &p); chan; |
965 |
|
|
chan = strtok_r(NULL, ",", &p)) |
966 |
michael |
3912 |
{ |
967 |
|
|
const char *key = NULL; |
968 |
|
|
|
969 |
|
|
/* If we have any more keys, take the first for this channel. */ |
970 |
|
|
if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ','))) |
971 |
|
|
*key_list++ = '\0'; |
972 |
|
|
|
973 |
|
|
/* Empty keys are the same as no keys. */ |
974 |
|
|
if (key && *key == '\0') |
975 |
|
|
key = NULL; |
976 |
|
|
|
977 |
michael |
6373 |
if (!channel_check_name(chan, 1)) |
978 |
michael |
3912 |
{ |
979 |
michael |
6682 |
sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, chan); |
980 |
michael |
3912 |
continue; |
981 |
|
|
} |
982 |
|
|
|
983 |
michael |
6682 |
if (!HasFlag(client_p, FLAGS_EXEMPTRESV) && |
984 |
|
|
!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) && |
985 |
|
|
((conf = match_find_resv(chan)) && !resv_find_exempt(client_p, conf))) |
986 |
michael |
3912 |
{ |
987 |
|
|
++conf->count; |
988 |
michael |
6682 |
sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, chan, conf->reason); |
989 |
michael |
4151 |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
990 |
michael |
3912 |
"Forbidding reserved channel %s from user %s", |
991 |
michael |
6682 |
chan, get_client_name(client_p, HIDE_IP)); |
992 |
michael |
3912 |
continue; |
993 |
|
|
} |
994 |
|
|
|
995 |
michael |
6682 |
if (dlink_list_length(&client_p->channel) >= |
996 |
michael |
3933 |
((class->max_channels) ? class->max_channels : ConfigChannel.max_channels)) |
997 |
michael |
3912 |
{ |
998 |
michael |
6682 |
sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, chan); |
999 |
michael |
3912 |
break; |
1000 |
|
|
} |
1001 |
|
|
|
1002 |
|
|
if ((chptr = hash_find_channel(chan))) |
1003 |
|
|
{ |
1004 |
michael |
6682 |
if (IsMember(client_p, chptr)) |
1005 |
michael |
3912 |
continue; |
1006 |
|
|
|
1007 |
|
|
/* |
1008 |
|
|
* can_join checks for +i key, bans. |
1009 |
|
|
*/ |
1010 |
michael |
6682 |
if ((i = can_join(client_p, chptr, key))) |
1011 |
michael |
3912 |
{ |
1012 |
michael |
6682 |
sendto_one_numeric(client_p, &me, i, chptr->name); |
1013 |
michael |
3912 |
continue; |
1014 |
|
|
} |
1015 |
|
|
|
1016 |
|
|
/* |
1017 |
|
|
* This should never be the case unless there is some sort of |
1018 |
|
|
* persistant channels. |
1019 |
|
|
*/ |
1020 |
michael |
4977 |
if (!dlink_list_length(&chptr->members)) |
1021 |
michael |
3912 |
flags = CHFL_CHANOP; |
1022 |
|
|
else |
1023 |
|
|
flags = 0; |
1024 |
|
|
} |
1025 |
|
|
else |
1026 |
|
|
{ |
1027 |
|
|
flags = CHFL_CHANOP; |
1028 |
michael |
6373 |
chptr = channel_make(chan); |
1029 |
michael |
3912 |
} |
1030 |
|
|
|
1031 |
michael |
6682 |
if (!HasUMode(client_p, UMODE_OPER)) |
1032 |
|
|
check_spambot_warning(client_p, chptr->name); |
1033 |
michael |
3912 |
|
1034 |
michael |
6682 |
add_user_to_channel(chptr, client_p, flags, 1); |
1035 |
michael |
3912 |
|
1036 |
|
|
/* |
1037 |
michael |
5545 |
* Set timestamp if appropriate, and propagate |
1038 |
michael |
3912 |
*/ |
1039 |
|
|
if (flags == CHFL_CHANOP) |
1040 |
|
|
{ |
1041 |
michael |
4818 |
chptr->creationtime = CurrentTime; |
1042 |
michael |
3912 |
chptr->mode.mode |= MODE_TOPICLIMIT; |
1043 |
|
|
chptr->mode.mode |= MODE_NOPRIVMSGS; |
1044 |
|
|
|
1045 |
michael |
6782 |
sendto_server(client_p, 0, 0, ":%s SJOIN %ju %s +nt :@%s", |
1046 |
|
|
me.id, chptr->creationtime, |
1047 |
michael |
6682 |
chptr->name, client_p->id); |
1048 |
michael |
3912 |
|
1049 |
|
|
/* |
1050 |
|
|
* Notify all other users on the new channel |
1051 |
|
|
*/ |
1052 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s", |
1053 |
|
|
client_p->name, client_p->username, |
1054 |
michael |
6827 |
client_p->host, chptr->name, client_p->account, client_p->info); |
1055 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s", |
1056 |
|
|
client_p->name, client_p->username, |
1057 |
|
|
client_p->host, chptr->name); |
1058 |
|
|
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s MODE %s +nt", |
1059 |
michael |
4618 |
me.name, chptr->name); |
1060 |
michael |
3912 |
|
1061 |
michael |
6682 |
if (client_p->away[0]) |
1062 |
michael |
6759 |
sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0, |
1063 |
|
|
":%s!%s@%s AWAY :%s", |
1064 |
|
|
client_p->name, client_p->username, |
1065 |
|
|
client_p->host, client_p->away); |
1066 |
michael |
3912 |
} |
1067 |
|
|
else |
1068 |
|
|
{ |
1069 |
michael |
6782 |
sendto_server(client_p, 0, 0, ":%s JOIN %ju %s +", |
1070 |
|
|
client_p->id, chptr->creationtime, |
1071 |
michael |
4618 |
chptr->name); |
1072 |
michael |
3912 |
|
1073 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s", |
1074 |
|
|
client_p->name, client_p->username, |
1075 |
michael |
6827 |
client_p->host, chptr->name, client_p->account, client_p->info); |
1076 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s", |
1077 |
|
|
client_p->name, client_p->username, |
1078 |
|
|
client_p->host, chptr->name); |
1079 |
michael |
4792 |
|
1080 |
michael |
6682 |
if (client_p->away[0]) |
1081 |
michael |
6759 |
sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0, |
1082 |
|
|
":%s!%s@%s AWAY :%s", |
1083 |
|
|
client_p->name, client_p->username, |
1084 |
|
|
client_p->host, client_p->away); |
1085 |
michael |
3912 |
} |
1086 |
|
|
|
1087 |
michael |
6682 |
del_invite(chptr, client_p); |
1088 |
michael |
3912 |
|
1089 |
|
|
if (chptr->topic[0]) |
1090 |
|
|
{ |
1091 |
michael |
6682 |
sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic); |
1092 |
|
|
sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name, |
1093 |
michael |
3912 |
chptr->topic_info, chptr->topic_time); |
1094 |
|
|
} |
1095 |
|
|
|
1096 |
michael |
6682 |
channel_member_names(client_p, chptr, 1); |
1097 |
michael |
3912 |
|
1098 |
michael |
6682 |
client_p->connection->last_join_time = CurrentTime; |
1099 |
michael |
3912 |
} |
1100 |
|
|
} |
1101 |
|
|
|
1102 |
|
|
/*! \brief Removes a client from a specific channel |
1103 |
michael |
6682 |
* \param client_p Pointer to source client to remove |
1104 |
michael |
3912 |
* \param name Name of channel to remove from |
1105 |
|
|
* \param reason Part reason to show |
1106 |
|
|
*/ |
1107 |
|
|
static void |
1108 |
michael |
6682 |
channel_part_one_client(struct Client *client_p, const char *name, const char *reason) |
1109 |
michael |
3912 |
{ |
1110 |
|
|
struct Channel *chptr = NULL; |
1111 |
michael |
4815 |
struct Membership *member = NULL; |
1112 |
michael |
3912 |
|
1113 |
|
|
if ((chptr = hash_find_channel(name)) == NULL) |
1114 |
|
|
{ |
1115 |
michael |
6682 |
sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name); |
1116 |
michael |
3912 |
return; |
1117 |
|
|
} |
1118 |
|
|
|
1119 |
michael |
6682 |
if ((member = find_channel_link(client_p, chptr)) == NULL) |
1120 |
michael |
3912 |
{ |
1121 |
michael |
6682 |
sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name); |
1122 |
michael |
3912 |
return; |
1123 |
|
|
} |
1124 |
|
|
|
1125 |
michael |
6682 |
if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER)) |
1126 |
|
|
check_spambot_warning(client_p, NULL); |
1127 |
michael |
3912 |
|
1128 |
|
|
/* |
1129 |
|
|
* Remove user from the old channel (if any) |
1130 |
|
|
* only allow /part reasons in -m chans |
1131 |
|
|
*/ |
1132 |
michael |
6682 |
if (*reason && (!MyConnect(client_p) || |
1133 |
michael |
6906 |
((client_p->connection->firsttime + |
1134 |
|
|
ConfigGeneral.anti_spam_exit_message_time) < CurrentTime && |
1135 |
|
|
can_send(chptr, client_p, member, reason, 0) < 0))) |
1136 |
michael |
3912 |
{ |
1137 |
michael |
6682 |
sendto_server(client_p, 0, 0, ":%s PART %s :%s", |
1138 |
|
|
client_p->id, chptr->name, reason); |
1139 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s :%s", |
1140 |
michael |
6682 |
client_p->name, client_p->username, |
1141 |
|
|
client_p->host, chptr->name, reason); |
1142 |
michael |
3912 |
} |
1143 |
|
|
else |
1144 |
|
|
{ |
1145 |
michael |
6682 |
sendto_server(client_p, 0, 0, ":%s PART %s", |
1146 |
|
|
client_p->id, chptr->name); |
1147 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s", |
1148 |
michael |
6682 |
client_p->name, client_p->username, |
1149 |
|
|
client_p->host, chptr->name); |
1150 |
michael |
3912 |
} |
1151 |
|
|
|
1152 |
michael |
4815 |
remove_user_from_channel(member); |
1153 |
michael |
3912 |
} |
1154 |
|
|
|
1155 |
|
|
void |
1156 |
michael |
6682 |
channel_do_part(struct Client *client_p, char *channel, const char *reason) |
1157 |
michael |
3912 |
{ |
1158 |
|
|
char *p = NULL, *name = NULL; |
1159 |
michael |
4785 |
char buf[KICKLEN + 1] = ""; |
1160 |
michael |
3912 |
|
1161 |
michael |
6682 |
assert(IsClient(client_p)); |
1162 |
michael |
5590 |
|
1163 |
michael |
3937 |
if (!EmptyString(reason)) |
1164 |
michael |
4785 |
strlcpy(buf, reason, sizeof(buf)); |
1165 |
michael |
3912 |
|
1166 |
michael |
6546 |
for (name = strtok_r(channel, ",", &p); name; |
1167 |
|
|
name = strtok_r(NULL, ",", &p)) |
1168 |
michael |
6682 |
channel_part_one_client(client_p, name, buf); |
1169 |
michael |
3912 |
} |