ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/recover.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 * recover.C: This file contains code for the ChanServ RECOVER 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: recover.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: recover.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
21
22 REGISTER_MODULE ("chanserv/recover", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23
24 static void cs_cmd_recover (sourceinfo_t *si, int parc, char *parv[]);
25
26 command_t const cs_recover = { "RECOVER", N_("Regain control of your channel."), AC_NONE, 1, cs_cmd_recover };
27
28 E cmdvec cs_cmdtree;
29 E helpvec cs_helptree;
30
31 bool
32 _modinit (module *m)
33 {
34 cs_cmdtree << cs_recover;
35 help_addentry (cs_helptree, "RECOVER", "help/chanserv/recover", NULL);
36
37 return true;
38 }
39
40 void
41 _moddeinit ()
42 {
43 cs_cmdtree >> cs_recover;
44 help_delentry (cs_helptree, "RECOVER");
45 }
46
47 static void
48 cs_cmd_recover (sourceinfo_t *si, int parc, char *parv[])
49 {
50 chanuser_t *cu, *origin_cu = NULL;
51 mychan_t *mc;
52 node_t *n, *tn;
53 chanban_t *cb;
54 char *name = parv[0];
55 char hostbuf2[BUFSIZE];
56 char e;
57 bool added_exempt = false;
58 int i;
59 char str[3];
60
61 if (!name)
62 {
63 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "RECOVER");
64 command_fail (si, fault::needmoreparams, _("Syntax: RECOVER <#channel>"));
65 return;
66 }
67
68 if (!(mc = mychan_t::find (name)))
69 {
70 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name);
71 return;
72 }
73
74 if (mc->find_metadata ("private:close:closer"))
75 {
76 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), name);
77 return;
78 }
79
80 if (!mc->chan)
81 {
82 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), name);
83 return;
84 }
85
86 if (!chanacs_source_has_flag (mc, si, CA_RECOVER))
87 {
88 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
89 return;
90 }
91
92 verbose (mc, "\2%s\2 used RECOVER.", get_source_name (si));
93 logcommand (si, CMDLOG_SET, "%s RECOVER", mc->name);
94
95 /* deop everyone */
96 LIST_FOREACH (n, mc->chan->members.head)
97 {
98 cu = (chanuser_t *) n->data;
99
100 if (cu->user == si->su)
101 origin_cu = cu;
102 else if (is_internal_client (cu->user))
103 ;
104 else
105 {
106 if (ircd->uses_owner && (ircd->owner_mode & cu->modes))
107 {
108 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, ircd->owner_mchar[1], CLIENT_NAME (cu->user));
109 cu->modes &= ~ircd->owner_mode;
110 }
111 if (ircd->uses_protect && (ircd->protect_mode & cu->modes))
112 {
113 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, ircd->protect_mchar[1], CLIENT_NAME (cu->user));
114 cu->modes &= ~ircd->protect_mode;
115 }
116 if ((CMODE_OP & cu->modes))
117 {
118 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, 'o', CLIENT_NAME (cu->user));
119 cu->modes &= ~CMODE_OP;
120 }
121 if (ircd->uses_halfops && (ircd->halfops_mode & cu->modes))
122 {
123 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, ircd->halfops_mchar[1], CLIENT_NAME (cu->user));
124 cu->modes &= ~ircd->halfops_mode;
125 }
126 }
127 }
128
129 if (origin_cu == NULL)
130 {
131 /* if requester is not on channel,
132 * remove modes that keep people out */
133 if (CMODE_LIMIT & mc->chan->modes)
134 channel_mode_va (si->service->me, mc->chan, 1, "-l");
135 if (CMODE_KEY & mc->chan->modes)
136 channel_mode_va (si->service->me, mc->chan, 2, "-k", "*");
137
138 /* stuff like join throttling
139 * XXX only remove modes that could keep people out
140 * -- jilles */
141 str[0] = '-';
142 str[2] = '\0';
143 for (i = 0; ignore_mode_list[i].mode != '\0'; i++)
144 {
145 str[1] = ignore_mode_list[i].mode;
146 if (mc->chan->extmodes[i] != NULL)
147 channel_mode_va (si->service->me, mc->chan, 1, str);
148 }
149 }
150 else
151 {
152 if (!(CMODE_OP & origin_cu->modes))
153 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, 'o', CLIENT_NAME (si->su));
154 origin_cu->modes |= CMODE_OP;
155 }
156
157 if (origin_cu != NULL || (chanacs_source_flags (mc, si) & (CA_OP | CA_AUTOOP)))
158 {
159
160 channel_mode_va (si->service->me, mc->chan, 1, "+im");
161 }
162 else if (CMODE_INVITE & mc->chan->modes)
163 {
164 channel_mode_va (si->service->me, mc->chan, 1, "-i");
165 }
166
167 /* unban the user */
168 snprintf (hostbuf2, BUFSIZE, "%s!%s@%s", si->su->nick, si->su->user, si->su->vhost);
169
170 for (n = phandler->next_matching_ban (mc->chan, si->su, 'b', mc->chan->bans.head); n != NULL; n = phandler->next_matching_ban (mc->chan, si->su, 'b', tn))
171 {
172 tn = n->next;
173 cb = static_cast<chanban_t *> (n->data);
174
175 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, cb->type, cb->mask);
176 chanban_delete (cb);
177 }
178
179 if (origin_cu == NULL)
180 {
181 /* set an exempt on the user calling this */
182 e = ircd->except_mchar;
183 if (e != '\0')
184 {
185 if (!chanban_find (mc->chan, hostbuf2, e))
186 {
187 chanban_add (mc->chan, hostbuf2, e);
188 modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, e, hostbuf2);
189 added_exempt = true;
190 }
191 }
192 }
193
194 modestack_flush_channel (mc->chan);
195
196 /* invite them back. must have sent +i before this */
197 if (origin_cu == NULL)
198 phandler->invite_sts (si->service->me, si->su, mc->chan);
199
200 if (added_exempt)
201 command_success_nodata (si, _("Recover complete for \2%s\2, ban exception \2%s\2 added."), mc->chan->name, hostbuf2);
202 else
203 command_success_nodata (si, _("Recover complete for \2%s\2."), mc->chan->name);
204 }
205
206 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
207 * vim:ts=8
208 * vim:sw=8
209 * vim:noexpandtab
210 */