]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_mode.c: Sets a user or channel mode. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
24 | * $Id: m_mode.c 1006 2006-03-09 15:32:14Z nenolod $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
212380e3 AC |
28 | #include "channel.h" |
29 | #include "client.h" | |
30 | #include "hash.h" | |
4562c604 | 31 | #include "match.h" |
212380e3 AC |
32 | #include "ircd.h" |
33 | #include "numeric.h" | |
34 | #include "s_user.h" | |
35 | #include "s_conf.h" | |
36 | #include "s_serv.h" | |
4016731b | 37 | #include "logger.h" |
212380e3 AC |
38 | #include "send.h" |
39 | #include "msg.h" | |
40 | #include "parse.h" | |
41 | #include "modules.h" | |
42 | #include "packet.h" | |
212380e3 AC |
43 | #include "s_newconf.h" |
44 | ||
45 | static int m_mode(struct Client *, struct Client *, int, const char **); | |
46 | static int ms_mode(struct Client *, struct Client *, int, const char **); | |
47 | static int ms_tmode(struct Client *, struct Client *, int, const char **); | |
48 | static int ms_bmask(struct Client *, struct Client *, int, const char **); | |
49 | ||
50 | struct Message mode_msgtab = { | |
51 | "MODE", 0, 0, 0, MFLG_SLOW, | |
52 | {mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}} | |
53 | }; | |
54 | struct Message tmode_msgtab = { | |
55 | "TMODE", 0, 0, 0, MFLG_SLOW, | |
56 | {mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore} | |
57 | }; | |
58 | struct Message bmask_msgtab = { | |
59 | "BMASK", 0, 0, 0, MFLG_SLOW, | |
60 | {mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore} | |
61 | }; | |
62 | ||
63 | mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &bmask_msgtab, NULL }; | |
64 | ||
65 | DECLARE_MODULE_AV1(mode, NULL, NULL, mode_clist, NULL, NULL, "$Revision: 1006 $"); | |
66 | ||
67 | /* | |
68 | * m_mode - MODE command handler | |
69 | * parv[0] - sender | |
70 | * parv[1] - channel | |
71 | */ | |
72 | static int | |
73 | m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
74 | { | |
75 | struct Channel *chptr = NULL; | |
76 | struct membership *msptr; | |
77 | int n = 2; | |
78 | const char *dest; | |
79 | int operspy = 0; | |
80 | ||
81 | dest = parv[1]; | |
82 | ||
83 | if(IsOperSpy(source_p) && *dest == '!') | |
84 | { | |
85 | dest++; | |
86 | operspy = 1; | |
87 | ||
88 | if(EmptyString(dest)) | |
89 | { | |
90 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
91 | me.name, source_p->name, "MODE"); | |
92 | return 0; | |
93 | } | |
94 | } | |
95 | ||
96 | /* Now, try to find the channel in question */ | |
97 | if(!IsChanPrefix(*dest)) | |
98 | { | |
99 | /* if here, it has to be a non-channel name */ | |
100 | user_mode(client_p, source_p, parc, parv); | |
101 | return 0; | |
102 | } | |
103 | ||
104 | if(!check_channel_name(dest)) | |
105 | { | |
106 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]); | |
107 | return 0; | |
108 | } | |
109 | ||
110 | chptr = find_channel(dest); | |
111 | ||
112 | if(chptr == NULL) | |
113 | { | |
114 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
115 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
116 | return 0; | |
117 | } | |
118 | ||
119 | /* Now know the channel exists */ | |
120 | if(parc < n + 1) | |
121 | { | |
122 | if(operspy) | |
123 | report_operspy(source_p, "MODE", chptr->chname); | |
124 | ||
125 | sendto_one(source_p, form_str(RPL_CHANNELMODEIS), | |
126 | me.name, source_p->name, parv[1], | |
127 | operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p)); | |
128 | ||
129 | sendto_one(source_p, form_str(RPL_CREATIONTIME), | |
130 | me.name, source_p->name, parv[1], chptr->channelts); | |
131 | } | |
132 | else | |
133 | { | |
134 | msptr = find_channel_membership(chptr, source_p); | |
135 | ||
212380e3 AC |
136 | /* Finish the flood grace period... */ |
137 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
138 | { | |
139 | if(!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0'))) | |
140 | flood_endgrace(source_p); | |
141 | } | |
142 | ||
143 | set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n); | |
144 | } | |
145 | ||
146 | return 0; | |
147 | } | |
148 | ||
149 | static int | |
150 | ms_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
151 | { | |
152 | struct Channel *chptr; | |
153 | ||
154 | chptr = find_channel(parv[1]); | |
155 | ||
156 | if(chptr == NULL) | |
157 | { | |
158 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
159 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
160 | return 0; | |
161 | } | |
162 | ||
163 | set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2); | |
164 | ||
165 | return 0; | |
166 | } | |
167 | ||
168 | static int | |
169 | ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
170 | { | |
171 | struct Channel *chptr = NULL; | |
172 | struct membership *msptr; | |
173 | ||
174 | /* Now, try to find the channel in question */ | |
175 | if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) | |
176 | { | |
177 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); | |
178 | return 0; | |
179 | } | |
180 | ||
181 | chptr = find_channel(parv[2]); | |
182 | ||
183 | if(chptr == NULL) | |
184 | { | |
185 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
186 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
187 | return 0; | |
188 | } | |
189 | ||
190 | /* TS is higher, drop it. */ | |
191 | if(atol(parv[1]) > chptr->channelts) | |
192 | return 0; | |
193 | ||
194 | if(IsServer(source_p)) | |
195 | { | |
196 | set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3); | |
197 | } | |
198 | else | |
199 | { | |
200 | msptr = find_channel_membership(chptr, source_p); | |
201 | ||
212380e3 AC |
202 | set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3); |
203 | } | |
204 | ||
205 | return 0; | |
206 | } | |
207 | ||
208 | static int | |
209 | ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
210 | { | |
211 | static char modebuf[BUFSIZE]; | |
212 | static char parabuf[BUFSIZE]; | |
213 | struct Channel *chptr; | |
5b96d9a6 | 214 | rb_dlink_list *banlist; |
212380e3 AC |
215 | const char *s; |
216 | char *t; | |
217 | char *mbuf; | |
218 | char *pbuf; | |
219 | long mode_type; | |
220 | int mlen; | |
221 | int plen = 0; | |
222 | int tlen; | |
223 | int arglen; | |
224 | int modecount = 0; | |
225 | int needcap = NOCAPS; | |
226 | int mems; | |
227 | struct Client *fakesource_p; | |
228 | ||
229 | if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) | |
230 | return 0; | |
231 | ||
232 | if((chptr = find_channel(parv[2])) == NULL) | |
233 | return 0; | |
234 | ||
235 | /* TS is higher, drop it. */ | |
236 | if(atol(parv[1]) > chptr->channelts) | |
237 | return 0; | |
238 | ||
239 | switch (parv[3][0]) | |
240 | { | |
241 | case 'b': | |
242 | banlist = &chptr->banlist; | |
243 | mode_type = CHFL_BAN; | |
244 | mems = ALL_MEMBERS; | |
245 | break; | |
246 | ||
247 | case 'e': | |
248 | banlist = &chptr->exceptlist; | |
249 | mode_type = CHFL_EXCEPTION; | |
250 | needcap = CAP_EX; | |
251 | mems = ONLY_CHANOPS; | |
252 | break; | |
253 | ||
254 | case 'I': | |
255 | banlist = &chptr->invexlist; | |
256 | mode_type = CHFL_INVEX; | |
257 | needcap = CAP_IE; | |
258 | mems = ONLY_CHANOPS; | |
259 | break; | |
260 | ||
261 | case 'q': | |
262 | banlist = &chptr->quietlist; | |
263 | mode_type = CHFL_QUIET; | |
264 | mems = ALL_MEMBERS; | |
265 | break; | |
266 | ||
267 | /* maybe we should just blindly propagate this? */ | |
268 | default: | |
269 | return 0; | |
270 | } | |
271 | ||
272 | parabuf[0] = '\0'; | |
273 | s = LOCAL_COPY(parv[4]); | |
274 | ||
275 | /* Hide connecting server on netburst -- jilles */ | |
276 | if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) | |
277 | fakesource_p = &me; | |
278 | else | |
279 | fakesource_p = source_p; | |
7cdb0a09 | 280 | mlen = rb_sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname); |
212380e3 AC |
281 | mbuf = modebuf + mlen; |
282 | pbuf = parabuf; | |
283 | ||
284 | while(*s == ' ') | |
285 | s++; | |
286 | ||
287 | /* next char isnt a space, point t to the next one */ | |
288 | if((t = strchr(s, ' ')) != NULL) | |
289 | { | |
290 | *t++ = '\0'; | |
291 | ||
292 | /* double spaces will break the parser */ | |
293 | while(*t == ' ') | |
294 | t++; | |
295 | } | |
296 | ||
297 | /* couldve skipped spaces and got nothing.. */ | |
298 | while(!EmptyString(s)) | |
299 | { | |
300 | /* ban with a leading ':' -- this will break the protocol */ | |
301 | if(*s == ':') | |
302 | goto nextban; | |
303 | ||
304 | tlen = strlen(s); | |
305 | ||
306 | /* I dont even want to begin parsing this.. */ | |
307 | if(tlen > MODEBUFLEN) | |
308 | break; | |
309 | ||
310 | if(add_id(fakesource_p, chptr, s, banlist, mode_type)) | |
311 | { | |
312 | /* this new one wont fit.. */ | |
313 | if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 || | |
314 | modecount >= MAXMODEPARAMS) | |
315 | { | |
316 | *mbuf = '\0'; | |
317 | *(pbuf - 1) = '\0'; | |
318 | sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf); | |
319 | sendto_server(client_p, chptr, needcap, CAP_TS6, | |
320 | "%s %s", modebuf, parabuf); | |
321 | ||
322 | mbuf = modebuf + mlen; | |
323 | pbuf = parabuf; | |
324 | plen = modecount = 0; | |
325 | } | |
326 | ||
327 | *mbuf++ = parv[3][0]; | |
7cdb0a09 | 328 | arglen = rb_sprintf(pbuf, "%s ", s); |
212380e3 AC |
329 | pbuf += arglen; |
330 | plen += arglen; | |
331 | modecount++; | |
332 | } | |
333 | ||
334 | nextban: | |
335 | s = t; | |
336 | ||
337 | if(s != NULL) | |
338 | { | |
339 | if((t = strchr(s, ' ')) != NULL) | |
340 | { | |
341 | *t++ = '\0'; | |
342 | ||
343 | while(*t == ' ') | |
344 | t++; | |
345 | } | |
346 | } | |
347 | } | |
348 | ||
349 | if(modecount) | |
350 | { | |
351 | *mbuf = '\0'; | |
352 | *(pbuf - 1) = '\0'; | |
353 | sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf); | |
354 | sendto_server(client_p, chptr, needcap, CAP_TS6, "%s %s", modebuf, parabuf); | |
355 | } | |
356 | ||
357 | sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s", | |
358 | source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]); | |
359 | return 0; | |
360 | } | |
361 |