/** * forward.C: This file contains code for the Memoserv FORWARD function * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005 Atheme Development Group * Rights to this code are as documented in doc/pod/license.pod. * * $Id: forward.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include #include static char const rcsid[] = "$Id: forward.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("memoserv/forward", false, "The Ermyth Team "); static void ms_cmd_forward (sourceinfo_t *si, int parc, char *parv[]); command_t const ms_forward = { "FORWARD", N_(N_("Forwards a memo.")), AC_NONE, 2, ms_cmd_forward }; E cmdvec ms_cmdtree; E helpvec ms_helptree; bool _modinit (module *m) { ms_cmdtree << ms_forward; help_addentry (ms_helptree, "forward", "help/memoserv/forward", NULL); return true; } void _moddeinit () { ms_cmdtree >> ms_forward; help_delentry (ms_helptree, "FORWARD"); } static void ms_cmd_forward (sourceinfo_t *si, int parc, char *parv[]) { /* Misc structs etc */ user_t *tu; myuser_t *tmu; mymemo_t *memo, *newmemo; unsigned memonum = 0; myuser_t::mzignore_vector::iterator miit, miit_end; /* Grab args */ char *target = parv[0]; char *arg = parv[1]; /* Arg validator */ if (!target || !arg) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FORWARD"); command_fail (si, fault::needmoreparams, "Syntax: FORWARD "); return; } else memonum = atoi (arg); /* user logged in? */ if (si->smu == NULL) { command_fail (si, fault::noprivs, _("You are not logged in.")); return; } if (si->smu->flags & MU_WAITAUTH) { command_fail (si, fault::notverified, _("You need to verify your email address before you may send memos.")); return; } /* Check to see if any memos */ if (si->smu->memos.empty ()) { command_fail (si, fault::nosuch_key, _("You have no memos to forward.")); return; } /* Check to see if target user exists */ if (!(tmu = myuser_t::find_ext (target))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target); return; } /* Make sure target isn't sender */ if (si->smu == tmu) { command_fail (si, fault::noprivs, _("You cannot send yourself a memo.")); return; } /* Make sure arg is an int */ if (!memonum) { command_fail (si, fault::badparams, _("Invalid message index.")); return; } /* check if targetuser has nomemo set */ if (tmu->flags & MU_NOMEMO) { command_fail (si, fault::noprivs, "\2%s\2 does not wish to receive memos.", target); return; } /* Check to see if memo n exists */ if (memonum > si->smu->memos.size ()) { command_fail (si, fault::nosuch_key, _("Invalid memo number.")); return; } /* Check to make sure target inbox not full */ if (tmu->memos.size () >= me.mdlimit) { command_fail (si, fault::toomany, _("Target inbox is full.")); logcommand (si, CMDLOG_SET, "failed FORWARD to %s (target inbox full)", tmu->name); return; } /* rate limit it -- jilles */ if (NOW - si->smu->memo_ratelimit_time > MEMO_MAX_TIME) si->smu->memo_ratelimit_num = 0; if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv (si, PRIV_FLOOD)) { command_fail (si, fault::toomany, _("Too many memos; please wait a while and try again")); return; } si->smu->memo_ratelimit_num++; si->smu->memo_ratelimit_time = NOW; /* Make sure we're not on ignore */ for (miit = tmu->memo_ignores.begin (), miit_end = tmu->memo_ignores.end (); miit != miit_end; ++miit) { if (!strcasecmp (*miit, si->smu->name)) { /* Lie... change this if you want it to fail silent */ logcommand (si, CMDLOG_SET, "failed FORWARD to %s (on ignore list)", tmu->name); command_success_nodata (si, _("The memo has been successfully forwarded to \2%s\2."), target); return; } } logcommand (si, CMDLOG_SET, "FORWARD to %s", tmu->name); /* Go to forwarding memos */ memo = si->smu->memos[memonum - 1]; newmemo = new mymemo_t; /* Create memo */ newmemo->sent = NOW; newmemo->status = 0; strlcpy (newmemo->sender, si->smu->name, NICKLEN); strlcpy (newmemo->text, memo->text, MEMOLEN); /* Create node, add to their linked list of memos */ tmu->memos.insert (newmemo); tmu->memoct_new++; /* Should we email this? */ if (tmu->flags & MU_EMAILMEMOS) { if (sendemail (si->su, EMAIL_MEMO, tmu, memo->text)) { command_success_nodata (si, _("Your memo has been emailed to \2%s\2."), target); return; } } /* Note: do not disclose other nicks they're logged in with * -- jilles */ tu = user_find_named (target); if (tu != NULL && tu->myuser == tmu) command_success_nodata (si, _("%s is currently online, and you may talk directly, by sending a private message."), target); if (si->su == NULL || !irccasecmp (si->su->nick, si->smu->name)) tmu->notice (memosvs.nick, "You have a new forwarded memo from %s.", si->smu->name); else tmu->notice (memosvs.nick, "You have a new forwarded memo from %s (nick: %s).", si->smu->name, si->su->nick); command_success_nodata (si, _("The memo has been successfully forwarded to \2%s\2."), target); return; }