ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/halfop.C
Revision: 1.4
Committed: Sun Jul 22 18:38:42 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +5 -5 lines
Log Message:
-fixed help
- temporarily work around corruption in jsonrpc

File Contents

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