| 1 |
/* |
| 2 |
* Copyright (c) 2005 Atheme Development Group |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains code for the Memoserv FSEND function |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "atheme-compat.h" |
| 9 |
|
| 10 |
static void |
| 11 |
ms_cmd_fsend(sourceinfo_t *si, int parc, char *parv[]) |
| 12 |
{ |
| 13 |
/* misc structs etc */ |
| 14 |
user_t *tu; |
| 15 |
myuser_t *tmu; |
| 16 |
mowgli_node_t *n; |
| 17 |
mymemo_t *memo; |
| 18 |
service_t *memoserv; |
| 19 |
|
| 20 |
/* Grab args */ |
| 21 |
char *target = parv[0]; |
| 22 |
char *m = parv[1]; |
| 23 |
|
| 24 |
/* Arg validation */ |
| 25 |
if (!target || !m) |
| 26 |
{ |
| 27 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FSEND"); |
| 28 |
command_fail(si, fault_needmoreparams, _("Syntax: FSEND <user> <memo>")); |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
if (!si->smu) |
| 33 |
{ |
| 34 |
command_fail(si, fault_noprivs, STR_NOT_LOGGED_IN); |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
/* rate limit it -- jilles */ |
| 39 |
if (CURRTIME - si->smu->memo_ratelimit_time > MEMO_MAX_TIME) |
| 40 |
si->smu->memo_ratelimit_num = 0; |
| 41 |
|
| 42 |
if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv(si, PRIV_FLOOD)) |
| 43 |
{ |
| 44 |
command_fail(si, fault_toomany, _("You have used this command too many times; " |
| 45 |
"please wait a while and try again.")); |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
/* Check for memo text length -- includes/common.h */ |
| 50 |
if (strlen(m) > COMPAT_MEMOLEN) |
| 51 |
{ |
| 52 |
command_fail(si, fault_badparams, _("Please make sure your memo is not greater than %u characters"), |
| 53 |
COMPAT_MEMOLEN); |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
/* Check to make sure the memo doesn't contain hostile CTCP responses. |
| 58 |
* realistically, we'll probably want to check the _entire_ message for this... --nenolod |
| 59 |
*/ |
| 60 |
if (*m == '\001') |
| 61 |
{ |
| 62 |
command_fail(si, fault_badparams, _("Your memo contains invalid characters.")); |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
memoserv = service_find("memoserv"); |
| 67 |
if (memoserv == NULL) |
| 68 |
memoserv = si->service; |
| 69 |
|
| 70 |
if (*target != '#' && *target != '!') |
| 71 |
{ |
| 72 |
/* See if target is valid */ |
| 73 |
if (!(tmu = myuser_find_ext(target))) |
| 74 |
{ |
| 75 |
command_fail(si, fault_nosuch_target, |
| 76 |
STR_IS_NOT_REGISTERED, target); |
| 77 |
|
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
si->smu->memo_ratelimit_num++; |
| 82 |
si->smu->memo_ratelimit_time = CURRTIME; |
| 83 |
|
| 84 |
/* Check to make sure target inbox not full */ |
| 85 |
if (tmu->memos.count >= me.mdlimit) |
| 86 |
{ |
| 87 |
command_fail(si, fault_toomany, _("The inbox for \2%s\2 is full"), target); |
| 88 |
logcommand(si, CMDLOG_SET, "failed SEND to \2%s\2 (target inbox full)", entity(tmu)->name); |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
logcommand(si, CMDLOG_ADMIN, "FSEND: to \2%s\2", entity(tmu)->name); |
| 93 |
|
| 94 |
/* Malloc and populate struct */ |
| 95 |
memo = smalloc(sizeof(mymemo_t)); |
| 96 |
memo->sent = CURRTIME; |
| 97 |
memo->status = 0; |
| 98 |
mowgli_strlcpy(memo->sender,entity(si->smu)->name, sizeof memo->sender); |
| 99 |
mowgli_strlcpy(memo->text, "[FORCE] ", sizeof memo->text); |
| 100 |
mowgli_strlcat(memo->text, m, sizeof memo->text); |
| 101 |
|
| 102 |
/* Create a linked list node and add to memos */ |
| 103 |
n = mowgli_node_create(); |
| 104 |
mowgli_node_add(memo, n, &tmu->memos); |
| 105 |
tmu->memoct_new++; |
| 106 |
|
| 107 |
/* Should we email this? */ |
| 108 |
if (tmu->flags & MU_EMAILMEMOS) |
| 109 |
{ |
| 110 |
compat_sendemail(si->su, tmu, EMAIL_MEMO, tmu->email, memo->text); |
| 111 |
} |
| 112 |
|
| 113 |
/* Note: do not disclose other nicks they're logged in with |
| 114 |
* -- jilles |
| 115 |
* |
| 116 |
* Actually, I don't see the point in this at all. If they want this information, |
| 117 |
* they should use WHOIS. --nenolod |
| 118 |
*/ |
| 119 |
tu = user_find_named(target); |
| 120 |
if (tu != NULL && tu->myuser == tmu) |
| 121 |
command_success_nodata(si, _("%s is currently online, and you may talk directly, " |
| 122 |
"by sending a private message."), target); |
| 123 |
|
| 124 |
/* Is the user online? If so, tell them about the new memo. */ |
| 125 |
if (si->su == NULL || !irccasecmp(si->su->nick, entity(si->smu)->name)) |
| 126 |
myuser_notice(memoserv->nick, tmu, "You have a new memo from %s (%zu).", |
| 127 |
entity(si->smu)->name, MOWGLI_LIST_LENGTH(&tmu->memos)); |
| 128 |
else |
| 129 |
myuser_notice(memoserv->nick, tmu, "You have a new memo from %s (nickname: %s) (%zu).", |
| 130 |
entity(si->smu)->name, si->su->nick, MOWGLI_LIST_LENGTH(&tmu->memos)); |
| 131 |
|
| 132 |
myuser_notice(memoserv->nick, tmu, "To read it, type \2/msg %s READ %zu\2", |
| 133 |
memoserv->disp, MOWGLI_LIST_LENGTH(&tmu->memos)); |
| 134 |
|
| 135 |
/* Tell user memo sent */ |
| 136 |
command_success_nodata(si, _("The memo has been successfully sent to \2%s\2."), target); |
| 137 |
} |
| 138 |
else if (*target == '#') |
| 139 |
{ |
| 140 |
command_fail(si, fault_nosuch_target, _("Channel memos may not be forced.")); |
| 141 |
} |
| 142 |
else |
| 143 |
{ |
| 144 |
command_fail(si, fault_nosuch_target, _("Group memos may not be forced.")); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
/* MARK is prolly the most appropriate priv (that I can think of), if you can |
| 149 |
* think of a better one, feel free to change it. --jdhore |
| 150 |
*/ |
| 151 |
static command_t ms_fsend = { |
| 152 |
.name = "FSEND", |
| 153 |
.desc = N_("Forcibly sends a memo to a user."), |
| 154 |
.access = PRIV_MARK, |
| 155 |
.maxparc = 2, |
| 156 |
.cmd = &ms_cmd_fsend, |
| 157 |
.help = { .path = "contrib/fsend" }, |
| 158 |
}; |
| 159 |
|
| 160 |
static void |
| 161 |
mod_init(module_t *const restrict m) |
| 162 |
{ |
| 163 |
service_named_bind_command("memoserv", &ms_fsend); |
| 164 |
} |
| 165 |
|
| 166 |
static void |
| 167 |
mod_deinit(const module_unload_intent_t intent) |
| 168 |
{ |
| 169 |
service_named_unbind_command("memoserv", &ms_fsend); |
| 170 |
} |
| 171 |
|
| 172 |
SIMPLE_DECLARE_MODULE_V1("contrib/ms_fsend", MODULE_UNLOAD_CAPABILITY_OK) |