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