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