]> jfr.im git - irc/rqf/shadowircd.git/blob - extensions/m_omode.c
451b627222454f4d374b7d0c9801b56f6f9d8907
[irc/rqf/shadowircd.git] / extensions / m_omode.c
1 /*
2 * Charybdis: an advanced Internet Relay Chat Daemon(ircd).
3 * m_omode.c: allows oper mode hacking
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2004 ircd-ratbox development team
8 * Copyright (C) 2006 Charybdis development team
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * $Id: m_omode.c 3121 2007-01-02 13:23:04Z jilles $
26 */
27
28 #include "stdinc.h"
29 #include "channel.h"
30 #include "client.h"
31 #include "hash.h"
32 #include "match.h"
33 #include "ircd.h"
34 #include "numeric.h"
35 #include "s_user.h"
36 #include "s_conf.h"
37 #include "s_newconf.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 int mo_omode(struct Client *, struct Client *, int, const char **);
46
47 struct Message omode_msgtab = {
48 "OMODE", 0, 0, 0, MFLG_SLOW,
49 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_omode, 3}}
50 };
51
52 mapi_clist_av1 omode_clist[] = { &omode_msgtab, NULL };
53
54 DECLARE_MODULE_AV1(omode, NULL, NULL, omode_clist, NULL, NULL, "$Revision: 3121 $");
55
56 /*
57 * mo_omode - MODE command handler
58 * parv[1] - channel
59 */
60 static int
61 mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
62 {
63 struct Channel *chptr = NULL;
64 struct membership *msptr;
65 char params[512];
66 int i;
67 int wasonchannel;
68
69 /* admins only */
70 if(!IsOperAdmin(source_p))
71 {
72 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
73 return 0;
74 }
75
76 /* Now, try to find the channel in question */
77 if(!IsChanPrefix(parv[1][0]) || !check_channel_name(parv[1]))
78 {
79 sendto_one_numeric(source_p, ERR_BADCHANNAME,
80 form_str(ERR_BADCHANNAME), parv[1]);
81 return 0;
82 }
83
84 chptr = find_channel(parv[1]);
85
86 if(chptr == NULL)
87 {
88 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
89 form_str(ERR_NOSUCHCHANNEL), parv[1]);
90 return 0;
91 }
92
93 /* Now know the channel exists */
94 msptr = find_channel_membership(chptr, source_p);
95 wasonchannel = msptr != NULL;
96
97 if (is_any_op(msptr))
98 {
99 sendto_one_notice(source_p, ":Use a normal MODE you idiot");
100 return 0;
101 }
102
103 params[0] = '\0';
104 for (i = 2; i < parc; i++)
105 {
106 if (i != 2)
107 rb_strlcat(params, " ", sizeof params);
108 rb_strlcat(params, parv[i], sizeof params);
109 }
110
111 sendto_wallops_flags(UMODE_WALLOP, &me,
112 "OMODE called for [%s] [%s] by %s!%s@%s",
113 parv[1], params, source_p->name, source_p->username, source_p->host);
114 ilog(L_MAIN, "OMODE called for [%s] [%s] by %s",
115 parv[1], params, get_oper_name(source_p));
116
117 if(*chptr->chname != '&')
118 sendto_server(NULL, NULL, NOCAPS, NOCAPS,
119 ":%s WALLOPS :OMODE called for [%s] [%s] by %s!%s@%s",
120 me.name, parv[1], params, source_p->name, source_p->username,
121 source_p->host);
122
123 #if 0
124 set_channel_mode(client_p, source_p->servptr, chptr, msptr,
125 parc - 2, parv + 2);
126 #else
127 if (parc == 4 && !strcmp(parv[2], "+a") && !irccmp(parv[3], source_p->name))
128 {
129 /* Admining themselves */
130 if (!wasonchannel)
131 {
132 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
133 form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname);
134 return 0;
135 }
136 sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +a %s",
137 me.name, parv[1], source_p->name);
138 sendto_server(NULL, chptr, CAP_TS6, NOCAPS,
139 ":%s TMODE %ld %s +a %s",
140 me.id, (long) chptr->channelts, parv[1],
141 source_p->id);
142 msptr->flags |= CHFL_ADMIN;
143 }
144 else if (parc == 4 && !strcmp(parv[2], "+o") && !irccmp(parv[3], source_p->name))
145 {
146 /* Opping themselves */
147 if (!wasonchannel)
148 {
149 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
150 form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname);
151 return 0;
152 }
153 sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +o %s",
154 me.name, parv[1], source_p->name);
155 sendto_server(NULL, chptr, CAP_TS6, NOCAPS,
156 ":%s TMODE %ld %s +o %s",
157 me.id, (long) chptr->channelts, parv[1],
158 source_p->id);
159 msptr->flags |= CHFL_CHANOP;
160 }
161 else if (parc == 4 && !strcmp(parv[2], "+h") && !irccmp(parv[3], source_p->name))
162 {
163 /* Halfopping themselves */
164 if (!wasonchannel)
165 {
166 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
167 form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname);
168 return 0;
169 }
170 sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +h %s",
171 me.name, parv[1], source_p->name);
172 sendto_server(NULL, chptr, CAP_TS6, NOCAPS,
173 ":%s TMODE %ld %s +h %s",
174 me.id, (long) chptr->channelts, parv[1],
175 source_p->id);
176 msptr->flags |= CHFL_HALFOP;
177 }
178 else if (ConfigChannel.use_admin)
179 {
180 /* Hack it so set_channel_mode() will accept */
181 if (wasonchannel)
182 msptr->flags |= CHFL_ADMIN;
183 else
184 {
185 add_user_to_channel(chptr, source_p, CHFL_CHANOP);
186 msptr = find_channel_membership(chptr, source_p);
187 }
188 set_channel_mode(client_p, source_p, chptr, msptr,
189 parc - 2, parv + 2);
190 /* We know they were not opped before and they can't have opped
191 * themselves as set_channel_mode() does not allow that
192 * -- jilles */
193 if (wasonchannel)
194 msptr->flags &= ~CHFL_ADMIN;
195 else
196 remove_user_from_channel(msptr);
197 }
198 else
199 {
200 /* CHFL_ADMIN is only useful if admin is enabled
201 * so hack it with op if it is not. */
202 if (wasonchannel)
203 msptr->flags |= CHFL_CHANOP;
204 else
205 {
206 add_user_to_channel(chptr, source_p, CHFL_CHANOP);
207 msptr = find_channel_membership(chptr, source_p);
208 }
209 set_channel_mode(client_p, source_p, chptr, msptr,
210 parc - 2, parv + 2);
211 /* We know they were not opped before and they can't have opped
212 * themselves as set_channel_mode() does not allow that
213 * -- jilles */
214 if (wasonchannel)
215 msptr->flags &= ~CHFL_CHANOP;
216 else
217 remove_user_from_channel(msptr);
218 }
219 #endif
220 return 0;
221 }