ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/voice.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months 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

# Content
1 /**
2 * voice.C: This file contains code for the ChanServ VOICE 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 * Copyright © 2005 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: voice.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/module.h>
17 #include <account/mychan.h>
18 #include <account/chanacs.h>
19
20 static char const rcsid[] = "$Id: voice.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
21
22 REGISTER_MODULE ("chanserv/voice", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23
24 static void cs_cmd_voice (sourceinfo_t *si, int parc, char *parv[]);
25 static void cs_cmd_devoice (sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t const cs_voice = { "VOICE", N_("Gives channel voice to a user."), AC_NONE, 2, cs_cmd_voice };
28 command_t const cs_devoice = { "DEVOICE", N_("Removes channel voice from a user."), AC_NONE, 2, cs_cmd_devoice };
29
30 E cmdvec cs_cmdtree;
31 E helpvec cs_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 cs_cmdtree << cs_voice;
37 cs_cmdtree << cs_devoice;
38
39 help_addentry (cs_helptree, "VOICE", "help/chanserv/voice", NULL);
40 help_addentry (cs_helptree, "DEVOICE", "help/chanserv/devoice", NULL);
41
42 return true;
43 }
44
45 void
46 _moddeinit ()
47 {
48 cs_cmdtree >> cs_voice;
49 cs_cmdtree >> cs_devoice;
50
51 help_delentry (cs_helptree, "VOICE");
52 help_delentry (cs_helptree, "DEVOICE");
53 }
54
55 static void
56 cs_cmd_voice (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 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "VOICE");
67 command_fail (si, fault::needmoreparams, _("Syntax: VOICE <#channel> [nickname]"));
68 return;
69 }
70
71 mc = mychan_t::find (chan);
72 if (!mc)
73 {
74 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
75 return;
76 }
77
78 if (mc->find_metadata ("private:close:closer"))
79 {
80 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
81 return;
82 }
83
84 if (!chanacs_source_has_flag (mc, si, CA_VOICE))
85 {
86 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
87 return;
88 }
89
90 /* figure out who we're going to voice */
91 if (!nick)
92 tu = si->su;
93 else
94 {
95 if (!(tu = user_find_named (nick)))
96 {
97 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
98 return;
99 }
100 }
101
102 if (is_internal_client (tu))
103 return;
104
105 cu = chanuser_find (mc->chan, tu);
106 if (!cu)
107 {
108 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
109 return;
110 }
111
112 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, 'v', CLIENT_NAME (tu));
113 cu->modes |= CMODE_VOICE;
114
115 if (si->c == NULL && tu != si->su)
116 notice (chansvs.nick, tu->nick, "You have been voiced on %s by %s", mc->name, get_source_name (si));
117
118 logcommand (si, CMDLOG_SET, "%s VOICE %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost);
119 if (!chanuser_find (mc->chan, si->su))
120 command_success_nodata (si, _("\2%s\2 has been voiced on \2%s\2."), tu->nick, mc->name);
121 }
122
123 static void
124 cs_cmd_devoice (sourceinfo_t *si, int parc, char *parv[])
125 {
126 char *chan = parv[0];
127 char *nick = parv[1];
128 mychan_t *mc;
129 user_t *tu;
130 chanuser_t *cu;
131
132 if (!chan)
133 {
134 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DEVOICE");
135 command_fail (si, fault::needmoreparams, _("Syntax: DEVOICE <#channel> [nickname]"));
136 return;
137 }
138
139 mc = mychan_t::find (chan);
140 if (!mc)
141 {
142 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
143 return;
144 }
145
146 if (!chanacs_source_has_flag (mc, si, CA_VOICE))
147 {
148 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
149 return;
150 }
151
152 /* figure out who we're going to devoice */
153 if (!nick)
154 tu = si->su;
155 else
156 {
157 if (!(tu = user_find_named (nick)))
158 {
159 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
160 return;
161 }
162 }
163
164 if (is_internal_client (tu))
165 return;
166
167 cu = chanuser_find (mc->chan, tu);
168 if (!cu)
169 {
170 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
171 return;
172 }
173
174 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, 'v', CLIENT_NAME (tu));
175 cu->modes &= ~CMODE_VOICE;
176
177 if (si->c == NULL && tu != si->su)
178 notice (chansvs.nick, tu->nick, "You have been devoiced on %s by %s", mc->name, get_source_name (si));
179
180 logcommand (si, CMDLOG_SET, "%s DEVOICE %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost);
181 if (!chanuser_find (mc->chan, si->su))
182 command_success_nodata (si, _("\2%s\2 has been devoiced on \2%s\2."), tu->nick, mc->name);
183 }
184
185 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
186 * vim:ts=8
187 * vim:sw=8
188 * vim:noexpandtab
189 */