Debian Codegraph @

modules/memoserv/send.c

raw
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 SEND function
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "memoserv/send", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void ms_cmd_send(sourceinfo_t *si, int parc, char *parv[]);
19 static unsigned int *maxmemos;
20
21
22 command_t ms_send = { "SEND", N_("Sends a memo to a user."),
23 AC_AUTHENTICATED, 2, ms_cmd_send, { .path = "memoserv/send" } };
24
25 void _modinit(module_t *m)
26 {
27 service_named_bind_command("memoserv", &ms_send);
28 MODULE_TRY_REQUEST_SYMBOL(m, maxmemos, "memoserv/main", "maxmemos");
29 }
30
31 void _moddeinit(module_unload_intent_t intent)
32 {
33 service_named_unbind_command("memoserv", &ms_send);
34 }
35
36 static void ms_cmd_send(sourceinfo_t *si, int parc, char *parv[])
37 {
38 /* misc structs etc */
39 user_t *tu;
40 myuser_t *tmu;
41 mowgli_node_t *n;
42 mymemo_t *memo;
43 command_t *cmd;
44 service_t *memoserv;
45
46 /* Grab args */
47 char *target = parv[0];
48 char *m = parv[1];
49
50 /* Arg validation */
51 if (!target || !m)
52 {
53 command_fail(si, fault_needmoreparams,
54 STR_INSUFFICIENT_PARAMS, "SEND");
55
56 command_fail(si, fault_needmoreparams,
57 "Syntax: SEND <user> <memo>");
58
59 return;
60 }
61
62 if (si->smu->flags & MU_WAITAUTH)
63 {
64 command_fail(si, fault_notverified, _("You need to verify your email address before you may send memos."));
65 return;
66 }
67
68 /* rate limit it -- jilles */
69 if (CURRTIME - si->smu->memo_ratelimit_time > MEMO_MAX_TIME)
70 si->smu->memo_ratelimit_num = 0;
71 if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv(si, PRIV_FLOOD))
72 {
73 command_fail(si, fault_toomany, _("You have used this command too many times; please wait a while and try again."));
74 return;
75 }
76
77 /* Check for memo text length -- includes/common.h */
78 if (strlen(m) >= MEMOLEN)
79 {
80 command_fail(si, fault_badparams,
81 "Please make sure your memo is less than %d characters", MEMOLEN);
82
83 return;
84 }
85
86 /* Check to make sure the memo doesn't contain hostile CTCP responses.
87 * realistically, we'll probably want to check the _entire_ message for this... --nenolod
88 */
89 if (*m == '\001')
90 {
91 command_fail(si, fault_badparams, _("Your memo contains invalid characters."));
92 return;
93 }
94
95 memoserv = service_find("memoserv");
96 if (memoserv == NULL)
97 memoserv = si->service;
98
99 if (*target != '#' && *target != '!')
100 {
101 /* See if target is valid */
102 if (!(tmu = myuser_find_ext(target)))
103 {
104 command_fail(si, fault_nosuch_target,
105 "\2%s\2 is not registered.", target);
106
107 return;
108 }
109
110 si->smu->memo_ratelimit_num++;
111 si->smu->memo_ratelimit_time = CURRTIME;
112
113 /* Does the user allow memos? --pfish */
114 if (tmu->flags & MU_NOMEMO)
115 {
116 command_fail(si, fault_noprivs,
117 "\2%s\2 does not wish to receive memos.", target);
118
119 return;
120 }
121
122 /* Check to make sure target inbox not full */
123 if (tmu->memos.count >= *maxmemos)
124 {
125 command_fail(si, fault_toomany, _("%s's inbox is full"), target);
126 logcommand(si, CMDLOG_SET, "failed SEND to \2%s\2 (target inbox full)", entity(tmu)->name);
127 return;
128 }
129
130
131 /* Make sure we're not on ignore */
132 MOWGLI_ITER_FOREACH(n, tmu->memo_ignores.head)
133 {
134 mynick_t *mn;
135 myuser_t *mu;
136
137 if (nicksvs.no_nick_ownership)
138 mu = myuser_find((const char *)n->data);
139 else
140 {
141 mn = mynick_find((const char *)n->data);
142 mu = mn != NULL ? mn->owner : NULL;
143 }
144 if (mu == si->smu)
145 {
146 logcommand(si, CMDLOG_SET, "failed SEND to \2%s\2 (on ignore list)", entity(tmu)->name);
147 command_success_nodata(si, _("The memo has been successfully sent to \2%s\2."), target);
148 return;
149 }
150 }
151 logcommand(si, CMDLOG_SET, "SEND: to \2%s\2", entity(tmu)->name);
152
153 /* Malloc and populate struct */
154 memo = smalloc(sizeof(mymemo_t));
155 memo->sent = CURRTIME;
156 memo->status = 0;
157 mowgli_strlcpy(memo->sender,entity(si->smu)->name,NICKLEN);
158 mowgli_strlcpy(memo->text,m,MEMOLEN);
159
160 /* Create a linked list node and add to memos */
161 n = mowgli_node_create();
162 mowgli_node_add(memo, n, &tmu->memos);
163 tmu->memoct_new++;
164
165 /* Should we email this? */
166 if (tmu->flags & MU_EMAILMEMOS)
167 {
168 sendemail(si->su, tmu, EMAIL_MEMO, tmu->email, memo->text);
169 }
170
171 /* Note: do not disclose other nicks they're logged in with
172 * -- jilles
173 *
174 * Actually, I don't see the point in this at all. If they want this information,
175 * they should use WHOIS. --nenolod
176 */
177 tu = user_find_named(target);
178 if (tu != NULL && tu->myuser == tmu)
179 command_success_nodata(si, _("%s is currently online, and you may talk directly, by sending a private message."), target);
180
181 /* Is the user online? If so, tell them about the new memo. */
182 if (si->su == NULL || !irccasecmp(si->su->nick, entity(si->smu)->name))
183 myuser_notice(memoserv->nick, tmu, "You have a new memo from %s (%zu).", entity(si->smu)->name, MOWGLI_LIST_LENGTH(&tmu->memos));
184 else
185 myuser_notice(memoserv->nick, tmu, "You have a new memo from %s (nick: %s) (%zu).", entity(si->smu)->name, si->su->nick, MOWGLI_LIST_LENGTH(&tmu->memos));
186 myuser_notice(memoserv->nick, tmu, _("To read it, type /%s%s READ %zu"),
187 ircd->uses_rcommand ? "" : "msg ", memoserv->disp, MOWGLI_LIST_LENGTH(&tmu->memos));
188
189 /* Tell user memo sent */
190 command_success_nodata(si, _("The memo has been successfully sent to \2%s\2."), target);
191 }
192 else if (*target == '#')
193 {
194 cmd = command_find(memoserv->commands, "SENDOPS");
195 if (cmd != NULL)
196 command_exec(memoserv, si, cmd, parc, parv);
197 else
198 command_fail(si, fault_nosuch_target, _("Channel memos are administratively disabled."));
199 }
200 else
201 {
202 cmd = command_find(memoserv->commands, "SENDGROUP");
203 if (cmd != NULL)
204 command_exec(memoserv, si, cmd, parc, parv);
205 else
206 command_fail(si, fault_nosuch_target, _("Group memos are administratively disabled."));
207 }
208
209 return;
210 }
211
212 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
213 * vim:ts=8
214 * vim:sw=8
215 * vim:noexpandtab
216 */