/[svn]/ircd-hybrid/modules/core/m_mode.c
ViewVC logotype

Annotation of /ircd-hybrid/modules/core/m_mode.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations)
Sun Oct 2 20:34:05 2005 UTC (15 years, 8 months ago) by knight
File MIME type: text/x-chdr
File size: 9156 byte(s)
- Fix svn:keywords

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     if (*parv[1] == '\0')
100     {
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     if (!check_channel_name(parv[1]))
115     {
116     sendto_one(source_p, form_str(ERR_BADCHANNAME),
117     me.name, source_p->name, parv[1]);
118     return;
119     }
120    
121     chptr = hash_find_channel(parv[1]);
122    
123     if (chptr == NULL)
124     {
125     /* if chptr isn't found locally, it =could= exist
126     * on the uplink. So ask.
127     */
128    
129     /* LazyLinks */
130     /* only send a mode upstream if a local client sent this request
131     * -davidt
132     */
133     if (MyClient(source_p) && !ServerInfo.hub && uplink &&
134     IsCapable(uplink, CAP_LL))
135     {
136     #if 0
137     /* cache the channel if it exists on uplink */
138     /* Lets not for now -db */
139    
140     sendto_one(uplink, ":%s CBURST %s",
141     me.name, chptr->chname);
142     #endif
143     sendto_one(uplink, ":%s MODE %s %s",
144     ID_or_name(source_p, uplink),
145     chptr->chname, (parv[2] ? parv[2] : ""));
146     return;
147     }
148     else
149     {
150     sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
151     ID_or_name(&me, source_p->from),
152     ID_or_name(source_p, source_p->from),
153     parv[1]);
154     return;
155     }
156     }
157    
158     /* Now known the channel exists */
159     if (parc < 3)
160     {
161     channel_modes(chptr, source_p, modebuf, parabuf);
162     sendto_one(source_p, form_str(RPL_CHANNELMODEIS),
163     me.name, source_p->name, chptr->chname, modebuf, parabuf);
164     sendto_one(source_p, form_str(RPL_CREATIONTIME),
165     me.name, source_p->name, chptr->chname, chptr->channelts);
166     }
167     /* bounce all modes from people we deop on sjoin
168     * servers have always gotten away with murder,
169     * including telnet servers *g* - Dianora
170     *
171     * XXX Is it worth the bother to make an ms_mode() ? - Dianora
172     */
173     else if (IsServer(source_p))
174     {
175     set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2,
176     chptr->chname);
177     }
178     else
179     {
180     member = find_channel_link(source_p, chptr);
181    
182     if (!has_member_flags(member, CHFL_DEOPPED))
183     {
184     /* Finish the flood grace period... */
185     if (MyClient(source_p) && !IsFloodDone(source_p))
186     {
187     if (!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0')))
188     flood_endgrace(source_p);
189     }
190    
191     set_channel_mode(client_p, source_p, chptr, member, parc - 2, parv + 2,
192     chptr->chname);
193     }
194     }
195     }
196    
197     /*
198     * ms_tmode()
199     *
200     * inputs - parv[0] = UID
201     * parv[1] = TS
202     * parv[2] = channel name
203     * parv[3] = modestring
204     */
205     static void
206     ms_tmode(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
207     {
208     struct Channel *chptr = NULL;
209     struct Membership *member = NULL;
210    
211     if ((chptr = hash_find_channel(parv[2])) == NULL)
212     {
213     sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
214     ID_or_name(&me, client_p), ID_or_name(source_p, client_p), parv[2]);
215     return;
216     }
217    
218     if (atol(parv[1]) > chptr->channelts)
219     return;
220    
221     if (IsServer(source_p))
222     set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3, chptr->chname);
223     else
224     {
225     member = find_channel_link(source_p, chptr);
226    
227     /* XXX are we sure we just want to bail here? */
228     if (has_member_flags(member, CHFL_DEOPPED))
229     return;
230    
231     set_channel_mode(client_p, source_p, chptr, member, parc - 3, parv + 3, chptr->chname);
232     }
233     }
234    
235     /*
236     * ms_bmask()
237     *
238     * inputs - parv[0] = SID
239     * parv[1] = TS
240     * parv[2] = channel name
241     * parv[3] = type of ban to add ('b' 'I' or 'e')
242     * parv[4] = space delimited list of masks to add
243     * outputs - none
244     * side effects - propagates unchanged bmask line to CAP_TS6 servers,
245     * sends plain modes to the others. nothing is sent
246     * to the server the issuing server is connected through
247     */
248     static void
249     ms_bmask(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
250     {
251     static char modebuf[IRCD_BUFSIZE];
252     static char parabuf[IRCD_BUFSIZE];
253     static char banbuf[IRCD_BUFSIZE];
254     struct Channel *chptr;
255     char *s, *t, *mbuf, *pbuf;
256     long mode_type;
257     int mlen, tlen;
258     int modecount = 0;
259     int needcap = NOCAPS;
260    
261     if ((chptr = hash_find_channel(parv[2])) == NULL)
262     return;
263    
264     /* TS is higher, drop it. */
265     if (atol(parv[1]) > chptr->channelts)
266     return;
267    
268     switch (*parv[3])
269     {
270     case 'b':
271     mode_type = CHFL_BAN;
272     break;
273    
274     case 'e':
275     mode_type = CHFL_EXCEPTION;
276     needcap = CAP_EX;
277     break;
278    
279     case 'I':
280     mode_type = CHFL_INVEX;
281     needcap = CAP_IE;
282     break;
283    
284     /* maybe we should just blindly propagate this? */
285     default:
286     return;
287     }
288    
289     parabuf[0] = '\0';
290     s = banbuf;
291     strlcpy(s, parv[4], sizeof(banbuf));
292    
293     /* only need to construct one buffer, for non-ts6 servers */
294     mlen = ircsprintf(modebuf, ":%s MODE %s +",
295     source_p->name, chptr->chname);
296     mbuf = modebuf + mlen;
297     pbuf = parabuf;
298    
299     do {
300     if ((t = strchr(s, ' ')) != NULL)
301     *t++ = '\0';
302     tlen = strlen(s);
303    
304     /* I dont even want to begin parsing this.. */
305     if (tlen > MODEBUFLEN)
306     break;
307    
308     if (tlen && *s != ':' && add_id(source_p, chptr, s, mode_type))
309     {
310     /* this new one wont fit.. */
311     if (mbuf - modebuf + 2 + pbuf - parabuf + tlen > IRCD_BUFSIZE - 2 ||
312     modecount >= MAXMODEPARAMS)
313     {
314     *mbuf = '\0';
315     *(pbuf - 1) = '\0';
316    
317     sendto_channel_local(ALL_MEMBERS, NO, chptr, "%s %s",
318     modebuf, parabuf);
319     sendto_server(client_p, NULL, chptr, needcap, CAP_TS6, NOFLAGS,
320     "%s %s", modebuf, parabuf);
321    
322     mbuf = modebuf + mlen;
323     pbuf = parabuf;
324     modecount = 0;
325     }
326    
327     *mbuf++ = parv[3][0];
328     pbuf += ircsprintf(pbuf, "%s ", s);
329     modecount++;
330     }
331    
332     s = t;
333     } while (s != NULL);
334    
335     if (modecount)
336     {
337     *mbuf = *(pbuf - 1) = '\0';
338     sendto_channel_local(ALL_MEMBERS, NO, chptr, "%s %s", modebuf, parabuf);
339     sendto_server(client_p, NULL, chptr, needcap, CAP_TS6, NOFLAGS,
340     "%s %s", modebuf, parabuf);
341     }
342    
343     /* assumption here is that since the server sent BMASK, they are TS6, so they have an ID */
344     sendto_server(client_p, NULL, chptr, CAP_TS6|needcap, NOCAPS, NOFLAGS,
345     ":%s BMASK %lu %s %s :%s",
346     source_p->id, (unsigned long)chptr->channelts, chptr->chname,
347     parv[3], parv[4]);
348     }

Properties

Name Value
svn:eol-style native
svn:keywords "Id Revision"

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28