1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2820 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
adx |
30 |
* |
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 |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
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 |
michael |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2820 |
/*! \file m_sjoin.c |
23 |
|
|
* \brief Includes required functions for processing the SJOIN command. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "channel.h" |
30 |
|
|
#include "channel_mode.h" |
31 |
|
|
#include "client.h" |
32 |
|
|
#include "hash.h" |
33 |
|
|
#include "irc_string.h" |
34 |
|
|
#include "ircd.h" |
35 |
|
|
#include "numeric.h" |
36 |
|
|
#include "send.h" |
37 |
|
|
#include "parse.h" |
38 |
|
|
#include "modules.h" |
39 |
michael |
3347 |
#include "server.h" |
40 |
michael |
1309 |
#include "conf.h" |
41 |
michael |
3347 |
#include "misc.h" |
42 |
adx |
30 |
|
43 |
|
|
|
44 |
|
|
static char modebuf[MODEBUFLEN]; |
45 |
|
|
static char parabuf[MODEBUFLEN]; |
46 |
|
|
static char sendbuf[MODEBUFLEN]; |
47 |
|
|
static const char *para[MAXMODEPARAMS]; |
48 |
|
|
static char *mbuf; |
49 |
|
|
static int pargs; |
50 |
|
|
|
51 |
|
|
static void set_final_mode(struct Mode *, struct Mode *); |
52 |
|
|
static void remove_our_modes(struct Channel *, struct Client *); |
53 |
|
|
static void remove_a_mode(struct Channel *, struct Client *, int, char); |
54 |
michael |
3041 |
static void remove_ban_list(struct Channel *, struct Client *, dlink_list *, char); |
55 |
adx |
30 |
|
56 |
michael |
885 |
|
57 |
adx |
30 |
/* ms_sjoin() |
58 |
|
|
* |
59 |
michael |
3120 |
* parv[0] - command |
60 |
adx |
30 |
* parv[1] - TS |
61 |
|
|
* parv[2] - channel |
62 |
|
|
* parv[3] - modes + n arguments (key and/or limit) |
63 |
|
|
* parv[4+n] - flags+nick list (all in one parameter) |
64 |
|
|
* |
65 |
|
|
* process a SJOIN, taking the TS's into account to either ignore the |
66 |
|
|
* incoming modes or undo the existing ones or merge them, and JOIN |
67 |
|
|
* all the specified users while sending JOIN/MODEs to local clients |
68 |
|
|
*/ |
69 |
michael |
2820 |
static int |
70 |
michael |
3156 |
ms_sjoin(struct Client *source_p, int parc, char *parv[]) |
71 |
adx |
30 |
{ |
72 |
michael |
632 |
struct Channel *chptr = NULL; |
73 |
|
|
struct Client *target_p = NULL; |
74 |
adx |
30 |
time_t newts; |
75 |
|
|
time_t oldts; |
76 |
|
|
time_t tstosend; |
77 |
michael |
632 |
struct Mode mode, *oldmode; |
78 |
adx |
30 |
int args = 0; |
79 |
michael |
1243 |
char keep_our_modes = 1; |
80 |
|
|
char keep_new_modes = 1; |
81 |
|
|
char have_many_nicks = 0; |
82 |
adx |
30 |
int lcount; |
83 |
|
|
char uid_prefix[4]; |
84 |
michael |
3135 |
char *up = NULL; |
85 |
adx |
30 |
int len_uid = 0; |
86 |
michael |
632 |
int isnew = 0; |
87 |
adx |
30 |
int buflen = 0; |
88 |
michael |
2820 |
int slen; |
89 |
adx |
30 |
unsigned int fl; |
90 |
|
|
char *s; |
91 |
michael |
2820 |
char *sptr; |
92 |
michael |
3135 |
char uid_buf[IRCD_BUFSIZE]; /* buffer for modes/prefixes */ |
93 |
|
|
char *uid_ptr; |
94 |
adx |
30 |
char *p; /* pointer used making sjbuf */ |
95 |
|
|
const char *servername = (ConfigServerHide.hide_servers || IsHidden(source_p)) ? |
96 |
michael |
2820 |
me.name : source_p->name; |
97 |
adx |
30 |
|
98 |
michael |
3626 |
if (!IsServer(source_p)) |
99 |
michael |
2820 |
return 0; |
100 |
adx |
30 |
|
101 |
michael |
632 |
if (!check_channel_name(parv[2], 0)) |
102 |
|
|
{ |
103 |
michael |
1618 |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
104 |
michael |
3162 |
"*** Too long or invalid channel name from %s(via %s): %s", |
105 |
|
|
source_p->name, source_p->from->name, parv[2]); |
106 |
michael |
2820 |
return 0; |
107 |
michael |
632 |
} |
108 |
adx |
30 |
|
109 |
|
|
modebuf[0] = '\0'; |
110 |
|
|
mbuf = modebuf; |
111 |
|
|
pargs = 0; |
112 |
|
|
newts = atol(parv[1]); |
113 |
|
|
|
114 |
|
|
mode.mode = 0; |
115 |
|
|
mode.limit = 0; |
116 |
|
|
mode.key[0] = '\0'; |
117 |
|
|
|
118 |
michael |
3751 |
for (const char *modes = parv[3]; *modes; ++modes) |
119 |
adx |
30 |
{ |
120 |
michael |
3751 |
switch (*modes) |
121 |
adx |
30 |
{ |
122 |
|
|
case 'k': |
123 |
|
|
strlcpy(mode.key, parv[4 + args], sizeof(mode.key)); |
124 |
michael |
3751 |
++args; |
125 |
michael |
632 |
|
126 |
|
|
if (parc < 5 + args) |
127 |
michael |
2820 |
return 0; |
128 |
adx |
30 |
break; |
129 |
michael |
3752 |
|
130 |
adx |
30 |
case 'l': |
131 |
|
|
mode.limit = atoi(parv[4 + args]); |
132 |
michael |
3751 |
++args; |
133 |
michael |
632 |
|
134 |
|
|
if (parc < 5 + args) |
135 |
michael |
2820 |
return 0; |
136 |
adx |
30 |
break; |
137 |
michael |
3752 |
|
138 |
|
|
default: |
139 |
|
|
mode.mode |= ModeTable[(unsigned char)*modes].d; |
140 |
|
|
break; |
141 |
adx |
30 |
} |
142 |
|
|
} |
143 |
|
|
|
144 |
michael |
632 |
if ((chptr = hash_find_channel(parv[2])) == NULL) |
145 |
|
|
{ |
146 |
|
|
isnew = 1; |
147 |
|
|
chptr = make_channel(parv[2]); |
148 |
|
|
} |
149 |
|
|
|
150 |
adx |
30 |
parabuf[0] = '\0'; |
151 |
michael |
632 |
oldts = chptr->channelts; |
152 |
adx |
30 |
oldmode = &chptr->mode; |
153 |
|
|
|
154 |
michael |
4341 |
if (ConfigGeneral.ignore_bogus_ts) |
155 |
adx |
30 |
{ |
156 |
|
|
if (newts < 800000000) |
157 |
|
|
{ |
158 |
michael |
1618 |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
159 |
michael |
3169 |
"*** Bogus TS %lu on %s ignored from %s(via %s)", |
160 |
michael |
4617 |
(unsigned long)newts, chptr->name, |
161 |
michael |
3169 |
source_p->name, source_p->from->name); |
162 |
adx |
30 |
|
163 |
|
|
newts = (oldts == 0) ? 0 : 800000000; |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
else |
167 |
|
|
{ |
168 |
|
|
if (!newts && !isnew && oldts) |
169 |
|
|
{ |
170 |
michael |
4794 |
sendto_channel_local(0, chptr, |
171 |
michael |
2820 |
":%s NOTICE %s :*** Notice -- TS for %s changed from %lu to 0", |
172 |
michael |
4617 |
me.name, chptr->name, chptr->name, (unsigned long)oldts); |
173 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
174 |
michael |
2820 |
"Server %s changing TS on %s from %lu to 0", |
175 |
michael |
4617 |
source_p->name, chptr->name, (unsigned long)oldts); |
176 |
adx |
30 |
} |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
if (isnew) |
180 |
|
|
chptr->channelts = tstosend = newts; |
181 |
|
|
else if (newts == 0 || oldts == 0) |
182 |
|
|
chptr->channelts = tstosend = 0; |
183 |
|
|
else if (newts == oldts) |
184 |
|
|
tstosend = oldts; |
185 |
|
|
else if (newts < oldts) |
186 |
|
|
{ |
187 |
michael |
1243 |
keep_our_modes = 0; |
188 |
adx |
30 |
chptr->channelts = tstosend = newts; |
189 |
|
|
} |
190 |
|
|
else |
191 |
|
|
{ |
192 |
michael |
1243 |
keep_new_modes = 0; |
193 |
adx |
30 |
tstosend = oldts; |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
if (!keep_new_modes) |
197 |
|
|
mode = *oldmode; |
198 |
|
|
else if (keep_our_modes) |
199 |
|
|
{ |
200 |
|
|
mode.mode |= oldmode->mode; |
201 |
michael |
3246 |
|
202 |
adx |
30 |
if (oldmode->limit > mode.limit) |
203 |
|
|
mode.limit = oldmode->limit; |
204 |
|
|
if (strcmp(mode.key, oldmode->key) < 0) |
205 |
michael |
3334 |
strlcpy(mode.key, oldmode->key, sizeof(mode.key)); |
206 |
adx |
30 |
} |
207 |
michael |
3246 |
|
208 |
adx |
30 |
set_final_mode(&mode, oldmode); |
209 |
|
|
chptr->mode = mode; |
210 |
|
|
|
211 |
|
|
/* Lost the TS, other side wins, so remove modes on this side */ |
212 |
|
|
if (!keep_our_modes) |
213 |
|
|
{ |
214 |
michael |
4807 |
/* Update channel name to be the correct case */ |
215 |
|
|
if (!isnew) |
216 |
michael |
4809 |
strlcpy(chptr->name, parv[2], sizeof(chptr->name)); |
217 |
michael |
4807 |
|
218 |
adx |
30 |
remove_our_modes(chptr, source_p); |
219 |
michael |
873 |
|
220 |
michael |
4809 |
if (dlink_list_length(&chptr->banlist)) |
221 |
|
|
remove_ban_list(chptr, source_p, &chptr->banlist, 'b'); |
222 |
|
|
|
223 |
|
|
if (dlink_list_length(&chptr->exceptlist)) |
224 |
|
|
remove_ban_list(chptr, source_p, &chptr->exceptlist, 'e'); |
225 |
|
|
|
226 |
|
|
if (dlink_list_length(&chptr->invexlist)) |
227 |
|
|
remove_ban_list(chptr, source_p, &chptr->invexlist, 'I'); |
228 |
michael |
4812 |
|
229 |
michael |
4809 |
clear_ban_cache(chptr); |
230 |
michael |
4812 |
clear_invites(chptr); |
231 |
michael |
4809 |
|
232 |
michael |
1203 |
if (chptr->topic[0]) |
233 |
michael |
873 |
{ |
234 |
michael |
3940 |
channel_set_topic(chptr, "", "", 0, 0); |
235 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s TOPIC %s :", |
236 |
michael |
873 |
(IsHidden(source_p) || |
237 |
|
|
ConfigServerHide.hide_servers) ? |
238 |
michael |
4617 |
me.name : source_p->name, chptr->name); |
239 |
michael |
873 |
} |
240 |
|
|
|
241 |
michael |
4794 |
sendto_channel_local(0, chptr, |
242 |
michael |
2820 |
":%s NOTICE %s :*** Notice -- TS for %s changed from %lu to %lu", |
243 |
michael |
4617 |
me.name, chptr->name, chptr->name, |
244 |
michael |
2820 |
(unsigned long)oldts, (unsigned long)newts); |
245 |
adx |
30 |
} |
246 |
|
|
|
247 |
|
|
if (*modebuf != '\0') |
248 |
|
|
{ |
249 |
|
|
/* This _SHOULD_ be to ALL_MEMBERS |
250 |
|
|
* It contains only +imnpstlk, etc */ |
251 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s MODE %s %s %s", |
252 |
michael |
4617 |
servername, chptr->name, modebuf, parabuf); |
253 |
adx |
30 |
} |
254 |
|
|
|
255 |
michael |
3246 |
if (*parv[3] != '0' && keep_new_modes) |
256 |
adx |
30 |
channel_modes(chptr, source_p, modebuf, parabuf); |
257 |
|
|
else |
258 |
|
|
{ |
259 |
|
|
modebuf[0] = '0'; |
260 |
|
|
modebuf[1] = '\0'; |
261 |
|
|
} |
262 |
|
|
|
263 |
michael |
1793 |
buflen = snprintf(uid_buf, sizeof(uid_buf), ":%s SJOIN %lu %s %s %s:", |
264 |
michael |
3186 |
source_p->id, (unsigned long)tstosend, |
265 |
michael |
4617 |
chptr->name, modebuf, parabuf); |
266 |
adx |
30 |
uid_ptr = uid_buf + buflen; |
267 |
|
|
|
268 |
michael |
3751 |
/* |
269 |
|
|
* Check we can fit a nick on the end, as well as \r\n and a prefix " |
270 |
adx |
30 |
* @%+", and a space. |
271 |
|
|
*/ |
272 |
|
|
if (buflen >= (IRCD_BUFSIZE - IRCD_MAX(NICKLEN, IDLEN) - 2 - 3 - 1)) |
273 |
|
|
{ |
274 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
275 |
michael |
3162 |
"Long SJOIN from server: %s(via %s) (ignored)", |
276 |
|
|
source_p->name, source_p->from->name); |
277 |
michael |
2820 |
return 0; |
278 |
adx |
30 |
} |
279 |
|
|
|
280 |
|
|
mbuf = modebuf; |
281 |
|
|
sendbuf[0] = '\0'; |
282 |
|
|
pargs = 0; |
283 |
|
|
|
284 |
|
|
*mbuf++ = '+'; |
285 |
|
|
|
286 |
|
|
s = parv[args + 4]; |
287 |
|
|
while (*s == ' ') |
288 |
michael |
3751 |
++s; |
289 |
michael |
3246 |
|
290 |
|
|
if ((p = strchr(s, ' '))) |
291 |
adx |
30 |
{ |
292 |
|
|
*p++ = '\0'; |
293 |
michael |
3751 |
|
294 |
adx |
30 |
while (*p == ' ') |
295 |
michael |
3751 |
++p; |
296 |
adx |
30 |
have_many_nicks = *p; |
297 |
|
|
} |
298 |
|
|
|
299 |
|
|
while (*s) |
300 |
|
|
{ |
301 |
michael |
1243 |
int valid_mode = 1; |
302 |
adx |
30 |
fl = 0; |
303 |
|
|
|
304 |
|
|
do |
305 |
|
|
{ |
306 |
|
|
switch (*s) |
307 |
|
|
{ |
308 |
michael |
3751 |
case '@': |
309 |
|
|
fl |= CHFL_CHANOP; |
310 |
|
|
++s; |
311 |
|
|
break; |
312 |
|
|
case '%': |
313 |
|
|
fl |= CHFL_HALFOP; |
314 |
|
|
++s; |
315 |
|
|
break; |
316 |
|
|
case '+': |
317 |
|
|
fl |= CHFL_VOICE; |
318 |
|
|
++s; |
319 |
|
|
break; |
320 |
|
|
default: |
321 |
|
|
valid_mode = 0; |
322 |
|
|
break; |
323 |
adx |
30 |
} |
324 |
|
|
} while (valid_mode); |
325 |
|
|
|
326 |
|
|
/* |
327 |
michael |
4580 |
* If the client doesn't exist, or if it's fake direction/server, skip. |
328 |
michael |
4299 |
* we cannot send ERR_NOSUCHNICK here because if it's a UID, we cannot |
329 |
|
|
* lookup the nick, and it's better to never send the numeric than only |
330 |
adx |
30 |
* sometimes. |
331 |
|
|
*/ |
332 |
michael |
3751 |
if ((target_p = find_chasing(source_p, s)) == NULL || target_p->from != source_p->from) |
333 |
adx |
30 |
goto nextnick; |
334 |
|
|
|
335 |
michael |
3186 |
len_uid = strlen(target_p->id); |
336 |
adx |
30 |
up = uid_prefix; |
337 |
|
|
|
338 |
|
|
if (keep_new_modes) |
339 |
|
|
{ |
340 |
|
|
if (fl & CHFL_CHANOP) |
341 |
|
|
{ |
342 |
|
|
*up++ = '@'; |
343 |
michael |
2820 |
len_uid++; |
344 |
adx |
30 |
} |
345 |
michael |
3725 |
|
346 |
adx |
30 |
if (fl & CHFL_HALFOP) |
347 |
|
|
{ |
348 |
|
|
*up++ = '%'; |
349 |
michael |
2820 |
len_uid++; |
350 |
adx |
30 |
} |
351 |
michael |
3725 |
|
352 |
adx |
30 |
if (fl & CHFL_VOICE) |
353 |
|
|
{ |
354 |
|
|
*up++ = '+'; |
355 |
michael |
2820 |
len_uid++; |
356 |
adx |
30 |
} |
357 |
|
|
} |
358 |
|
|
else |
359 |
michael |
3694 |
fl = 0; |
360 |
|
|
|
361 |
michael |
3135 |
*up = '\0'; |
362 |
adx |
30 |
|
363 |
|
|
if ((uid_ptr - uid_buf + len_uid) > (IRCD_BUFSIZE - 2)) |
364 |
|
|
{ |
365 |
michael |
3156 |
sendto_server(source_p, NOCAPS, NOCAPS, "%s", uid_buf); |
366 |
michael |
2820 |
|
367 |
michael |
1793 |
buflen = snprintf(uid_buf, sizeof(uid_buf), ":%s SJOIN %lu %s %s %s:", |
368 |
michael |
3186 |
source_p->id, (unsigned long)tstosend, |
369 |
michael |
4617 |
chptr->name, modebuf, parabuf); |
370 |
adx |
30 |
uid_ptr = uid_buf + buflen; |
371 |
|
|
} |
372 |
|
|
|
373 |
michael |
3186 |
uid_ptr += sprintf(uid_ptr, "%s%s ", uid_prefix, target_p->id); |
374 |
michael |
2820 |
|
375 |
adx |
30 |
if (!IsMember(target_p, chptr)) |
376 |
|
|
{ |
377 |
|
|
add_user_to_channel(chptr, target_p, fl, !have_many_nicks); |
378 |
michael |
4793 |
|
379 |
|
|
sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s", |
380 |
|
|
target_p->name, target_p->username, |
381 |
|
|
target_p->host, chptr->name, |
382 |
|
|
(!IsDigit(target_p->svid[0]) && target_p->svid[0] != '*') ? target_p->svid : "*", |
383 |
|
|
target_p->info); |
384 |
|
|
sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s", |
385 |
|
|
target_p->name, target_p->username, |
386 |
|
|
target_p->host, chptr->name); |
387 |
|
|
|
388 |
michael |
1734 |
if (target_p->away[0]) |
389 |
michael |
4793 |
sendto_channel_local_butone(target_p, CAP_AWAY_NOTIFY, 0, chptr, |
390 |
michael |
1734 |
":%s!%s@%s AWAY :%s", |
391 |
|
|
target_p->name, target_p->username, |
392 |
|
|
target_p->host, target_p->away); |
393 |
adx |
30 |
} |
394 |
|
|
|
395 |
|
|
if (fl & CHFL_CHANOP) |
396 |
|
|
{ |
397 |
|
|
*mbuf++ = 'o'; |
398 |
|
|
para[pargs++] = target_p->name; |
399 |
|
|
|
400 |
|
|
if (pargs >= MAXMODEPARAMS) |
401 |
|
|
{ |
402 |
michael |
2820 |
/* |
403 |
|
|
* Ok, the code is now going to "walk" through |
404 |
|
|
* sendbuf, filling in para strings. So, I will use sptr |
405 |
|
|
* to point into the sendbuf. |
406 |
|
|
* Notice, that ircsprintf() returns the number of chars |
407 |
|
|
* successfully inserted into string. |
408 |
|
|
* - Dianora |
409 |
|
|
*/ |
410 |
adx |
30 |
|
411 |
michael |
2820 |
sptr = sendbuf; |
412 |
adx |
30 |
*mbuf = '\0'; |
413 |
michael |
2820 |
|
414 |
michael |
3246 |
for (lcount = 0; lcount < MAXMODEPARAMS; ++lcount) |
415 |
adx |
30 |
{ |
416 |
michael |
2820 |
slen = sprintf(sptr, " %s", para[lcount]); /* see? */ |
417 |
|
|
sptr += slen; /* ready for next */ |
418 |
adx |
30 |
} |
419 |
michael |
3246 |
|
420 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s MODE %s %s%s", |
421 |
|
|
servername, chptr->name, modebuf, sendbuf); |
422 |
adx |
30 |
mbuf = modebuf; |
423 |
|
|
*mbuf++ = '+'; |
424 |
|
|
|
425 |
|
|
sendbuf[0] = '\0'; |
426 |
|
|
pargs = 0; |
427 |
|
|
} |
428 |
|
|
} |
429 |
michael |
3725 |
|
430 |
adx |
30 |
if (fl & CHFL_HALFOP) |
431 |
|
|
{ |
432 |
|
|
*mbuf++ = 'h'; |
433 |
|
|
para[pargs++] = target_p->name; |
434 |
|
|
|
435 |
|
|
if (pargs >= MAXMODEPARAMS) |
436 |
|
|
{ |
437 |
|
|
sptr = sendbuf; |
438 |
|
|
*mbuf = '\0'; |
439 |
michael |
3246 |
|
440 |
|
|
for (lcount = 0; lcount < MAXMODEPARAMS; ++lcount) |
441 |
adx |
30 |
{ |
442 |
michael |
1793 |
slen = sprintf(sptr, " %s", para[lcount]); |
443 |
adx |
30 |
sptr += slen; |
444 |
|
|
} |
445 |
michael |
3246 |
|
446 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s MODE %s %s%s", |
447 |
michael |
4617 |
servername, chptr->name, modebuf, sendbuf); |
448 |
adx |
30 |
|
449 |
|
|
mbuf = modebuf; |
450 |
|
|
*mbuf++ = '+'; |
451 |
|
|
|
452 |
|
|
sendbuf[0] = '\0'; |
453 |
|
|
pargs = 0; |
454 |
|
|
} |
455 |
|
|
} |
456 |
michael |
3725 |
|
457 |
adx |
30 |
if (fl & CHFL_VOICE) |
458 |
|
|
{ |
459 |
|
|
*mbuf++ = 'v'; |
460 |
|
|
para[pargs++] = target_p->name; |
461 |
|
|
|
462 |
|
|
if (pargs >= MAXMODEPARAMS) |
463 |
|
|
{ |
464 |
michael |
2820 |
sptr = sendbuf; |
465 |
adx |
30 |
*mbuf = '\0'; |
466 |
michael |
3246 |
|
467 |
|
|
for (lcount = 0; lcount < MAXMODEPARAMS; ++lcount) |
468 |
adx |
30 |
{ |
469 |
michael |
1793 |
slen = sprintf(sptr, " %s", para[lcount]); |
470 |
michael |
2820 |
sptr += slen; |
471 |
adx |
30 |
} |
472 |
michael |
3246 |
|
473 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s MODE %s %s%s", |
474 |
michael |
4617 |
servername, chptr->name, modebuf, sendbuf); |
475 |
adx |
30 |
|
476 |
|
|
mbuf = modebuf; |
477 |
|
|
*mbuf++ = '+'; |
478 |
|
|
|
479 |
|
|
sendbuf[0] = '\0'; |
480 |
|
|
pargs = 0; |
481 |
|
|
} |
482 |
|
|
} |
483 |
|
|
|
484 |
|
|
nextnick: |
485 |
|
|
if ((s = p) == NULL) |
486 |
|
|
break; |
487 |
michael |
3246 |
|
488 |
adx |
30 |
while (*s == ' ') |
489 |
michael |
3246 |
++s; |
490 |
|
|
|
491 |
|
|
if ((p = strchr(s, ' '))) |
492 |
adx |
30 |
{ |
493 |
michael |
3246 |
*p++ = '\0'; |
494 |
|
|
|
495 |
adx |
30 |
while (*p == ' ') |
496 |
michael |
3246 |
++p; |
497 |
adx |
30 |
} |
498 |
|
|
} |
499 |
|
|
|
500 |
|
|
*mbuf = '\0'; |
501 |
|
|
*(uid_ptr - 1) = '\0'; |
502 |
|
|
|
503 |
|
|
/* |
504 |
|
|
* checking for lcount < MAXMODEPARAMS at this time is wrong |
505 |
|
|
* since the code has already verified above that pargs < MAXMODEPARAMS |
506 |
|
|
* checking for para[lcount] != '\0' is also wrong, since |
507 |
|
|
* there is no place where para[lcount] is set! |
508 |
|
|
* - Dianora |
509 |
|
|
*/ |
510 |
|
|
|
511 |
michael |
3246 |
if (pargs) |
512 |
adx |
30 |
{ |
513 |
|
|
sptr = sendbuf; |
514 |
|
|
|
515 |
michael |
3246 |
for (lcount = 0; lcount < pargs; ++lcount) |
516 |
adx |
30 |
{ |
517 |
michael |
1793 |
slen = sprintf(sptr, " %s", para[lcount]); |
518 |
adx |
30 |
sptr += slen; |
519 |
|
|
} |
520 |
|
|
|
521 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s MODE %s %s%s", |
522 |
michael |
4617 |
servername, chptr->name, modebuf, sendbuf); |
523 |
adx |
30 |
} |
524 |
|
|
|
525 |
michael |
4299 |
/* |
526 |
|
|
* If this happens, it's the result of a malformed SJOIN |
527 |
adx |
30 |
* a remnant from the old persistent channel code. *sigh* |
528 |
|
|
* Or it could be the result of a client just leaving |
529 |
|
|
* and leaving us with a channel formed just as the client parts. |
530 |
|
|
* - Dianora |
531 |
|
|
*/ |
532 |
michael |
3246 |
if (!dlink_list_length(&chptr->members) && isnew) |
533 |
adx |
30 |
{ |
534 |
|
|
destroy_channel(chptr); |
535 |
michael |
2820 |
return 0; |
536 |
adx |
30 |
} |
537 |
|
|
|
538 |
michael |
3246 |
if (*parv[4 + args] == '\0') |
539 |
michael |
2820 |
return 0; |
540 |
adx |
30 |
|
541 |
michael |
3156 |
sendto_server(source_p, NOCAPS, NOCAPS, "%s", uid_buf); |
542 |
michael |
2820 |
return 0; |
543 |
adx |
30 |
} |
544 |
|
|
|
545 |
|
|
/* set_final_mode |
546 |
|
|
* |
547 |
|
|
* inputs - channel mode |
548 |
|
|
* - old channel mode |
549 |
|
|
* output - NONE |
550 |
|
|
* side effects - walk through all the channel modes turning off modes |
551 |
|
|
* that were on in oldmode but aren't on in mode. |
552 |
|
|
* Then walk through turning on modes that are on in mode |
553 |
|
|
* but were not set in oldmode. |
554 |
|
|
*/ |
555 |
|
|
static void |
556 |
|
|
set_final_mode(struct Mode *mode, struct Mode *oldmode) |
557 |
|
|
{ |
558 |
|
|
char *pbuf = parabuf; |
559 |
michael |
3751 |
int len = 0; |
560 |
adx |
30 |
|
561 |
|
|
*mbuf++ = '-'; |
562 |
|
|
|
563 |
michael |
3751 |
for (const struct mode_letter *tab = chan_modes; tab->letter; ++tab) |
564 |
michael |
1175 |
if ((tab->mode & oldmode->mode) && |
565 |
|
|
!(tab->mode & mode->mode)) |
566 |
|
|
*mbuf++ = tab->letter; |
567 |
adx |
30 |
|
568 |
michael |
3246 |
if (oldmode->limit && mode->limit == 0) |
569 |
adx |
30 |
*mbuf++ = 'l'; |
570 |
|
|
|
571 |
|
|
if (oldmode->key[0] && !mode->key[0]) |
572 |
|
|
{ |
573 |
|
|
*mbuf++ = 'k'; |
574 |
michael |
1793 |
len = sprintf(pbuf, "%s ", oldmode->key); |
575 |
adx |
30 |
pbuf += len; |
576 |
|
|
pargs++; |
577 |
|
|
} |
578 |
|
|
|
579 |
michael |
3246 |
if (*(mbuf - 1) == '-') |
580 |
|
|
*(mbuf - 1) = '+'; |
581 |
adx |
30 |
else |
582 |
|
|
*mbuf++ = '+'; |
583 |
|
|
|
584 |
michael |
3751 |
for (const struct mode_letter *tab = chan_modes; tab->letter; ++tab) |
585 |
michael |
1175 |
if ((tab->mode & mode->mode) && |
586 |
|
|
!(tab->mode & oldmode->mode)) |
587 |
|
|
*mbuf++ = tab->letter; |
588 |
adx |
30 |
|
589 |
michael |
3246 |
if (mode->limit && oldmode->limit != mode->limit) |
590 |
adx |
30 |
{ |
591 |
|
|
*mbuf++ = 'l'; |
592 |
michael |
1793 |
len = sprintf(pbuf, "%d ", mode->limit); |
593 |
adx |
30 |
pbuf += len; |
594 |
|
|
pargs++; |
595 |
|
|
} |
596 |
|
|
|
597 |
|
|
if (mode->key[0] && strcmp(oldmode->key, mode->key)) |
598 |
|
|
{ |
599 |
|
|
*mbuf++ = 'k'; |
600 |
michael |
1793 |
len = sprintf(pbuf, "%s ", mode->key); |
601 |
adx |
30 |
pbuf += len; |
602 |
|
|
pargs++; |
603 |
|
|
} |
604 |
michael |
3246 |
|
605 |
|
|
if (*(mbuf - 1) == '+') |
606 |
|
|
*(mbuf - 1) = '\0'; |
607 |
adx |
30 |
else |
608 |
|
|
*mbuf = '\0'; |
609 |
|
|
} |
610 |
|
|
|
611 |
|
|
/* remove_our_modes() |
612 |
|
|
* |
613 |
|
|
* inputs - pointer to channel to remove modes from |
614 |
|
|
* - client pointer |
615 |
|
|
* output - NONE |
616 |
|
|
* side effects - Go through the local members, remove all their |
617 |
|
|
* chanop modes etc., this side lost the TS. |
618 |
|
|
*/ |
619 |
|
|
static void |
620 |
|
|
remove_our_modes(struct Channel *chptr, struct Client *source_p) |
621 |
|
|
{ |
622 |
|
|
remove_a_mode(chptr, source_p, CHFL_CHANOP, 'o'); |
623 |
|
|
remove_a_mode(chptr, source_p, CHFL_HALFOP, 'h'); |
624 |
|
|
remove_a_mode(chptr, source_p, CHFL_VOICE, 'v'); |
625 |
|
|
} |
626 |
|
|
|
627 |
|
|
/* remove_a_mode() |
628 |
|
|
* |
629 |
|
|
* inputs - pointer to channel |
630 |
|
|
* - server or client removing the mode |
631 |
|
|
* - mask o/h/v mask to be removed |
632 |
|
|
* - flag o/h/v to be removed |
633 |
|
|
* output - NONE |
634 |
|
|
* side effects - remove ONE mode from all members of a channel |
635 |
|
|
*/ |
636 |
|
|
static void |
637 |
|
|
remove_a_mode(struct Channel *chptr, struct Client *source_p, |
638 |
|
|
int mask, char flag) |
639 |
|
|
{ |
640 |
michael |
4816 |
dlink_node *node = NULL; |
641 |
adx |
30 |
char lmodebuf[MODEBUFLEN]; |
642 |
michael |
3246 |
char *sp = sendbuf; |
643 |
adx |
30 |
const char *lpara[MAXMODEPARAMS]; |
644 |
michael |
3751 |
unsigned int count = 0; |
645 |
|
|
int l = 0; |
646 |
adx |
30 |
|
647 |
|
|
mbuf = lmodebuf; |
648 |
|
|
*mbuf++ = '-'; |
649 |
|
|
*sp = '\0'; |
650 |
|
|
|
651 |
michael |
4816 |
DLINK_FOREACH(node, chptr->members.head) |
652 |
adx |
30 |
{ |
653 |
michael |
4816 |
struct Membership *member = node->data; |
654 |
adx |
30 |
|
655 |
michael |
4816 |
if ((member->flags & mask) == 0) |
656 |
adx |
30 |
continue; |
657 |
|
|
|
658 |
michael |
4816 |
member->flags &= ~mask; |
659 |
adx |
30 |
|
660 |
michael |
4816 |
lpara[count++] = member->client_p->name; |
661 |
adx |
30 |
|
662 |
|
|
*mbuf++ = flag; |
663 |
|
|
|
664 |
|
|
if (count >= MAXMODEPARAMS) |
665 |
|
|
{ |
666 |
michael |
3751 |
for (unsigned int i = 0; i < MAXMODEPARAMS; ++i) |
667 |
adx |
30 |
{ |
668 |
michael |
1793 |
l = sprintf(sp, " %s", lpara[i]); |
669 |
michael |
2820 |
sp += l; |
670 |
adx |
30 |
} |
671 |
|
|
|
672 |
|
|
*mbuf = '\0'; |
673 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s MODE %s %s%s", |
674 |
michael |
2820 |
(IsHidden(source_p) || ConfigServerHide.hide_servers) ? |
675 |
|
|
me.name : source_p->name, |
676 |
michael |
4617 |
chptr->name, lmodebuf, sendbuf); |
677 |
adx |
30 |
mbuf = lmodebuf; |
678 |
|
|
*mbuf++ = '-'; |
679 |
|
|
count = 0; |
680 |
|
|
sp = sendbuf; |
681 |
|
|
*sp = '\0'; |
682 |
|
|
} |
683 |
|
|
} |
684 |
|
|
|
685 |
michael |
3246 |
if (count) |
686 |
adx |
30 |
{ |
687 |
|
|
*mbuf = '\0'; |
688 |
michael |
3246 |
|
689 |
michael |
3751 |
for (unsigned int i = 0; i < count; ++i) |
690 |
adx |
30 |
{ |
691 |
michael |
1793 |
l = sprintf(sp, " %s", lpara[i]); |
692 |
adx |
30 |
sp += l; |
693 |
|
|
} |
694 |
michael |
3246 |
|
695 |
michael |
4794 |
sendto_channel_local(0, chptr, ":%s MODE %s %s%s", |
696 |
michael |
2820 |
(IsHidden(source_p) || ConfigServerHide.hide_servers) ? |
697 |
|
|
me.name : source_p->name, |
698 |
michael |
4617 |
chptr->name, lmodebuf, sendbuf); |
699 |
adx |
30 |
} |
700 |
|
|
} |
701 |
|
|
|
702 |
|
|
/* remove_ban_list() |
703 |
|
|
* |
704 |
michael |
3041 |
* inputs - channel, source, list to remove, char of mode |
705 |
adx |
30 |
* outputs - none |
706 |
michael |
3135 |
* side effects - given ban list is removed, modes are sent to local clients |
707 |
adx |
30 |
*/ |
708 |
|
|
static void |
709 |
|
|
remove_ban_list(struct Channel *chptr, struct Client *source_p, |
710 |
michael |
3041 |
dlink_list *list, char c) |
711 |
adx |
30 |
{ |
712 |
|
|
char lmodebuf[MODEBUFLEN]; |
713 |
|
|
char lparabuf[IRCD_BUFSIZE]; |
714 |
michael |
4816 |
dlink_node *node = NULL, *node_next = NULL; |
715 |
adx |
30 |
char *pbuf = NULL; |
716 |
michael |
2820 |
int count = 0; |
717 |
adx |
30 |
int cur_len, mlen, plen; |
718 |
|
|
|
719 |
|
|
pbuf = lparabuf; |
720 |
michael |
3751 |
cur_len = mlen = snprintf(lmodebuf, sizeof(lmodebuf), ":%s MODE %s -", |
721 |
michael |
4617 |
source_p->name, chptr->name); |
722 |
adx |
30 |
mbuf = lmodebuf + mlen; |
723 |
|
|
|
724 |
michael |
4816 |
DLINK_FOREACH_SAFE(node, node_next, list->head) |
725 |
adx |
30 |
{ |
726 |
michael |
4816 |
struct Ban *ban = node->data; |
727 |
adx |
30 |
|
728 |
michael |
4816 |
plen = ban->len + 4; /* another +b and "!@ " */ |
729 |
michael |
3246 |
|
730 |
adx |
30 |
if (count >= MAXMODEPARAMS || |
731 |
|
|
(cur_len + 1 /* space between */ + (plen - 1)) > IRCD_BUFSIZE - 2) |
732 |
|
|
{ |
733 |
|
|
/* NUL-terminate and remove trailing space */ |
734 |
|
|
*mbuf = *(pbuf - 1) = '\0'; |
735 |
michael |
4794 |
sendto_channel_local(0, chptr, "%s %s", lmodebuf, lparabuf); |
736 |
adx |
30 |
cur_len = mlen; |
737 |
|
|
mbuf = lmodebuf + mlen; |
738 |
|
|
pbuf = lparabuf; |
739 |
|
|
count = 0; |
740 |
michael |
2820 |
} |
741 |
adx |
30 |
|
742 |
|
|
*mbuf++ = c; |
743 |
|
|
cur_len += plen; |
744 |
michael |
4816 |
pbuf += sprintf(pbuf, "%s!%s@%s ", ban->name, ban->user, ban->host); |
745 |
adx |
30 |
++count; |
746 |
|
|
|
747 |
michael |
4816 |
remove_ban(ban, list); |
748 |
adx |
30 |
} |
749 |
|
|
|
750 |
|
|
*mbuf = *(pbuf - 1) = '\0'; |
751 |
michael |
4794 |
sendto_channel_local(0, chptr, "%s %s", lmodebuf, lparabuf); |
752 |
adx |
30 |
} |
753 |
michael |
1230 |
|
754 |
michael |
2820 |
static struct Message sjoin_msgtab = |
755 |
|
|
{ |
756 |
michael |
4546 |
"SJOIN", NULL, 0, 0, 5, MAXPARA, MFLG_SLOW, 0, |
757 |
michael |
2820 |
{ m_unregistered, m_ignore, ms_sjoin, m_ignore, m_ignore, m_ignore } |
758 |
michael |
1230 |
}; |
759 |
|
|
|
760 |
|
|
static void |
761 |
|
|
module_init(void) |
762 |
|
|
{ |
763 |
|
|
mod_add_cmd(&sjoin_msgtab); |
764 |
|
|
} |
765 |
|
|
|
766 |
|
|
static void |
767 |
|
|
module_exit(void) |
768 |
|
|
{ |
769 |
|
|
mod_del_cmd(&sjoin_msgtab); |
770 |
|
|
} |
771 |
|
|
|
772 |
michael |
2820 |
struct module module_entry = |
773 |
|
|
{ |
774 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
775 |
|
|
.name = NULL, |
776 |
|
|
.version = "$Revision$", |
777 |
|
|
.handle = NULL, |
778 |
|
|
.modinit = module_init, |
779 |
|
|
.modexit = module_exit, |
780 |
|
|
.flags = MODULE_FLAG_CORE |
781 |
|
|
}; |