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