ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/op.C
Revision: 1.4
Committed: Sun Jul 22 18:38:43 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +4 -4 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     * This file contains code for the CService OP functions.
6     *
7 pippijn 1.4 * $Id: op.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: op.C,v 1.3 2007-07-21 13:23:18 pippijn Exp $";
15 pippijn 1.1
16     struct cs_op_listeners : callback::has_listeners
17     {
18     };
19    
20     cs_op_listeners listeners;
21    
22     DECLARE_MODULE_V1 ("chanserv/op", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
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 cs_op = { "OP", N_("Gives channel ops to a user."),
28     AC_NONE, 2, cs_cmd_op
29     };
30     command_t cs_deop = { "DEOP", N_("Removes channel ops from a user."),
31     AC_NONE, 2, cs_cmd_deop
32     };
33    
34     cmdvec *cs_cmdtree;
35     helpvec *cs_helptree;
36    
37     void
38     _modinit (module_t *m)
39     {
40     MODULE_USE_SYMBOL_T (cs_cmdtree, cmdvec, "chanserv/main", "cs_cmdtree");
41     MODULE_USE_SYMBOL_T (cs_helptree, helpvec, "chanserv/main", "cs_helptree");
42    
43     cs_cmdtree << cs_op;
44     cs_cmdtree << cs_deop;
45    
46 pippijn 1.4 help_addentry (cs_helptree, "OP", "help/chanserv/op", NULL);
47     help_addentry (cs_helptree, "DEOP", "help/chanserv/deop", NULL);
48 pippijn 1.1 }
49    
50     void
51     _moddeinit ()
52     {
53     cs_cmdtree >> cs_op;
54     cs_cmdtree >> cs_deop;
55    
56     help_delentry (cs_helptree, "OP");
57     help_delentry (cs_helptree, "DEOP");
58     }
59    
60     static void
61     cs_cmd_op (sourceinfo_t *si, int parc, char *parv[])
62     {
63     char *chan = parv[0];
64     char *nick = parv[1];
65     mychan_t *mc;
66     user_t *tu;
67     chanuser_t *cu;
68    
69     if (!chan)
70     {
71     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "OP");
72     command_fail (si, fault_needmoreparams, _("Syntax: OP <#channel> [nickname]"));
73     return;
74     }
75    
76     mc = mychan_find (chan);
77     if (!mc)
78     {
79     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), chan);
80     return;
81     }
82    
83     if (!chanacs_source_has_flag (mc, si, CA_OP))
84     {
85     command_fail (si, fault_noprivs, _("You are not authorized to perform this operation."));
86     return;
87     }
88    
89     if (mc->find_metadata ("private:close:closer"))
90     {
91     command_fail (si, fault_noprivs, _("\2%s\2 is closed."), chan);
92     return;
93     }
94    
95     /* figure out who we're going to op */
96     if (!nick)
97     tu = si->su;
98     else
99     {
100     if (!(tu = user_find_named (nick)))
101     {
102     command_fail (si, fault_nosuch_target, _("\2%s\2 is not online."), nick);
103     return;
104     }
105     }
106    
107     if (is_internal_client (tu))
108     return;
109    
110     /* SECURE check; we can skip this if sender == target, because we already verified */
111     if ((si->su != tu) && (mc->flags & MC_SECURE) && !chanacs_user_has_flag (mc, tu, CA_OP) && !chanacs_user_has_flag (mc, tu, CA_AUTOOP))
112     {
113     command_fail (si, fault_noprivs, _("You are not authorized to perform this operation."), mc->name);
114     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);
115     return;
116     }
117    
118     cu = chanuser_find (mc->chan, tu);
119     if (!cu)
120     {
121     command_fail (si, fault_nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
122     return;
123     }
124    
125     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, 'o', CLIENT_NAME (tu));
126     cu->modes |= CMODE_OP;
127    
128     if (si->c == NULL && tu != si->su)
129     notice (chansvs.nick, tu->nick, "You have been opped on %s by %s", mc->name, get_source_name (si));
130    
131     logcommand (si, CMDLOG_SET, "%s OP %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost);
132     if (!chanuser_find (mc->chan, si->su))
133     command_success_nodata (si, _("\2%s\2 has been opped on \2%s\2."), tu->nick, mc->name);
134     }
135    
136     static void
137     cs_cmd_deop (sourceinfo_t *si, int parc, char *parv[])
138     {
139     char *chan = parv[0];
140     char *nick = parv[1];
141     mychan_t *mc;
142     user_t *tu;
143     chanuser_t *cu;
144    
145     if (!chan)
146     {
147     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "DEOP");
148     command_fail (si, fault_needmoreparams, _("Syntax: DEOP <#channel> [nickname]"));
149     return;
150     }
151    
152     mc = mychan_find (chan);
153     if (!mc)
154     {
155     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), chan);
156     return;
157     }
158    
159     if (!chanacs_source_has_flag (mc, si, CA_OP))
160     {
161     command_fail (si, fault_noprivs, _("You are not authorized to perform this operation."));
162     return;
163     }
164    
165     if (mc->find_metadata ("private:close:closer"))
166     {
167     command_fail (si, fault_noprivs, _("\2%s\2 is closed."), chan);
168     return;
169     }
170    
171     /* figure out who we're going to deop */
172     if (!nick)
173     tu = si->su;
174     else
175     {
176     if (!(tu = user_find_named (nick)))
177     {
178     command_fail (si, fault_nosuch_target, _("\2%s\2 is not online."), nick);
179     return;
180     }
181     }
182    
183     if (is_internal_client (tu))
184     return;
185    
186     cu = chanuser_find (mc->chan, tu);
187     if (!cu)
188     {
189     command_fail (si, fault_nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
190     return;
191     }
192    
193     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, 'o', CLIENT_NAME (tu));
194     cu->modes &= ~CMODE_OP;
195    
196     if (si->c == NULL && tu != si->su)
197     notice (chansvs.nick, tu->nick, "You have been deopped on %s by %s", mc->name, get_source_name (si));
198    
199     logcommand (si, CMDLOG_SET, "%s DEOP %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost);
200     if (!chanuser_find (mc->chan, si->su))
201     command_success_nodata (si, _("\2%s\2 has been deopped on \2%s\2."), tu->nick, mc->name);
202     }
203    
204     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
205     * vim:ts=8
206     * vim:sw=8
207     * vim:noexpandtab
208     */