/[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 848 - (hide annotations)
Mon Feb 19 17:22:44 2007 UTC (14 years, 4 months ago) by db
Original Path: ircd-hybrid-7.2/modules/core/m_mode.c
File MIME type: text/x-chdr
File size: 8512 byte(s)
- This remnant of LazyLinks DIE DIE DIE


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

Properties

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

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