ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/nickserv/group.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 * group.C: This file contains code for the NickServ GROUP command.
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 © 2006 Jilles Tjoelker, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: group.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/mynick.h>
19 #include <account/myuser.h>
20
21 static char const rcsid[] = "$Id: group.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
22
23 REGISTER_MODULE ("nickserv/group", false, "The Ermyth Team <http://ermyth.xinutec.org>");
24
25 static void ns_cmd_group (sourceinfo_t *si, int parc, char *parv[]);
26 static void ns_cmd_ungroup (sourceinfo_t *si, int parc, char *parv[]);
27 static void ns_cmd_fungroup (sourceinfo_t *si, int parc, char *parv[]);
28
29 command_t const ns_group = { "GROUP", N_("Adds a nickname to your account."), AC_NONE, 0, ns_cmd_group };
30 command_t const ns_ungroup = { "UNGROUP", N_("Removes a nickname from your account."), AC_NONE, 1, ns_cmd_ungroup };
31 command_t const ns_fungroup = { "FUNGROUP", N_("Forces removal of a nickname from an account."), PRIV_USER_ADMIN, 1, ns_cmd_fungroup };
32
33 E cmdvec ns_cmdtree;
34 E helpvec ns_helptree;
35
36 bool
37 _modinit (module *m)
38 {
39 ns_cmdtree << ns_group;
40 ns_cmdtree << ns_ungroup;
41 ns_cmdtree << ns_fungroup;
42
43 help_addentry (ns_helptree, "GROUP", "help/nickserv/group", NULL);
44 help_addentry (ns_helptree, "UNGROUP", "help/nickserv/ungroup", NULL);
45 help_addentry (ns_helptree, "FUNGROUP", "help/nickserv/fungroup", NULL);
46
47 return true;
48 }
49
50 void
51 _moddeinit ()
52 {
53 ns_cmdtree >> ns_group;
54 ns_cmdtree >> ns_ungroup;
55 ns_cmdtree >> ns_fungroup;
56
57 help_delentry (ns_helptree, "GROUP");
58 help_delentry (ns_helptree, "UNGROUP");
59 help_delentry (ns_helptree, "FUNGROUP");
60 }
61
62 static void
63 ns_cmd_group (sourceinfo_t *si, int parc, char *parv[])
64 {
65 mynick_t *mn;
66
67 if (si->su == NULL)
68 {
69 command_fail (si, fault::noprivs, _("\2%s\2 can only be executed via IRC."), "GROUP");
70 return;
71 }
72
73 if (nicksvs.no_nick_ownership)
74 {
75 command_fail (si, fault::noprivs, _("Nickname ownership is disabled."));
76 return;
77 }
78
79 if (si->smu == NULL)
80 {
81 command_fail (si, fault::noprivs, _("You are not logged in."));
82 return;
83 }
84
85 if (LIST_LENGTH (&si->smu->nicks) >= me.maxnicks && !has_priv (si, PRIV_REG_NOLIMIT))
86 {
87 command_fail (si, fault::noprivs, _("You have too many nicks registered already."));
88 return;
89 }
90
91 mn = mynick_t::find (si->su->nick);
92 if (mn != NULL)
93 {
94 if (mn->owner == si->smu)
95 command_fail (si, fault::nochange, _("Nick \2%s\2 is already registered to your account."), mn->nick);
96 else
97 command_fail (si, fault::alreadyexists, _("Nick \2%s\2 is already registered to \2%s\2."), mn->nick, mn->owner->name);
98 return;
99 }
100
101 if (IsDigit (si->su->nick[0]))
102 {
103 command_fail (si, fault::badparams, _("For security reasons, you can't register your UID."));
104 return;
105 }
106
107 logcommand (si, CMDLOG_REGISTER, "GROUP");
108 snoop ("GROUP: \2%s\2 to \2%s\2", si->su->nick, si->smu->name);
109 mn = mynick_t::create (si->smu, si->su->nick);
110 mn->registered = NOW;
111 mn->lastseen = NOW;
112 command_success_nodata (si, _("Nick \2%s\2 is now registered to your account."), mn->nick);
113 mn->callback.group (mn, si->smu, si);
114 }
115
116 static void
117 ns_cmd_ungroup (sourceinfo_t *si, int parc, char *parv[])
118 {
119 mynick_t *mn;
120 char const *target;
121
122 if (si->smu == NULL)
123 {
124 command_fail (si, fault::noprivs, _("You are not logged in."));
125 return;
126 }
127
128 if (parc >= 1)
129 target = parv[0];
130 else if (si->su != NULL)
131 target = si->su->nick;
132 else
133 target = "?";
134
135 mn = mynick_t::find (target);
136 if (mn == NULL)
137 {
138 command_fail (si, fault::nosuch_target, _("Nick \2%s\2 is not registered."), target);
139 return;
140 }
141 if (mn->owner != si->smu)
142 {
143 command_fail (si, fault::noprivs, _("Nick \2%s\2 is not registered to your account."), mn->nick);
144 return;
145 }
146 if (!irccasecmp (mn->nick, si->smu->name))
147 {
148 command_fail (si, fault::noprivs, _("Nick \2%s\2 is your account name; you may not remove it."), mn->nick);
149 return;
150 }
151
152 logcommand (si, CMDLOG_REGISTER, "UNGROUP %s", mn->nick);
153 snoop ("UNGROUP: \2%s\2 by \2%s\2", target, get_source_name (si));
154 mn->callback.group (mn, si->smu, si);
155 command_success_nodata (si, _("Nick \2%s\2 has been removed from your account."), mn->nick);
156 mn->refcnt_dec ();
157 }
158
159 static void
160 ns_cmd_fungroup (sourceinfo_t *si, int parc, char *parv[])
161 {
162 mynick_t *mn;
163 myuser_t *mu;
164
165 if (parc < 1)
166 {
167 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FUNGROUP");
168 command_fail (si, fault::needmoreparams, _("Syntax: FUNGROUP <nickname>"));
169 return;
170 }
171
172 mn = mynick_t::find (parv[0]);
173 if (mn == NULL)
174 {
175 command_fail (si, fault::nosuch_target, _("Nick \2%s\2 is not registered."), parv[0]);
176 return;
177 }
178 mu = mn->owner;
179 if (!irccasecmp (mn->nick, mu->name))
180 {
181 command_fail (si, fault::noprivs, _("Nick \2%s\2 is an account name; you may not remove it."), mn->nick);
182 return;
183 }
184
185 logcommand (si, CMDLOG_ADMIN | LG_REGISTER, "FUNGROUP %s", mn->nick);
186 wallops ("%s dropped the nick \2%s\2 from %s", get_oper_name (si), mn->nick, mu->name);
187 snoop ("FUNGROUP: \2%s\2 from \2%s\2 by \2%s\2", mn->nick, mu->name, get_source_name (si));
188 mn->callback.group (mn, mu, si);
189 command_success_nodata (si, _("Nick \2%s\2 has been removed from account \2%s\2."), mn->nick, mu->name);
190 mn->refcnt_dec ();
191 }