/[svn]/ircd-hybrid/trunk/modules/core/m_mode.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/core/m_mode.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3150 - (show annotations)
Fri Mar 14 14:11:34 2014 UTC (6 years, 3 months ago) by michael
File MIME type: text/x-chdr
File size: 7532 byte(s)
- Removed unused client_p pointer from all chm_* channel mode handlers

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
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 /*! \file m_mode.c
23 * \brief Includes required functions for processing the MODE/TMODE/BMASK command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #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 #include "conf.h"
38 #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 * parv[0] - command
48 * parv[1] - channel
49 */
50 static int
51 m_mode(struct Client *client_p, struct Client *source_p,
52 int parc, char *parv[])
53 {
54 struct Channel *chptr = NULL;
55 struct Membership *member = NULL;
56 char modebuf[MODEBUFLEN];
57 char parabuf[MODEBUFLEN];
58
59 if (EmptyString(parv[1]))
60 {
61 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "MODE");
62 return 0;
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 0;
71 }
72
73 if ((chptr = hash_find_channel(parv[1])) == NULL)
74 {
75 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
76 return 0;
77 }
78
79 /* Now known the channel exists */
80 if (parc < 3)
81 {
82 channel_modes(chptr, source_p, modebuf, parabuf);
83 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 return 0;
86 }
87
88 /*
89 * bounce all modes from people we deop on sjoin
90 * servers have always gotten away with murder,
91 * including telnet servers *g* - Dianora
92 */
93 if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
94 set_channel_mode(source_p, chptr, NULL, parc - 2, parv + 2);
95 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 set_channel_mode(source_p, chptr, member, parc - 2, parv + 2);
107 }
108 }
109
110 return 0;
111 }
112
113 /*
114 * ms_tmode()
115 *
116 * inputs - parv[0] = command
117 * parv[1] = TS
118 * parv[2] = channel name
119 * parv[3] = modestring
120 */
121 static int
122 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 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]);
130 return 0;
131 }
132
133 if (atol(parv[1]) > chptr->channelts)
134 return 0;
135
136 if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
137 set_channel_mode(source_p, chptr, NULL, parc - 3, parv + 3);
138 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 return 0;
145
146 set_channel_mode(source_p, chptr, member, parc - 3, parv + 3);
147 }
148
149 return 0;
150 }
151
152 /*
153 * ms_bmask()
154 *
155 * inputs - parv[0] = command
156 * 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 servers,
162 */
163 static int
164 ms_bmask(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
165 {
166 char modebuf[IRCD_BUFSIZE];
167 char parabuf[IRCD_BUFSIZE];
168 char banbuf[IRCD_BUFSIZE];
169 struct Channel *chptr;
170 char *s, *t, *mbuf, *pbuf;
171 unsigned int mode_type = 0;
172 int mlen, tlen;
173 int modecount = 0;
174
175 if ((chptr = hash_find_channel(parv[2])) == NULL)
176 return 0;
177
178 /* TS is higher, drop it. */
179 if (atol(parv[1]) > chptr->channelts)
180 return 0;
181
182 switch (*parv[3])
183 {
184 case 'b':
185 mode_type = CHFL_BAN;
186 break;
187
188 case 'e':
189 mode_type = CHFL_EXCEPTION;
190 break;
191
192 case 'I':
193 mode_type = CHFL_INVEX;
194 break;
195
196 /* maybe we should just blindly propagate this? */
197 default:
198 return 0;
199 }
200
201 parabuf[0] = '\0';
202 s = banbuf;
203 strlcpy(s, parv[4], sizeof(banbuf));
204
205 /* only need to construct one buffer, for non-ts6 servers */
206 mlen = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s +",
207 (IsHidden(source_p) || ConfigServerHide.hide_servers) ? me.name : source_p->name,
208 chptr->chname);
209 mbuf = modebuf + mlen;
210 pbuf = parabuf;
211
212 do
213 {
214 if ((t = strchr(s, ' ')))
215 *t++ = '\0';
216 tlen = strlen(s);
217
218 /* I don't even want to begin parsing this.. */
219 if (tlen > MODEBUFLEN)
220 break;
221
222 if (tlen && *s != ':' && add_id(source_p, chptr, s, mode_type))
223 {
224 /* this new one wont fit.. */
225 if (mbuf - modebuf + 2 + pbuf - parabuf + tlen > IRCD_BUFSIZE - 2 ||
226 modecount >= MAXMODEPARAMS)
227 {
228 *mbuf = '\0';
229 *(pbuf - 1) = '\0';
230
231 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s",
232 modebuf, parabuf);
233 mbuf = modebuf + mlen;
234 pbuf = parabuf;
235 modecount = 0;
236 }
237
238 *mbuf++ = parv[3][0];
239 pbuf += sprintf(pbuf, "%s ", s);
240 modecount++;
241 }
242
243 s = t;
244 } while (s != NULL);
245
246 if (modecount)
247 {
248 *mbuf = *(pbuf - 1) = '\0';
249 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
250 }
251
252 /* assumption here is that since the server sent BMASK, they are TS6, so they have an ID */
253 sendto_server(client_p, NOCAPS, NOCAPS, ":%s BMASK %lu %s %s :%s",
254 source_p->id, (unsigned long)chptr->channelts, chptr->chname,
255 parv[3], parv[4]);
256 return 0;
257 }
258
259 static struct Message mode_msgtab =
260 {
261 "MODE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
262 { m_unregistered, m_mode, m_mode, m_ignore, m_mode, m_ignore }
263 };
264
265 static struct Message tmode_msgtab =
266 {
267 "TMODE", 0, 0, 4, MAXPARA, MFLG_SLOW, 0,
268 { m_ignore, m_ignore, ms_tmode, m_ignore, m_ignore, m_ignore }
269 };
270
271 static struct Message bmask_msgtab =
272 {
273 "BMASK", 0, 0, 5, MAXPARA, MFLG_SLOW, 0,
274 { m_ignore, m_ignore, ms_bmask, m_ignore, m_ignore, m_ignore }
275 };
276
277 static void
278 module_init(void)
279 {
280 mod_add_cmd(&mode_msgtab);
281 mod_add_cmd(&tmode_msgtab);
282 mod_add_cmd(&bmask_msgtab);
283 }
284
285 static void
286 module_exit(void)
287 {
288 mod_del_cmd(&mode_msgtab);
289 mod_del_cmd(&tmode_msgtab);
290 mod_del_cmd(&bmask_msgtab);
291 }
292
293 struct module module_entry =
294 {
295 .node = { NULL, NULL, NULL },
296 .name = NULL,
297 .version = "$Revision$",
298 .handle = NULL,
299 .modinit = module_init,
300 .modexit = module_exit,
301 .flags = MODULE_FLAG_CORE
302 };

Properties

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

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