ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/op.C
Revision: 1.6
Committed: Thu Aug 30 19:56:22 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +20 -20 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

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.6 * $Id: op.C,v 1.5 2007-08-28 17:08:08 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.6 static char const rcsid[] = "$Id: op.C,v 1.5 2007-08-28 17:08:08 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 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "OP");
62     command_fail (si, fault::needmoreparams, _("Syntax: OP <#channel> [nickname]"));
63 pippijn 1.1 return;
64     }
65    
66 pippijn 1.6 mc = mychan_t::find (chan);
67 pippijn 1.1 if (!mc)
68     {
69 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
70 pippijn 1.1 return;
71     }
72    
73     if (!chanacs_source_has_flag (mc, si, CA_OP))
74     {
75 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
76 pippijn 1.1 return;
77     }
78    
79     if (mc->find_metadata ("private:close:closer"))
80     {
81 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
82 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
93 pippijn 1.1 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 pippijn 1.6 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 pippijn 1.1 return;
106     }
107    
108     cu = chanuser_find (mc->chan, tu);
109     if (!cu)
110     {
111 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
112 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DEOP");
138     command_fail (si, fault::needmoreparams, _("Syntax: DEOP <#channel> [nickname]"));
139 pippijn 1.1 return;
140     }
141    
142 pippijn 1.6 mc = mychan_t::find (chan);
143 pippijn 1.1 if (!mc)
144     {
145 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
146 pippijn 1.1 return;
147     }
148    
149     if (!chanacs_source_has_flag (mc, si, CA_OP))
150     {
151 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
152 pippijn 1.1 return;
153     }
154    
155     if (mc->find_metadata ("private:close:closer"))
156     {
157 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
158 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
169 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
180 pippijn 1.1 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     */