1 |
/** |
2 |
* halfop.C: This file contains code for the ChanServ HALFOP 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: halfop.C,v 1.7 2007-09-16 18:54:42 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: halfop.C,v 1.7 2007-09-16 18:54:42 pippijn Exp $"; |
21 |
|
22 |
REGISTER_MODULE ("chanserv/halfop", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
23 |
|
24 |
static void cs_cmd_halfop (sourceinfo_t *si, int parc, char *parv[]); |
25 |
static void cs_cmd_dehalfop (sourceinfo_t *si, int parc, char *parv[]); |
26 |
|
27 |
command_t const cs_halfop = { "HALFOP", N_("Gives channel halfops to a user."), AC_NONE, 2, cs_cmd_halfop }; |
28 |
command_t const cs_dehalfop = { "DEHALFOP", N_("Removes channel halfops from a user."), AC_NONE, 2, cs_cmd_dehalfop }; |
29 |
|
30 |
E cmdvec cs_cmdtree; |
31 |
E helpvec cs_helptree; |
32 |
|
33 |
bool |
34 |
_modinit (module *m) |
35 |
{ |
36 |
if (ircd && !ircd->uses_halfops) |
37 |
{ |
38 |
slog (LG_INFO, "Module %s requires halfop support, refusing to load.", m->name); |
39 |
return false; |
40 |
} |
41 |
|
42 |
cs_cmdtree << cs_halfop; |
43 |
cs_cmdtree << cs_dehalfop; |
44 |
|
45 |
help_addentry (cs_helptree, "HALFOP", "help/chanserv/halfop", NULL); |
46 |
help_addentry (cs_helptree, "DEHALFOP", "help/chanserv/dehalfop", NULL); |
47 |
|
48 |
return true; |
49 |
} |
50 |
|
51 |
void |
52 |
_moddeinit () |
53 |
{ |
54 |
cs_cmdtree >> cs_halfop; |
55 |
cs_cmdtree >> cs_dehalfop; |
56 |
|
57 |
help_delentry (cs_helptree, "HALFOP"); |
58 |
help_delentry (cs_helptree, "DEHALFOP"); |
59 |
} |
60 |
|
61 |
static void |
62 |
cs_cmd_halfop (sourceinfo_t *si, int parc, char *parv[]) |
63 |
{ |
64 |
char *chan = parv[0]; |
65 |
char *nick = parv[1]; |
66 |
mychan_t *mc; |
67 |
user_t *tu; |
68 |
chanuser_t *cu; |
69 |
|
70 |
if (!ircd->uses_halfops) |
71 |
{ |
72 |
command_fail (si, fault::noprivs, _("Your IRC server does not support halfops.")); |
73 |
return; |
74 |
} |
75 |
|
76 |
if (!chan) |
77 |
{ |
78 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "HALFOP"); |
79 |
command_fail (si, fault::needmoreparams, _("Syntax: HALFOP <#channel> [nickname]")); |
80 |
return; |
81 |
} |
82 |
|
83 |
mc = mychan_t::find (chan); |
84 |
if (!mc) |
85 |
{ |
86 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
87 |
return; |
88 |
} |
89 |
|
90 |
if (!chanacs_source_has_flag (mc, si, CA_HALFOP)) |
91 |
{ |
92 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
93 |
return; |
94 |
} |
95 |
|
96 |
if (mc->find_metadata ("private:close:closer")) |
97 |
{ |
98 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); |
99 |
return; |
100 |
} |
101 |
|
102 |
/* figure out who we're going to halfop */ |
103 |
if (!nick) |
104 |
tu = si->su; |
105 |
else |
106 |
{ |
107 |
if (!(tu = user_find_named (nick))) |
108 |
{ |
109 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); |
110 |
return; |
111 |
} |
112 |
} |
113 |
|
114 |
if (is_internal_client (tu)) |
115 |
return; |
116 |
|
117 |
/* SECURE check; we can skip this if sender == target, because we already verified */ |
118 |
if ((si->su != tu) && (mc->flags & MC_SECURE) && !chanacs_user_has_flag (mc, tu, CA_HALFOP) && !chanacs_user_has_flag (mc, tu, CA_AUTOHALFOP)) |
119 |
{ |
120 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."), mc->name); |
121 |
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); |
122 |
return; |
123 |
} |
124 |
|
125 |
cu = chanuser_find (mc->chan, tu); |
126 |
if (!cu) |
127 |
{ |
128 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name); |
129 |
return; |
130 |
} |
131 |
|
132 |
modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, 'h', CLIENT_NAME (tu)); |
133 |
cu->modes |= ircd->halfops_mode; |
134 |
|
135 |
if (si->c == NULL && tu != si->su) |
136 |
notice (chansvs.nick, tu->nick, "You have been halfopped on %s by %s", mc->name, get_source_name (si)); |
137 |
|
138 |
logcommand (si, CMDLOG_SET, "%s HALFOP %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost); |
139 |
if (!chanuser_find (mc->chan, si->su)) |
140 |
command_success_nodata (si, _("\2%s\2 has been halfopped on \2%s\2."), tu->nick, mc->name); |
141 |
} |
142 |
|
143 |
static void |
144 |
cs_cmd_dehalfop (sourceinfo_t *si, int parc, char *parv[]) |
145 |
{ |
146 |
char *chan = parv[0]; |
147 |
char *nick = parv[1]; |
148 |
mychan_t *mc; |
149 |
user_t *tu; |
150 |
chanuser_t *cu; |
151 |
|
152 |
if (!ircd->uses_halfops) |
153 |
{ |
154 |
command_fail (si, fault::noprivs, _("Your IRC server does not support halfops.")); |
155 |
return; |
156 |
} |
157 |
|
158 |
if (!chan) |
159 |
{ |
160 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DEHALFOP"); |
161 |
command_fail (si, fault::needmoreparams, _("Syntax: DEHALFOP <#channel> [nickname]")); |
162 |
return; |
163 |
} |
164 |
|
165 |
mc = mychan_t::find (chan); |
166 |
if (!mc) |
167 |
{ |
168 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
169 |
return; |
170 |
} |
171 |
|
172 |
if (!chanacs_source_has_flag (mc, si, CA_HALFOP)) |
173 |
{ |
174 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
175 |
return; |
176 |
} |
177 |
|
178 |
if (mc->find_metadata ("private:close:closer")) |
179 |
{ |
180 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); |
181 |
return; |
182 |
} |
183 |
|
184 |
/* figure out who we're going to dehalfop */ |
185 |
if (!nick) |
186 |
tu = si->su; |
187 |
else |
188 |
{ |
189 |
if (!(tu = user_find_named (nick))) |
190 |
{ |
191 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); |
192 |
return; |
193 |
} |
194 |
} |
195 |
|
196 |
if (is_internal_client (tu)) |
197 |
return; |
198 |
|
199 |
cu = chanuser_find (mc->chan, tu); |
200 |
if (!cu) |
201 |
{ |
202 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name); |
203 |
return; |
204 |
} |
205 |
|
206 |
modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, 'h', CLIENT_NAME (tu)); |
207 |
cu->modes &= ~ircd->halfops_mode; |
208 |
|
209 |
if (si->c == NULL && tu != si->su) |
210 |
notice (chansvs.nick, tu->nick, "You have been dehalfopped on %s by %s", mc->name, get_source_name (si)); |
211 |
|
212 |
logcommand (si, CMDLOG_SET, "%s DEHALFOP %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost); |
213 |
if (!chanuser_find (mc->chan, si->su)) |
214 |
command_success_nodata (si, _("\2%s\2 has been dehalfopped on \2%s\2."), tu->nick, mc->name); |
215 |
} |
216 |
|
217 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
218 |
* vim:ts=8 |
219 |
* vim:sw=8 |
220 |
* vim:noexpandtab |
221 |
*/ |