ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/list.C
Revision: 1.3
Committed: Sat Jul 21 13:23:20 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -2 lines
Log Message:
- added rcsid to some files
- more documentation tweaks
- made most protocol commands local to phandler.C
- added ircd metadata (inspircd only for now)
- added inspircd swhois support

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005 Atheme Development Group
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 Memoserv LIST function
6     *
7 pippijn 1.3 * $Id: list.C,v 1.2 2007-07-21 01:29:09 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11     #include <account/myuser.h>
12     #include <account/mymemo.h>
13    
14 pippijn 1.3 static char const rcsid[] = "$Id$";
15 pippijn 1.1
16     struct ms_list_listeners : callback::has_listeners
17     {
18     };
19    
20     ms_list_listeners listeners;
21    
22     DECLARE_MODULE_V1 ("memoserv/list", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
23    
24     static void ms_cmd_list (sourceinfo_t *si, int parc, char *parv[]);
25    
26     command_t ms_list = { "LIST", N_(N_("Lists all of your memos.")),
27     AC_NONE, 0, ms_cmd_list
28     };
29    
30     cmdvec *ms_cmdtree;
31     helpvec *ms_helptree;
32    
33     void
34     _modinit (module_t *m)
35     {
36     MODULE_USE_SYMBOL_T (ms_cmdtree, cmdvec, "memoserv/main", "ms_cmdtree");
37     MODULE_USE_SYMBOL_T (ms_helptree, helpvec, "memoserv/main", "ms_helptree");
38    
39     ms_cmdtree << ms_list;
40     help_addentry (ms_helptree, "LIST", "help/memoserv/list", NULL);
41     }
42    
43     void
44     _moddeinit ()
45     {
46     ms_cmdtree >> ms_list;
47     help_delentry (ms_helptree, "LIST");
48     }
49    
50     static void
51     ms_cmd_list (sourceinfo_t *si, int parc, char *parv[])
52     {
53     /* Misc structs etc */
54     mymemo_t *memo;
55     myuser_t::memo_vector::iterator mzit, mzit_end;
56     unsigned int i = 0;
57     char strfbuf[32];
58     struct tm tm;
59     char line[512];
60     char chan[CHANNELLEN];
61     char *p;
62    
63     /* user logged in? */
64     if (si->smu == NULL)
65     {
66     command_fail (si, fault_noprivs, _("You are not logged in."));
67     return;
68     }
69    
70     command_success_nodata (si, ngettext (N_("You have %d memo (%d new)."), N_("You have %d memos (%d new)."), si->smu->memos.size ()), si->smu->memos.size (), si->smu->memoct_new);
71    
72     /* Check to see if any memos */
73     if (si->smu->memos.empty ())
74     return;
75    
76     /* Go to listing memos */
77     command_success_nodata (si, " ");
78    
79     for (mzit = si->smu->memos.begin (), mzit_end = si->smu->memos.end (); mzit != mzit_end; ++mzit)
80     {
81     memo = *mzit;
82     i++;
83     tm = *localtime (&memo->sent);
84    
85     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
86    
87     snprintf (line, sizeof line, _("- %d From: %s Sent: %s"), i, memo->sender, strfbuf);
88     if (memo->status & MEMO_CHANNEL && *memo->text == '#')
89     {
90     strlcat (line, " ", sizeof line);
91     strlcat (line, _("To:"), sizeof line);
92     strlcat (line, " ", sizeof line);
93     strlcpy (chan, memo->text, sizeof chan);
94     p = strchr (chan, ' ');
95     if (p != NULL)
96     *p = '\0';
97     strlcat (line, chan, sizeof line);
98     }
99     if (!(memo->status & MEMO_READ))
100     {
101     strlcat (line, " ", sizeof line);
102     strlcat (line, _("[unread]"), sizeof line);
103     }
104     command_success_nodata (si, "%s", line);
105     }
106    
107     return;
108     }