Debian Codegraph @

modules/chanserv/recover.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the CService RECOVER functions.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "chanserv/recover", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void cs_cmd_recover(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t cs_recover = { "RECOVER", N_("Regain control of your channel."),
21 AC_NONE, 1, cs_cmd_recover, { .path = "cservice/recover" } };
22
23 void _modinit(module_t *m)
24 {
25 service_named_bind_command("chanserv", &cs_recover);
26 }
27
28 void _moddeinit(module_unload_intent_t intent)
29 {
30 service_named_unbind_command("chanserv", &cs_recover);
31 }
32
33 static void cs_cmd_recover(sourceinfo_t *si, int parc, char *parv[])
34 {
35 chanuser_t *cu, *origin_cu = NULL;
36 mychan_t *mc;
37 mowgli_node_t *n, *tn;
38 chanban_t *cb;
39 char *name = parv[0];
40 char hostbuf2[BUFSIZE];
41 char e;
42 bool added_exempt = false;
43 int i;
44 char str[3];
45
46 if (!name)
47 {
48 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "RECOVER");
49 command_fail(si, fault_needmoreparams, _("Syntax: RECOVER <#channel>"));
50 return;
51 }
52
53 if (!(mc = mychan_find(name)))
54 {
55 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), name);
56 return;
57 }
58
59 if (metadata_find(mc, "private:close:closer"))
60 {
61 command_fail(si, fault_noprivs, _("\2%s\2 is closed."), name);
62 return;
63 }
64
65 if (!chanacs_source_has_flag(mc, si, CA_RECOVER))
66 {
67 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
68 return;
69 }
70
71 if (!mc->chan)
72 {
73 if (chansvs.changets)
74 {
75 /* Otherwise, our modes are likely ignored. */
76 join(mc->name, chansvs.nick);
77 mc->flags |= MC_INHABIT;
78 }
79 if (!mc->chan)
80 {
81 command_fail(si, fault_nosuch_target, _("\2%s\2 is currently empty."), name);
82 return;
83 }
84 }
85
86 command_add_flood(si, FLOOD_HEAVY);
87 verbose(mc, _("\2%s\2 used RECOVER."), get_source_name(si));
88 logcommand(si, CMDLOG_DO, "RECOVER: \2%s\2", mc->name);
89
90 /* deop everyone */
91 MOWGLI_ITER_FOREACH(n, mc->chan->members.head)
92 {
93 cu = (chanuser_t *)n->data;
94
95 if (cu->user == si->su)
96 origin_cu = cu;
97 else if (is_internal_client(cu->user))
98 ;
99 else
100 {
101 if (ircd->uses_owner && (ircd->owner_mode & cu->modes))
102 {
103 modestack_mode_param(chansvs.nick, mc->chan, MTYPE_DEL, ircd->owner_mchar[1], CLIENT_NAME(cu->user));
104 cu->modes &= ~ircd->owner_mode;
105 }
106 if (ircd->uses_protect && (ircd->protect_mode & cu->modes))
107 {
108 modestack_mode_param(chansvs.nick, mc->chan, MTYPE_DEL, ircd->protect_mchar[1], CLIENT_NAME(cu->user));
109 cu->modes &= ~ircd->protect_mode;
110 }
111 if ((CSTATUS_OP & cu->modes))
112 {
113 modestack_mode_param(chansvs.nick, mc->chan, MTYPE_DEL, 'o', CLIENT_NAME(cu->user));
114 cu->modes &= ~CSTATUS_OP;
115 }
116 if (ircd->uses_halfops && (ircd->halfops_mode & cu->modes))
117 {
118 modestack_mode_param(chansvs.nick, mc->chan, MTYPE_DEL, ircd->halfops_mchar[1], CLIENT_NAME(cu->user));
119 cu->modes &= ~ircd->halfops_mode;
120 }
121 }
122 }
123
124 if (origin_cu == NULL)
125 {
126 /* if requester is not on channel,
127 * remove modes that keep people out */
128 if (CMODE_LIMIT & mc->chan->modes)
129 channel_mode_va(si->service->me, mc->chan, 1, "-l");
130 if (CMODE_KEY & mc->chan->modes)
131 channel_mode_va(si->service->me, mc->chan, 2, "-k", "*");
132
133 /* stuff like join throttling
134 * XXX only remove modes that could keep people out
135 * -- jilles */
136 str[0] = '-';
137 str[2] = '\0';
138 for (i = 0; ignore_mode_list[i].mode != '\0'; i++)
139 {
140 str[1] = ignore_mode_list[i].mode;
141 if (mc->chan->extmodes[i] != NULL)
142 channel_mode_va(si->service->me, mc->chan, 1, str);
143 }
144 }
145 else
146 {
147 if (!(CSTATUS_OP & origin_cu->modes))
148 modestack_mode_param(chansvs.nick, mc->chan, MTYPE_ADD, 'o', CLIENT_NAME(si->su));
149 origin_cu->modes |= CSTATUS_OP;
150 }
151
152 if (origin_cu != NULL || (si->su != NULL && chanacs_source_flags(mc, si) & (CA_OP | CA_AUTOOP)))
153 {
154
155 channel_mode_va(si->service->me, mc->chan, 1, "+im");
156 }
157 else if (CMODE_INVITE & mc->chan->modes)
158 {
159 channel_mode_va(si->service->me, mc->chan, 1, "-i");
160 }
161
162 if (si->su != NULL)
163 {
164 /* unban the user */
165 snprintf(hostbuf2, BUFSIZE, "%s!%s@%s", si->su->nick, si->su->user, si->su->vhost);
166
167 for (n = next_matching_ban(mc->chan, si->su, 'b', mc->chan->bans.head); n != NULL; n = next_matching_ban(mc->chan, si->su, 'b', tn))
168 {
169 tn = n->next;
170 cb = n->data;
171
172 modestack_mode_param(chansvs.nick, mc->chan, MTYPE_DEL, cb->type, cb->mask);
173 chanban_delete(cb);
174 }
175
176 if (origin_cu == NULL)
177 {
178 /* set an exempt on the user calling this */
179 e = ircd->except_mchar;
180 if (e != '\0')
181 {
182 if (!chanban_find(mc->chan, hostbuf2, e))
183 {
184 chanban_add(mc->chan, hostbuf2, e);
185 modestack_mode_param(chansvs.nick, mc->chan, MTYPE_ADD, e, hostbuf2);
186 added_exempt = true;
187 }
188 }
189 }
190 }
191
192 modestack_flush_channel(mc->chan);
193
194 /* invite them back. must have sent +i before this */
195 if (origin_cu == NULL && si->su != NULL)
196 invite_sts(si->service->me, si->su, mc->chan);
197
198 if (added_exempt)
199 command_success_nodata(si, _("Recover complete for \2%s\2, ban exception \2%s\2 added."), mc->chan->name, hostbuf2);
200 else
201 command_success_nodata(si, _("Recover complete for \2%s\2."), mc->chan->name);
202 }
203
204 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
205 * vim:ts=8
206 * vim:sw=8
207 * vim:noexpandtab
208 */