ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/core/m_mode.c
Revision: 1178
Committed: Mon Aug 15 08:11:31 2011 UTC (14 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 8245 byte(s)
Log Message:
- Cleanup and restore older parts of the irc-command parser.
  Gives back ability to specify maximum amount of parameters
  that are processed within a command.

File Contents

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

Properties

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