ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/quiet.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 * quiet.C: This file contains code for the ChanServ QUIET/UNQUIET function.
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: quiet.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: quiet.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
21
22 REGISTER_MODULE ("chanserv/quiet", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23
24 static void cs_cmd_quiet (sourceinfo_t *si, int parc, char *parv[]);
25 static void cs_cmd_unquiet (sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t const cs_quiet = { "QUIET", N_("Sets a quiet on a channel."), AC_NONE, 2, cs_cmd_quiet };
28 command_t const cs_unquiet = { "UNQUIET", N_("Removes a quiet on a channel."), AC_NONE, 2, cs_cmd_unquiet };
29
30 E cmdvec cs_cmdtree;
31 E helpvec cs_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 if (ircd && !strchr (ircd->ban_like_modes, 'q'))
37 {
38 slog (LG_INFO, "Module %s requires a ban-like mode +q, refusing to load.", m->name);
39 return false;
40 }
41
42 cs_cmdtree << cs_quiet;
43 cs_cmdtree << cs_unquiet;
44
45 help_addentry (cs_helptree, "QUIET", "help/chanserv/quiet", NULL);
46 help_addentry (cs_helptree, "UNQUIET", "help/chanserv/unquiet", NULL);
47
48 return true;
49 }
50
51 void
52 _moddeinit ()
53 {
54 cs_cmdtree >> cs_quiet;
55 cs_cmdtree >> cs_unquiet;
56
57 help_delentry (cs_helptree, "QUIET");
58 help_delentry (cs_helptree, "UNQUIET");
59 }
60
61 static void
62 cs_cmd_quiet (sourceinfo_t *si, int parc, char *parv[])
63 {
64 char *channel = parv[0];
65 char *target = parv[1];
66 channel_t *c = channel_find (channel);
67 mychan_t *mc = mychan_t::find (channel);
68 user_t *tu;
69
70 if (!channel || !target)
71 {
72 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "QUIET");
73 command_fail (si, fault::needmoreparams, _("Syntax: QUIET <#channel> <nickname|hostmask>"));
74 return;
75 }
76
77 if (!mc)
78 {
79 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), channel);
80 return;
81 }
82
83 if (!c)
84 {
85 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), channel);
86 return;
87 }
88
89 if (!si->smu)
90 {
91 command_fail (si, fault::noprivs, _("You are not logged in."));
92 return;
93 }
94
95 if (!chanacs_source_has_flag (mc, si, CA_REMOVE))
96 {
97 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
98 return;
99 }
100
101 if (mc->find_metadata ("private:close:closer"))
102 {
103 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), channel);
104 return;
105 }
106
107 if (validhostmask (target))
108 {
109 modestack_mode_param (chansvs.nick, c, MTYPE_ADD, 'q', target);
110 chanban_add (c, target, 'q');
111 logcommand (si, CMDLOG_DO, "%s QUIET %s", mc->name, target);
112 if (!chanuser_find (mc->chan, si->su))
113 command_success_nodata (si, _("Quieted \2%s\2 on \2%s\2."), target, channel);
114 return;
115 }
116 else if ((tu = user_find_named (target)))
117 {
118 char hostbuf[BUFSIZE];
119
120 hostbuf[0] = '\0';
121
122 strlcat (hostbuf, "*!*@", BUFSIZE);
123 strlcat (hostbuf, tu->vhost, BUFSIZE);
124
125 modestack_mode_param (chansvs.nick, c, MTYPE_ADD, 'q', hostbuf);
126 chanban_add (c, hostbuf, 'q');
127 logcommand (si, CMDLOG_DO, "%s QUIET %s (for user %s!%s@%s)", mc->name, hostbuf, tu->nick, tu->user, tu->vhost);
128 if (!chanuser_find (mc->chan, si->su))
129 command_success_nodata (si, _("Quieted \2%s\2 on \2%s\2."), target, channel);
130 return;
131 }
132 else
133 {
134 command_fail (si, fault::badparams, _("Invalid nickname/hostmask provided: \2%s\2"), target);
135 command_fail (si, fault::badparams, _("Syntax: QUIET <#channel> <nickname|hostmask>"));
136 return;
137 }
138 }
139
140 static void
141 cs_cmd_unquiet (sourceinfo_t *si, int parc, char *parv[])
142 {
143 char *channel = parv[0];
144 char *target = parv[1];
145 channel_t *c = channel_find (channel);
146 mychan_t *mc = mychan_t::find (channel);
147 user_t *tu;
148 chanban_t *cb;
149
150 if (!channel)
151 {
152 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "UNQUIET");
153 command_fail (si, fault::needmoreparams, _("Syntax: UNQUIET <#channel> <nickname|hostmask>"));
154 return;
155 }
156
157 if (!target)
158 {
159 if (si->su == NULL)
160 {
161 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "UNQUIET");
162 command_fail (si, fault::needmoreparams, _("Syntax: UNQUIET <#channel> <nickname|hostmask>"));
163 return;
164 }
165 target = si->su->nick;
166 }
167
168 if (!mc)
169 {
170 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), channel);
171 return;
172 }
173
174 if (!c)
175 {
176 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), channel);
177 return;
178 }
179
180 if (!si->smu)
181 {
182 command_fail (si, fault::noprivs, _("You are not logged in."));
183 return;
184 }
185
186 if (!chanacs_source_has_flag (mc, si, CA_REMOVE))
187 {
188 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
189 return;
190 }
191
192 if ((tu = user_find_named (target)))
193 {
194 node_t *n, *tn;
195 char hostbuf2[BUFSIZE];
196 int count = 0;
197
198 snprintf (hostbuf2, BUFSIZE, "%s!%s@%s", tu->nick, tu->user, tu->vhost);
199 for (n = phandler->next_matching_ban (c, tu, 'q', c->bans.head); n != NULL; n = phandler->next_matching_ban (c, tu, 'q', tn))
200 {
201 tn = n->next;
202 cb = static_cast<chanban_t *> (n->data);
203
204 logcommand (si, CMDLOG_DO, "%s UNQUIET %s (for user %s)", mc->name, cb->mask, hostbuf2);
205 modestack_mode_param (chansvs.nick, c, MTYPE_DEL, cb->type, cb->mask);
206 chanban_delete (cb);
207 count++;
208 }
209 if (count > 0)
210 command_success_nodata (si, _("Unquieted \2%s\2 on \2%s\2 (%d ban%s removed)."), target, channel, count, (count != 1 ? "s" : ""));
211 else
212 command_success_nodata (si, _("No quiets found matching \2%s\2 on \2%s\2."), target, channel);
213 return;
214 }
215 else if ((cb = chanban_find (c, target, 'q')) != NULL || validhostmask (target))
216 {
217 if (cb)
218 {
219 modestack_mode_param (chansvs.nick, c, MTYPE_DEL, 'q', target);
220 chanban_delete (cb);
221 logcommand (si, CMDLOG_DO, "%s UNQUIET %s", mc->name, target);
222 if (!chanuser_find (mc->chan, si->su))
223 command_success_nodata (si, _("Unquieted \2%s\2 on \2%s\2."), target, channel);
224 }
225 else
226 command_fail (si, fault::nosuch_key, _("No such quiet \2%s\2 on \2%s\2."), target, channel);
227
228 return;
229 }
230 else
231 {
232 command_fail (si, fault::badparams, _("Invalid nickname/hostmask provided: \2%s\2"), target);
233 command_fail (si, fault::badparams, _("Syntax: UNQUIET <#channel> [nickname|hostmask]"));
234 return;
235 }
236 }