Debian Codegraph @

modules/chanserv/register.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 REGISTER function.
6 *
7 */
8
9 #include "atheme.h"
10 #include "chanserv.h"
11
12 DECLARE_MODULE_V1
13 (
14 "chanserv/register", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 unsigned int ratelimit_count = 0;
20 time_t ratelimit_firsttime = 0;
21
22 static void cs_cmd_register(sourceinfo_t *si, int parc, char *parv[]);
23
24 command_t cs_register = { "REGISTER", N_("Registers a channel."),
25 AC_AUTHENTICATED, 3, cs_cmd_register, { .path = "cservice/register" } };
26
27 void _modinit(module_t *m)
28 {
29 service_named_bind_command("chanserv", &cs_register);
30 }
31
32 void _moddeinit(module_unload_intent_t intent)
33 {
34 service_named_unbind_command("chanserv", &cs_register);
35 }
36
37 static void cs_cmd_register(sourceinfo_t *si, int parc, char *parv[])
38 {
39 channel_t *c;
40 chanuser_t *cu;
41 mychan_t *mc;
42 char *name = parv[0];
43 char str[21];
44 hook_channel_register_check_t hdatac;
45 hook_channel_req_t hdata;
46 unsigned int fl;
47
48 /* This command is not useful on registered channels, ignore it if
49 * it is a fantasy command so users can program bots to react on
50 * it without interference from ChanServ.
51 */
52 if (si->c != NULL)
53 return;
54
55 if (!name)
56 {
57 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "REGISTER");
58 command_fail(si, fault_needmoreparams, _("To register a channel: REGISTER <#channel>"));
59 return;
60 }
61
62 if (*name != '#')
63 {
64 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "REGISTER");
65 command_fail(si, fault_badparams, _("Syntax: REGISTER <#channel>"));
66 return;
67 }
68
69 if (si->smu->flags & MU_WAITAUTH)
70 {
71 command_fail(si, fault_notverified, _("You need to verify your email address before you may register channels."));
72 return;
73 }
74
75 /* make sure it isn't already registered */
76 if ((mc = mychan_find(name)))
77 {
78 if (!use_channel_private || !(mc->flags & MC_PRIVATE))
79 command_fail(si, fault_alreadyexists, _("\2%s\2 is already registered to \2%s\2."), mc->name, mychan_founder_names(mc));
80 else
81 command_fail(si, fault_alreadyexists, _("\2%s\2 is already registered."), mc->name);
82 return;
83 }
84
85 /* make sure the channel exists */
86 if (!(c = channel_find(name)))
87 {
88 command_fail(si, fault_nosuch_target, _("The channel \2%s\2 must exist in order to register it."), name);
89 return;
90 }
91
92 /* make sure they're in it */
93 if (!(cu = chanuser_find(c, si->su)))
94 {
95 command_fail(si, fault_noprivs, _("You must be in \2%s\2 in order to register it."), name);
96 return;
97 }
98
99 /* make sure they're opped (or protected/owner on unreal/inspircd) */
100 if (!((CSTATUS_OP | CSTATUS_PROTECT | CSTATUS_OWNER) & cu->modes))
101 {
102 command_fail(si, fault_noprivs, _("You must be a channel operator in \2%s\2 in order to register it."), name);
103 return;
104 }
105
106 if (metadata_find(si->smu, "private:restrict:setter"))
107 {
108 command_fail(si, fault_noprivs, _("You have been restricted from registering channels by network staff."));
109 return;
110 }
111
112 if ((unsigned int)(CURRTIME - ratelimit_firsttime) > config_options.ratelimit_period)
113 ratelimit_count = 0, ratelimit_firsttime = CURRTIME;
114
115 if (ratelimit_count > config_options.ratelimit_uses && !has_priv(si, PRIV_FLOOD))
116 {
117 command_fail(si, fault_toomany, _("The system is currently too busy to process your registration, please try again later."));
118 slog(LG_INFO, "CHANSERV:REGISTER:THROTTLED: \2%s\2 by \2%s\2", name, entity(si->smu)->name);
119 return;
120 }
121
122 hdatac.si = si;
123 hdatac.name = name;
124 hdatac.chan = c;
125 hdatac.approved = 0;
126 hook_call_channel_can_register(&hdatac);
127 if (hdatac.approved != 0)
128 return;
129
130 if (!myentity_can_register_channel(entity(si->smu)))
131 {
132 command_fail(si, fault_toomany, _("You have too many channels registered."));
133 return;
134 }
135
136 if (config_options.ratelimit_uses && config_options.ratelimit_period)
137 ratelimit_count++;
138
139 logcommand(si, CMDLOG_REGISTER, "REGISTER: \2%s\2", name);
140
141 mc = mychan_add(name);
142 mc->registered = CURRTIME;
143 mc->used = CURRTIME;
144 mc->mlock_on |= (CMODE_NOEXT | CMODE_TOPIC);
145 if (c->limit == 0)
146 mc->mlock_off |= CMODE_LIMIT;
147 if (c->key == NULL)
148 mc->mlock_off |= CMODE_KEY;
149 mc->flags |= config_options.defcflags;
150
151 chanacs_add(mc, entity(si->smu), custom_founder_check(), CURRTIME, entity(si->smu));
152
153 if (c->ts > 0)
154 {
155 snprintf(str, sizeof str, "%lu", (unsigned long)c->ts);
156 metadata_add(mc, "private:channelts", str);
157 }
158
159 if (chansvs.deftemplates != NULL && *chansvs.deftemplates != '\0')
160 metadata_add(mc, "private:templates",
161 chansvs.deftemplates);
162
163 command_success_nodata(si, _("\2%s\2 is now registered to \2%s\2."), mc->name, entity(si->smu)->name);
164
165 hdata.si = si;
166 hdata.mc = mc;
167 hook_call_channel_register(&hdata);
168 /* Allow the hook to override this. */
169 fl = chanacs_source_flags(mc, si);
170 cu = chanuser_find(mc->chan, si->su);
171 if (cu == NULL)
172 ;
173 else if (ircd->uses_owner && fl & CA_USEOWNER && fl & CA_AUTOOP &&
174 !(cu->modes & CSTATUS_OWNER))
175 {
176 modestack_mode_param(si->service->nick, mc->chan, MTYPE_ADD,
177 ircd->owner_mchar[1], CLIENT_NAME(si->su));
178 cu->modes |= CSTATUS_OWNER;
179 }
180 else if (ircd->uses_protect && fl & CA_USEPROTECT && fl & CA_AUTOOP &&
181 !(cu->modes & CSTATUS_PROTECT))
182 {
183 modestack_mode_param(si->service->nick, mc->chan, MTYPE_ADD,
184 ircd->protect_mchar[1], CLIENT_NAME(si->su));
185 cu->modes |= CSTATUS_PROTECT;
186 }
187 }
188
189 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
190 * vim:ts=8
191 * vim:sw=8
192 * vim:noexpandtab
193 */