ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/op.C
Revision: 1.5
Committed: Tue Aug 28 17:08:08 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +14 -24 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

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