ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/send.C
Revision: 1.5
Committed: Tue Aug 28 22:18:30 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +3 -3 lines
Log Message:
added type traits

File Contents

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