ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/halfop.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# User Rev Content
1 pippijn 1.7 /**
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 pippijn 1.5 * Copyright © 2005 William Pitcock, et al.
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.8 * $Id: halfop.C,v 1.7 2007-09-16 18:54:42 pippijn Exp $
13 pippijn 1.1 */
14    
15     #include "atheme.h"
16 pippijn 1.5 #include <ermyth/module.h>
17 pippijn 1.1 #include <account/chanacs.h>
18     #include <account/mychan.h>
19    
20 pippijn 1.8 static char const rcsid[] = "$Id: halfop.C,v 1.7 2007-09-16 18:54:42 pippijn Exp $";
21 pippijn 1.1
22 pippijn 1.8 REGISTER_MODULE ("chanserv/halfop", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23 pippijn 1.1
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 pippijn 1.5 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 pippijn 1.1
30 pippijn 1.5 E cmdvec cs_cmdtree;
31     E helpvec cs_helptree;
32 pippijn 1.1
33 pippijn 1.5 bool
34     _modinit (module *m)
35 pippijn 1.1 {
36 pippijn 1.5 if (ircd && !ircd->uses_halfops)
37 pippijn 1.1 {
38 pippijn 1.5 slog (LG_INFO, "Module %s requires halfop support, refusing to load.", m->name);
39     return false;
40 pippijn 1.1 }
41    
42     cs_cmdtree << cs_halfop;
43     cs_cmdtree << cs_dehalfop;
44    
45 pippijn 1.4 help_addentry (cs_helptree, "HALFOP", "help/chanserv/halfop", NULL);
46     help_addentry (cs_helptree, "DEHALFOP", "help/chanserv/dehalfop", NULL);
47 pippijn 1.5
48     return true;
49 pippijn 1.1 }
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 pippijn 1.6 command_fail (si, fault::noprivs, _("Your IRC server does not support halfops."));
73 pippijn 1.1 return;
74     }
75    
76     if (!chan)
77     {
78 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "HALFOP");
79     command_fail (si, fault::needmoreparams, _("Syntax: HALFOP <#channel> [nickname]"));
80 pippijn 1.1 return;
81     }
82    
83 pippijn 1.6 mc = mychan_t::find (chan);
84 pippijn 1.1 if (!mc)
85     {
86 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
87 pippijn 1.1 return;
88     }
89    
90     if (!chanacs_source_has_flag (mc, si, CA_HALFOP))
91     {
92 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
93 pippijn 1.1 return;
94     }
95    
96     if (mc->find_metadata ("private:close:closer"))
97     {
98 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
99 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
110 pippijn 1.1 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 pippijn 1.6 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 pippijn 1.1 return;
123     }
124    
125     cu = chanuser_find (mc->chan, tu);
126     if (!cu)
127     {
128 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
129 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::noprivs, _("Your IRC server does not support halfops."));
155 pippijn 1.1 return;
156     }
157    
158     if (!chan)
159     {
160 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DEHALFOP");
161     command_fail (si, fault::needmoreparams, _("Syntax: DEHALFOP <#channel> [nickname]"));
162 pippijn 1.1 return;
163     }
164    
165 pippijn 1.6 mc = mychan_t::find (chan);
166 pippijn 1.1 if (!mc)
167     {
168 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
169 pippijn 1.1 return;
170     }
171    
172     if (!chanacs_source_has_flag (mc, si, CA_HALFOP))
173     {
174 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
175 pippijn 1.1 return;
176     }
177    
178     if (mc->find_metadata ("private:close:closer"))
179     {
180 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
181 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
192 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
203 pippijn 1.1 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     */