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