/*
* Copyright (c) 2005 Atheme Development Group
* Rights to this code are as documented in doc/LICENSE.
*
* This file contains code for the Memoserv FORWARD function
*
* $Id: forward.c 3335 2005-10-31 03:48:14Z nenolod $
*/
#include "atheme.h"
DECLARE_MODULE_V1
(
"memoserv/forward", FALSE, _modinit, _moddeinit,
"$Id: forward.c 3335 2005-10-31 03:48:14Z nenolod $",
"Atheme Development Group <http://www.atheme.org>"
);
static void ms_cmd_forward(char *origin);
command_t ms_forward = { "FORWARD", "Forwards a memo",
AC_NONE, ms_cmd_forward };
list_t *ms_cmdtree;
list_t *ms_helptree;
void _modinit(module_t *m)
{
ms_cmdtree = module_locate_symbol("memoserv/main", "ms_cmdtree");
command_add(&ms_forward, ms_cmdtree);
ms_helptree = module_locate_symbol("memoserv/main", "ms_helptree");
help_addentry(ms_helptree, "forward", "help/memoserv/forward", NULL);
}
void _moddeinit()
{
command_delete(&ms_forward, ms_cmdtree);
help_delentry(ms_helptree, "FORWARD");
}
static void ms_cmd_forward(char *origin)
{
/* Misc structs etc */
user_t *u = user_find(origin), *tu;
myuser_t *mu = u->myuser, *tmu;
mymemo_t *memo, *newmemo;
node_t *n, *temp;
uint8_t i = 1, memonum = 0;
/* Grab args */
char *target = strtok(NULL, " ");
char *arg = strtok(NULL, " ");
/* Arg validator */
if (!target || !arg)
{
notice(memosvs.nick, origin,
"Insufficient parameters specified for \2FORWARD\2.");
notice(memosvs.nick, origin,
"Syntax: FORWARD <account> <memo number>");
return;
}
else
memonum = atoi(arg);
/* user logged in? */
if (mu == NULL)
{
notice(memosvs.nick, origin, "You are not logged in.");
return;
}
if (mu->flags & MU_WAITAUTH)
{
notice(memosvs.nick, origin, "You need to verify your email address before you may send memos.");
return;
}
/* Check to see if any memos */
if (!mu->memos.count)
{
notice(memosvs.nick, origin, "You have no memos to forward.");
return;
}
/* Check to see if target user exists */
if (!(tmu = myuser_find(target)))
{
notice(memosvs.nick, origin, "%s is not registered.", target);
return;
}
/* Make sure target isn't sender */
if (mu == tmu)
{
notice(memosvs.nick, origin, "You cannot send yourself a memo.");
return;
}
/* Make sure arg is an int */
if (!memonum)
{
notice(memosvs.nick, origin, "Invalid message index.");
return;
}
/* check if targetuser has nomemo set */
if (tmu->flags & MU_NOMEMO)
{
notice(memosvs.nick, origin,
"\2%s\2