ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/nickserv/ghost.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 * 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 * Copyright © 2005-2007 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: ghost.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: ghost.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
22
23 REGISTER_MODULE ("nickserv/ghost", false, "The Ermyth Team <http://ermyth.xinutec.org>");
24
25 static void ns_cmd_ghost (sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t const ns_ghost = { "GHOST", N_("Reclaims use of a nickname."), AC_NONE, 2, ns_cmd_ghost };
28
29 E cmdvec ns_cmdtree;
30 E helpvec ns_helptree;
31
32 bool
33 _modinit (module *m)
34 {
35 ns_cmdtree << ns_ghost;
36 help_addentry (ns_helptree, "GHOST", "help/nickserv/ghost", NULL);
37
38 return true;
39 }
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 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "GHOST");
60 command_fail (si, fault::needmoreparams, _("Syntax: GHOST <target> [password]"));
61 return;
62 }
63
64 if (nicksvs.no_nick_ownership)
65 mn = NULL, mu = myuser_t::find (target);
66 else
67 {
68 mn = mynick_t::find (target);
69 mu = mn != NULL ? mn->owner : NULL;
70 }
71 target_u = user_find_named (target);
72 if (!mu && (!target_u || !target_u->myuser))
73 {
74 command_fail (si, fault::nosuch_target, _("\2%s\2 is not a registered nickname."), target);
75 return;
76 }
77
78 if (!target_u)
79 {
80 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), target);
81 return;
82 }
83 else if (target_u == si->su)
84 {
85 command_fail (si, fault::badparams, _("You may not ghost yourself."));
86 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 (!nicksvs.no_nick_ownership && password && mn && mu->verify_password (password))) /* we have their nick's password */
92 {
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 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 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 command_fail (si, fault::authfail, _("Invalid password for \2%s\2."), mu->name);
116 }
117 else
118 {
119 logcommand (si, CMDLOG_DO, "failed GHOST %s (invalid login)", target);
120 command_fail (si, fault::noprivs, _("You may not ghost \2%s\2."), target);
121 }
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 */