ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/ghost.C
Revision: 1.9
Committed: Sat Sep 22 14:27:27 2007 UTC (19 years, 1 month 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

# User Rev Content
1 pippijn 1.8 /**
2     * ghost.C: This file contains code for the NickServ GHOST 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 pippijn 1.4 * Copyright © 2005-2007 William Pitcock, et al.
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.9 * $Id: ghost.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $
13 pippijn 1.1 */
14    
15     #include "atheme.h"
16 pippijn 1.9 #include <libermyth.h>
17 pippijn 1.4 #include <ermyth/module.h>
18 pippijn 1.1 #include <account/mynick.h>
19     #include <account/myuser.h>
20    
21 pippijn 1.9 static char const rcsid[] = "$Id: ghost.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
22 pippijn 1.1
23 pippijn 1.9 REGISTER_MODULE ("nickserv/ghost", false, "The Ermyth Team <http://ermyth.xinutec.org>");
24 pippijn 1.1
25     static void ns_cmd_ghost (sourceinfo_t *si, int parc, char *parv[]);
26    
27 pippijn 1.4 command_t const ns_ghost = { "GHOST", N_("Reclaims use of a nickname."), AC_NONE, 2, ns_cmd_ghost };
28 pippijn 1.1
29 pippijn 1.4 E cmdvec ns_cmdtree;
30     E helpvec ns_helptree;
31 pippijn 1.1
32 pippijn 1.4 bool
33     _modinit (module *m)
34 pippijn 1.1 {
35     ns_cmdtree << ns_ghost;
36     help_addentry (ns_helptree, "GHOST", "help/nickserv/ghost", NULL);
37 pippijn 1.4
38     return true;
39 pippijn 1.1 }
40    
41     void
42     _moddeinit ()
43     {
44     ns_cmdtree >> ns_ghost;
45     help_delentry (ns_helptree, "GHOST");
46     }
47    
48     void
49     ns_cmd_ghost (sourceinfo_t *si, int parc, char *parv[])
50     {
51     myuser_t *mu;
52     char *target = parv[0];
53     char *password = parv[1];
54     user_t *target_u;
55     mynick_t *mn;
56    
57     if (!target)
58     {
59 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "GHOST");
60     command_fail (si, fault::needmoreparams, _("Syntax: GHOST <target> [password]"));
61 pippijn 1.1 return;
62     }
63    
64     if (nicksvs.no_nick_ownership)
65 pippijn 1.5 mn = NULL, mu = myuser_t::find (target);
66 pippijn 1.1 else
67     {
68 pippijn 1.7 mn = mynick_t::find (target);
69 pippijn 1.1 mu = mn != NULL ? mn->owner : NULL;
70     }
71     target_u = user_find_named (target);
72     if (!mu && (!target_u || !target_u->myuser))
73     {
74 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not a registered nickname."), target);
75 pippijn 1.1 return;
76     }
77    
78     if (!target_u)
79     {
80 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), target);
81 pippijn 1.1 return;
82     }
83     else if (target_u == si->su)
84     {
85 pippijn 1.6 command_fail (si, fault::badparams, _("You may not ghost yourself."));
86 pippijn 1.1 return;
87     }
88    
89     if ((target_u->myuser && target_u->myuser == si->smu) || /* they're identified under our account */
90     (!nicksvs.no_nick_ownership && mn && mu == si->smu) || /* we're identified under their nick's account */
91 pippijn 1.4 (!nicksvs.no_nick_ownership && password && mn && mu->verify_password (password))) /* we have their nick's password */
92 pippijn 1.1 {
93     /* If we're ghosting an unregistered nick, mu will be unset,
94     * however if it _is_ registered, we still need to set it or
95     * the wrong user will have their last seen time updated... */
96     if (target_u->myuser && target_u->myuser == si->smu)
97     mu = target_u->myuser;
98    
99     logcommand (si, CMDLOG_DO, "GHOST %s!%s@%s", target_u->nick, target_u->user, target_u->vhost);
100    
101 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));
102 pippijn 1.1 user_delete (target_u);
103    
104     command_success_nodata (si, _("\2%s\2 has been ghosted."), target);
105    
106     /* don't update the nick's last seen time */
107     mu->lastlogin = NOW;
108    
109     return;
110     }
111    
112     if (password && mu)
113     {
114     logcommand (si, CMDLOG_DO, "failed GHOST %s (bad password)", target);
115 pippijn 1.6 command_fail (si, fault::authfail, _("Invalid password for \2%s\2."), mu->name);
116 pippijn 1.1 }
117     else
118     {
119     logcommand (si, CMDLOG_DO, "failed GHOST %s (invalid login)", target);
120 pippijn 1.6 command_fail (si, fault::noprivs, _("You may not ghost \2%s\2."), target);
121 pippijn 1.1 }
122     }
123    
124     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
125     * vim:ts=8
126     * vim:sw=8
127     * vim:noexpandtab
128     */