ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/nickserv/freeze.C
Revision: 1.8
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.7: +5 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * freeze.C: Gives services the ability to freeze nicknames
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 Patrick Fish, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: freeze.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <util/numeric.h>
17 #include <libermyth.h>
18 #include <ermyth/module.h>
19 #include <account/myuser.h>
20
21 static char const rcsid[] = "$Id: freeze.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
22
23 REGISTER_MODULE ("nickserv/freeze", false, "The Ermyth Team <http://ermyth.xinutec.org>");
24
25 static void ns_cmd_freeze (sourceinfo_t *si, int parc, char *parv[]);
26
27 /* FREEZE ON|OFF -- don't pollute the root with THAW */
28 command_t const ns_freeze = { "FREEZE", N_("Freezes an account."), PRIV_USER_ADMIN, 3, ns_cmd_freeze };
29
30 E cmdvec ns_cmdtree;
31 E helpvec ns_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 ns_cmdtree << ns_freeze;
37 help_addentry (ns_helptree, "FREEZE", "help/nickserv/freeze", NULL);
38
39 return true;
40 }
41
42 void
43 _moddeinit ()
44 {
45 ns_cmdtree >> ns_freeze;
46 help_delentry (ns_helptree, "FREEZE");
47 }
48
49 static void
50 ns_cmd_freeze (sourceinfo_t *si, int parc, char *parv[])
51 {
52 myuser_t *mu;
53 char *target = parv[0];
54 char *action = parv[1];
55 char *reason = parv[2];
56 user_t *u;
57
58 if (!target || !action)
59 {
60 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FREEZE");
61 command_fail (si, fault::needmoreparams, _("Usage: FREEZE <nickname> <ON|OFF> [reason]"));
62 return;
63 }
64
65 mu = myuser_t::find_ext (target);
66
67 if (!mu)
68 {
69 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target);
70 return;
71 }
72
73 if (!strcasecmp (action, "ON"))
74 {
75 if (!reason)
76 {
77 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FREEZE");
78 command_fail (si, fault::needmoreparams, _("Usage: FREEZE <nickname> ON <reason>"));
79 return;
80 }
81
82 if (is_soper (mu))
83 {
84 command_fail (si, fault::badparams, _("The account \2%s\2 belongs to a services operator; it cannot be frozen."), target);
85 return;
86 }
87
88 if (mu->find_metadata ("private:freeze:freezer"))
89 {
90 command_fail (si, fault::badparams, _("\2%s\2 is already frozen."), target);
91 return;
92 }
93
94 mu->add_metadata ("private:freeze:freezer", get_oper_name (si));
95 mu->add_metadata ("private:freeze:reason", reason);
96 mu->add_metadata ("private:freeze:timestamp", itoa (NOW));
97 /* log them out */
98 while (!mu->logins.empty ())
99 {
100 u = mu->logins.back ();
101 if (!phandler->ircd_on_logout (u->nick, mu->name, NULL))
102 {
103 u->myuser = NULL;
104 mu->logins.erase (u);
105 }
106 }
107 mu->flags |= MU_NOBURSTLOGIN;
108
109 wallops ("%s froze the account \2%s\2 (%s).", get_oper_name (si), target, reason);
110 logcommand (si, CMDLOG_ADMIN, "FREEZE %s ON", target);
111 command_success_nodata (si, _("\2%s\2 is now frozen."), target);
112 }
113 else if (!strcasecmp (action, "OFF"))
114 {
115 if (!mu->find_metadata ("private:freeze:freezer"))
116 {
117 command_fail (si, fault::badparams, _("\2%s\2 is not frozen."), target);
118 return;
119 }
120
121 mu->del_metadata ("private:freeze:freezer");
122 mu->del_metadata ("private:freeze:reason");
123 mu->del_metadata ("private:freeze:timestamp");
124
125 wallops ("%s thawed the account \2%s\2.", get_oper_name (si), target);
126 logcommand (si, CMDLOG_ADMIN, "FREEZE %s OFF", target);
127 command_success_nodata (si, _("\2%s\2 has been thawed"), target);
128 }
129 else
130 {
131 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FREEZE");
132 command_fail (si, fault::needmoreparams, _("Usage: FREEZE <account> <ON|OFF> [reason]"));
133 }
134 }