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