ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/core/m_mode.c
Revision: 1309
Committed: Sun Mar 25 11:24:18 2012 UTC (12 years ago) by michael
Content type: text/x-csrc
File size: 8210 byte(s)
Log Message:
- renaming files:

  ircd_parser.y -> conf_parser.y
  ircd_lexer.l  -> conf_lexer.l
  s_conf.c      -> conf.c
  s_conf.h      -> conf.h
  s_log.c       -> log.c
  s_log.h       -> log.h

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

Properties

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