ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/info.C
Revision: 1.8
Committed: Sun Sep 9 20:05:52 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.7: +3 -3 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

File Contents

# User Rev Content
1 pippijn 1.1 /*
2 pippijn 1.4 * Copyright © 2005-2006 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 INFO functions.
6     *
7 pippijn 1.8 * $Id: info.C,v 1.7 2007-09-05 11:23:13 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.8 static char const rcsid[] = "$Id: info.C,v 1.7 2007-09-05 11:23:13 pippijn Exp $";
16 pippijn 1.1
17 pippijn 1.4 REGISTER_MODULE ("nickserv/info", false, "The Ermyth Team <http://ermyth.schmorp.de>");
18 pippijn 1.1
19     static void ns_cmd_info (sourceinfo_t *si, int parc, char *parv[]);
20    
21 pippijn 1.4 command_t const ns_info = { "INFO", N_("Displays information on registrations."), AC_NONE, 2, ns_cmd_info };
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_info;
30     help_addentry (ns_helptree, "INFO", "help/nickserv/info", NULL);
31 pippijn 1.4
32     return true;
33 pippijn 1.1 }
34    
35     void
36     _moddeinit ()
37     {
38     ns_cmdtree >> ns_info;
39     help_delentry (ns_helptree, "INFO");
40     }
41    
42     static void
43     ns_cmd_info (sourceinfo_t *si, int parc, char *parv[])
44     {
45     myuser_t *mu;
46     mynick_t *mn = NULL;
47     user_t *u;
48     char *name = parv[0];
49 pippijn 1.4 char buf[BUFSIZE], strfbuf[32], lastlogin[32], *p;
50 pippijn 1.1 struct tm tm, tm2;
51 pippijn 1.7 metadata *md;
52 pippijn 1.1 node_t *n;
53    
54     if (!name)
55     {
56 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "INFO");
57     command_fail (si, fault::needmoreparams, _("Syntax: INFO <nickname>"));
58 pippijn 1.1 return;
59     }
60    
61 pippijn 1.5 if (!(mu = myuser_t::find_ext (name)))
62 pippijn 1.1 {
63 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name);
64 pippijn 1.1 return;
65     }
66    
67     tm = *localtime (&mu->registered);
68     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
69     tm2 = *localtime (&mu->lastlogin);
70     strftime (lastlogin, sizeof (lastlogin) - 1, "%b %d %H:%M:%S %Y", &tm2);
71    
72     command_success_nodata (si, _("Information on \2%s\2:"), mu->name);
73    
74     command_success_nodata (si, _("Registered: %s (%s ago)"), strfbuf, time_ago (mu->registered));
75 pippijn 1.4
76     if ((md = mu->find_metadata ("private:host:vhost")))
77     {
78     strlcpy (buf, md->value, sizeof buf);
79     if ((md = mu->find_metadata ("private:usercloak")))
80     {
81     p = strchr (buf, '@');
82     if (p == NULL)
83     p = buf;
84     else
85     p++;
86     strlcpy (p, md->value, sizeof buf - (p - buf));
87     }
88     command_success_nodata (si, _("Last address: %s"), buf);
89     }
90    
91     if (has_priv (si, PRIV_USER_AUSPEX))
92     {
93     if ((md = mu->find_metadata ("private:host:actual")))
94     command_success_nodata (si, _("Last real address: %s"), md->value);
95     }
96    
97 pippijn 1.1 if (mu->logins.empty ())
98     command_success_nodata (si, _("Last seen: %s (%s ago)"), lastlogin, time_ago (mu->lastlogin));
99     else if (mu == si->smu || has_priv (si, PRIV_USER_AUSPEX))
100     {
101     myuser_t::login_vector::iterator it, it_end;
102     buf[0] = '\0';
103     for (it = mu->logins.begin (), it_end = mu->logins.end (); it != it_end; ++it)
104     {
105     if (strlen (buf) > 80)
106     {
107     command_success_nodata (si, _("Logins from: %s"), buf);
108     buf[0] = '\0';
109     }
110     if (buf[0])
111     strcat (buf, " ");
112     strcat (buf, (*it)->nick);
113     }
114     if (buf[0])
115     command_success_nodata (si, _("Logins from: %s"), buf);
116     }
117     else
118     command_success_nodata (si, _("Logins from: <hidden>"));
119    
120     if (!nicksvs.no_nick_ownership)
121     {
122     /* describe queried nick */
123 pippijn 1.8 mn = mynick_t::find (*name == '=' ? name + 1 : name);
124 pippijn 1.1 if (mn != NULL && mn->owner == mu)
125     {
126     tm = *localtime (&mn->registered);
127     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
128     command_success_nodata (si, _("Nick %s registered: %s (%s ago)"), mn->nick, strfbuf, time_ago (mn->registered));
129     u = user_find_named (mn->nick);
130     if (u != NULL && u->myuser == mu)
131     command_success_nodata (si, _("Nick %s is currently online"), mn->nick);
132     else
133     {
134     tm = *localtime (&mn->lastseen);
135     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
136     command_success_nodata (si, _("Nick %s last seen: %s (%s ago)"), mn->nick, strfbuf, time_ago (mn->lastseen));
137     }
138     }
139     /* list registered nicks if privileged */
140     if (mu == si->smu || has_priv (si, PRIV_USER_AUSPEX))
141     {
142     buf[0] = '\0';
143     LIST_FOREACH (n, mu->nicks.head)
144     {
145     if (strlen (buf) > 80)
146     {
147     command_success_nodata (si, _("Registered nicks: %s"), buf);
148     buf[0] = '\0';
149     }
150     if (buf[0])
151     strcat (buf, " ");
152     strcat (buf, ((mynick_t *) (n->data))->nick);
153     }
154     if (buf[0])
155     command_success_nodata (si, _("Registered nicks: %s"), buf);
156     }
157     }
158    
159     if (!(mu->flags & MU_HIDEMAIL) || (si->smu == mu || has_priv (si, PRIV_USER_AUSPEX)))
160     command_success_nodata (si, _("Email: %s%s"), mu->email, (mu->flags & MU_HIDEMAIL) ? " (hidden)" : "");
161    
162     *buf = '\0';
163    
164 pippijn 1.7 if (mu->flags & MU_HIDEMAIL)
165 pippijn 1.1 strcat (buf, "HideMail");
166    
167 pippijn 1.7 if (mu->flags & MU_HOLD)
168 pippijn 1.1 {
169     if (*buf)
170     strcat (buf, ", ");
171    
172     strcat (buf, "Hold");
173     }
174 pippijn 1.7 if (mu->flags & MU_NEVEROP)
175 pippijn 1.1 {
176     if (*buf)
177     strcat (buf, ", ");
178    
179     strcat (buf, "NeverOp");
180     }
181 pippijn 1.7 if (mu->flags & MU_NOOP)
182 pippijn 1.1 {
183     if (*buf)
184     strcat (buf, ", ");
185    
186     strcat (buf, "NoOp");
187     }
188 pippijn 1.7 if (mu->flags & MU_NOMEMO)
189 pippijn 1.1 {
190     if (*buf)
191     strcat (buf, ", ");
192    
193     strcat (buf, "NoMemo");
194     }
195 pippijn 1.7 if (mu->flags & MU_EMAILMEMOS)
196 pippijn 1.1 {
197     if (*buf)
198     strcat (buf, ", ");
199    
200     strcat (buf, "EMailMemos");
201     }
202    
203     if (*buf)
204     command_success_nodata (si, _("Flags: %s"), buf);
205    
206     if (mu->soper && (mu == si->smu || has_priv (si, PRIV_VIEWPRIVS)))
207     {
208     command_success_nodata (si, _("Oper class: %s"), mu->soper->operclass ? mu->soper->operclass->name : mu->soper->classname);
209     }
210    
211     if (has_priv (si, PRIV_USER_AUSPEX) && (md = mu->find_metadata ("private:freeze:freezer")))
212     {
213 pippijn 1.4 char const * const setter = md->value;
214 pippijn 1.1 time_t ts;
215    
216     md = mu->find_metadata ("private:freeze:reason");
217 pippijn 1.4 char const * const reason = md != NULL ? md->value : "unknown";
218 pippijn 1.1
219     md = mu->find_metadata ("private:freeze:timestamp");
220     ts = md != NULL ? atoi (md->value) : 0;
221    
222     tm = *localtime (&ts);
223     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
224    
225     command_success_nodata (si, _("%s was \2FROZEN\2 by %s on %s (%s)"), mu->name, setter, strfbuf, reason);
226     }
227    
228     if (has_priv (si, PRIV_USER_AUSPEX) && (md = mu->find_metadata ("private:mark:setter")))
229     {
230 pippijn 1.4 char const * const setter = md->value;
231 pippijn 1.1 time_t ts;
232    
233     md = mu->find_metadata ("private:mark:reason");
234 pippijn 1.4 char const * const reason = md != NULL ? md->value : "unknown";
235 pippijn 1.1
236     md = mu->find_metadata ("private:mark:timestamp");
237     ts = md != NULL ? atoi (md->value) : 0;
238    
239     tm = *localtime (&ts);
240     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
241    
242     command_success_nodata (si, _("%s was \2MARKED\2 by %s on %s (%s)"), mu->name, setter, strfbuf, reason);
243     }
244    
245 pippijn 1.7 if (mu->flags & MU_WAITAUTH)
246 pippijn 1.1 command_success_nodata (si, _("%s has not completed registration verification"), mu->name);
247    
248 pippijn 1.4 mn->callback.info (mn, mu, si);
249 pippijn 1.1
250     command_success_nodata (si, _("*** \2End of Info\2 ***"));
251    
252     logcommand (si, CMDLOG_GET, "INFO %s", mu->name);
253     }