ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/register.C
Revision: 1.9
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.8: +4 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * register.C: This file contains code for the ChanServ REGISTER 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: register.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <libermyth.h>
17 #include <ermyth/module.h>
18 #include <account/mychan.h>
19 #include <account/myuser.h>
20 #include <account/chanacs.h>
21
22 static char const rcsid[] = "$Id: register.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
23
24 REGISTER_MODULE ("chanserv/register", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25
26 static void cs_cmd_register (sourceinfo_t *si, int parc, char *parv[]);
27
28 command_t const cs_register = { "REGISTER", N_("Registers a channel."), AC_NONE, 3, cs_cmd_register };
29
30 E cmdvec cs_cmdtree;
31 E helpvec cs_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 cs_cmdtree << cs_register;
37 help_addentry (cs_helptree, "REGISTER", "help/chanserv/register", NULL);
38
39 return true;
40 }
41
42 void
43 _moddeinit ()
44 {
45 cs_cmdtree >> cs_register;
46 help_delentry (cs_helptree, "REGISTER");
47 }
48
49 static void
50 cs_cmd_register (sourceinfo_t *si, int parc, char *parv[])
51 {
52 channel_t *c;
53 chanuser_t *cu;
54 mychan_t *mc;
55 char *name = parv[0];
56 char str[21];
57
58 if (!name)
59 {
60 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "REGISTER");
61 command_fail (si, fault::needmoreparams, _("To register a channel: REGISTER <#channel>"));
62 return;
63 }
64
65 if (*name != '#')
66 {
67 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "REGISTER");
68 command_fail (si, fault::badparams, _("Syntax: REGISTER <#channel>"));
69 return;
70 }
71
72 /* make sure they're logged in */
73 if (!si->smu)
74 {
75 command_fail (si, fault::noprivs, _("You are not logged in."));
76 return;
77 }
78
79 if (si->smu->flags & MU_WAITAUTH)
80 {
81 command_fail (si, fault::notverified, _("You need to verify your email address before you may register channels."));
82 return;
83 }
84
85 /* make sure it isn't already registered */
86 if ((mc = mychan_t::find (name)))
87 {
88 command_fail (si, fault::alreadyexists, _("\2%s\2 is already registered to \2%s\2."), mc->name, mc->founder_names ());
89 return;
90 }
91
92 /* make sure the channel exists */
93 if (!(c = channel_find (name)))
94 {
95 command_fail (si, fault::nosuch_target, _("The channel \2%s\2 must exist in order to register it."), name);
96 return;
97 }
98
99 /* make sure they're in it */
100 if (!(cu = chanuser_find (c, si->su)))
101 {
102 command_fail (si, fault::noprivs, _("You must be in \2%s\2 in order to register it."), name);
103 return;
104 }
105
106 /* make sure they're opped */
107 if (!(CMODE_OP & cu->modes))
108 {
109 command_fail (si, fault::noprivs, _("You must be a channel operator in \2%s\2 in order to register it."), name);
110 return;
111 }
112
113 if ((si->smu->num_channels () >= me.maxchans) && !has_priv (si, PRIV_REG_NOLIMIT))
114 {
115 command_fail (si, fault::toomany, _("You have too many channels registered."));
116 return;
117 }
118
119 logcommand (si, CMDLOG_REGISTER, "%s REGISTER", name);
120 snoop ("REGISTER: \2%s\2 to \2%s\2 as \2%s\2", name, get_oper_name (si), si->smu->name);
121
122 mc = mychan_t::create (name);
123 mc->registered = NOW;
124 mc->used = NOW;
125 mc->mlock_on |= (CMODE_NOEXT | CMODE_TOPIC);
126 if (c->limit == 0)
127 mc->mlock_off |= CMODE_LIMIT;
128 if (c->key == NULL)
129 mc->mlock_off |= CMODE_KEY;
130 mc->flags |= config_options.defcflags;
131
132 chanacs_add (mc, si->smu, CA_INITIAL & ca_all, NOW);
133
134 if (c->ts > 0)
135 {
136 snprintf (str, sizeof str, "%lu", (unsigned long) c->ts);
137 mc->add_metadata ("private:channelts", str);
138 }
139
140 command_success_nodata (si, _("\2%s\2 is now registered to \2%s\2."), mc->name, si->smu->name);
141
142 mc->callback.registered (mc, si);
143 }