1 |
/** |
2 |
* status.C: This file contains code for the ChanServ STATUS 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 William Pitcock, et al. |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: status.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <ermyth/module.h> |
17 |
#include <account/mynick.h> |
18 |
#include <account/myuser.h> |
19 |
|
20 |
static char const rcsid[] = "$Id: status.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $"; |
21 |
|
22 |
REGISTER_MODULE ("nickserv/status", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
23 |
|
24 |
static void ns_cmd_acc (sourceinfo_t *si, int parc, char *parv[]); |
25 |
static void ns_cmd_status (sourceinfo_t *si, int parc, char *parv[]); |
26 |
|
27 |
command_t const ns_status = { "STATUS", N_("Displays session information."), AC_NONE, 0, ns_cmd_status }; |
28 |
command_t const ns_acc = { "ACC", N_("Displays parsable session information"), AC_NONE, 2, ns_cmd_acc }; |
29 |
|
30 |
E cmdvec ns_cmdtree; |
31 |
E helpvec ns_helptree; |
32 |
|
33 |
bool |
34 |
_modinit (module *m) |
35 |
{ |
36 |
ns_cmdtree << ns_acc; |
37 |
help_addentry (ns_helptree, "ACC", "help/nickserv/acc", NULL); |
38 |
ns_cmdtree << ns_status; |
39 |
help_addentry (ns_helptree, "STATUS", "help/nickserv/status", NULL); |
40 |
|
41 |
return true; |
42 |
} |
43 |
|
44 |
void |
45 |
_moddeinit () |
46 |
{ |
47 |
ns_cmdtree >> ns_acc; |
48 |
help_delentry (ns_helptree, "ACC"); |
49 |
ns_cmdtree >> ns_status; |
50 |
help_delentry (ns_helptree, "STATUS"); |
51 |
} |
52 |
|
53 |
static void |
54 |
ns_cmd_acc (sourceinfo_t *si, int parc, char *parv[]) |
55 |
{ |
56 |
char const *targuser = parv[0]; |
57 |
char *targaccount = parv[1]; |
58 |
user_t *u; |
59 |
myuser_t *mu; |
60 |
mynick_t *mn; |
61 |
|
62 |
if (!targuser) |
63 |
{ |
64 |
u = si->su; |
65 |
targuser = u != NULL ? u->nick : "?"; |
66 |
} |
67 |
else |
68 |
u = user_find_named (targuser); |
69 |
|
70 |
if (!u) |
71 |
{ |
72 |
command_fail (si, fault::nosuch_target, _("%s%s%s ACC 0 (offline)"), targuser, parc >= 2 ? " -> " : "", parc >= 2 ? targaccount : ""); |
73 |
return; |
74 |
} |
75 |
|
76 |
if (!targaccount) |
77 |
targaccount = u->nick; |
78 |
if (!strcmp (targaccount, "*")) |
79 |
mu = u->myuser; |
80 |
else |
81 |
mu = myuser_t::find_ext (targaccount); |
82 |
|
83 |
if (!mu) |
84 |
{ |
85 |
command_fail (si, fault::nosuch_target, _("%s%s%s ACC 0 (not registered)"), u->nick, parc >= 2 ? " -> " : "", parc >= 2 ? targaccount : ""); |
86 |
return; |
87 |
} |
88 |
|
89 |
if (u->myuser == mu) |
90 |
command_success_nodata (si, "%s%s%s ACC 3", u->nick, parc >= 2 ? " -> " : "", parc >= 2 ? mu->name : ""); |
91 |
else if ((mn = mynick_t::find (u->nick)) != NULL && mn->owner == mu && mu->access_verify (u)) |
92 |
command_success_nodata (si, "%s%s%s ACC 2", u->nick, parc >= 2 ? " -> " : "", parc >= 2 ? mu->name : ""); |
93 |
else |
94 |
command_success_nodata (si, "%s%s%s ACC 1", u->nick, parc >= 2 ? " -> " : "", parc >= 2 ? mu->name : ""); |
95 |
} |
96 |
|
97 |
static void |
98 |
ns_cmd_status (sourceinfo_t *si, int parc, char *parv[]) |
99 |
{ |
100 |
logcommand (si, CMDLOG_GET, "STATUS"); |
101 |
|
102 |
if (!si->smu) |
103 |
command_success_nodata (si, _("You are not logged in.")); |
104 |
else |
105 |
{ |
106 |
command_success_nodata (si, _("You are logged in as \2%s\2."), si->smu->name); |
107 |
|
108 |
if (is_soper (si->smu)) |
109 |
{ |
110 |
soper_t *soper = si->smu->soper; |
111 |
|
112 |
command_success_nodata (si, _("You are a services operator of class %s."), soper->operclass ? soper->operclass->name : soper->classname); |
113 |
} |
114 |
} |
115 |
|
116 |
if (si->su != NULL) |
117 |
{ |
118 |
mynick_t *mn; |
119 |
|
120 |
mn = mynick_t::find (si->su->nick); |
121 |
if (mn != NULL && mn->owner != si->smu && mn->owner->access_verify (si->su)) |
122 |
command_success_nodata (si, _("You are recognized as \2%s\2."), mn->owner->name); |
123 |
} |
124 |
|
125 |
if (si->su != NULL && is_admin (si->su)) |
126 |
command_success_nodata (si, _("You are a server administrator.")); |
127 |
|
128 |
if (si->su != NULL && is_ircop (si->su)) |
129 |
command_success_nodata (si, _("You are an IRC operator.")); |
130 |
} |
131 |
|
132 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
133 |
* vim:ts=8 |
134 |
* vim:sw=8 |
135 |
* vim:noexpandtab |
136 |
*/ |