1 |
/** |
2 |
* op.C: This file contains code for the ChanServ OP functions. |
3 |
* |
4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
* Rights to this code are as documented in COPYING. |
6 |
* |
7 |
* |
8 |
* Portions of this file were derived from sources bearing the following license: |
9 |
* Copyright © 2005 William Pitcock, et al. |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: op.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <ermyth/module.h> |
17 |
#include <account/chanacs.h> |
18 |
#include <account/mychan.h> |
19 |
|
20 |
static char const rcsid[] = "$Id: op.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $"; |
21 |
|
22 |
REGISTER_MODULE ("chanserv/op", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
23 |
|
24 |
static void cs_cmd_op (sourceinfo_t *si, int parc, char *parv[]); |
25 |
static void cs_cmd_deop (sourceinfo_t *si, int parc, char *parv[]); |
26 |
|
27 |
command_t const cs_op = { "OP", N_("Gives channel ops to a user."), AC_NONE, 2, cs_cmd_op }; |
28 |
command_t const cs_deop = { "DEOP", N_("Removes channel ops from a user."), AC_NONE, 2, cs_cmd_deop }; |
29 |
|
30 |
E cmdvec cs_cmdtree; |
31 |
E helpvec cs_helptree; |
32 |
|
33 |
bool |
34 |
_modinit (module *m) |
35 |
{ |
36 |
cs_cmdtree << cs_op; |
37 |
cs_cmdtree << cs_deop; |
38 |
|
39 |
help_addentry (cs_helptree, "OP", "help/chanserv/op", NULL); |
40 |
help_addentry (cs_helptree, "DEOP", "help/chanserv/deop", NULL); |
41 |
|
42 |
return true; |
43 |
} |
44 |
|
45 |
void |
46 |
_moddeinit () |
47 |
{ |
48 |
cs_cmdtree >> cs_op; |
49 |
cs_cmdtree >> cs_deop; |
50 |
|
51 |
help_delentry (cs_helptree, "OP"); |
52 |
help_delentry (cs_helptree, "DEOP"); |
53 |
} |
54 |
|
55 |
static void |
56 |
cs_cmd_op (sourceinfo_t *si, int parc, char *parv[]) |
57 |
{ |
58 |
char *chan = parv[0]; |
59 |
char *nick = parv[1]; |
60 |
mychan_t *mc; |
61 |
user_t *tu; |
62 |
chanuser_t *cu; |
63 |
|
64 |
if (!chan) |
65 |
{ |
66 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "OP"); |
67 |
command_fail (si, fault::needmoreparams, _("Syntax: OP <#channel> [nickname]")); |
68 |
return; |
69 |
} |
70 |
|
71 |
mc = mychan_t::find (chan); |
72 |
if (!mc) |
73 |
{ |
74 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
75 |
return; |
76 |
} |
77 |
|
78 |
if (!chanacs_source_has_flag (mc, si, CA_OP)) |
79 |
{ |
80 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
81 |
return; |
82 |
} |
83 |
|
84 |
if (mc->find_metadata ("private:close:closer")) |
85 |
{ |
86 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); |
87 |
return; |
88 |
} |
89 |
|
90 |
/* figure out who we're going to op */ |
91 |
if (!nick) |
92 |
tu = si->su; |
93 |
else |
94 |
{ |
95 |
if (!(tu = user_find_named (nick))) |
96 |
{ |
97 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); |
98 |
return; |
99 |
} |
100 |
} |
101 |
|
102 |
if (is_internal_client (tu)) |
103 |
return; |
104 |
|
105 |
/* SECURE check; we can skip this if sender == target, because we already verified */ |
106 |
if ((si->su != tu) && (mc->flags & MC_SECURE) && !chanacs_user_has_flag (mc, tu, CA_OP) && !chanacs_user_has_flag (mc, tu, CA_AUTOOP)) |
107 |
{ |
108 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."), mc->name); |
109 |
command_fail (si, fault::noprivs, _("\2%s\2 has the SECURE option enabled, and \2%s\2 does not have appropriate access."), mc->name, tu->nick); |
110 |
return; |
111 |
} |
112 |
|
113 |
cu = chanuser_find (mc->chan, tu); |
114 |
if (!cu) |
115 |
{ |
116 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name); |
117 |
return; |
118 |
} |
119 |
|
120 |
modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, 'o', CLIENT_NAME (tu)); |
121 |
cu->modes |= CMODE_OP; |
122 |
|
123 |
if (si->c == NULL && tu != si->su) |
124 |
notice (chansvs.nick, tu->nick, "You have been opped on %s by %s", mc->name, get_source_name (si)); |
125 |
|
126 |
logcommand (si, CMDLOG_SET, "%s OP %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost); |
127 |
if (!chanuser_find (mc->chan, si->su)) |
128 |
command_success_nodata (si, _("\2%s\2 has been opped on \2%s\2."), tu->nick, mc->name); |
129 |
} |
130 |
|
131 |
static void |
132 |
cs_cmd_deop (sourceinfo_t *si, int parc, char *parv[]) |
133 |
{ |
134 |
char *chan = parv[0]; |
135 |
char *nick = parv[1]; |
136 |
mychan_t *mc; |
137 |
user_t *tu; |
138 |
chanuser_t *cu; |
139 |
|
140 |
if (!chan) |
141 |
{ |
142 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DEOP"); |
143 |
command_fail (si, fault::needmoreparams, _("Syntax: DEOP <#channel> [nickname]")); |
144 |
return; |
145 |
} |
146 |
|
147 |
mc = mychan_t::find (chan); |
148 |
if (!mc) |
149 |
{ |
150 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
151 |
return; |
152 |
} |
153 |
|
154 |
if (!chanacs_source_has_flag (mc, si, CA_OP)) |
155 |
{ |
156 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
157 |
return; |
158 |
} |
159 |
|
160 |
if (mc->find_metadata ("private:close:closer")) |
161 |
{ |
162 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); |
163 |
return; |
164 |
} |
165 |
|
166 |
/* figure out who we're going to deop */ |
167 |
if (!nick) |
168 |
tu = si->su; |
169 |
else |
170 |
{ |
171 |
if (!(tu = user_find_named (nick))) |
172 |
{ |
173 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); |
174 |
return; |
175 |
} |
176 |
} |
177 |
|
178 |
if (is_internal_client (tu)) |
179 |
return; |
180 |
|
181 |
cu = chanuser_find (mc->chan, tu); |
182 |
if (!cu) |
183 |
{ |
184 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name); |
185 |
return; |
186 |
} |
187 |
|
188 |
modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, 'o', CLIENT_NAME (tu)); |
189 |
cu->modes &= ~CMODE_OP; |
190 |
|
191 |
if (si->c == NULL && tu != si->su) |
192 |
notice (chansvs.nick, tu->nick, "You have been deopped on %s by %s", mc->name, get_source_name (si)); |
193 |
|
194 |
logcommand (si, CMDLOG_SET, "%s DEOP %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost); |
195 |
if (!chanuser_find (mc->chan, si->su)) |
196 |
command_success_nodata (si, _("\2%s\2 has been deopped on \2%s\2."), tu->nick, mc->name); |
197 |
} |
198 |
|
199 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
200 |
* vim:ts=8 |
201 |
* vim:sw=8 |
202 |
* vim:noexpandtab |
203 |
*/ |