/** * send.C: This file contains code for the Memoserv SEND 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: send.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include #include static char const rcsid[] = "$Id: send.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("memoserv/send", false, "The Ermyth Team "); static void ms_cmd_send (sourceinfo_t *si, int parc, char *parv[]); command_t const ms_send = { "SEND", N_("Sends a memo to a user."), AC_NONE, 2, ms_cmd_send }; E cmdvec ms_cmdtree; E helpvec ms_helptree; bool _modinit (module *m) { ms_cmdtree << ms_send; help_addentry (ms_helptree, "SEND", "help/memoserv/send", NULL); return true; } void _moddeinit () { ms_cmdtree >> ms_send; help_delentry (ms_helptree, "SEND"); } static void ms_cmd_send (sourceinfo_t *si, int parc, char *parv[]) { /* misc structs etc */ user_t *tu; myuser_t *tmu; mymemo_t *memo; command_t const *cmd; myuser_t::mzignore_vector::iterator miit, miit_end; /* Grab args */ char *target = parv[0]; char *m = parv[1]; /* Arg validation */ if (!target || !m) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "SEND"); command_fail (si, fault::needmoreparams, "Syntax: SEND "); return; } /* user logged in? */ if (!si->smu) { 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; } /* 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, _("You have used this command too many times; please wait a while and try again.")); return; } si->smu->memo_ratelimit_num++; si->smu->memo_ratelimit_time = NOW; /* Check for memo text length -- includes/common.h */ if (strlen (m) >= MEMOLEN) { command_fail (si, fault::badparams, "Please make sure your memo is less than %d characters", MEMOLEN); return; } /* Check to make sure the memo doesn't contain hostile CTCP responses. * realistically, we'll probably want to check the _entire_ message for this... --nenolod */ if (*m == '\001') { command_fail (si, fault::badparams, _("Your memo contains invalid characters.")); return; } if (*target != '#') { /* See if target is valid */ if (!(tmu = myuser_t::find_ext (target))) { command_fail (si, fault::nosuch_target, "\2%s\2 is not registered.", target); return; } /* Does the user allow memos? --pfish */ if (tmu->flags & MU_NOMEMO) { command_fail (si, fault::noprivs, "\2%s\2 does not wish to receive memos.", target); return; } /* Check to make sure target inbox not full */ if (tmu->memos.size () >= me.mdlimit) { command_fail (si, fault::toomany, _("%s's inbox is full"), target); logcommand (si, CMDLOG_SET, "failed SEND to %s (target inbox full)", tmu->name); return; } /* 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)) { logcommand (si, CMDLOG_SET, "failed SEND to %s (on ignore list)", tmu->name); command_success_nodata (si, _("The memo has been successfully sent to \2%s\2."), target); return; } } logcommand (si, CMDLOG_SET, "SEND to %s", tmu->name); /* Malloc and populate struct */ memo = new mymemo_t; memo->sent = NOW; memo->status = 0; strlcpy (memo->sender, si->smu->name, NICKLEN); strlcpy (memo->text, m, MEMOLEN); /* Create a linked list node and add to memos */ tmu->memos.insert (memo); 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; } } /* Is the user online? If so, tell them about the new memo. */ /* Note: do not disclose other nicks they're logged in with * -- jilles * * Actually, I don't see the point in this at all. If they want this information, * they should use WHOIS. --nenolod */ 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 memo from %s.", si->smu->name); else tmu->notice (memosvs.nick, "You have a new memo from %s (nick: %s).", si->smu->name, si->su->nick); /* Tell user memo sent */ command_success_nodata (si, _("The memo has been successfully sent to \2%s\2."), target); } else { cmd = si->service->cmdtree->find ("SENDOPS"); if (cmd != NULL) cmd->exec (si->service, si, parc, parv); else command_fail (si, fault::nosuch_target, _("Channel memos are administratively disabled.")); } return; }