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