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: 3109
Committed: Thu Mar 6 19:25:12 2014 UTC (10 years, 1 month ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/core/m_mode.c
File size: 7888 byte(s)
Log Message:
- Applied Adam's sendto_one_numeric() changes

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2820 /*! \file m_mode.c
23     * \brief Includes required functions for processing the MODE/TMODE/BMASK command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "channel.h"
30     #include "channel_mode.h"
31     #include "client.h"
32     #include "hash.h"
33     #include "irc_string.h"
34     #include "ircd.h"
35     #include "numeric.h"
36     #include "s_user.h"
37 michael 1309 #include "conf.h"
38 adx 30 #include "s_serv.h"
39     #include "send.h"
40     #include "parse.h"
41     #include "modules.h"
42     #include "packet.h"
43    
44    
45     /*
46     * m_mode - MODE command handler
47 michael 3096 * parv[0] - command
48 adx 30 * parv[1] - channel
49     */
50 michael 2820 static int
51 adx 30 m_mode(struct Client *client_p, struct Client *source_p,
52     int parc, char *parv[])
53     {
54     struct Channel *chptr = NULL;
55 michael 1895 struct Membership *member = NULL;
56     char modebuf[MODEBUFLEN];
57     char parabuf[MODEBUFLEN];
58 adx 30
59 michael 885 if (EmptyString(parv[1]))
60 adx 30 {
61 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "MODE");
62 michael 2820 return 0;
63 adx 30 }
64    
65     /* Now, try to find the channel in question */
66     if (!IsChanPrefix(*parv[1]))
67     {
68     /* if here, it has to be a non-channel name */
69     set_user_mode(client_p, source_p, parc, parv);
70 michael 2820 return 0;
71 adx 30 }
72    
73 michael 885 if ((chptr = hash_find_channel(parv[1])) == NULL)
74 adx 30 {
75 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
76 michael 2820 return 0;
77 db 848 }
78 adx 30
79     /* Now known the channel exists */
80     if (parc < 3)
81     {
82     channel_modes(chptr, source_p, modebuf, parabuf);
83 michael 3109 sendto_one_numeric(source_p, &me, RPL_CHANNELMODEIS, chptr->chname, modebuf, parabuf);
84     sendto_one_numeric(source_p, &me, RPL_CREATIONTIME, chptr->chname, chptr->channelts);
85 michael 2820 return 0;
86 adx 30 }
87 michael 1895
88     /*
89     * bounce all modes from people we deop on sjoin
90 adx 30 * servers have always gotten away with murder,
91     * including telnet servers *g* - Dianora
92     */
93 michael 2644 if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
94 michael 2937 set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2);
95 adx 30 else
96     {
97     member = find_channel_link(source_p, chptr);
98    
99     if (!has_member_flags(member, CHFL_DEOPPED))
100     {
101     /* Finish the flood grace period... */
102     if (MyClient(source_p) && !IsFloodDone(source_p))
103     if (!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0')))
104     flood_endgrace(source_p);
105    
106 michael 2937 set_channel_mode(client_p, source_p, chptr, member, parc - 2, parv + 2);
107 adx 30 }
108     }
109 michael 2820
110     return 0;
111 adx 30 }
112    
113     /*
114     * ms_tmode()
115     *
116 michael 3096 * inputs - parv[0] = command
117 adx 30 * parv[1] = TS
118     * parv[2] = channel name
119     * parv[3] = modestring
120     */
121 michael 2820 static int
122 adx 30 ms_tmode(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
123     {
124     struct Channel *chptr = NULL;
125     struct Membership *member = NULL;
126    
127     if ((chptr = hash_find_channel(parv[2])) == NULL)
128     {
129 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]);
130 michael 2820 return 0;
131 adx 30 }
132    
133     if (atol(parv[1]) > chptr->channelts)
134 michael 2820 return 0;
135 adx 30
136 michael 2644 if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
137 michael 2937 set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3);
138 adx 30 else
139     {
140     member = find_channel_link(source_p, chptr);
141    
142     /* XXX are we sure we just want to bail here? */
143     if (has_member_flags(member, CHFL_DEOPPED))
144 michael 2820 return 0;
145 adx 30
146 michael 2937 set_channel_mode(client_p, source_p, chptr, member, parc - 3, parv + 3);
147 adx 30 }
148 michael 2820
149     return 0;
150 adx 30 }
151    
152     /*
153     * ms_bmask()
154     *
155 michael 3096 * inputs - parv[0] = command
156 adx 30 * parv[1] = TS
157     * parv[2] = channel name
158     * parv[3] = type of ban to add ('b' 'I' or 'e')
159     * parv[4] = space delimited list of masks to add
160     * outputs - none
161     * side effects - propagates unchanged bmask line to CAP_TS6 servers,
162     * sends plain modes to the others. nothing is sent
163     * to the server the issuing server is connected through
164     */
165 michael 2820 static int
166 adx 30 ms_bmask(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
167     {
168 michael 2820 char modebuf[IRCD_BUFSIZE];
169     char parabuf[IRCD_BUFSIZE];
170     char banbuf[IRCD_BUFSIZE];
171 adx 30 struct Channel *chptr;
172     char *s, *t, *mbuf, *pbuf;
173 michael 3044 unsigned int mode_type = 0;
174 adx 30 int mlen, tlen;
175     int modecount = 0;
176    
177     if ((chptr = hash_find_channel(parv[2])) == NULL)
178 michael 2820 return 0;
179 adx 30
180     /* TS is higher, drop it. */
181     if (atol(parv[1]) > chptr->channelts)
182 michael 2820 return 0;
183 adx 30
184     switch (*parv[3])
185     {
186     case 'b':
187     mode_type = CHFL_BAN;
188     break;
189    
190     case 'e':
191     mode_type = CHFL_EXCEPTION;
192     break;
193    
194     case 'I':
195     mode_type = CHFL_INVEX;
196     break;
197    
198     /* maybe we should just blindly propagate this? */
199     default:
200 michael 2820 return 0;
201 adx 30 }
202    
203     parabuf[0] = '\0';
204     s = banbuf;
205     strlcpy(s, parv[4], sizeof(banbuf));
206    
207     /* only need to construct one buffer, for non-ts6 servers */
208 michael 1793 mlen = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s +",
209 michael 2560 (IsHidden(source_p) || ConfigServerHide.hide_servers) ? me.name : source_p->name,
210     chptr->chname);
211 adx 30 mbuf = modebuf + mlen;
212     pbuf = parabuf;
213    
214 michael 2820 do
215     {
216     if ((t = strchr(s, ' ')))
217 adx 30 *t++ = '\0';
218     tlen = strlen(s);
219    
220 michael 2820 /* I don't even want to begin parsing this.. */
221 adx 30 if (tlen > MODEBUFLEN)
222     break;
223    
224     if (tlen && *s != ':' && add_id(source_p, chptr, s, mode_type))
225     {
226     /* this new one wont fit.. */
227     if (mbuf - modebuf + 2 + pbuf - parabuf + tlen > IRCD_BUFSIZE - 2 ||
228     modecount >= MAXMODEPARAMS)
229     {
230     *mbuf = '\0';
231     *(pbuf - 1) = '\0';
232    
233 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s",
234 adx 30 modebuf, parabuf);
235 michael 3041 sendto_server(client_p, NOCAPS, CAP_TS6,
236 adx 30 "%s %s", modebuf, parabuf);
237    
238     mbuf = modebuf + mlen;
239     pbuf = parabuf;
240     modecount = 0;
241     }
242    
243     *mbuf++ = parv[3][0];
244 michael 1793 pbuf += sprintf(pbuf, "%s ", s);
245 adx 30 modecount++;
246     }
247    
248     s = t;
249     } while (s != NULL);
250    
251     if (modecount)
252     {
253     *mbuf = *(pbuf - 1) = '\0';
254 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
255 michael 3041 sendto_server(client_p, NOCAPS, CAP_TS6,
256 adx 30 "%s %s", modebuf, parabuf);
257     }
258    
259     /* assumption here is that since the server sent BMASK, they are TS6, so they have an ID */
260 michael 3041 sendto_server(client_p, CAP_TS6, NOCAPS, ":%s BMASK %lu %s %s :%s",
261 adx 30 source_p->id, (unsigned long)chptr->channelts, chptr->chname,
262     parv[3], parv[4]);
263 michael 2820 return 0;
264 adx 30 }
265 michael 1230
266 michael 2820 static struct Message mode_msgtab =
267     {
268 michael 1230 "MODE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
269 michael 2820 { m_unregistered, m_mode, m_mode, m_ignore, m_mode, m_ignore }
270 michael 1230 };
271    
272 michael 2820 static struct Message tmode_msgtab =
273     {
274 michael 1230 "TMODE", 0, 0, 4, MAXPARA, MFLG_SLOW, 0,
275 michael 2820 { m_ignore, m_ignore, ms_tmode, m_ignore, m_ignore, m_ignore }
276 michael 1230 };
277    
278 michael 2820 static struct Message bmask_msgtab =
279     {
280 michael 1230 "BMASK", 0, 0, 5, MAXPARA, MFLG_SLOW, 0,
281 michael 2820 { m_ignore, m_ignore, ms_bmask, m_ignore, m_ignore, m_ignore }
282 michael 1230 };
283    
284     static void
285     module_init(void)
286     {
287     mod_add_cmd(&mode_msgtab);
288     mod_add_cmd(&tmode_msgtab);
289     mod_add_cmd(&bmask_msgtab);
290     }
291    
292     static void
293     module_exit(void)
294     {
295     mod_del_cmd(&mode_msgtab);
296     mod_del_cmd(&tmode_msgtab);
297     mod_del_cmd(&bmask_msgtab);
298     }
299    
300 michael 2820 struct module module_entry =
301     {
302 michael 1230 .node = { NULL, NULL, NULL },
303     .name = NULL,
304     .version = "$Revision$",
305     .handle = NULL,
306     .modinit = module_init,
307     .modexit = module_exit,
308     .flags = MODULE_FLAG_CORE
309     };

Properties

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