1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
|
* |
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 |
35 |
|
#include "irc_string.h" |
36 |
|
#include "ircd.h" |
37 |
|
#include "numeric.h" |
38 |
< |
#include "s_serv.h" /* captab */ |
39 |
< |
#include "s_user.h" |
38 |
> |
#include "server.h" |
39 |
|
#include "send.h" |
40 |
|
#include "event.h" |
41 |
|
#include "memory.h" |
42 |
|
#include "mempool.h" |
43 |
< |
#include "s_misc.h" |
43 |
> |
#include "misc.h" |
44 |
|
#include "resv.h" |
45 |
|
|
47 |
– |
struct config_channel_entry ConfigChannel; |
48 |
– |
dlink_list global_channel_list = { NULL, NULL, 0 }; |
49 |
– |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
46 |
|
|
47 |
< |
static mp_pool_t *member_pool = NULL; |
48 |
< |
static mp_pool_t *channel_pool = NULL; |
47 |
> |
dlink_list channel_list; |
48 |
> |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
49 |
|
|
50 |
+ |
static mp_pool_t *member_pool, *channel_pool; |
51 |
|
static char buf[IRCD_BUFSIZE]; |
55 |
– |
static char modebuf[MODEBUFLEN]; |
56 |
– |
static char parabuf[MODEBUFLEN]; |
52 |
|
|
53 |
|
|
54 |
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
58 |
|
{ |
59 |
|
add_capability("EX", CAP_EX, 1); |
60 |
|
add_capability("IE", CAP_IE, 1); |
66 |
– |
add_capability("CHW", CAP_CHW, 1); |
61 |
|
|
62 |
|
channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL); |
63 |
|
ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN); |
64 |
|
member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER); |
65 |
|
} |
66 |
|
|
67 |
< |
/*! \brief adds a user to a channel by adding another link to the |
67 |
> |
/*! \brief Adds a user to a channel by adding another link to the |
68 |
|
* channels member chain. |
69 |
< |
* \param chptr pointer to channel to add client to |
70 |
< |
* \param who pointer to client (who) to add |
71 |
< |
* \param flags flags for chanops etc |
72 |
< |
* \param flood_ctrl whether to count this join in flood calculations |
69 |
> |
* \param chptr Pointer to channel to add client to |
70 |
> |
* \param who Pointer to client (who) to add |
71 |
> |
* \param flags Flags for chanops etc |
72 |
> |
* \param flood_ctrl Whether to count this join in flood calculations |
73 |
|
*/ |
74 |
|
void |
75 |
|
add_user_to_channel(struct Channel *chptr, struct Client *who, |
80 |
|
if (GlobalSetOptions.joinfloodtime > 0) |
81 |
|
{ |
82 |
|
if (flood_ctrl) |
83 |
< |
chptr->number_joined++; |
83 |
> |
++chptr->number_joined; |
84 |
|
|
85 |
|
chptr->number_joined -= (CurrentTime - chptr->last_join_time) * |
86 |
|
(((float)GlobalSetOptions.joinfloodcount) / |
119 |
|
dlinkAdd(ms, &ms->usernode, &who->channel); |
120 |
|
} |
121 |
|
|
122 |
< |
/*! \brief deletes an user from a channel by removing a link in the |
122 |
> |
/*! \brief Deletes an user from a channel by removing a link in the |
123 |
|
* channels member chain. |
124 |
< |
* \param member pointer to Membership struct |
124 |
> |
* \param member Pointer to Membership struct |
125 |
|
*/ |
126 |
|
void |
127 |
|
remove_user_from_channel(struct Membership *member) |
146 |
|
*/ |
147 |
|
static void |
148 |
|
send_members(struct Client *client_p, struct Channel *chptr, |
149 |
< |
char *lmodebuf, char *lparabuf) |
149 |
> |
char *modebuf, char *parabuf) |
150 |
|
{ |
151 |
|
const dlink_node *ptr = NULL; |
152 |
|
int tlen; /* length of text to append */ |
153 |
|
char *t, *start; /* temp char pointer */ |
154 |
|
|
155 |
|
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:", |
156 |
< |
ID_or_name(&me, client_p), |
157 |
< |
(unsigned long)chptr->channelts, |
164 |
< |
chptr->chname, lmodebuf, lparabuf); |
156 |
> |
me.id, (unsigned long)chptr->channelts, |
157 |
> |
chptr->chname, modebuf, parabuf); |
158 |
|
|
159 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
160 |
|
{ |
161 |
|
const struct Membership *ms = ptr->data; |
162 |
|
|
163 |
< |
tlen = strlen(IsCapable(client_p, CAP_TS6) ? |
171 |
< |
ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */ |
163 |
> |
tlen = strlen(ms->client_p->id) + 1; /* +1 for space */ |
164 |
|
|
165 |
|
if (ms->flags & CHFL_CHANOP) |
166 |
< |
tlen++; |
167 |
< |
#ifdef HALFOPS |
168 |
< |
else if (ms->flags & CHFL_HALFOP) |
177 |
< |
tlen++; |
178 |
< |
#endif |
166 |
> |
++tlen; |
167 |
> |
if (ms->flags & CHFL_HALFOP) |
168 |
> |
++tlen; |
169 |
|
if (ms->flags & CHFL_VOICE) |
170 |
< |
tlen++; |
170 |
> |
++tlen; |
171 |
|
|
172 |
< |
/* space will be converted into CR, but we also need space for LF.. |
173 |
< |
* That's why we use '- 1' here |
174 |
< |
* -adx */ |
172 |
> |
/* |
173 |
> |
* Space will be converted into CR, but we also need space for LF.. |
174 |
> |
* That's why we use '- 1' here -adx |
175 |
> |
*/ |
176 |
|
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
177 |
|
{ |
178 |
< |
*(t - 1) = '\0'; /* kill the space and terminate the string */ |
178 |
> |
*(t - 1) = '\0'; /* Kill the space and terminate the string */ |
179 |
|
sendto_one(client_p, "%s", buf); |
180 |
|
t = start; |
181 |
|
} |
182 |
|
|
183 |
< |
if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP))) |
184 |
< |
*t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ? |
185 |
< |
'%' : '@'; |
186 |
< |
if ((ms->flags & CHFL_VOICE)) |
183 |
> |
if (ms->flags & CHFL_CHANOP) |
184 |
> |
*t++ = '@'; |
185 |
> |
if (ms->flags & CHFL_HALFOP) |
186 |
> |
*t++ = '%'; |
187 |
> |
if (ms->flags & CHFL_VOICE) |
188 |
|
*t++ = '+'; |
189 |
|
|
190 |
< |
if (IsCapable(client_p, CAP_TS6)) |
191 |
< |
strcpy(t, ID(ms->client_p)); |
200 |
< |
else |
201 |
< |
strcpy(t, ms->client_p->name); |
190 |
> |
strcpy(t, ms->client_p->id); |
191 |
> |
|
192 |
|
t += strlen(t); |
193 |
|
*t++ = ' '; |
194 |
|
} |
195 |
|
|
196 |
< |
/* should always be non-NULL unless we have a kind of persistent channels */ |
197 |
< |
if (chptr->members.head != NULL) |
198 |
< |
t--; /* take the space out */ |
196 |
> |
/* Should always be non-NULL unless we have a kind of persistent channels */ |
197 |
> |
if (chptr->members.head) |
198 |
> |
t--; /* Take the space out */ |
199 |
|
*t = '\0'; |
200 |
|
sendto_one(client_p, "%s", buf); |
201 |
|
} |
202 |
|
|
203 |
< |
/*! \brief sends +b/+e/+I |
204 |
< |
* \param client_p client pointer to server |
205 |
< |
* \param chptr pointer to channel |
206 |
< |
* \param top pointer to top of mode link list to send |
207 |
< |
* \param flag char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
203 |
> |
/*! \brief Sends +b/+e/+I |
204 |
> |
* \param client_p Client pointer to server |
205 |
> |
* \param chptr Pointer to channel |
206 |
> |
* \param list Pointer to list of modes to send |
207 |
> |
* \param flag Char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
208 |
|
*/ |
209 |
|
static void |
210 |
|
send_mode_list(struct Client *client_p, struct Channel *chptr, |
211 |
< |
const dlink_list *top, char flag) |
211 |
> |
const dlink_list *list, char flag) |
212 |
|
{ |
213 |
< |
int ts5 = !IsCapable(client_p, CAP_TS6); |
214 |
< |
const dlink_node *lp = NULL; |
215 |
< |
char pbuf[IRCD_BUFSIZE]; |
216 |
< |
int tlen, mlen, cur_len, count = 0; |
227 |
< |
char *mp = NULL, *pp = pbuf; |
213 |
> |
const dlink_node *ptr = NULL; |
214 |
> |
char pbuf[IRCD_BUFSIZE] = ""; |
215 |
> |
int tlen, mlen, cur_len; |
216 |
> |
char *pp = pbuf; |
217 |
|
|
218 |
< |
if (top == NULL || top->length == 0) |
218 |
> |
if (list->length == 0) |
219 |
|
return; |
220 |
|
|
221 |
< |
if (ts5) |
222 |
< |
mlen = snprintf(buf, sizeof(buf), ":%s MODE %s +", me.name, chptr->chname); |
223 |
< |
else |
235 |
< |
mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id, |
236 |
< |
(unsigned long)chptr->channelts, chptr->chname, flag); |
221 |
> |
mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id, |
222 |
> |
(unsigned long)chptr->channelts, chptr->chname, flag); |
223 |
> |
cur_len = mlen; |
224 |
|
|
225 |
< |
/* MODE needs additional one byte for space between buf and pbuf */ |
239 |
< |
cur_len = mlen + ts5; |
240 |
< |
mp = buf + mlen; |
241 |
< |
|
242 |
< |
DLINK_FOREACH(lp, top->head) |
225 |
> |
DLINK_FOREACH(ptr, list->head) |
226 |
|
{ |
227 |
< |
const struct Ban *banptr = lp->data; |
227 |
> |
const struct Ban *banptr = ptr->data; |
228 |
|
|
229 |
< |
/* must add another b/e/I letter if we use MODE */ |
247 |
< |
tlen = banptr->len + 3 + ts5; |
229 |
> |
tlen = banptr->len + 3; /* +3 for ! + @ + space */ |
230 |
|
|
231 |
|
/* |
232 |
< |
* send buffer and start over if we cannot fit another ban, |
251 |
< |
* or if the target is non-ts6 and we have too many modes in |
252 |
< |
* in this line. |
232 |
> |
* Send buffer and start over if we cannot fit another ban |
233 |
|
*/ |
234 |
< |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 || |
255 |
< |
(!IsCapable(client_p, CAP_TS6) && |
256 |
< |
(count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN))) |
234 |
> |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
235 |
|
{ |
236 |
< |
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
237 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
236 |
> |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
237 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
238 |
|
|
239 |
< |
cur_len = mlen + ts5; |
262 |
< |
mp = buf + mlen; |
239 |
> |
cur_len = mlen; |
240 |
|
pp = pbuf; |
264 |
– |
count = 0; |
265 |
– |
} |
266 |
– |
|
267 |
– |
count++; |
268 |
– |
if (ts5) |
269 |
– |
{ |
270 |
– |
*mp++ = flag; |
271 |
– |
*mp = '\0'; |
241 |
|
} |
242 |
|
|
243 |
< |
pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->username, |
243 |
> |
pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user, |
244 |
|
banptr->host); |
245 |
|
cur_len += tlen; |
246 |
|
} |
247 |
|
|
248 |
< |
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
249 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
248 |
> |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
249 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
250 |
|
} |
251 |
|
|
252 |
< |
/*! \brief send "client_p" a full list of the modes for channel chptr |
253 |
< |
* \param client_p pointer to client client_p |
254 |
< |
* \param chptr pointer to channel pointer |
252 |
> |
/*! \brief Send "client_p" a full list of the modes for channel chptr |
253 |
> |
* \param client_p Pointer to client client_p |
254 |
> |
* \param chptr Pointer to channel pointer |
255 |
|
*/ |
256 |
|
void |
257 |
|
send_channel_modes(struct Client *client_p, struct Channel *chptr) |
258 |
|
{ |
259 |
< |
*modebuf = *parabuf = '\0'; |
259 |
> |
char modebuf[MODEBUFLEN] = ""; |
260 |
> |
char parabuf[MODEBUFLEN] = ""; |
261 |
> |
|
262 |
|
channel_modes(chptr, client_p, modebuf, parabuf); |
263 |
|
send_members(client_p, chptr, modebuf, parabuf); |
264 |
|
|
267 |
|
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
268 |
|
} |
269 |
|
|
270 |
< |
/*! \brief check channel name for invalid characters |
271 |
< |
* \param name pointer to channel name string |
272 |
< |
* \param local indicates whether it's a local or remote creation |
270 |
> |
/*! \brief Check channel name for invalid characters |
271 |
> |
* \param name Pointer to channel name string |
272 |
> |
* \param local Indicates whether it's a local or remote creation |
273 |
|
* \return 0 if invalid, 1 otherwise |
274 |
|
*/ |
275 |
|
int |
276 |
|
check_channel_name(const char *name, const int local) |
277 |
|
{ |
278 |
|
const char *p = name; |
279 |
< |
const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
279 |
> |
|
280 |
|
assert(name != NULL); |
281 |
|
|
282 |
|
if (!IsChanPrefix(*p)) |
295 |
|
return 0; |
296 |
|
} |
297 |
|
|
298 |
< |
return p - name <= max_length; |
298 |
> |
return p - name <= CHANNELLEN; |
299 |
|
} |
300 |
|
|
301 |
|
void |
304 |
|
dlinkDelete(&bptr->node, list); |
305 |
|
|
306 |
|
MyFree(bptr->name); |
307 |
< |
MyFree(bptr->username); |
307 |
> |
MyFree(bptr->user); |
308 |
|
MyFree(bptr->host); |
309 |
|
MyFree(bptr->who); |
310 |
|
|
320 |
|
void |
321 |
|
free_channel_list(dlink_list *list) |
322 |
|
{ |
323 |
< |
dlink_node *ptr = NULL, *next_ptr = NULL; |
323 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
324 |
|
|
325 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) |
325 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, list->head) |
326 |
|
remove_ban(ptr->data, list); |
327 |
|
|
328 |
|
assert(list->tail == NULL && list->head == NULL); |
330 |
|
|
331 |
|
/*! \brief Get Channel block for chname (and allocate a new channel |
332 |
|
* block, if it didn't exist before) |
333 |
< |
* \param chname channel name |
334 |
< |
* \return channel block |
333 |
> |
* \param chname Channel name |
334 |
> |
* \return Channel block |
335 |
|
*/ |
336 |
|
struct Channel * |
337 |
|
make_channel(const char *chname) |
344 |
|
|
345 |
|
memset(chptr, 0, sizeof(*chptr)); |
346 |
|
|
347 |
< |
/* doesn't hurt to set it here */ |
347 |
> |
/* Doesn't hurt to set it here */ |
348 |
|
chptr->channelts = CurrentTime; |
349 |
|
chptr->last_join_time = CurrentTime; |
350 |
|
|
351 |
|
strlcpy(chptr->chname, chname, sizeof(chptr->chname)); |
352 |
< |
dlinkAdd(chptr, &chptr->node, &global_channel_list); |
352 |
> |
dlinkAdd(chptr, &chptr->node, &channel_list); |
353 |
|
|
354 |
|
hash_add_channel(chptr); |
355 |
|
|
356 |
|
return chptr; |
357 |
|
} |
358 |
|
|
359 |
< |
/*! \brief walk through this channel, and destroy it. |
360 |
< |
* \param chptr channel pointer |
359 |
> |
/*! \brief Walk through this channel, and destroy it. |
360 |
> |
* \param chptr Channel pointer |
361 |
|
*/ |
362 |
|
void |
363 |
|
destroy_channel(struct Channel *chptr) |
367 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head) |
368 |
|
del_invite(chptr, ptr->data); |
369 |
|
|
370 |
< |
/* free ban/exception/invex lists */ |
370 |
> |
/* Free ban/exception/invex lists */ |
371 |
|
free_channel_list(&chptr->banlist); |
372 |
|
free_channel_list(&chptr->exceptlist); |
373 |
|
free_channel_list(&chptr->invexlist); |
374 |
|
|
375 |
< |
dlinkDelete(&chptr->node, &global_channel_list); |
375 |
> |
dlinkDelete(&chptr->node, &channel_list); |
376 |
|
hash_del_channel(chptr); |
377 |
|
|
378 |
|
mp_pool_release(chptr); |
379 |
|
} |
380 |
|
|
381 |
|
/*! |
382 |
< |
* \param chptr pointer to channel |
383 |
< |
* \return string pointer "=" if public, "@" if secret else "*" |
382 |
> |
* \param chptr Pointer to channel |
383 |
> |
* \return String pointer "=" if public, "@" if secret else "*" |
384 |
|
*/ |
385 |
|
static const char * |
386 |
|
channel_pub_or_secret(const struct Channel *chptr) |
393 |
|
} |
394 |
|
|
395 |
|
/*! \brief lists all names on given channel |
396 |
< |
* \param source_p pointer to client struct requesting names |
397 |
< |
* \param chptr pointer to channel block |
398 |
< |
* \param show_eon show ENDOFNAMES numeric or not |
396 |
> |
* \param source_p Pointer to client struct requesting names |
397 |
> |
* \param chptr Pointer to channel block |
398 |
> |
* \param show_eon Show RPL_ENDOFNAMES numeric or not |
399 |
|
* (don't want it with /names with no params) |
400 |
|
*/ |
401 |
|
void |
403 |
|
int show_eon) |
404 |
|
{ |
405 |
|
const dlink_node *ptr = NULL; |
406 |
< |
char lbuf[IRCD_BUFSIZE + 1]; |
406 |
> |
char lbuf[IRCD_BUFSIZE + 1] = ""; |
407 |
|
char *t = NULL, *start = NULL; |
408 |
|
int tlen = 0; |
409 |
|
int is_member = IsMember(source_p, chptr); |
410 |
|
int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0; |
411 |
+ |
int uhnames = HasCap(source_p, CAP_UHNAMES) != 0; |
412 |
|
|
413 |
|
if (PubChannel(chptr) || is_member) |
414 |
|
{ |
415 |
< |
t = lbuf + snprintf(lbuf, sizeof(lbuf), form_str(RPL_NAMREPLY), |
415 |
> |
t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY), |
416 |
|
me.name, source_p->name, |
417 |
|
channel_pub_or_secret(chptr), chptr->chname); |
418 |
|
start = t; |
424 |
|
if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member) |
425 |
|
continue; |
426 |
|
|
427 |
< |
tlen = strlen(ms->client_p->name) + 1; /* nick + space */ |
427 |
> |
if (!uhnames) |
428 |
> |
tlen = strlen(ms->client_p->name) + 1; /* +1 for space */ |
429 |
> |
else |
430 |
> |
tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) + |
431 |
> |
strlen(ms->client_p->host) + 3; /* +3 for ! + @ + space */ |
432 |
|
|
433 |
|
if (!multi_prefix) |
434 |
|
{ |
452 |
|
t = start; |
453 |
|
} |
454 |
|
|
455 |
< |
t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
456 |
< |
ms->client_p->name); |
455 |
> |
if (!uhnames) |
456 |
> |
t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
457 |
> |
ms->client_p->name); |
458 |
> |
else |
459 |
> |
t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix), |
460 |
> |
ms->client_p->name, ms->client_p->username, |
461 |
> |
ms->client_p->host); |
462 |
|
} |
463 |
|
|
464 |
< |
if (tlen != 0) |
464 |
> |
if (tlen) |
465 |
|
{ |
466 |
|
*(t - 1) = '\0'; |
467 |
|
sendto_one(source_p, "%s", lbuf); |
469 |
|
} |
470 |
|
|
471 |
|
if (show_eon) |
472 |
< |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
492 |
< |
me.name, source_p->name, chptr->chname); |
472 |
> |
sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname); |
473 |
|
} |
474 |
|
|
475 |
< |
/*! \brief adds client to invite list |
476 |
< |
* \param chptr pointer to channel block |
477 |
< |
* \param who pointer to client to add invite to |
475 |
> |
/*! \brief Adds client to invite list |
476 |
> |
* \param chptr Pointer to channel block |
477 |
> |
* \param who Pointer to client to add invite to |
478 |
|
*/ |
479 |
|
void |
480 |
|
add_invite(struct Channel *chptr, struct Client *who) |
482 |
|
del_invite(chptr, who); |
483 |
|
|
484 |
|
/* |
485 |
< |
* delete last link in chain if the list is max length |
485 |
> |
* Delete last link in chain if the list is max length |
486 |
|
*/ |
487 |
|
if (dlink_list_length(&who->localClient->invited) >= |
488 |
< |
ConfigChannel.max_chans_per_user) |
488 |
> |
ConfigChannel.max_channels) |
489 |
|
del_invite(who->localClient->invited.tail->data, who); |
490 |
|
|
491 |
< |
/* add client to channel invite list */ |
491 |
> |
/* Add client to channel invite list */ |
492 |
|
dlinkAdd(who, make_dlink_node(), &chptr->invites); |
493 |
|
|
494 |
< |
/* add channel to the end of the client invite list */ |
494 |
> |
/* Add channel to the end of the client invite list */ |
495 |
|
dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited); |
496 |
|
} |
497 |
|
|
498 |
|
/*! \brief Delete Invite block from channel invite list |
499 |
|
* and client invite list |
500 |
< |
* \param chptr pointer to Channel struct |
501 |
< |
* \param who pointer to client to remove invites from |
500 |
> |
* \param chptr Pointer to Channel struct |
501 |
> |
* \param who Pointer to client to remove invites from |
502 |
|
*/ |
503 |
|
void |
504 |
|
del_invite(struct Channel *chptr, struct Client *who) |
524 |
|
* (like in get_client_name) |
525 |
|
*/ |
526 |
|
const char * |
527 |
< |
get_member_status(const struct Membership *ms, int combine) |
527 |
> |
get_member_status(const struct Membership *ms, const int combine) |
528 |
|
{ |
529 |
|
static char buffer[4]; |
530 |
|
char *p = buffer; |
536 |
|
*p++ = '@'; |
537 |
|
} |
538 |
|
|
559 |
– |
#ifdef HALFOPS |
539 |
|
if (ms->flags & CHFL_HALFOP) |
540 |
|
{ |
541 |
|
if (!combine) |
542 |
|
return "%"; |
543 |
|
*p++ = '%'; |
544 |
|
} |
566 |
– |
#endif |
545 |
|
|
546 |
|
if (ms->flags & CHFL_VOICE) |
547 |
|
*p++ = '+'; |
551 |
|
} |
552 |
|
|
553 |
|
/*! |
554 |
< |
* \param who pointer to Client to check |
555 |
< |
* \param list pointer to ban list to search |
554 |
> |
* \param who Pointer to Client to check |
555 |
> |
* \param list Pointer to ban list to search |
556 |
|
* \return 1 if ban found for given n!u\@h mask, 0 otherwise |
557 |
|
* |
558 |
|
*/ |
565 |
|
{ |
566 |
|
const struct Ban *bp = ptr->data; |
567 |
|
|
568 |
< |
if (!match(bp->name, who->name) && !match(bp->username, who->username)) |
568 |
> |
if (!match(bp->name, who->name) && !match(bp->user, who->username)) |
569 |
|
{ |
570 |
|
switch (bp->type) |
571 |
|
{ |
595 |
|
} |
596 |
|
|
597 |
|
/*! |
598 |
< |
* \param chptr pointer to channel block |
599 |
< |
* \param who pointer to client to check access fo |
598 |
> |
* \param chptr Pointer to channel block |
599 |
> |
* \param who Pointer to client to check access fo |
600 |
|
* \return 0 if not banned, 1 otherwise |
601 |
|
*/ |
602 |
|
int |
609 |
|
return 0; |
610 |
|
} |
611 |
|
|
612 |
< |
/*! |
613 |
< |
* \param source_p pointer to client attempting to join |
614 |
< |
* \param chptr pointer to channel |
615 |
< |
* \param key key sent by client attempting to join if present |
612 |
> |
/*! Tests if a client can join a certain channel |
613 |
> |
* \param source_p Pointer to client attempting to join |
614 |
> |
* \param chptr Pointer to channel |
615 |
> |
* \param key Key sent by client attempting to join if present |
616 |
|
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
617 |
|
* or 0 if allowed to join. |
618 |
|
*/ |
619 |
|
int |
620 |
|
can_join(struct Client *source_p, struct Channel *chptr, const char *key) |
621 |
|
{ |
622 |
< |
if (is_banned(chptr, source_p)) |
645 |
< |
return ERR_BANNEDFROMCHAN; |
646 |
< |
|
647 |
< |
#ifdef HAVE_LIBCRYPTO |
648 |
< |
if ((chptr->mode.mode & MODE_SSLONLY) && !source_p->localClient->fd.ssl) |
622 |
> |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
623 |
|
return ERR_SSLONLYCHAN; |
650 |
– |
#endif |
624 |
|
|
625 |
|
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
626 |
|
return ERR_NEEDREGGEDNICK; |
640 |
|
chptr->mode.limit) |
641 |
|
return ERR_CHANNELISFULL; |
642 |
|
|
643 |
+ |
if (is_banned(chptr, source_p)) |
644 |
+ |
return ERR_BANNEDFROMCHAN; |
645 |
+ |
|
646 |
|
return 0; |
647 |
|
} |
648 |
|
|
649 |
|
int |
650 |
|
has_member_flags(const struct Membership *ms, const unsigned int flags) |
651 |
|
{ |
652 |
< |
if (ms != NULL) |
677 |
< |
return ms->flags & flags; |
678 |
< |
return 0; |
652 |
> |
return ms && (ms->flags & flags); |
653 |
|
} |
654 |
|
|
655 |
|
struct Membership * |
660 |
|
if (!IsClient(client_p)) |
661 |
|
return NULL; |
662 |
|
|
663 |
< |
DLINK_FOREACH(ptr, client_p->channel.head) |
664 |
< |
if (((struct Membership *)ptr->data)->chptr == chptr) |
665 |
< |
return ptr->data; |
663 |
> |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
664 |
> |
{ |
665 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
666 |
> |
if (((struct Membership *)ptr->data)->client_p == client_p) |
667 |
> |
return ptr->data; |
668 |
> |
} |
669 |
> |
else |
670 |
> |
{ |
671 |
> |
DLINK_FOREACH(ptr, client_p->channel.head) |
672 |
> |
if (((struct Membership *)ptr->data)->chptr == chptr) |
673 |
> |
return ptr->data; |
674 |
> |
} |
675 |
|
|
676 |
|
return NULL; |
677 |
|
} |
678 |
|
|
679 |
< |
/* |
680 |
< |
* Basically the same functionality as in bahamut |
679 |
> |
/*! Tests if a client can send to a channel |
680 |
> |
* \param message The actual message string the client wants to send |
681 |
> |
* \return 1 if the message does contain any control codes, 0 otherwise |
682 |
|
*/ |
683 |
|
static int |
684 |
|
msg_has_ctrls(const char *message) |
688 |
|
for (; *p; ++p) |
689 |
|
{ |
690 |
|
if (*p > 31 || *p == 1) |
691 |
< |
continue; |
691 |
> |
continue; /* No control code or CTCP */ |
692 |
|
|
693 |
< |
if (*p == 27) |
693 |
> |
if (*p == 27) /* Escape */ |
694 |
|
{ |
695 |
+ |
/* ISO 2022 charset shift sequence */ |
696 |
|
if (*(p + 1) == '$' || |
697 |
|
*(p + 1) == '(') |
698 |
|
{ |
701 |
|
} |
702 |
|
} |
703 |
|
|
704 |
< |
return 1; |
704 |
> |
return 1; /* Control code */ |
705 |
|
} |
706 |
|
|
707 |
|
return 0; |
708 |
|
} |
709 |
|
|
710 |
< |
/*! |
711 |
< |
* \param chptr pointer to Channel struct |
712 |
< |
* \param source_p pointer to Client struct |
713 |
< |
* \param ms pointer to Membership struct (can be NULL) |
710 |
> |
/*! Tests if a client can send to a channel |
711 |
> |
* \param chptr Pointer to Channel struct |
712 |
> |
* \param source_p Pointer to Client struct |
713 |
> |
* \param ms Pointer to Membership struct (can be NULL) |
714 |
> |
* \param message The actual message string the client wants to send |
715 |
|
* \return CAN_SEND_OPV if op or voiced on channel\n |
716 |
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
717 |
|
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
735 |
|
if (ms || (ms = find_channel_link(source_p, chptr))) |
736 |
|
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
737 |
|
return CAN_SEND_OPV; |
738 |
+ |
if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
739 |
+ |
return ERR_CANNOTSENDTOCHAN; |
740 |
|
if (chptr->mode.mode & MODE_MODERATED) |
741 |
|
return ERR_CANNOTSENDTOCHAN; |
742 |
|
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
743 |
|
return ERR_NEEDREGGEDNICK; |
744 |
|
|
745 |
< |
/* cache can send if banned */ |
745 |
> |
/* Cache can send if banned */ |
746 |
|
if (MyClient(source_p)) |
747 |
|
{ |
748 |
|
if (ms) |
771 |
|
/*! \brief Updates the client's oper_warn_count_down, warns the |
772 |
|
* IRC operators if necessary, and updates |
773 |
|
* join_leave_countdown as needed. |
774 |
< |
* \param source_p pointer to struct Client to check |
775 |
< |
* \param name channel name or NULL if this is a part. |
774 |
> |
* \param source_p Pointer to struct Client to check |
775 |
> |
* \param name Channel name or NULL if this is a part. |
776 |
|
*/ |
777 |
|
void |
778 |
|
check_spambot_warning(struct Client *source_p, const char *name) |
791 |
|
|
792 |
|
if (source_p->localClient->oper_warn_count_down == 0) |
793 |
|
{ |
794 |
< |
/* Its already known as a possible spambot */ |
795 |
< |
if (name != NULL) |
794 |
> |
/* It's already known as a possible spambot */ |
795 |
> |
if (name) |
796 |
|
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
797 |
|
"User %s (%s@%s) trying to join %s is a possible spambot", |
798 |
|
source_p->name, source_p->username, |
820 |
|
{ |
821 |
|
if ((CurrentTime - (source_p->localClient->last_join_time)) < |
822 |
|
GlobalSetOptions.spam_time) |
823 |
< |
{ |
836 |
< |
/* oh, its a possible spambot */ |
837 |
< |
source_p->localClient->join_leave_count++; |
838 |
< |
} |
823 |
> |
source_p->localClient->join_leave_count++; /* It's a possible spambot */ |
824 |
|
} |
825 |
|
|
826 |
< |
if (name != NULL) |
826 |
> |
if (name) |
827 |
|
source_p->localClient->last_join_time = CurrentTime; |
828 |
|
else |
829 |
|
source_p->localClient->last_leave_time = CurrentTime; |
830 |
|
} |
831 |
|
} |
832 |
|
|
833 |
< |
/*! \brief compares usercount and servercount against their split |
833 |
> |
/*! \brief Compares usercount and servercount against their split |
834 |
|
* values and adjusts splitmode accordingly |
835 |
|
* \param unused Unused address pointer |
836 |
|
*/ |
861 |
|
} |
862 |
|
} |
863 |
|
|
864 |
< |
/*! \brief Sets the channel topic for chptr |
864 |
> |
/*! \brief Sets the channel topic for a certain channel |
865 |
|
* \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 |
< |
* \param topicts timestamp on the topic |
868 |
> |
* \param topicts Timestamp on the topic |
869 |
> |
* \param local Whether the topic is set by a local client |
870 |
|
*/ |
871 |
|
void |
872 |
< |
set_channel_topic(struct Channel *chptr, const char *topic, |
872 |
> |
channel_set_topic(struct Channel *chptr, const char *topic, |
873 |
|
const char *topic_info, time_t topicts, int local) |
874 |
|
{ |
875 |
|
if (local) |
878 |
|
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
879 |
|
|
880 |
|
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
881 |
< |
chptr->topic_time = topicts; |
881 |
> |
chptr->topic_time = topicts; |
882 |
> |
} |
883 |
> |
|
884 |
> |
/* do_join_0() |
885 |
> |
* |
886 |
> |
* inputs - pointer to client doing join 0 |
887 |
> |
* output - NONE |
888 |
> |
* side effects - Use has decided to join 0. This is legacy |
889 |
> |
* from the days when channels were numbers not names. *sigh* |
890 |
> |
* There is a bunch of evilness necessary here due to |
891 |
> |
* anti spambot code. |
892 |
> |
*/ |
893 |
> |
void |
894 |
> |
channel_do_join_0(struct Client *source_p) |
895 |
> |
{ |
896 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
897 |
> |
|
898 |
> |
if (source_p->channel.head) |
899 |
> |
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
900 |
> |
check_spambot_warning(source_p, NULL); |
901 |
> |
|
902 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head) |
903 |
> |
{ |
904 |
> |
struct Channel *chptr = ((struct Membership *)ptr->data)->chptr; |
905 |
> |
|
906 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s", |
907 |
> |
source_p->id, chptr->chname); |
908 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s", |
909 |
> |
source_p->name, source_p->username, |
910 |
> |
source_p->host, chptr->chname); |
911 |
> |
|
912 |
> |
remove_user_from_channel(ptr->data); |
913 |
> |
} |
914 |
> |
} |
915 |
> |
|
916 |
> |
static char * |
917 |
> |
channel_find_last0(struct Client *source_p, char *chanlist) |
918 |
> |
{ |
919 |
> |
int join0 = 0; |
920 |
> |
|
921 |
> |
for (char *p = chanlist; *p; ++p) /* Find last "JOIN 0" */ |
922 |
> |
{ |
923 |
> |
if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0')) |
924 |
> |
{ |
925 |
> |
if ((*p + 1) == ',') |
926 |
> |
++p; |
927 |
> |
|
928 |
> |
chanlist = p + 1; |
929 |
> |
join0 = 1; |
930 |
> |
} |
931 |
> |
else |
932 |
> |
{ |
933 |
> |
while (*p != ',' && *p != '\0') /* Skip past channel name */ |
934 |
> |
++p; |
935 |
> |
|
936 |
> |
if (*p == '\0') /* Hit the end */ |
937 |
> |
break; |
938 |
> |
} |
939 |
> |
} |
940 |
> |
|
941 |
> |
if (join0) |
942 |
> |
channel_do_join_0(source_p); |
943 |
> |
|
944 |
> |
return chanlist; |
945 |
> |
} |
946 |
> |
|
947 |
> |
void |
948 |
> |
channel_do_join(struct Client *source_p, char *channel, char *key_list) |
949 |
> |
{ |
950 |
> |
char *p = NULL; |
951 |
> |
char *chan = NULL; |
952 |
> |
char *chan_list = NULL; |
953 |
> |
struct Channel *chptr = NULL; |
954 |
> |
struct MaskItem *conf = NULL; |
955 |
> |
const struct ClassItem *class = get_class_ptr(&source_p->localClient->confs); |
956 |
> |
int i = 0; |
957 |
> |
unsigned int flags = 0; |
958 |
> |
|
959 |
> |
chan_list = channel_find_last0(source_p, channel); |
960 |
> |
|
961 |
> |
for (chan = strtoken(&p, chan_list, ","); chan; |
962 |
> |
chan = strtoken(&p, NULL, ",")) |
963 |
> |
{ |
964 |
> |
const char *key = NULL; |
965 |
> |
|
966 |
> |
/* If we have any more keys, take the first for this channel. */ |
967 |
> |
if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ','))) |
968 |
> |
*key_list++ = '\0'; |
969 |
> |
|
970 |
> |
/* Empty keys are the same as no keys. */ |
971 |
> |
if (key && *key == '\0') |
972 |
> |
key = NULL; |
973 |
> |
|
974 |
> |
if (!check_channel_name(chan, 1)) |
975 |
> |
{ |
976 |
> |
sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan); |
977 |
> |
continue; |
978 |
> |
} |
979 |
> |
|
980 |
> |
if (!IsExemptResv(source_p) && |
981 |
> |
!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) && |
982 |
> |
((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf))) |
983 |
> |
{ |
984 |
> |
++conf->count; |
985 |
> |
sendto_one_numeric(source_p, &me, ERR_CHANBANREASON, |
986 |
> |
chan, conf->reason ? conf->reason : "Reserved channel"); |
987 |
> |
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
988 |
> |
"Forbidding reserved channel %s from user %s", |
989 |
> |
chan, get_client_name(source_p, HIDE_IP)); |
990 |
> |
continue; |
991 |
> |
} |
992 |
> |
|
993 |
> |
if (dlink_list_length(&source_p->channel) >= |
994 |
> |
((class->max_channels) ? class->max_channels : ConfigChannel.max_channels)) |
995 |
> |
{ |
996 |
> |
sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan); |
997 |
> |
break; |
998 |
> |
} |
999 |
> |
|
1000 |
> |
if ((chptr = hash_find_channel(chan))) |
1001 |
> |
{ |
1002 |
> |
if (IsMember(source_p, chptr)) |
1003 |
> |
continue; |
1004 |
> |
|
1005 |
> |
if (splitmode && !HasUMode(source_p, UMODE_OPER) && |
1006 |
> |
ConfigChannel.no_join_on_split) |
1007 |
> |
{ |
1008 |
> |
sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->chname); |
1009 |
> |
continue; |
1010 |
> |
} |
1011 |
> |
|
1012 |
> |
/* |
1013 |
> |
* can_join checks for +i key, bans. |
1014 |
> |
*/ |
1015 |
> |
if ((i = can_join(source_p, chptr, key))) |
1016 |
> |
{ |
1017 |
> |
sendto_one_numeric(source_p, &me, i, chptr->chname); |
1018 |
> |
continue; |
1019 |
> |
} |
1020 |
> |
|
1021 |
> |
/* |
1022 |
> |
* This should never be the case unless there is some sort of |
1023 |
> |
* persistant channels. |
1024 |
> |
*/ |
1025 |
> |
if (dlink_list_length(&chptr->members) == 0) |
1026 |
> |
flags = CHFL_CHANOP; |
1027 |
> |
else |
1028 |
> |
flags = 0; |
1029 |
> |
} |
1030 |
> |
else |
1031 |
> |
{ |
1032 |
> |
if (splitmode && !HasUMode(source_p, UMODE_OPER) && |
1033 |
> |
(ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split)) |
1034 |
> |
{ |
1035 |
> |
sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chan); |
1036 |
> |
continue; |
1037 |
> |
} |
1038 |
> |
|
1039 |
> |
flags = CHFL_CHANOP; |
1040 |
> |
chptr = make_channel(chan); |
1041 |
> |
} |
1042 |
> |
|
1043 |
> |
if (!HasUMode(source_p, UMODE_OPER)) |
1044 |
> |
check_spambot_warning(source_p, chptr->chname); |
1045 |
> |
|
1046 |
> |
add_user_to_channel(chptr, source_p, flags, 1); |
1047 |
> |
|
1048 |
> |
/* |
1049 |
> |
* Set timestamp if appropriate, and propagate |
1050 |
> |
*/ |
1051 |
> |
if (flags == CHFL_CHANOP) |
1052 |
> |
{ |
1053 |
> |
chptr->channelts = CurrentTime; |
1054 |
> |
chptr->mode.mode |= MODE_TOPICLIMIT; |
1055 |
> |
chptr->mode.mode |= MODE_NOPRIVMSGS; |
1056 |
> |
|
1057 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s SJOIN %lu %s +nt :@%s", |
1058 |
> |
me.id, (unsigned long)chptr->channelts, |
1059 |
> |
chptr->chname, source_p->id); |
1060 |
> |
|
1061 |
> |
/* |
1062 |
> |
* Notify all other users on the new channel |
1063 |
> |
*/ |
1064 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s", |
1065 |
> |
source_p->name, source_p->username, |
1066 |
> |
source_p->host, chptr->chname); |
1067 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt", |
1068 |
> |
me.name, chptr->chname); |
1069 |
> |
|
1070 |
> |
if (source_p->away[0]) |
1071 |
> |
sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr, |
1072 |
> |
":%s!%s@%s AWAY :%s", |
1073 |
> |
source_p->name, source_p->username, |
1074 |
> |
source_p->host, source_p->away); |
1075 |
> |
} |
1076 |
> |
else |
1077 |
> |
{ |
1078 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s JOIN %lu %s +", |
1079 |
> |
source_p->id, (unsigned long)chptr->channelts, |
1080 |
> |
chptr->chname); |
1081 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s", |
1082 |
> |
source_p->name, source_p->username, |
1083 |
> |
source_p->host, chptr->chname); |
1084 |
> |
|
1085 |
> |
if (source_p->away[0]) |
1086 |
> |
sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr, |
1087 |
> |
":%s!%s@%s AWAY :%s", |
1088 |
> |
source_p->name, source_p->username, |
1089 |
> |
source_p->host, source_p->away); |
1090 |
> |
} |
1091 |
> |
|
1092 |
> |
del_invite(chptr, source_p); |
1093 |
> |
|
1094 |
> |
if (chptr->topic[0]) |
1095 |
> |
{ |
1096 |
> |
sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->chname, chptr->topic); |
1097 |
> |
sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->chname, |
1098 |
> |
chptr->topic_info, chptr->topic_time); |
1099 |
> |
} |
1100 |
> |
|
1101 |
> |
channel_member_names(source_p, chptr, 1); |
1102 |
> |
|
1103 |
> |
source_p->localClient->last_join_time = CurrentTime; |
1104 |
> |
} |
1105 |
> |
} |
1106 |
> |
|
1107 |
> |
/*! \brief Removes a client from a specific channel |
1108 |
> |
* \param source_p Pointer to source client to remove |
1109 |
> |
* \param name Name of channel to remove from |
1110 |
> |
* \param reason Part reason to show |
1111 |
> |
*/ |
1112 |
> |
static void |
1113 |
> |
channel_part_one_client(struct Client *source_p, const char *name, const char *reason) |
1114 |
> |
{ |
1115 |
> |
struct Channel *chptr = NULL; |
1116 |
> |
struct Membership *ms = NULL; |
1117 |
> |
|
1118 |
> |
if ((chptr = hash_find_channel(name)) == NULL) |
1119 |
> |
{ |
1120 |
> |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name); |
1121 |
> |
return; |
1122 |
> |
} |
1123 |
> |
|
1124 |
> |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
1125 |
> |
{ |
1126 |
> |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname); |
1127 |
> |
return; |
1128 |
> |
} |
1129 |
> |
|
1130 |
> |
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
1131 |
> |
check_spambot_warning(source_p, NULL); |
1132 |
> |
|
1133 |
> |
/* |
1134 |
> |
* Remove user from the old channel (if any) |
1135 |
> |
* only allow /part reasons in -m chans |
1136 |
> |
*/ |
1137 |
> |
if (*reason && (!MyConnect(source_p) || |
1138 |
> |
((can_send(chptr, source_p, ms, reason) && |
1139 |
> |
(source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) |
1140 |
> |
< CurrentTime)))) |
1141 |
> |
{ |
1142 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s :%s", |
1143 |
> |
source_p->id, chptr->chname, reason); |
1144 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s", |
1145 |
> |
source_p->name, source_p->username, |
1146 |
> |
source_p->host, chptr->chname, reason); |
1147 |
> |
} |
1148 |
> |
else |
1149 |
> |
{ |
1150 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s", |
1151 |
> |
source_p->id, chptr->chname); |
1152 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s", |
1153 |
> |
source_p->name, source_p->username, |
1154 |
> |
source_p->host, chptr->chname); |
1155 |
> |
} |
1156 |
> |
|
1157 |
> |
remove_user_from_channel(ms); |
1158 |
> |
} |
1159 |
> |
|
1160 |
> |
void |
1161 |
> |
channel_do_part(struct Client *source_p, char *channel, char *reason) |
1162 |
> |
{ |
1163 |
> |
char *p = NULL, *name = NULL; |
1164 |
> |
char reasonbuf[KICKLEN + 1] = ""; |
1165 |
> |
|
1166 |
> |
if (!EmptyString(reason)) |
1167 |
> |
strlcpy(reasonbuf, reason, sizeof(reasonbuf)); |
1168 |
> |
|
1169 |
> |
for (name = strtoken(&p, channel, ","); name; |
1170 |
> |
name = strtoken(&p, NULL, ",")) |
1171 |
> |
channel_part_one_client(source_p, name, reasonbuf); |
1172 |
|
} |