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 |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
28 |
< |
#include "tools.h" |
28 |
> |
#include "list.h" |
29 |
|
#include "channel.h" |
30 |
|
#include "channel_mode.h" |
31 |
|
#include "client.h" |
32 |
– |
#include "common.h" |
32 |
|
#include "hash.h" |
33 |
+ |
#include "conf.h" |
34 |
|
#include "hostmask.h" |
35 |
|
#include "irc_string.h" |
36 |
– |
#include "sprintf_irc.h" |
36 |
|
#include "ircd.h" |
38 |
– |
#include "list.h" |
37 |
|
#include "numeric.h" |
38 |
< |
#include "s_serv.h" /* captab */ |
41 |
< |
#include "s_user.h" |
38 |
> |
#include "server.h" |
39 |
|
#include "send.h" |
43 |
– |
#include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ |
40 |
|
#include "event.h" |
41 |
|
#include "memory.h" |
42 |
< |
#include "balloc.h" |
42 |
> |
#include "mempool.h" |
43 |
> |
#include "misc.h" |
44 |
> |
#include "resv.h" |
45 |
|
|
48 |
– |
struct config_channel_entry ConfigChannel; |
49 |
– |
dlink_list global_channel_list = { NULL, NULL, 0 }; |
50 |
– |
dlink_list lazylink_channels = { NULL, NULL, 0 }; |
51 |
– |
BlockHeap *ban_heap; /*! \todo ban_heap shouldn't be a global var */ |
52 |
– |
|
53 |
– |
static BlockHeap *topic_heap = NULL; |
54 |
– |
static BlockHeap *member_heap = NULL; |
55 |
– |
static BlockHeap *channel_heap = NULL; |
46 |
|
|
47 |
+ |
dlink_list channel_list; |
48 |
+ |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
49 |
+ |
|
50 |
+ |
struct event splitmode_event = |
51 |
+ |
{ |
52 |
+ |
.name = "check_splitmode", |
53 |
+ |
.handler = check_splitmode, |
54 |
+ |
.when = 5 |
55 |
+ |
}; |
56 |
+ |
|
57 |
+ |
static mp_pool_t *member_pool, *channel_pool; |
58 |
|
static char buf[IRCD_BUFSIZE]; |
58 |
– |
static char modebuf[MODEBUFLEN]; |
59 |
– |
static char parabuf[MODEBUFLEN]; |
59 |
|
|
60 |
|
|
61 |
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
62 |
|
*/ |
63 |
|
void |
64 |
< |
init_channels(void) |
64 |
> |
channel_init(void) |
65 |
|
{ |
66 |
|
add_capability("EX", CAP_EX, 1); |
67 |
|
add_capability("IE", CAP_IE, 1); |
69 |
– |
add_capability("CHW", CAP_CHW, 1); |
68 |
|
|
69 |
< |
channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE); |
70 |
< |
ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE); |
71 |
< |
topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE); |
74 |
< |
member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2); |
69 |
> |
channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL); |
70 |
> |
ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN); |
71 |
> |
member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER); |
72 |
|
} |
73 |
|
|
74 |
< |
/*! \brief adds a user to a channel by adding another link to the |
74 |
> |
/*! \brief Adds a user to a channel by adding another link to the |
75 |
|
* channels member chain. |
76 |
< |
* \param chptr pointer to channel to add client to |
77 |
< |
* \param who pointer to client (who) to add |
78 |
< |
* \param flags flags for chanops etc |
79 |
< |
* \param flood_ctrl whether to count this join in flood calculations |
76 |
> |
* \param chptr Pointer to channel to add client to |
77 |
> |
* \param who Pointer to client (who) to add |
78 |
> |
* \param flags Flags for chanops etc |
79 |
> |
* \param flood_ctrl Whether to count this join in flood calculations |
80 |
|
*/ |
81 |
|
void |
82 |
|
add_user_to_channel(struct Channel *chptr, struct Client *who, |
87 |
|
if (GlobalSetOptions.joinfloodtime > 0) |
88 |
|
{ |
89 |
|
if (flood_ctrl) |
90 |
< |
chptr->number_joined++; |
90 |
> |
++chptr->number_joined; |
91 |
|
|
92 |
|
chptr->number_joined -= (CurrentTime - chptr->last_join_time) * |
93 |
|
(((float)GlobalSetOptions.joinfloodcount) / |
105 |
|
if (!IsSetJoinFloodNoticed(chptr)) |
106 |
|
{ |
107 |
|
SetJoinFloodNoticed(chptr); |
108 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
108 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
109 |
|
"Possible Join Flooder %s on %s target: %s", |
110 |
|
get_client_name(who, HIDE_IP), |
111 |
|
who->servptr->name, chptr->chname); |
115 |
|
chptr->last_join_time = CurrentTime; |
116 |
|
} |
117 |
|
|
118 |
< |
ms = BlockHeapAlloc(member_heap); |
118 |
> |
ms = mp_pool_get(member_pool); |
119 |
|
ms->client_p = who; |
120 |
|
ms->chptr = chptr; |
121 |
|
ms->flags = flags; |
122 |
|
|
123 |
|
dlinkAdd(ms, &ms->channode, &chptr->members); |
124 |
+ |
|
125 |
+ |
if (MyConnect(who)) |
126 |
+ |
dlinkAdd(ms, &ms->locchannode, &chptr->locmembers); |
127 |
+ |
|
128 |
|
dlinkAdd(ms, &ms->usernode, &who->channel); |
129 |
|
} |
130 |
|
|
131 |
< |
/*! \brief deletes an user from a channel by removing a link in the |
131 |
> |
/*! \brief Deletes an user from a channel by removing a link in the |
132 |
|
* channels member chain. |
133 |
< |
* \param member pointer to Membership struct |
133 |
> |
* \param member Pointer to Membership struct |
134 |
|
*/ |
135 |
|
void |
136 |
|
remove_user_from_channel(struct Membership *member) |
139 |
|
struct Channel *chptr = member->chptr; |
140 |
|
|
141 |
|
dlinkDelete(&member->channode, &chptr->members); |
142 |
+ |
|
143 |
+ |
if (MyConnect(client_p)) |
144 |
+ |
dlinkDelete(&member->locchannode, &chptr->locmembers); |
145 |
+ |
|
146 |
|
dlinkDelete(&member->usernode, &client_p->channel); |
147 |
|
|
148 |
< |
BlockHeapFree(member_heap, member); |
148 |
> |
mp_pool_release(member); |
149 |
|
|
150 |
< |
if (dlink_list_length(&chptr->members) == 0) |
150 |
> |
if (chptr->members.head == NULL) |
151 |
|
destroy_channel(chptr); |
152 |
|
} |
153 |
|
|
159 |
|
*/ |
160 |
|
static void |
161 |
|
send_members(struct Client *client_p, struct Channel *chptr, |
162 |
< |
char *lmodebuf, char *lparabuf) |
162 |
> |
char *modebuf, char *parabuf) |
163 |
|
{ |
164 |
< |
struct Membership *ms; |
160 |
< |
dlink_node *ptr; |
164 |
> |
const dlink_node *ptr = NULL; |
165 |
|
int tlen; /* length of text to append */ |
166 |
|
char *t, *start; /* temp char pointer */ |
167 |
|
|
168 |
< |
start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:", |
169 |
< |
ID_or_name(&me, client_p), |
170 |
< |
(unsigned long)chptr->channelts, |
167 |
< |
chptr->chname, lmodebuf, lparabuf); |
168 |
> |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:", |
169 |
> |
me.id, (unsigned long)chptr->channelts, |
170 |
> |
chptr->chname, modebuf, parabuf); |
171 |
|
|
172 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
173 |
|
{ |
174 |
< |
ms = ptr->data; |
174 |
> |
const struct Membership *ms = ptr->data; |
175 |
|
|
176 |
< |
tlen = strlen(IsCapable(client_p, CAP_TS6) ? |
174 |
< |
ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */ |
176 |
> |
tlen = strlen(ms->client_p->id) + 1; /* +1 for space */ |
177 |
|
|
178 |
|
if (ms->flags & CHFL_CHANOP) |
179 |
< |
tlen++; |
180 |
< |
#ifdef HALFOPS |
181 |
< |
else if (ms->flags & CHFL_HALFOP) |
180 |
< |
tlen++; |
181 |
< |
#endif |
179 |
> |
++tlen; |
180 |
> |
if (ms->flags & CHFL_HALFOP) |
181 |
> |
++tlen; |
182 |
|
if (ms->flags & CHFL_VOICE) |
183 |
< |
tlen++; |
183 |
> |
++tlen; |
184 |
|
|
185 |
< |
/* space will be converted into CR, but we also need space for LF.. |
186 |
< |
* That's why we use '- 1' here |
187 |
< |
* -adx */ |
188 |
< |
if (t + tlen - buf > sizeof(buf) - 1) |
185 |
> |
/* |
186 |
> |
* Space will be converted into CR, but we also need space for LF.. |
187 |
> |
* That's why we use '- 1' here -adx |
188 |
> |
*/ |
189 |
> |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
190 |
|
{ |
191 |
< |
*(t - 1) = '\0'; /* kill the space and terminate the string */ |
191 |
> |
*(t - 1) = '\0'; /* Kill the space and terminate the string */ |
192 |
|
sendto_one(client_p, "%s", buf); |
193 |
|
t = start; |
194 |
|
} |
195 |
|
|
196 |
< |
if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP))) |
197 |
< |
*t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ? |
198 |
< |
'%' : '@'; |
199 |
< |
if ((ms->flags & CHFL_VOICE)) |
196 |
> |
if (ms->flags & CHFL_CHANOP) |
197 |
> |
*t++ = '@'; |
198 |
> |
if (ms->flags & CHFL_HALFOP) |
199 |
> |
*t++ = '%'; |
200 |
> |
if (ms->flags & CHFL_VOICE) |
201 |
|
*t++ = '+'; |
202 |
|
|
203 |
< |
if (IsCapable(client_p, CAP_TS6)) |
204 |
< |
strcpy(t, ID(ms->client_p)); |
203 |
< |
else |
204 |
< |
strcpy(t, ms->client_p->name); |
203 |
> |
strcpy(t, ms->client_p->id); |
204 |
> |
|
205 |
|
t += strlen(t); |
206 |
|
*t++ = ' '; |
207 |
|
} |
208 |
|
|
209 |
< |
/* should always be non-NULL unless we have a kind of persistent channels */ |
210 |
< |
if (chptr->members.head != NULL) |
211 |
< |
t--; /* take the space out */ |
209 |
> |
/* Should always be non-NULL unless we have a kind of persistent channels */ |
210 |
> |
if (chptr->members.head) |
211 |
> |
t--; /* Take the space out */ |
212 |
|
*t = '\0'; |
213 |
|
sendto_one(client_p, "%s", buf); |
214 |
|
} |
215 |
|
|
216 |
< |
/*! \brief sends +b/+e/+I |
217 |
< |
* \param client_p client pointer to server |
218 |
< |
* \param chptr pointer to channel |
219 |
< |
* \param top pointer to top of mode link list to send |
220 |
< |
* \param flag char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
216 |
> |
/*! \brief Sends +b/+e/+I |
217 |
> |
* \param client_p Client pointer to server |
218 |
> |
* \param chptr Pointer to channel |
219 |
> |
* \param list Pointer to list of modes to send |
220 |
> |
* \param flag Char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
221 |
|
*/ |
222 |
|
static void |
223 |
|
send_mode_list(struct Client *client_p, struct Channel *chptr, |
224 |
< |
dlink_list *top, char flag) |
224 |
> |
const dlink_list *list, char flag) |
225 |
|
{ |
226 |
< |
int ts5 = !IsCapable(client_p, CAP_TS6); |
227 |
< |
dlink_node *lp; |
228 |
< |
struct Ban *banptr; |
229 |
< |
char pbuf[IRCD_BUFSIZE]; |
230 |
< |
int tlen, mlen, cur_len, count = 0; |
231 |
< |
char *mp = NULL, *pp = pbuf; |
226 |
> |
const dlink_node *ptr = NULL; |
227 |
> |
char pbuf[IRCD_BUFSIZE] = ""; |
228 |
> |
int tlen, mlen, cur_len; |
229 |
> |
char *pp = pbuf; |
230 |
|
|
231 |
< |
if (top == NULL || top->length == 0) |
231 |
> |
if (list->length == 0) |
232 |
|
return; |
233 |
|
|
234 |
< |
if (ts5) |
235 |
< |
mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname); |
236 |
< |
else |
239 |
< |
mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id, |
240 |
< |
(unsigned long)chptr->channelts, chptr->chname, flag); |
241 |
< |
|
242 |
< |
/* MODE needs additional one byte for space between buf and pbuf */ |
243 |
< |
cur_len = mlen + ts5; |
244 |
< |
mp = buf + mlen; |
234 |
> |
mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id, |
235 |
> |
(unsigned long)chptr->channelts, chptr->chname, flag); |
236 |
> |
cur_len = mlen; |
237 |
|
|
238 |
< |
DLINK_FOREACH(lp, top->head) |
238 |
> |
DLINK_FOREACH(ptr, list->head) |
239 |
|
{ |
240 |
< |
banptr = lp->data; |
240 |
> |
const struct Ban *banptr = ptr->data; |
241 |
|
|
242 |
< |
/* must add another b/e/I letter if we use MODE */ |
251 |
< |
tlen = banptr->len + 3 + ts5; |
242 |
> |
tlen = banptr->len + 3; /* +3 for ! + @ + space */ |
243 |
|
|
244 |
|
/* |
245 |
< |
* send buffer and start over if we cannot fit another ban, |
255 |
< |
* or if the target is non-ts6 and we have too many modes in |
256 |
< |
* in this line. |
245 |
> |
* Send buffer and start over if we cannot fit another ban |
246 |
|
*/ |
247 |
< |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 || |
259 |
< |
(!IsCapable(client_p, CAP_TS6) && |
260 |
< |
(count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN))) |
247 |
> |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
248 |
|
{ |
249 |
< |
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
250 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
249 |
> |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
250 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
251 |
|
|
252 |
< |
cur_len = mlen + ts5; |
266 |
< |
mp = buf + mlen; |
252 |
> |
cur_len = mlen; |
253 |
|
pp = pbuf; |
268 |
– |
count = 0; |
269 |
– |
} |
270 |
– |
|
271 |
– |
count++; |
272 |
– |
if (ts5) |
273 |
– |
{ |
274 |
– |
*mp++ = flag; |
275 |
– |
*mp = '\0'; |
254 |
|
} |
255 |
|
|
256 |
< |
pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username, |
257 |
< |
banptr->host); |
256 |
> |
pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user, |
257 |
> |
banptr->host); |
258 |
|
cur_len += tlen; |
259 |
|
} |
260 |
|
|
261 |
< |
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
262 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
261 |
> |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
262 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
263 |
|
} |
264 |
|
|
265 |
< |
/*! \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 |
265 |
> |
/*! \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 |
|
*/ |
269 |
|
void |
270 |
|
send_channel_modes(struct Client *client_p, struct Channel *chptr) |
271 |
|
{ |
272 |
< |
if (chptr->chname[0] != '#') |
273 |
< |
return; |
272 |
> |
char modebuf[MODEBUFLEN] = ""; |
273 |
> |
char parabuf[MODEBUFLEN] = ""; |
274 |
|
|
297 |
– |
*modebuf = *parabuf = '\0'; |
275 |
|
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 |
< |
|
280 |
< |
if (IsCapable(client_p, CAP_EX)) |
304 |
< |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
305 |
< |
if (IsCapable(client_p, CAP_IE)) |
306 |
< |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
279 |
> |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
280 |
> |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
281 |
|
} |
282 |
|
|
283 |
< |
/*! \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 |
283 |
> |
/*! \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 |
|
* \return 0 if invalid, 1 otherwise |
287 |
|
*/ |
288 |
|
int |
289 |
< |
check_channel_name(const char *name, int local) |
289 |
> |
check_channel_name(const char *name, const int local) |
290 |
|
{ |
291 |
|
const char *p = name; |
292 |
< |
int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
292 |
> |
|
293 |
|
assert(name != NULL); |
294 |
|
|
295 |
|
if (!IsChanPrefix(*p)) |
296 |
|
return 0; |
297 |
|
|
298 |
< |
if (!local) |
298 |
> |
if (!local || !ConfigChannel.disable_fake_channels) |
299 |
|
{ |
300 |
|
while (*++p) |
301 |
|
if (!IsChanChar(*p)) |
304 |
|
else |
305 |
|
{ |
306 |
|
while (*++p) |
307 |
< |
if (!IsChanChar(*p) || |
334 |
< |
(IsFchanChar(*p) && ConfigChannel.disable_fake_channels)) |
307 |
> |
if (!IsVisibleChanChar(*p)) |
308 |
|
return 0; |
309 |
|
} |
310 |
|
|
311 |
< |
return p - name <= max_length; |
311 |
> |
return p - name <= CHANNELLEN; |
312 |
|
} |
313 |
|
|
314 |
|
void |
317 |
|
dlinkDelete(&bptr->node, list); |
318 |
|
|
319 |
|
MyFree(bptr->name); |
320 |
< |
MyFree(bptr->username); |
320 |
> |
MyFree(bptr->user); |
321 |
|
MyFree(bptr->host); |
322 |
|
MyFree(bptr->who); |
323 |
|
|
324 |
< |
BlockHeapFree(ban_heap, bptr); |
324 |
> |
mp_pool_release(bptr); |
325 |
|
} |
326 |
|
|
327 |
|
/* free_channel_list() |
333 |
|
void |
334 |
|
free_channel_list(dlink_list *list) |
335 |
|
{ |
336 |
< |
dlink_node *ptr = NULL, *next_ptr = NULL; |
336 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
337 |
|
|
338 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) |
338 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, list->head) |
339 |
|
remove_ban(ptr->data, list); |
340 |
|
|
341 |
|
assert(list->tail == NULL && list->head == NULL); |
343 |
|
|
344 |
|
/*! \brief Get Channel block for chname (and allocate a new channel |
345 |
|
* block, if it didn't exist before) |
346 |
< |
* \param chname channel name |
347 |
< |
* \return channel block |
346 |
> |
* \param chname Channel name |
347 |
> |
* \return Channel block |
348 |
|
*/ |
349 |
|
struct Channel * |
350 |
|
make_channel(const char *chname) |
353 |
|
|
354 |
|
assert(!EmptyString(chname)); |
355 |
|
|
356 |
< |
chptr = BlockHeapAlloc(channel_heap); |
356 |
> |
chptr = mp_pool_get(channel_pool); |
357 |
|
|
358 |
< |
/* doesn't hurt to set it here */ |
358 |
> |
/* Doesn't hurt to set it here */ |
359 |
|
chptr->channelts = CurrentTime; |
360 |
|
chptr->last_join_time = CurrentTime; |
361 |
|
|
362 |
|
strlcpy(chptr->chname, chname, sizeof(chptr->chname)); |
363 |
< |
dlinkAdd(chptr, &chptr->node, &global_channel_list); |
363 |
> |
dlinkAdd(chptr, &chptr->node, &channel_list); |
364 |
|
|
365 |
|
hash_add_channel(chptr); |
366 |
|
|
367 |
|
return chptr; |
368 |
|
} |
369 |
|
|
370 |
< |
/*! \brief walk through this channel, and destroy it. |
371 |
< |
* \param chptr channel pointer |
370 |
> |
/*! \brief Walk through this channel, and destroy it. |
371 |
> |
* \param chptr Channel pointer |
372 |
|
*/ |
373 |
|
void |
374 |
|
destroy_channel(struct Channel *chptr) |
378 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head) |
379 |
|
del_invite(chptr, ptr->data); |
380 |
|
|
381 |
< |
/* free ban/exception/invex lists */ |
381 |
> |
/* Free ban/exception/invex lists */ |
382 |
|
free_channel_list(&chptr->banlist); |
383 |
|
free_channel_list(&chptr->exceptlist); |
384 |
|
free_channel_list(&chptr->invexlist); |
385 |
|
|
386 |
< |
/* Free the topic */ |
414 |
< |
free_topic(chptr); |
415 |
< |
|
416 |
< |
dlinkDelete(&chptr->node, &global_channel_list); |
386 |
> |
dlinkDelete(&chptr->node, &channel_list); |
387 |
|
hash_del_channel(chptr); |
388 |
|
|
389 |
< |
if (ServerInfo.hub) |
420 |
< |
if ((ptr = dlinkFindDelete(&lazylink_channels, chptr))) |
421 |
< |
free_dlink_node(ptr); |
422 |
< |
|
423 |
< |
BlockHeapFree(channel_heap, chptr); |
389 |
> |
mp_pool_release(chptr); |
390 |
|
} |
391 |
|
|
392 |
|
/*! |
393 |
< |
* \param chptr pointer to channel |
394 |
< |
* \return string pointer "=" if public, "@" if secret else "*" |
393 |
> |
* \param chptr Pointer to channel |
394 |
> |
* \return String pointer "=" if public, "@" if secret else "*" |
395 |
|
*/ |
396 |
|
static const char * |
397 |
< |
channel_pub_or_secret(struct Channel *chptr) |
397 |
> |
channel_pub_or_secret(const struct Channel *chptr) |
398 |
|
{ |
399 |
|
if (SecretChannel(chptr)) |
400 |
|
return "@"; |
404 |
|
} |
405 |
|
|
406 |
|
/*! \brief lists all names on given channel |
407 |
< |
* \param source_p pointer to client struct requesting names |
408 |
< |
* \param chptr pointer to channel block |
409 |
< |
* \param show_eon show ENDOFNAMES numeric or not |
407 |
> |
* \param source_p Pointer to client struct requesting names |
408 |
> |
* \param chptr Pointer to channel block |
409 |
> |
* \param show_eon Show RPL_ENDOFNAMES numeric or not |
410 |
|
* (don't want it with /names with no params) |
411 |
|
*/ |
412 |
|
void |
413 |
|
channel_member_names(struct Client *source_p, struct Channel *chptr, |
414 |
|
int show_eon) |
415 |
|
{ |
416 |
< |
struct Client *target_p = NULL; |
417 |
< |
struct Membership *ms = NULL; |
452 |
< |
dlink_node *ptr = NULL; |
453 |
< |
char lbuf[IRCD_BUFSIZE + 1]; |
416 |
> |
const dlink_node *ptr = NULL; |
417 |
> |
char lbuf[IRCD_BUFSIZE + 1] = ""; |
418 |
|
char *t = NULL, *start = NULL; |
419 |
|
int tlen = 0; |
420 |
|
int is_member = IsMember(source_p, chptr); |
421 |
< |
int multi_prefix = (source_p->localClient->cap_active & CAP_MULTI_PREFIX) != 0; |
421 |
> |
int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0; |
422 |
> |
int uhnames = HasCap(source_p, CAP_UHNAMES) != 0; |
423 |
|
|
424 |
|
if (PubChannel(chptr) || is_member) |
425 |
|
{ |
426 |
< |
t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY), |
427 |
< |
me.name, source_p->name, |
428 |
< |
channel_pub_or_secret(chptr), |
464 |
< |
chptr->chname); |
426 |
> |
t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY), |
427 |
> |
me.name, source_p->name, |
428 |
> |
channel_pub_or_secret(chptr), chptr->chname); |
429 |
|
start = t; |
430 |
|
|
431 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
432 |
|
{ |
433 |
< |
ms = ptr->data; |
470 |
< |
target_p = ms->client_p; |
433 |
> |
const struct Membership *ms = ptr->data; |
434 |
|
|
435 |
< |
if (IsInvisible(target_p) && !is_member) |
435 |
> |
if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member) |
436 |
|
continue; |
437 |
|
|
438 |
< |
tlen = strlen(target_p->name) + 1; /* nick + space */ |
438 |
> |
if (!uhnames) |
439 |
> |
tlen = strlen(ms->client_p->name) + 1; /* +1 for space */ |
440 |
> |
else |
441 |
> |
tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) + |
442 |
> |
strlen(ms->client_p->host) + 3; /* +3 for ! + @ + space */ |
443 |
|
|
444 |
|
if (!multi_prefix) |
445 |
|
{ |
456 |
|
++tlen; |
457 |
|
} |
458 |
|
|
459 |
< |
if (t + tlen - lbuf > IRCD_BUFSIZE) |
459 |
> |
if (t + tlen - lbuf > IRCD_BUFSIZE - 2) |
460 |
|
{ |
461 |
|
*(t - 1) = '\0'; |
462 |
|
sendto_one(source_p, "%s", lbuf); |
463 |
|
t = start; |
464 |
|
} |
465 |
|
|
466 |
< |
t += ircsprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
467 |
< |
target_p->name); |
466 |
> |
if (!uhnames) |
467 |
> |
t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
468 |
> |
ms->client_p->name); |
469 |
> |
else |
470 |
> |
t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix), |
471 |
> |
ms->client_p->name, ms->client_p->username, |
472 |
> |
ms->client_p->host); |
473 |
|
} |
474 |
|
|
475 |
< |
if (tlen != 0) |
475 |
> |
if (tlen) |
476 |
|
{ |
477 |
|
*(t - 1) = '\0'; |
478 |
|
sendto_one(source_p, "%s", lbuf); |
480 |
|
} |
481 |
|
|
482 |
|
if (show_eon) |
483 |
< |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
512 |
< |
me.name, source_p->name, chptr->chname); |
483 |
> |
sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname); |
484 |
|
} |
485 |
|
|
486 |
< |
/*! \brief adds client to invite list |
487 |
< |
* \param chptr pointer to channel block |
488 |
< |
* \param who pointer to client to add invite to |
486 |
> |
/*! \brief Adds client to invite list |
487 |
> |
* \param chptr Pointer to channel block |
488 |
> |
* \param who Pointer to client to add invite to |
489 |
|
*/ |
490 |
|
void |
491 |
|
add_invite(struct Channel *chptr, struct Client *who) |
493 |
|
del_invite(chptr, who); |
494 |
|
|
495 |
|
/* |
496 |
< |
* delete last link in chain if the list is max length |
496 |
> |
* Delete last link in chain if the list is max length |
497 |
|
*/ |
498 |
|
if (dlink_list_length(&who->localClient->invited) >= |
499 |
< |
ConfigChannel.max_chans_per_user) |
499 |
> |
ConfigChannel.max_channels) |
500 |
|
del_invite(who->localClient->invited.tail->data, who); |
501 |
|
|
502 |
< |
/* add client to channel invite list */ |
502 |
> |
/* Add client to channel invite list */ |
503 |
|
dlinkAdd(who, make_dlink_node(), &chptr->invites); |
504 |
|
|
505 |
< |
/* add channel to the end of the client invite list */ |
505 |
> |
/* Add channel to the end of the client invite list */ |
506 |
|
dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited); |
507 |
|
} |
508 |
|
|
509 |
|
/*! \brief Delete Invite block from channel invite list |
510 |
|
* and client invite list |
511 |
< |
* \param chptr pointer to Channel struct |
512 |
< |
* \param who pointer to client to remove invites from |
511 |
> |
* \param chptr Pointer to Channel struct |
512 |
> |
* \param who Pointer to client to remove invites from |
513 |
|
*/ |
514 |
|
void |
515 |
|
del_invite(struct Channel *chptr, struct Client *who) |
535 |
|
* (like in get_client_name) |
536 |
|
*/ |
537 |
|
const char * |
538 |
< |
get_member_status(const struct Membership *ms, int combine) |
538 |
> |
get_member_status(const struct Membership *ms, const int combine) |
539 |
|
{ |
540 |
< |
static char buffer[4]; |
541 |
< |
char *p = NULL; |
571 |
< |
|
572 |
< |
if (ms == NULL) |
573 |
< |
return ""; |
574 |
< |
p = buffer; |
540 |
> |
static char buffer[4]; /* 4 for @%+\0 */ |
541 |
> |
char *p = buffer; |
542 |
|
|
543 |
|
if (ms->flags & CHFL_CHANOP) |
544 |
|
{ |
547 |
|
*p++ = '@'; |
548 |
|
} |
549 |
|
|
583 |
– |
#ifdef HALFOPS |
550 |
|
if (ms->flags & CHFL_HALFOP) |
551 |
|
{ |
552 |
|
if (!combine) |
553 |
|
return "%"; |
554 |
|
*p++ = '%'; |
555 |
|
} |
590 |
– |
#endif |
556 |
|
|
557 |
|
if (ms->flags & CHFL_VOICE) |
558 |
|
*p++ = '+'; |
562 |
|
} |
563 |
|
|
564 |
|
/*! |
565 |
< |
* \param who pointer to Client to check |
566 |
< |
* \param list pointer to ban list to search |
565 |
> |
* \param who Pointer to Client to check |
566 |
> |
* \param list Pointer to ban list to search |
567 |
|
* \return 1 if ban found for given n!u\@h mask, 0 otherwise |
568 |
|
* |
569 |
|
*/ |
574 |
|
|
575 |
|
DLINK_FOREACH(ptr, list->head) |
576 |
|
{ |
577 |
< |
struct Ban *bp = ptr->data; |
577 |
> |
const struct Ban *bp = ptr->data; |
578 |
|
|
579 |
< |
if (match(bp->name, who->name) && match(bp->username, who->username)) |
579 |
> |
if (!match(bp->name, who->name) && !match(bp->user, who->username)) |
580 |
|
{ |
581 |
|
switch (bp->type) |
582 |
|
{ |
583 |
|
case HM_HOST: |
584 |
< |
if (match(bp->host, who->host) || match(bp->host, who->sockhost)) |
584 |
> |
if (!match(bp->host, who->host) || !match(bp->host, who->sockhost)) |
585 |
|
return 1; |
586 |
|
break; |
587 |
|
case HM_IPV4: |
606 |
|
} |
607 |
|
|
608 |
|
/*! |
609 |
< |
* \param chptr pointer to channel block |
610 |
< |
* \param who pointer to client to check access fo |
609 |
> |
* \param chptr Pointer to channel block |
610 |
> |
* \param who Pointer to client to check access fo |
611 |
|
* \return 0 if not banned, 1 otherwise |
612 |
|
*/ |
613 |
|
int |
614 |
< |
is_banned(struct Channel *chptr, struct Client *who) |
614 |
> |
is_banned(const struct Channel *chptr, const struct Client *who) |
615 |
|
{ |
616 |
|
if (find_bmask(who, &chptr->banlist)) |
617 |
< |
if (!ConfigChannel.use_except || !find_bmask(who, &chptr->exceptlist)) |
617 |
> |
if (!find_bmask(who, &chptr->exceptlist)) |
618 |
|
return 1; |
619 |
|
|
620 |
|
return 0; |
621 |
|
} |
622 |
|
|
623 |
< |
/*! |
624 |
< |
* \param source_p pointer to client attempting to join |
625 |
< |
* \param chptr pointer to channel |
626 |
< |
* \param key key sent by client attempting to join if present |
623 |
> |
/*! Tests if a client can join a certain channel |
624 |
> |
* \param source_p Pointer to client attempting to join |
625 |
> |
* \param chptr Pointer to channel |
626 |
> |
* \param key Key sent by client attempting to join if present |
627 |
|
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
628 |
|
* or 0 if allowed to join. |
629 |
|
*/ |
630 |
|
int |
631 |
|
can_join(struct Client *source_p, struct Channel *chptr, const char *key) |
632 |
|
{ |
633 |
< |
if (is_banned(chptr, source_p)) |
634 |
< |
return ERR_BANNEDFROMCHAN; |
633 |
> |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
634 |
> |
return ERR_SSLONLYCHAN; |
635 |
> |
|
636 |
> |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
637 |
> |
return ERR_NEEDREGGEDNICK; |
638 |
> |
|
639 |
> |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER)) |
640 |
> |
return ERR_OPERONLYCHAN; |
641 |
|
|
642 |
|
if (chptr->mode.mode & MODE_INVITEONLY) |
643 |
|
if (!dlinkFind(&source_p->localClient->invited, chptr)) |
644 |
< |
if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist)) |
644 |
> |
if (!find_bmask(source_p, &chptr->invexlist)) |
645 |
|
return ERR_INVITEONLYCHAN; |
646 |
|
|
647 |
< |
if (chptr->mode.key[0] && (!key || irccmp(chptr->mode.key, key))) |
647 |
> |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
648 |
|
return ERR_BADCHANNELKEY; |
649 |
|
|
650 |
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
651 |
|
chptr->mode.limit) |
652 |
|
return ERR_CHANNELISFULL; |
653 |
|
|
654 |
+ |
if (is_banned(chptr, source_p)) |
655 |
+ |
return ERR_BANNEDFROMCHAN; |
656 |
+ |
|
657 |
|
return 0; |
658 |
|
} |
659 |
|
|
660 |
|
int |
661 |
< |
has_member_flags(struct Membership *ms, unsigned int flags) |
661 |
> |
has_member_flags(const struct Membership *ms, const unsigned int flags) |
662 |
|
{ |
663 |
< |
if (ms != NULL) |
690 |
< |
return ms->flags & flags; |
691 |
< |
return 0; |
663 |
> |
return ms && (ms->flags & flags); |
664 |
|
} |
665 |
|
|
666 |
|
struct Membership * |
671 |
|
if (!IsClient(client_p)) |
672 |
|
return NULL; |
673 |
|
|
674 |
< |
DLINK_FOREACH(ptr, client_p->channel.head) |
675 |
< |
if (((struct Membership *)ptr->data)->chptr == chptr) |
676 |
< |
return (struct Membership *)ptr->data; |
674 |
> |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
675 |
> |
{ |
676 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
677 |
> |
if (((struct Membership *)ptr->data)->client_p == client_p) |
678 |
> |
return ptr->data; |
679 |
> |
} |
680 |
> |
else |
681 |
> |
{ |
682 |
> |
DLINK_FOREACH(ptr, client_p->channel.head) |
683 |
> |
if (((struct Membership *)ptr->data)->chptr == chptr) |
684 |
> |
return ptr->data; |
685 |
> |
} |
686 |
|
|
687 |
|
return NULL; |
688 |
|
} |
689 |
|
|
690 |
< |
/*! |
691 |
< |
* \param chptr pointer to Channel struct |
692 |
< |
* \param source_p pointer to Client struct |
693 |
< |
* \param ms pointer to Membership struct (can be NULL) |
690 |
> |
/*! Tests if a client can send to a channel |
691 |
> |
* \param message The actual message string the client wants to send |
692 |
> |
* \return 1 if the message does contain any control codes, 0 otherwise |
693 |
> |
*/ |
694 |
> |
static int |
695 |
> |
msg_has_ctrls(const char *message) |
696 |
> |
{ |
697 |
> |
const unsigned char *p = (const unsigned char *)message; |
698 |
> |
|
699 |
> |
for (; *p; ++p) |
700 |
> |
{ |
701 |
> |
if (*p > 31 || *p == 1) |
702 |
> |
continue; /* No control code or CTCP */ |
703 |
> |
|
704 |
> |
if (*p == 27) /* Escape */ |
705 |
> |
{ |
706 |
> |
/* ISO 2022 charset shift sequence */ |
707 |
> |
if (*(p + 1) == '$' || |
708 |
> |
*(p + 1) == '(') |
709 |
> |
{ |
710 |
> |
++p; |
711 |
> |
continue; |
712 |
> |
} |
713 |
> |
} |
714 |
> |
|
715 |
> |
return 1; /* Control code */ |
716 |
> |
} |
717 |
> |
|
718 |
> |
return 0; |
719 |
> |
} |
720 |
> |
|
721 |
> |
/*! Tests if a client can send to a channel |
722 |
> |
* \param chptr Pointer to Channel struct |
723 |
> |
* \param source_p Pointer to Client struct |
724 |
> |
* \param ms Pointer to Membership struct (can be NULL) |
725 |
> |
* \param message The actual message string the client wants to send |
726 |
|
* \return CAN_SEND_OPV if op or voiced on channel\n |
727 |
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
728 |
< |
* CAN_SEND_NO if they cannot send to channel\n |
728 |
> |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
729 |
|
*/ |
730 |
|
int |
731 |
< |
can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms) |
731 |
> |
can_send(struct Channel *chptr, struct Client *source_p, |
732 |
> |
struct Membership *ms, const char *message) |
733 |
|
{ |
734 |
< |
if (IsServer(source_p)) |
734 |
> |
struct MaskItem *conf = NULL; |
735 |
> |
|
736 |
> |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
737 |
|
return CAN_SEND_OPV; |
738 |
|
|
739 |
|
if (MyClient(source_p) && !IsExemptResv(source_p)) |
740 |
< |
if (!(IsOper(source_p) && ConfigFileEntry.oper_pass_resv)) |
741 |
< |
if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels) |
742 |
< |
return CAN_SEND_NO; |
743 |
< |
|
744 |
< |
if (ms != NULL || (ms = find_channel_link(source_p, chptr))) |
745 |
< |
{ |
740 |
> |
if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv)) |
741 |
> |
if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf)) |
742 |
> |
return ERR_CANNOTSENDTOCHAN; |
743 |
> |
|
744 |
> |
if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message)) |
745 |
> |
return ERR_NOCTRLSONCHAN; |
746 |
> |
if (ms || (ms = find_channel_link(source_p, chptr))) |
747 |
|
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
748 |
|
return CAN_SEND_OPV; |
749 |
+ |
if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
750 |
+ |
return ERR_CANNOTSENDTOCHAN; |
751 |
+ |
if (chptr->mode.mode & MODE_MODERATED) |
752 |
+ |
return ERR_CANNOTSENDTOCHAN; |
753 |
+ |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
754 |
+ |
return ERR_NEEDREGGEDNICK; |
755 |
|
|
756 |
< |
/* cache can send if quiet_on_ban and banned */ |
757 |
< |
if (ConfigChannel.quiet_on_ban && MyClient(source_p)) |
756 |
> |
/* Cache can send if banned */ |
757 |
> |
if (MyClient(source_p)) |
758 |
> |
{ |
759 |
> |
if (ms) |
760 |
|
{ |
761 |
|
if (ms->flags & CHFL_BAN_SILENCED) |
762 |
< |
return CAN_SEND_NO; |
762 |
> |
return ERR_CANNOTSENDTOCHAN; |
763 |
|
|
764 |
|
if (!(ms->flags & CHFL_BAN_CHECKED)) |
765 |
|
{ |
766 |
|
if (is_banned(chptr, source_p)) |
767 |
|
{ |
768 |
|
ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED); |
769 |
< |
return CAN_SEND_NO; |
769 |
> |
return ERR_CANNOTSENDTOCHAN; |
770 |
|
} |
771 |
|
|
772 |
|
ms->flags |= CHFL_BAN_CHECKED; |
773 |
|
} |
774 |
|
} |
775 |
+ |
else if (is_banned(chptr, source_p)) |
776 |
+ |
return ERR_CANNOTSENDTOCHAN; |
777 |
|
} |
751 |
– |
else if (chptr->mode.mode & MODE_NOPRIVMSGS) |
752 |
– |
return CAN_SEND_NO; |
753 |
– |
|
754 |
– |
if (chptr->mode.mode & MODE_MODERATED) |
755 |
– |
return CAN_SEND_NO; |
778 |
|
|
779 |
|
return CAN_SEND_NONOP; |
780 |
|
} |
782 |
|
/*! \brief Updates the client's oper_warn_count_down, warns the |
783 |
|
* IRC operators if necessary, and updates |
784 |
|
* join_leave_countdown as needed. |
785 |
< |
* \param source_p pointer to struct Client to check |
786 |
< |
* \param name channel name or NULL if this is a part. |
785 |
> |
* \param source_p Pointer to struct Client to check |
786 |
> |
* \param name Channel name or NULL if this is a part. |
787 |
|
*/ |
788 |
|
void |
789 |
|
check_spambot_warning(struct Client *source_p, const char *name) |
802 |
|
|
803 |
|
if (source_p->localClient->oper_warn_count_down == 0) |
804 |
|
{ |
805 |
< |
/* Its already known as a possible spambot */ |
806 |
< |
if (name != NULL) |
807 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
805 |
> |
/* It's already known as a possible spambot */ |
806 |
> |
if (name) |
807 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
808 |
|
"User %s (%s@%s) trying to join %s is a possible spambot", |
809 |
|
source_p->name, source_p->username, |
810 |
|
source_p->host, name); |
811 |
|
else |
812 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
812 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
813 |
|
"User %s (%s@%s) is a possible spambot", |
814 |
|
source_p->name, source_p->username, |
815 |
|
source_p->host); |
831 |
|
{ |
832 |
|
if ((CurrentTime - (source_p->localClient->last_join_time)) < |
833 |
|
GlobalSetOptions.spam_time) |
834 |
< |
{ |
813 |
< |
/* oh, its a possible spambot */ |
814 |
< |
source_p->localClient->join_leave_count++; |
815 |
< |
} |
834 |
> |
source_p->localClient->join_leave_count++; /* It's a possible spambot */ |
835 |
|
} |
836 |
|
|
837 |
< |
if (name != NULL) |
837 |
> |
if (name) |
838 |
|
source_p->localClient->last_join_time = CurrentTime; |
839 |
|
else |
840 |
|
source_p->localClient->last_leave_time = CurrentTime; |
841 |
|
} |
842 |
|
} |
843 |
|
|
844 |
< |
/*! \brief compares usercount and servercount against their split |
844 |
> |
/*! \brief Compares usercount and servercount against their split |
845 |
|
* values and adjusts splitmode accordingly |
846 |
|
* \param unused Unused address pointer |
847 |
|
*/ |
857 |
|
{ |
858 |
|
splitmode = 1; |
859 |
|
|
860 |
< |
sendto_realops_flags(UMODE_ALL,L_ALL, |
860 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
861 |
|
"Network split, activating splitmode"); |
862 |
< |
eventAddIsh("check_splitmode", check_splitmode, NULL, 10); |
862 |
> |
event_add(&splitmode_event, NULL); |
863 |
|
} |
864 |
< |
else if (splitmode && (server > split_servers) && (Count.total > split_users)) |
864 |
> |
else if (splitmode && (server >= split_servers) && (Count.total >= split_users)) |
865 |
|
{ |
866 |
|
splitmode = 0; |
867 |
|
|
868 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
868 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
869 |
|
"Network rejoined, deactivating splitmode"); |
870 |
< |
eventDelete(check_splitmode, NULL); |
870 |
> |
event_delete(&splitmode_event); |
871 |
|
} |
872 |
|
} |
873 |
|
} |
874 |
|
|
875 |
< |
/*! \brief Allocates a new topic |
876 |
< |
* \param chptr Channel to allocate a new topic for |
875 |
> |
/*! \brief Sets the channel topic for a certain channel |
876 |
> |
* \param chptr Pointer to struct Channel |
877 |
> |
* \param topic The topic string |
878 |
> |
* \param topic_info n!u\@h formatted string of the topic setter |
879 |
> |
* \param topicts Timestamp on the topic |
880 |
> |
* \param local Whether the topic is set by a local client |
881 |
|
*/ |
882 |
< |
static void |
883 |
< |
allocate_topic(struct Channel *chptr) |
882 |
> |
void |
883 |
> |
channel_set_topic(struct Channel *chptr, const char *topic, |
884 |
> |
const char *topic_info, time_t topicts, int local) |
885 |
|
{ |
886 |
< |
void *ptr = NULL; |
886 |
> |
if (local) |
887 |
> |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1)); |
888 |
> |
else |
889 |
> |
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
890 |
|
|
891 |
< |
if (chptr == NULL) |
892 |
< |
return; |
891 |
> |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
892 |
> |
chptr->topic_time = topicts; |
893 |
> |
} |
894 |
> |
|
895 |
> |
/* do_join_0() |
896 |
> |
* |
897 |
> |
* inputs - pointer to client doing join 0 |
898 |
> |
* output - NONE |
899 |
> |
* side effects - Use has decided to join 0. This is legacy |
900 |
> |
* from the days when channels were numbers not names. *sigh* |
901 |
> |
* There is a bunch of evilness necessary here due to |
902 |
> |
* anti spambot code. |
903 |
> |
*/ |
904 |
> |
void |
905 |
> |
channel_do_join_0(struct Client *source_p) |
906 |
> |
{ |
907 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
908 |
|
|
909 |
< |
ptr = BlockHeapAlloc(topic_heap); |
909 |
> |
if (source_p->channel.head) |
910 |
> |
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
911 |
> |
check_spambot_warning(source_p, NULL); |
912 |
|
|
913 |
< |
/* Basically we allocate one large block for the topic and |
914 |
< |
* the topic info. We then split it up into two and shove it |
915 |
< |
* in the chptr |
916 |
< |
*/ |
917 |
< |
chptr->topic = ptr; |
918 |
< |
chptr->topic_info = (char *)ptr + TOPICLEN+1; |
919 |
< |
*chptr->topic = '\0'; |
920 |
< |
*chptr->topic_info = '\0'; |
913 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head) |
914 |
> |
{ |
915 |
> |
struct Channel *chptr = ((struct Membership *)ptr->data)->chptr; |
916 |
> |
|
917 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s", |
918 |
> |
source_p->id, chptr->chname); |
919 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s", |
920 |
> |
source_p->name, source_p->username, |
921 |
> |
source_p->host, chptr->chname); |
922 |
> |
|
923 |
> |
remove_user_from_channel(ptr->data); |
924 |
> |
} |
925 |
> |
} |
926 |
> |
|
927 |
> |
static char * |
928 |
> |
channel_find_last0(struct Client *source_p, char *chanlist) |
929 |
> |
{ |
930 |
> |
int join0 = 0; |
931 |
> |
|
932 |
> |
for (char *p = chanlist; *p; ++p) /* Find last "JOIN 0" */ |
933 |
> |
{ |
934 |
> |
if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0')) |
935 |
> |
{ |
936 |
> |
if ((*p + 1) == ',') |
937 |
> |
++p; |
938 |
> |
|
939 |
> |
chanlist = p + 1; |
940 |
> |
join0 = 1; |
941 |
> |
} |
942 |
> |
else |
943 |
> |
{ |
944 |
> |
while (*p != ',' && *p != '\0') /* Skip past channel name */ |
945 |
> |
++p; |
946 |
> |
|
947 |
> |
if (*p == '\0') /* Hit the end */ |
948 |
> |
break; |
949 |
> |
} |
950 |
> |
} |
951 |
> |
|
952 |
> |
if (join0) |
953 |
> |
channel_do_join_0(source_p); |
954 |
> |
|
955 |
> |
return chanlist; |
956 |
|
} |
957 |
|
|
958 |
|
void |
959 |
< |
free_topic(struct Channel *chptr) |
959 |
> |
channel_do_join(struct Client *source_p, char *channel, char *key_list) |
960 |
|
{ |
961 |
< |
void *ptr = NULL; |
962 |
< |
assert(chptr); |
963 |
< |
if (chptr->topic == NULL) |
964 |
< |
return; |
961 |
> |
char *p = NULL; |
962 |
> |
char *chan = NULL; |
963 |
> |
char *chan_list = NULL; |
964 |
> |
struct Channel *chptr = NULL; |
965 |
> |
struct MaskItem *conf = NULL; |
966 |
> |
const struct ClassItem *class = get_class_ptr(&source_p->localClient->confs); |
967 |
> |
int i = 0; |
968 |
> |
unsigned int flags = 0; |
969 |
|
|
970 |
< |
/* |
971 |
< |
* If you change allocate_topic you MUST change this as well |
972 |
< |
*/ |
973 |
< |
ptr = chptr->topic; |
974 |
< |
BlockHeapFree(topic_heap, ptr); |
975 |
< |
chptr->topic = NULL; |
976 |
< |
chptr->topic_info = NULL; |
970 |
> |
chan_list = channel_find_last0(source_p, channel); |
971 |
> |
|
972 |
> |
for (chan = strtoken(&p, chan_list, ","); chan; |
973 |
> |
chan = strtoken(&p, NULL, ",")) |
974 |
> |
{ |
975 |
> |
const char *key = NULL; |
976 |
> |
|
977 |
> |
/* If we have any more keys, take the first for this channel. */ |
978 |
> |
if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ','))) |
979 |
> |
*key_list++ = '\0'; |
980 |
> |
|
981 |
> |
/* Empty keys are the same as no keys. */ |
982 |
> |
if (key && *key == '\0') |
983 |
> |
key = NULL; |
984 |
> |
|
985 |
> |
if (!check_channel_name(chan, 1)) |
986 |
> |
{ |
987 |
> |
sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan); |
988 |
> |
continue; |
989 |
> |
} |
990 |
> |
|
991 |
> |
if (!IsExemptResv(source_p) && |
992 |
> |
!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) && |
993 |
> |
((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf))) |
994 |
> |
{ |
995 |
> |
++conf->count; |
996 |
> |
sendto_one_numeric(source_p, &me, ERR_CHANBANREASON, |
997 |
> |
chan, conf->reason ? conf->reason : "Reserved channel"); |
998 |
> |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
999 |
> |
"Forbidding reserved channel %s from user %s", |
1000 |
> |
chan, get_client_name(source_p, HIDE_IP)); |
1001 |
> |
continue; |
1002 |
> |
} |
1003 |
> |
|
1004 |
> |
if (dlink_list_length(&source_p->channel) >= |
1005 |
> |
((class->max_channels) ? class->max_channels : ConfigChannel.max_channels)) |
1006 |
> |
{ |
1007 |
> |
sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan); |
1008 |
> |
break; |
1009 |
> |
} |
1010 |
> |
|
1011 |
> |
if ((chptr = hash_find_channel(chan))) |
1012 |
> |
{ |
1013 |
> |
if (IsMember(source_p, chptr)) |
1014 |
> |
continue; |
1015 |
> |
|
1016 |
> |
if (splitmode && !HasUMode(source_p, UMODE_OPER) && |
1017 |
> |
ConfigChannel.no_join_on_split) |
1018 |
> |
{ |
1019 |
> |
sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->chname); |
1020 |
> |
continue; |
1021 |
> |
} |
1022 |
> |
|
1023 |
> |
/* |
1024 |
> |
* can_join checks for +i key, bans. |
1025 |
> |
*/ |
1026 |
> |
if ((i = can_join(source_p, chptr, key))) |
1027 |
> |
{ |
1028 |
> |
sendto_one_numeric(source_p, &me, i, chptr->chname); |
1029 |
> |
continue; |
1030 |
> |
} |
1031 |
> |
|
1032 |
> |
/* |
1033 |
> |
* This should never be the case unless there is some sort of |
1034 |
> |
* persistant channels. |
1035 |
> |
*/ |
1036 |
> |
if (dlink_list_length(&chptr->members) == 0) |
1037 |
> |
flags = CHFL_CHANOP; |
1038 |
> |
else |
1039 |
> |
flags = 0; |
1040 |
> |
} |
1041 |
> |
else |
1042 |
> |
{ |
1043 |
> |
if (splitmode && !HasUMode(source_p, UMODE_OPER) && |
1044 |
> |
(ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split)) |
1045 |
> |
{ |
1046 |
> |
sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chan); |
1047 |
> |
continue; |
1048 |
> |
} |
1049 |
> |
|
1050 |
> |
flags = CHFL_CHANOP; |
1051 |
> |
chptr = make_channel(chan); |
1052 |
> |
} |
1053 |
> |
|
1054 |
> |
if (!HasUMode(source_p, UMODE_OPER)) |
1055 |
> |
check_spambot_warning(source_p, chptr->chname); |
1056 |
> |
|
1057 |
> |
add_user_to_channel(chptr, source_p, flags, 1); |
1058 |
> |
|
1059 |
> |
/* |
1060 |
> |
* Set timestamp if appropriate, and propagate |
1061 |
> |
*/ |
1062 |
> |
if (flags == CHFL_CHANOP) |
1063 |
> |
{ |
1064 |
> |
chptr->channelts = CurrentTime; |
1065 |
> |
chptr->mode.mode |= MODE_TOPICLIMIT; |
1066 |
> |
chptr->mode.mode |= MODE_NOPRIVMSGS; |
1067 |
> |
|
1068 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s SJOIN %lu %s +nt :@%s", |
1069 |
> |
me.id, (unsigned long)chptr->channelts, |
1070 |
> |
chptr->chname, source_p->id); |
1071 |
> |
|
1072 |
> |
/* |
1073 |
> |
* Notify all other users on the new channel |
1074 |
> |
*/ |
1075 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s", |
1076 |
> |
source_p->name, source_p->username, |
1077 |
> |
source_p->host, chptr->chname); |
1078 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt", |
1079 |
> |
me.name, chptr->chname); |
1080 |
> |
|
1081 |
> |
if (source_p->away[0]) |
1082 |
> |
sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr, |
1083 |
> |
":%s!%s@%s AWAY :%s", |
1084 |
> |
source_p->name, source_p->username, |
1085 |
> |
source_p->host, source_p->away); |
1086 |
> |
} |
1087 |
> |
else |
1088 |
> |
{ |
1089 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s JOIN %lu %s +", |
1090 |
> |
source_p->id, (unsigned long)chptr->channelts, |
1091 |
> |
chptr->chname); |
1092 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s", |
1093 |
> |
source_p->name, source_p->username, |
1094 |
> |
source_p->host, chptr->chname); |
1095 |
> |
|
1096 |
> |
if (source_p->away[0]) |
1097 |
> |
sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr, |
1098 |
> |
":%s!%s@%s AWAY :%s", |
1099 |
> |
source_p->name, source_p->username, |
1100 |
> |
source_p->host, source_p->away); |
1101 |
> |
} |
1102 |
> |
|
1103 |
> |
del_invite(chptr, source_p); |
1104 |
> |
|
1105 |
> |
if (chptr->topic[0]) |
1106 |
> |
{ |
1107 |
> |
sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->chname, chptr->topic); |
1108 |
> |
sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->chname, |
1109 |
> |
chptr->topic_info, chptr->topic_time); |
1110 |
> |
} |
1111 |
> |
|
1112 |
> |
channel_member_names(source_p, chptr, 1); |
1113 |
> |
|
1114 |
> |
source_p->localClient->last_join_time = CurrentTime; |
1115 |
> |
} |
1116 |
|
} |
1117 |
|
|
1118 |
< |
/*! \brief Sets the channel topic for chptr |
1119 |
< |
* \param chptr Pointer to struct Channel |
1120 |
< |
* \param topic The topic string |
1121 |
< |
* \param topic_info n!u\@h formatted string of the topic setter |
900 |
< |
* \param topicts timestamp on the topic |
1118 |
> |
/*! \brief Removes a client from a specific channel |
1119 |
> |
* \param source_p Pointer to source client to remove |
1120 |
> |
* \param name Name of channel to remove from |
1121 |
> |
* \param reason Part reason to show |
1122 |
|
*/ |
1123 |
< |
void |
1124 |
< |
set_channel_topic(struct Channel *chptr, const char *topic, |
904 |
< |
const char *topic_info, time_t topicts) |
1123 |
> |
static void |
1124 |
> |
channel_part_one_client(struct Client *source_p, const char *name, const char *reason) |
1125 |
|
{ |
1126 |
< |
if (!EmptyString(topic)) |
1126 |
> |
struct Channel *chptr = NULL; |
1127 |
> |
struct Membership *ms = NULL; |
1128 |
> |
|
1129 |
> |
if ((chptr = hash_find_channel(name)) == NULL) |
1130 |
> |
{ |
1131 |
> |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name); |
1132 |
> |
return; |
1133 |
> |
} |
1134 |
> |
|
1135 |
> |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
1136 |
|
{ |
1137 |
< |
if (chptr->topic == NULL) |
1138 |
< |
allocate_topic(chptr); |
1137 |
> |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname); |
1138 |
> |
return; |
1139 |
> |
} |
1140 |
> |
|
1141 |
> |
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
1142 |
> |
check_spambot_warning(source_p, NULL); |
1143 |
|
|
1144 |
< |
strlcpy(chptr->topic, topic, TOPICLEN+1); |
1145 |
< |
strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); |
1146 |
< |
chptr->topic_time = topicts; |
1144 |
> |
/* |
1145 |
> |
* Remove user from the old channel (if any) |
1146 |
> |
* only allow /part reasons in -m chans |
1147 |
> |
*/ |
1148 |
> |
if (*reason && (!MyConnect(source_p) || |
1149 |
> |
((can_send(chptr, source_p, ms, reason) && |
1150 |
> |
(source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) |
1151 |
> |
< CurrentTime)))) |
1152 |
> |
{ |
1153 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s :%s", |
1154 |
> |
source_p->id, chptr->chname, reason); |
1155 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s", |
1156 |
> |
source_p->name, source_p->username, |
1157 |
> |
source_p->host, chptr->chname, reason); |
1158 |
|
} |
1159 |
|
else |
1160 |
|
{ |
1161 |
< |
/* |
1162 |
< |
* Do not reset chptr->topic_time here, it's required for |
1163 |
< |
* bursting topics properly. |
1164 |
< |
*/ |
1165 |
< |
if (chptr->topic != NULL) |
922 |
< |
free_topic(chptr); |
1161 |
> |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s", |
1162 |
> |
source_p->id, chptr->chname); |
1163 |
> |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s", |
1164 |
> |
source_p->name, source_p->username, |
1165 |
> |
source_p->host, chptr->chname); |
1166 |
|
} |
1167 |
+ |
|
1168 |
+ |
remove_user_from_channel(ms); |
1169 |
+ |
} |
1170 |
+ |
|
1171 |
+ |
void |
1172 |
+ |
channel_do_part(struct Client *source_p, char *channel, char *reason) |
1173 |
+ |
{ |
1174 |
+ |
char *p = NULL, *name = NULL; |
1175 |
+ |
char reasonbuf[KICKLEN + 1] = ""; |
1176 |
+ |
|
1177 |
+ |
if (!EmptyString(reason)) |
1178 |
+ |
strlcpy(reasonbuf, reason, sizeof(reasonbuf)); |
1179 |
+ |
|
1180 |
+ |
for (name = strtoken(&p, channel, ","); name; |
1181 |
+ |
name = strtoken(&p, NULL, ",")) |
1182 |
+ |
channel_part_one_client(source_p, name, reasonbuf); |
1183 |
|
} |