ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/ghost.C
Revision: 1.4
Committed: Tue Aug 28 17:08:09 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +14 -20 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.4 * Copyright © 2005-2007 William Pitcock, 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 GHOST function.
6     *
7 pippijn 1.4 * $Id: ghost.C,v 1.3 2007-07-21 13:23:20 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11 pippijn 1.4 #include <ermyth/module.h>
12 pippijn 1.1 #include <account/mynick.h>
13     #include <account/myuser.h>
14    
15 pippijn 1.4 static char const rcsid[] = "$Id: ghost.C,v 1.3 2007-07-21 13:23:20 pippijn Exp $";
16 pippijn 1.1
17 pippijn 1.4 REGISTER_MODULE ("nickserv/ghost", false, "The Ermyth Team <http://ermyth.schmorp.de>");
18 pippijn 1.1
19     static void ns_cmd_ghost (sourceinfo_t *si, int parc, char *parv[]);
20    
21 pippijn 1.4 command_t const ns_ghost = { "GHOST", N_("Reclaims use of a nickname."), AC_NONE, 2, ns_cmd_ghost };
22 pippijn 1.1
23 pippijn 1.4 E cmdvec ns_cmdtree;
24     E helpvec ns_helptree;
25 pippijn 1.1
26 pippijn 1.4 bool
27     _modinit (module *m)
28 pippijn 1.1 {
29     ns_cmdtree << ns_ghost;
30     help_addentry (ns_helptree, "GHOST", "help/nickserv/ghost", NULL);
31 pippijn 1.4
32     return true;
33 pippijn 1.1 }
34    
35     void
36     _moddeinit ()
37     {
38     ns_cmdtree >> ns_ghost;
39     help_delentry (ns_helptree, "GHOST");
40     }
41    
42     void
43     ns_cmd_ghost (sourceinfo_t *si, int parc, char *parv[])
44     {
45     myuser_t *mu;
46     char *target = parv[0];
47     char *password = parv[1];
48     user_t *target_u;
49     mynick_t *mn;
50    
51     if (!target)
52     {
53     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "GHOST");
54     command_fail (si, fault_needmoreparams, _("Syntax: GHOST <target> [password]"));
55     return;
56     }
57    
58     if (nicksvs.no_nick_ownership)
59     mn = NULL, mu = myuser_find (target);
60     else
61     {
62     mn = mynick_find (target);
63     mu = mn != NULL ? mn->owner : NULL;
64     }
65     target_u = user_find_named (target);
66     if (!mu && (!target_u || !target_u->myuser))
67     {
68     command_fail (si, fault_nosuch_target, _("\2%s\2 is not a registered nickname."), target);
69     return;
70     }
71    
72     if (!target_u)
73     {
74     command_fail (si, fault_nosuch_target, _("\2%s\2 is not online."), target);
75     return;
76     }
77     else if (target_u == si->su)
78     {
79     command_fail (si, fault_badparams, _("You may not ghost yourself."));
80     return;
81     }
82    
83     if ((target_u->myuser && target_u->myuser == si->smu) || /* they're identified under our account */
84     (!nicksvs.no_nick_ownership && mn && mu == si->smu) || /* we're identified under their nick's account */
85 pippijn 1.4 (!nicksvs.no_nick_ownership && password && mn && mu->verify_password (password))) /* we have their nick's password */
86 pippijn 1.1 {
87     /* If we're ghosting an unregistered nick, mu will be unset,
88     * however if it _is_ registered, we still need to set it or
89     * the wrong user will have their last seen time updated... */
90     if (target_u->myuser && target_u->myuser == si->smu)
91     mu = target_u->myuser;
92    
93     logcommand (si, CMDLOG_DO, "GHOST %s!%s@%s", target_u->nick, target_u->user, target_u->vhost);
94    
95 pippijn 1.4 phandler->skill (nicksvs.nick, target, "GHOST command used by %s", si->su != NULL && !strcmp (si->su->user, target_u->user) && !strcmp (si->su->vhost, target_u->vhost) ? si->su->nick : get_source_mask (si));
96 pippijn 1.1 user_delete (target_u);
97    
98     command_success_nodata (si, _("\2%s\2 has been ghosted."), target);
99    
100     /* don't update the nick's last seen time */
101     mu->lastlogin = NOW;
102    
103     return;
104     }
105    
106     if (password && mu)
107     {
108     logcommand (si, CMDLOG_DO, "failed GHOST %s (bad password)", target);
109     command_fail (si, fault_authfail, _("Invalid password for \2%s\2."), mu->name);
110     }
111     else
112     {
113     logcommand (si, CMDLOG_DO, "failed GHOST %s (invalid login)", target);
114     command_fail (si, fault_noprivs, _("You may not ghost \2%s\2."), target);
115     }
116     }
117    
118     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
119     * vim:ts=8
120     * vim:sw=8
121     * vim:noexpandtab
122     */