ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/core/m_mode.c
Revision: 1832
Committed: Fri Apr 19 19:16:09 2013 UTC (10 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/core/m_mode.c
File size: 8124 byte(s)
Log Message:
- Made all numeric defines use the actual string instead of the numeric value
  which allows to use gcc's printf format attribute
- Remove current message locale implementation

File Contents

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

Properties

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