ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/group.C
Revision: 1.5
Committed: Tue Aug 28 17:08:09 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +18 -42 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

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