/[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 1028 - (hide annotations)
Sun Nov 8 13:03:38 2009 UTC (11 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 8257 byte(s)
- move ircd-hybrid-7.2 to trunk

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 michael 1011 #include "list.h"
27 adx 30 #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    
45     static void m_mode(struct Client *, struct Client *, int, char *[]);
46     static void ms_tmode(struct Client *, struct Client *, int, char *[]);
47     static void ms_bmask(struct Client *, struct Client *, int, char *[]);
48    
49     struct Message mode_msgtab = {
50     "MODE", 0, 0, 2, 0, MFLG_SLOW, 0,
51     {m_unregistered, m_mode, m_mode, m_ignore, m_mode, m_ignore}
52     };
53    
54     struct Message tmode_msgtab = {
55     "TMODE", 0, 0, 4, 0, MFLG_SLOW, 0,
56     {m_ignore, m_ignore, ms_tmode, m_ignore, m_ignore, m_ignore}
57     };
58    
59     struct Message bmask_msgtab = {
60     "BMASK", 0, 0, 5, 0, MFLG_SLOW, 0,
61     {m_ignore, m_ignore, ms_bmask, m_ignore, m_ignore, m_ignore}
62     };
63    
64     #ifndef STATIC_MODULES
65     void
66     _modinit(void)
67     {
68     mod_add_cmd(&mode_msgtab);
69     mod_add_cmd(&tmode_msgtab);
70     mod_add_cmd(&bmask_msgtab);
71     }
72    
73     void
74     _moddeinit(void)
75     {
76     mod_del_cmd(&mode_msgtab);
77     mod_del_cmd(&tmode_msgtab);
78     mod_del_cmd(&bmask_msgtab);
79     }
80    
81 knight 31 const char *_version = "$Revision$";
82 adx 30 #endif
83    
84     /*
85     * m_mode - MODE command handler
86     * parv[0] - sender
87     * parv[1] - channel
88     */
89     static void
90     m_mode(struct Client *client_p, struct Client *source_p,
91     int parc, char *parv[])
92     {
93     struct Channel *chptr = NULL;
94     struct Membership *member;
95     static char modebuf[MODEBUFLEN];
96     static char parabuf[MODEBUFLEN];
97    
98 michael 885 if (EmptyString(parv[1]))
99 adx 30 {
100     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
101     me.name, source_p->name, "MODE");
102     return;
103     }
104    
105     /* Now, try to find the channel in question */
106     if (!IsChanPrefix(*parv[1]))
107     {
108     /* if here, it has to be a non-channel name */
109     set_user_mode(client_p, source_p, parc, parv);
110     return;
111     }
112    
113 michael 885 if ((chptr = hash_find_channel(parv[1])) == NULL)
114 adx 30 {
115 db 848 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
116     ID_or_name(&me, source_p->from),
117     ID_or_name(source_p, source_p->from),
118     parv[1]);
119     return;
120     }
121 adx 30
122     /* Now known the channel exists */
123     if (parc < 3)
124     {
125     channel_modes(chptr, source_p, modebuf, parabuf);
126     sendto_one(source_p, form_str(RPL_CHANNELMODEIS),
127     me.name, source_p->name, chptr->chname, modebuf, parabuf);
128     sendto_one(source_p, form_str(RPL_CREATIONTIME),
129     me.name, source_p->name, chptr->chname, chptr->channelts);
130     }
131     /* bounce all modes from people we deop on sjoin
132     * servers have always gotten away with murder,
133     * including telnet servers *g* - Dianora
134     *
135     * XXX Is it worth the bother to make an ms_mode() ? - Dianora
136     */
137     else if (IsServer(source_p))
138     {
139     set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2,
140     chptr->chname);
141     }
142     else
143     {
144     member = find_channel_link(source_p, chptr);
145    
146     if (!has_member_flags(member, CHFL_DEOPPED))
147     {
148     /* Finish the flood grace period... */
149     if (MyClient(source_p) && !IsFloodDone(source_p))
150     {
151     if (!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0')))
152     flood_endgrace(source_p);
153     }
154    
155     set_channel_mode(client_p, source_p, chptr, member, parc - 2, parv + 2,
156     chptr->chname);
157     }
158     }
159     }
160    
161     /*
162     * ms_tmode()
163     *
164     * inputs - parv[0] = UID
165     * parv[1] = TS
166     * parv[2] = channel name
167     * parv[3] = modestring
168     */
169     static void
170     ms_tmode(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
171     {
172     struct Channel *chptr = NULL;
173     struct Membership *member = NULL;
174    
175     if ((chptr = hash_find_channel(parv[2])) == NULL)
176     {
177     sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
178     ID_or_name(&me, client_p), ID_or_name(source_p, client_p), parv[2]);
179     return;
180     }
181    
182     if (atol(parv[1]) > chptr->channelts)
183     return;
184    
185     if (IsServer(source_p))
186     set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3, chptr->chname);
187     else
188     {
189     member = find_channel_link(source_p, chptr);
190    
191     /* XXX are we sure we just want to bail here? */
192     if (has_member_flags(member, CHFL_DEOPPED))
193     return;
194    
195     set_channel_mode(client_p, source_p, chptr, member, parc - 3, parv + 3, chptr->chname);
196     }
197     }
198    
199     /*
200     * ms_bmask()
201     *
202     * inputs - parv[0] = SID
203     * parv[1] = TS
204     * parv[2] = channel name
205     * parv[3] = type of ban to add ('b' 'I' or 'e')
206     * parv[4] = space delimited list of masks to add
207     * outputs - none
208     * side effects - propagates unchanged bmask line to CAP_TS6 servers,
209     * sends plain modes to the others. nothing is sent
210     * to the server the issuing server is connected through
211     */
212     static void
213     ms_bmask(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
214     {
215     static char modebuf[IRCD_BUFSIZE];
216     static char parabuf[IRCD_BUFSIZE];
217     static char banbuf[IRCD_BUFSIZE];
218     struct Channel *chptr;
219     char *s, *t, *mbuf, *pbuf;
220     long mode_type;
221     int mlen, tlen;
222     int modecount = 0;
223     int needcap = NOCAPS;
224    
225     if ((chptr = hash_find_channel(parv[2])) == NULL)
226     return;
227    
228     /* TS is higher, drop it. */
229     if (atol(parv[1]) > chptr->channelts)
230     return;
231    
232     switch (*parv[3])
233     {
234     case 'b':
235     mode_type = CHFL_BAN;
236     break;
237    
238     case 'e':
239     mode_type = CHFL_EXCEPTION;
240     needcap = CAP_EX;
241     break;
242    
243     case 'I':
244     mode_type = CHFL_INVEX;
245     needcap = CAP_IE;
246     break;
247    
248     /* maybe we should just blindly propagate this? */
249     default:
250     return;
251     }
252    
253     parabuf[0] = '\0';
254     s = banbuf;
255     strlcpy(s, parv[4], sizeof(banbuf));
256    
257     /* only need to construct one buffer, for non-ts6 servers */
258     mlen = ircsprintf(modebuf, ":%s MODE %s +",
259     source_p->name, chptr->chname);
260     mbuf = modebuf + mlen;
261     pbuf = parabuf;
262    
263     do {
264     if ((t = strchr(s, ' ')) != NULL)
265     *t++ = '\0';
266     tlen = strlen(s);
267    
268     /* I dont even want to begin parsing this.. */
269     if (tlen > MODEBUFLEN)
270     break;
271    
272     if (tlen && *s != ':' && add_id(source_p, chptr, s, mode_type))
273     {
274     /* this new one wont fit.. */
275     if (mbuf - modebuf + 2 + pbuf - parabuf + tlen > IRCD_BUFSIZE - 2 ||
276     modecount >= MAXMODEPARAMS)
277     {
278     *mbuf = '\0';
279     *(pbuf - 1) = '\0';
280    
281 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s",
282 adx 30 modebuf, parabuf);
283 michael 885 sendto_server(client_p, chptr, needcap, CAP_TS6,
284 adx 30 "%s %s", modebuf, parabuf);
285    
286     mbuf = modebuf + mlen;
287     pbuf = parabuf;
288     modecount = 0;
289     }
290    
291     *mbuf++ = parv[3][0];
292     pbuf += ircsprintf(pbuf, "%s ", s);
293     modecount++;
294     }
295    
296     s = t;
297     } while (s != NULL);
298    
299     if (modecount)
300     {
301     *mbuf = *(pbuf - 1) = '\0';
302 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
303 michael 885 sendto_server(client_p, chptr, needcap, CAP_TS6,
304 adx 30 "%s %s", modebuf, parabuf);
305     }
306    
307     /* assumption here is that since the server sent BMASK, they are TS6, so they have an ID */
308 michael 885 sendto_server(client_p, chptr, CAP_TS6|needcap, NOCAPS,
309 adx 30 ":%s BMASK %lu %s %s :%s",
310     source_p->id, (unsigned long)chptr->channelts, chptr->chname,
311     parv[3], parv[4]);
312     }

Properties

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

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