1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_mode.c: Sets a user or channel mode. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
|
|
#include "tools.h" |
27 |
|
|
#include "handlers.h" |
28 |
|
|
#include "channel.h" |
29 |
|
|
#include "channel_mode.h" |
30 |
|
|
#include "client.h" |
31 |
|
|
#include "hash.h" |
32 |
|
|
#include "irc_string.h" |
33 |
|
|
#include "sprintf_irc.h" |
34 |
|
|
#include "ircd.h" |
35 |
|
|
#include "numeric.h" |
36 |
|
|
#include "s_user.h" |
37 |
|
|
#include "s_conf.h" |
38 |
|
|
#include "s_serv.h" |
39 |
|
|
#include "send.h" |
40 |
|
|
#include "msg.h" |
41 |
|
|
#include "parse.h" |
42 |
|
|
#include "modules.h" |
43 |
|
|
#include "packet.h" |
44 |
|
|
#include "common.h" |
45 |
|
|
|
46 |
|
|
static void m_mode(struct Client *, struct Client *, int, char *[]); |
47 |
|
|
static void ms_tmode(struct Client *, struct Client *, int, char *[]); |
48 |
|
|
static void ms_bmask(struct Client *, struct Client *, int, char *[]); |
49 |
|
|
|
50 |
|
|
struct Message mode_msgtab = { |
51 |
|
|
"MODE", 0, 0, 2, 0, MFLG_SLOW, 0, |
52 |
|
|
{m_unregistered, m_mode, m_mode, m_ignore, m_mode, m_ignore} |
53 |
|
|
}; |
54 |
|
|
|
55 |
|
|
struct Message tmode_msgtab = { |
56 |
|
|
"TMODE", 0, 0, 4, 0, MFLG_SLOW, 0, |
57 |
|
|
{m_ignore, m_ignore, ms_tmode, m_ignore, m_ignore, m_ignore} |
58 |
|
|
}; |
59 |
|
|
|
60 |
|
|
struct Message bmask_msgtab = { |
61 |
|
|
"BMASK", 0, 0, 5, 0, MFLG_SLOW, 0, |
62 |
|
|
{m_ignore, m_ignore, ms_bmask, m_ignore, m_ignore, m_ignore} |
63 |
|
|
}; |
64 |
|
|
|
65 |
|
|
#ifndef STATIC_MODULES |
66 |
|
|
void |
67 |
|
|
_modinit(void) |
68 |
|
|
{ |
69 |
|
|
mod_add_cmd(&mode_msgtab); |
70 |
|
|
mod_add_cmd(&tmode_msgtab); |
71 |
|
|
mod_add_cmd(&bmask_msgtab); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
void |
75 |
|
|
_moddeinit(void) |
76 |
|
|
{ |
77 |
|
|
mod_del_cmd(&mode_msgtab); |
78 |
|
|
mod_del_cmd(&tmode_msgtab); |
79 |
|
|
mod_del_cmd(&bmask_msgtab); |
80 |
|
|
} |
81 |
|
|
|
82 |
knight |
31 |
const char *_version = "$Revision$"; |
83 |
adx |
30 |
#endif |
84 |
|
|
|
85 |
|
|
/* |
86 |
|
|
* m_mode - MODE command handler |
87 |
|
|
* parv[0] - sender |
88 |
|
|
* parv[1] - channel |
89 |
|
|
*/ |
90 |
|
|
static void |
91 |
|
|
m_mode(struct Client *client_p, struct Client *source_p, |
92 |
|
|
int parc, char *parv[]) |
93 |
|
|
{ |
94 |
|
|
struct Channel *chptr = NULL; |
95 |
|
|
struct Membership *member; |
96 |
|
|
static char modebuf[MODEBUFLEN]; |
97 |
|
|
static char parabuf[MODEBUFLEN]; |
98 |
|
|
|
99 |
michael |
885 |
if (EmptyString(parv[1])) |
100 |
adx |
30 |
{ |
101 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
102 |
|
|
me.name, source_p->name, "MODE"); |
103 |
|
|
return; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
/* Now, try to find the channel in question */ |
107 |
|
|
if (!IsChanPrefix(*parv[1])) |
108 |
|
|
{ |
109 |
|
|
/* if here, it has to be a non-channel name */ |
110 |
|
|
set_user_mode(client_p, source_p, parc, parv); |
111 |
|
|
return; |
112 |
|
|
} |
113 |
|
|
|
114 |
michael |
885 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
115 |
adx |
30 |
{ |
116 |
db |
848 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
117 |
|
|
ID_or_name(&me, source_p->from), |
118 |
|
|
ID_or_name(source_p, source_p->from), |
119 |
|
|
parv[1]); |
120 |
|
|
return; |
121 |
|
|
} |
122 |
adx |
30 |
|
123 |
|
|
/* Now known the channel exists */ |
124 |
|
|
if (parc < 3) |
125 |
|
|
{ |
126 |
|
|
channel_modes(chptr, source_p, modebuf, parabuf); |
127 |
|
|
sendto_one(source_p, form_str(RPL_CHANNELMODEIS), |
128 |
|
|
me.name, source_p->name, chptr->chname, modebuf, parabuf); |
129 |
|
|
sendto_one(source_p, form_str(RPL_CREATIONTIME), |
130 |
|
|
me.name, source_p->name, chptr->chname, chptr->channelts); |
131 |
|
|
} |
132 |
|
|
/* bounce all modes from people we deop on sjoin |
133 |
|
|
* servers have always gotten away with murder, |
134 |
|
|
* including telnet servers *g* - Dianora |
135 |
|
|
* |
136 |
|
|
* XXX Is it worth the bother to make an ms_mode() ? - Dianora |
137 |
|
|
*/ |
138 |
|
|
else if (IsServer(source_p)) |
139 |
|
|
{ |
140 |
|
|
set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2, |
141 |
|
|
chptr->chname); |
142 |
|
|
} |
143 |
|
|
else |
144 |
|
|
{ |
145 |
|
|
member = find_channel_link(source_p, chptr); |
146 |
|
|
|
147 |
|
|
if (!has_member_flags(member, CHFL_DEOPPED)) |
148 |
|
|
{ |
149 |
|
|
/* Finish the flood grace period... */ |
150 |
|
|
if (MyClient(source_p) && !IsFloodDone(source_p)) |
151 |
|
|
{ |
152 |
|
|
if (!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0'))) |
153 |
|
|
flood_endgrace(source_p); |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
set_channel_mode(client_p, source_p, chptr, member, parc - 2, parv + 2, |
157 |
|
|
chptr->chname); |
158 |
|
|
} |
159 |
|
|
} |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
/* |
163 |
|
|
* ms_tmode() |
164 |
|
|
* |
165 |
|
|
* inputs - parv[0] = UID |
166 |
|
|
* parv[1] = TS |
167 |
|
|
* parv[2] = channel name |
168 |
|
|
* parv[3] = modestring |
169 |
|
|
*/ |
170 |
|
|
static void |
171 |
|
|
ms_tmode(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) |
172 |
|
|
{ |
173 |
|
|
struct Channel *chptr = NULL; |
174 |
|
|
struct Membership *member = NULL; |
175 |
|
|
|
176 |
|
|
if ((chptr = hash_find_channel(parv[2])) == NULL) |
177 |
|
|
{ |
178 |
|
|
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
179 |
|
|
ID_or_name(&me, client_p), ID_or_name(source_p, client_p), parv[2]); |
180 |
|
|
return; |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
if (atol(parv[1]) > chptr->channelts) |
184 |
|
|
return; |
185 |
|
|
|
186 |
|
|
if (IsServer(source_p)) |
187 |
|
|
set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3, chptr->chname); |
188 |
|
|
else |
189 |
|
|
{ |
190 |
|
|
member = find_channel_link(source_p, chptr); |
191 |
|
|
|
192 |
|
|
/* XXX are we sure we just want to bail here? */ |
193 |
|
|
if (has_member_flags(member, CHFL_DEOPPED)) |
194 |
|
|
return; |
195 |
|
|
|
196 |
|
|
set_channel_mode(client_p, source_p, chptr, member, parc - 3, parv + 3, chptr->chname); |
197 |
|
|
} |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
/* |
201 |
|
|
* ms_bmask() |
202 |
|
|
* |
203 |
|
|
* inputs - parv[0] = SID |
204 |
|
|
* parv[1] = TS |
205 |
|
|
* parv[2] = channel name |
206 |
|
|
* parv[3] = type of ban to add ('b' 'I' or 'e') |
207 |
|
|
* parv[4] = space delimited list of masks to add |
208 |
|
|
* outputs - none |
209 |
|
|
* side effects - propagates unchanged bmask line to CAP_TS6 servers, |
210 |
|
|
* sends plain modes to the others. nothing is sent |
211 |
|
|
* to the server the issuing server is connected through |
212 |
|
|
*/ |
213 |
|
|
static void |
214 |
|
|
ms_bmask(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) |
215 |
|
|
{ |
216 |
|
|
static char modebuf[IRCD_BUFSIZE]; |
217 |
|
|
static char parabuf[IRCD_BUFSIZE]; |
218 |
|
|
static char banbuf[IRCD_BUFSIZE]; |
219 |
|
|
struct Channel *chptr; |
220 |
|
|
char *s, *t, *mbuf, *pbuf; |
221 |
|
|
long mode_type; |
222 |
|
|
int mlen, tlen; |
223 |
|
|
int modecount = 0; |
224 |
|
|
int needcap = NOCAPS; |
225 |
|
|
|
226 |
|
|
if ((chptr = hash_find_channel(parv[2])) == NULL) |
227 |
|
|
return; |
228 |
|
|
|
229 |
|
|
/* TS is higher, drop it. */ |
230 |
|
|
if (atol(parv[1]) > chptr->channelts) |
231 |
|
|
return; |
232 |
|
|
|
233 |
|
|
switch (*parv[3]) |
234 |
|
|
{ |
235 |
|
|
case 'b': |
236 |
|
|
mode_type = CHFL_BAN; |
237 |
|
|
break; |
238 |
|
|
|
239 |
|
|
case 'e': |
240 |
|
|
mode_type = CHFL_EXCEPTION; |
241 |
|
|
needcap = CAP_EX; |
242 |
|
|
break; |
243 |
|
|
|
244 |
|
|
case 'I': |
245 |
|
|
mode_type = CHFL_INVEX; |
246 |
|
|
needcap = CAP_IE; |
247 |
|
|
break; |
248 |
|
|
|
249 |
|
|
/* maybe we should just blindly propagate this? */ |
250 |
|
|
default: |
251 |
|
|
return; |
252 |
|
|
} |
253 |
|
|
|
254 |
|
|
parabuf[0] = '\0'; |
255 |
|
|
s = banbuf; |
256 |
|
|
strlcpy(s, parv[4], sizeof(banbuf)); |
257 |
|
|
|
258 |
|
|
/* only need to construct one buffer, for non-ts6 servers */ |
259 |
|
|
mlen = ircsprintf(modebuf, ":%s MODE %s +", |
260 |
|
|
source_p->name, chptr->chname); |
261 |
|
|
mbuf = modebuf + mlen; |
262 |
|
|
pbuf = parabuf; |
263 |
|
|
|
264 |
|
|
do { |
265 |
|
|
if ((t = strchr(s, ' ')) != NULL) |
266 |
|
|
*t++ = '\0'; |
267 |
|
|
tlen = strlen(s); |
268 |
|
|
|
269 |
|
|
/* I dont even want to begin parsing this.. */ |
270 |
|
|
if (tlen > MODEBUFLEN) |
271 |
|
|
break; |
272 |
|
|
|
273 |
|
|
if (tlen && *s != ':' && add_id(source_p, chptr, s, mode_type)) |
274 |
|
|
{ |
275 |
|
|
/* this new one wont fit.. */ |
276 |
|
|
if (mbuf - modebuf + 2 + pbuf - parabuf + tlen > IRCD_BUFSIZE - 2 || |
277 |
|
|
modecount >= MAXMODEPARAMS) |
278 |
|
|
{ |
279 |
|
|
*mbuf = '\0'; |
280 |
|
|
*(pbuf - 1) = '\0'; |
281 |
|
|
|
282 |
|
|
sendto_channel_local(ALL_MEMBERS, NO, chptr, "%s %s", |
283 |
|
|
modebuf, parabuf); |
284 |
michael |
885 |
sendto_server(client_p, chptr, needcap, CAP_TS6, |
285 |
adx |
30 |
"%s %s", modebuf, parabuf); |
286 |
|
|
|
287 |
|
|
mbuf = modebuf + mlen; |
288 |
|
|
pbuf = parabuf; |
289 |
|
|
modecount = 0; |
290 |
|
|
} |
291 |
|
|
|
292 |
|
|
*mbuf++ = parv[3][0]; |
293 |
|
|
pbuf += ircsprintf(pbuf, "%s ", s); |
294 |
|
|
modecount++; |
295 |
|
|
} |
296 |
|
|
|
297 |
|
|
s = t; |
298 |
|
|
} while (s != NULL); |
299 |
|
|
|
300 |
|
|
if (modecount) |
301 |
|
|
{ |
302 |
|
|
*mbuf = *(pbuf - 1) = '\0'; |
303 |
|
|
sendto_channel_local(ALL_MEMBERS, NO, chptr, "%s %s", modebuf, parabuf); |
304 |
michael |
885 |
sendto_server(client_p, chptr, needcap, CAP_TS6, |
305 |
adx |
30 |
"%s %s", modebuf, parabuf); |
306 |
|
|
} |
307 |
|
|
|
308 |
|
|
/* assumption here is that since the server sent BMASK, they are TS6, so they have an ID */ |
309 |
michael |
885 |
sendto_server(client_p, chptr, CAP_TS6|needcap, NOCAPS, |
310 |
adx |
30 |
":%s BMASK %lu %s %s :%s", |
311 |
|
|
source_p->id, (unsigned long)chptr->channelts, chptr->chname, |
312 |
|
|
parv[3], parv[4]); |
313 |
|
|
} |