ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/send.C
Revision: 1.2
Committed: Sat Jul 21 01:29:09 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -3 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005 Atheme Development Group
3 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * This file contains code for the Memoserv SEND function
6     *
7 pippijn 1.2 * $Id: send.C,v 1.1 2007-07-19 08:24:54 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11     #include <account/myuser.h>
12     #include <account/mymemo.h>
13    
14     static char const rcsid[] = "$Id";
15    
16     struct ms_send_listeners : callback::has_listeners
17     {
18     };
19    
20     ms_send_listeners listeners;
21    
22     DECLARE_MODULE_V1 ("memoserv/send", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
23    
24     static void ms_cmd_send (sourceinfo_t *si, int parc, char *parv[]);
25    
26     command_t ms_send = { "SEND", N_("Sends a memo to a user."),
27     AC_NONE, 2, ms_cmd_send
28     };
29    
30     cmdvec *ms_cmdtree;
31     helpvec *ms_helptree;
32    
33     void
34     _modinit (module_t *m)
35     {
36     MODULE_USE_SYMBOL_T (ms_cmdtree, cmdvec, "memoserv/main", "ms_cmdtree");
37     MODULE_USE_SYMBOL_T (ms_helptree, helpvec, "memoserv/main", "ms_helptree");
38    
39     ms_cmdtree << ms_send;
40     help_addentry (ms_helptree, "SEND", "help/memoserv/send", NULL);
41     }
42    
43     void
44     _moddeinit ()
45     {
46     ms_cmdtree >> ms_send;
47     help_delentry (ms_helptree, "SEND");
48     }
49    
50     static void
51     ms_cmd_send (sourceinfo_t *si, int parc, char *parv[])
52     {
53     /* misc structs etc */
54     user_t *tu;
55     myuser_t *tmu;
56     mymemo_t *memo;
57     command_t const *cmd;
58     myuser_t::mzignore_vector::iterator miit, miit_end;
59    
60     /* Grab args */
61     char *target = parv[0];
62     char *m = parv[1];
63    
64     /* Arg validation */
65     if (!target || !m)
66     {
67     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SEND");
68    
69     command_fail (si, fault_needmoreparams, "Syntax: SEND <user> <memo>");
70    
71     return;
72     }
73    
74     /* user logged in? */
75     if (!si->smu)
76     {
77     command_fail (si, fault_noprivs, _("You are not logged in."));
78     return;
79     }
80    
81     if (si->smu->flags & MU_WAITAUTH)
82     {
83     command_fail (si, fault_notverified, _("You need to verify your email address before you may send memos."));
84     return;
85     }
86    
87     /* rate limit it -- jilles */
88     if (NOW - si->smu->memo_ratelimit_time > MEMO_MAX_TIME)
89     si->smu->memo_ratelimit_num = 0;
90     if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv (si, PRIV_FLOOD))
91     {
92     command_fail (si, fault_toomany, _("You have used this command too many times; please wait a while and try again."));
93     return;
94     }
95     si->smu->memo_ratelimit_num++;
96     si->smu->memo_ratelimit_time = NOW;
97    
98     /* Check for memo text length -- includes/common.h */
99     if (strlen (m) >= MEMOLEN)
100     {
101     command_fail (si, fault_badparams, "Please make sure your memo is less than %d characters", MEMOLEN);
102    
103     return;
104     }
105    
106     /* Check to make sure the memo doesn't contain hostile CTCP responses.
107     * realistically, we'll probably want to check the _entire_ message for this... --nenolod
108     */
109     if (*m == '\001')
110     {
111     command_fail (si, fault_badparams, _("Your memo contains invalid characters."));
112     return;
113     }
114    
115     if (*target != '#')
116     {
117     /* See if target is valid */
118     if (!(tmu = myuser_find_ext (target)))
119     {
120     command_fail (si, fault_nosuch_target, "\2%s\2 is not registered.", target);
121    
122     return;
123     }
124    
125     /* Does the user allow memos? --pfish */
126     if (tmu->flags & MU_NOMEMO)
127     {
128     command_fail (si, fault_noprivs, "\2%s\2 does not wish to receive memos.", target);
129    
130     return;
131     }
132    
133     /* Check to make sure target inbox not full */
134     if (tmu->memos.size () >= me.mdlimit)
135     {
136     command_fail (si, fault_toomany, _("%s's inbox is full"), target);
137     logcommand (si, CMDLOG_SET, "failed SEND to %s (target inbox full)", tmu->name);
138     return;
139     }
140    
141    
142     /* Make sure we're not on ignore */
143     for (miit = tmu->memo_ignores.begin (), miit_end = tmu->memo_ignores.end (); miit != miit_end; ++miit)
144     {
145     if (!strcasecmp (*miit, si->smu->name))
146     {
147     logcommand (si, CMDLOG_SET, "failed SEND to %s (on ignore list)", tmu->name);
148     command_success_nodata (si, _("The memo has been successfully sent to \2%s\2."), target);
149     return;
150     }
151     }
152     logcommand (si, CMDLOG_SET, "SEND to %s", tmu->name);
153    
154     /* Malloc and populate struct */
155     memo = static_cast<mymemo_t *> (smalloc (sizeof (mymemo_t)));
156     memo->sent = NOW;
157     memo->status = 0;
158     strlcpy (memo->sender, si->smu->name, NICKLEN);
159     strlcpy (memo->text, m, MEMOLEN);
160    
161     /* Create a linked list node and add to memos */
162     tmu->memos.insert (memo);
163     tmu->memoct_new++;
164    
165     /* Should we email this? */
166     if (tmu->flags & MU_EMAILMEMOS)
167     {
168     if (sendemail (si->su, EMAIL_MEMO, tmu, memo->text))
169     {
170     command_success_nodata (si, _("Your memo has been emailed to \2%s\2."), target);
171     return;
172     }
173     }
174    
175     /* Is the user online? If so, tell them about the new memo. */
176     /* Note: do not disclose other nicks they're logged in with
177     * -- jilles
178     *
179     * Actually, I don't see the point in this at all. If they want this information,
180     * they should use WHOIS. --nenolod
181     */
182     tu = user_find_named (target);
183     if (tu != NULL && tu->myuser == tmu)
184     command_success_nodata (si, _("%s is currently online, and you may talk directly, by sending a private message."), target);
185    
186     if (si->su == NULL || !irccasecmp (si->su->nick, si->smu->name))
187     myuser_notice (memosvs.nick, tmu, "You have a new memo from %s.", si->smu->name);
188     else
189     myuser_notice (memosvs.nick, tmu, "You have a new memo from %s (nick: %s).", si->smu->name, si->su->nick);
190    
191     /* Tell user memo sent */
192     command_success_nodata (si, _("The memo has been successfully sent to \2%s\2."), target);
193     }
194     else
195     {
196     cmd = si->service->cmdtree->find ("SENDOPS");
197     if (cmd != NULL)
198     cmd->exec (si->service, si, parc, parv);
199     else
200     command_fail (si, fault_nosuch_target, _("Channel memos are administratively disabled."));
201     }
202    
203     return;
204     }