ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/op.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (19 years 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     * 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 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: op.C,v 1.7 2007-09-16 18:54:43 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: op.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
21 pippijn 1.1
22 pippijn 1.8 REGISTER_MODULE ("chanserv/op", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23 pippijn 1.1
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 pippijn 1.5 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 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     cs_cmdtree << cs_op;
37     cs_cmdtree << cs_deop;
38    
39 pippijn 1.4 help_addentry (cs_helptree, "OP", "help/chanserv/op", NULL);
40     help_addentry (cs_helptree, "DEOP", "help/chanserv/deop", NULL);
41 pippijn 1.5
42     return true;
43 pippijn 1.1 }
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 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "OP");
67     command_fail (si, fault::needmoreparams, _("Syntax: OP <#channel> [nickname]"));
68 pippijn 1.1 return;
69     }
70    
71 pippijn 1.6 mc = mychan_t::find (chan);
72 pippijn 1.1 if (!mc)
73     {
74 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
75 pippijn 1.1 return;
76     }
77    
78     if (!chanacs_source_has_flag (mc, si, CA_OP))
79     {
80 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
81 pippijn 1.1 return;
82     }
83    
84     if (mc->find_metadata ("private:close:closer"))
85     {
86 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
87 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
98 pippijn 1.1 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 pippijn 1.6 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 pippijn 1.1 return;
111     }
112    
113     cu = chanuser_find (mc->chan, tu);
114     if (!cu)
115     {
116 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
117 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DEOP");
143     command_fail (si, fault::needmoreparams, _("Syntax: DEOP <#channel> [nickname]"));
144 pippijn 1.1 return;
145     }
146    
147 pippijn 1.6 mc = mychan_t::find (chan);
148 pippijn 1.1 if (!mc)
149     {
150 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
151 pippijn 1.1 return;
152     }
153    
154     if (!chanacs_source_has_flag (mc, si, CA_OP))
155     {
156 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
157 pippijn 1.1 return;
158     }
159    
160     if (mc->find_metadata ("private:close:closer"))
161     {
162 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
163 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
174 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
185 pippijn 1.1 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     */