ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/forward.C
Revision: 1.7
Committed: Sun Sep 16 18:54:43 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.6: +10 -5 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.7 /**
2     * forward.C: This file contains code for the Memoserv FORWARD function
3     *
4     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5     * Rights to this code are as documented in COPYING.
6     *
7     *
8     * Portions of this file were derived from sources bearing the following license:
9 pippijn 1.4 * Copyright © 2005 Atheme Development Group
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.7 * $Id: forward.C,v 1.6 2007-08-30 19:56:22 pippijn Exp $
13 pippijn 1.1 */
14    
15     #include "atheme.h"
16 pippijn 1.4 #include <ermyth/module.h>
17 pippijn 1.1 #include <account/myuser.h>
18     #include <account/mymemo.h>
19    
20 pippijn 1.7 static char const rcsid[] = "$Id: forward.C,v 1.6 2007-08-30 19:56:22 pippijn Exp $";
21 pippijn 1.1
22 pippijn 1.4 REGISTER_MODULE ("memoserv/forward", false, "The Ermyth Team <http://ermyth.schmorp.de>");
23 pippijn 1.1
24     static void ms_cmd_forward (sourceinfo_t *si, int parc, char *parv[]);
25    
26 pippijn 1.4 command_t const ms_forward = { "FORWARD", N_(N_("Forwards a memo.")), AC_NONE, 2, ms_cmd_forward };
27 pippijn 1.1
28 pippijn 1.4 E cmdvec ms_cmdtree;
29     E helpvec ms_helptree;
30 pippijn 1.1
31 pippijn 1.4 bool
32     _modinit (module *m)
33 pippijn 1.1 {
34     ms_cmdtree << ms_forward;
35     help_addentry (ms_helptree, "forward", "help/memoserv/forward", NULL);
36 pippijn 1.4
37     return true;
38 pippijn 1.1 }
39    
40     void
41     _moddeinit ()
42     {
43     ms_cmdtree >> ms_forward;
44     help_delentry (ms_helptree, "FORWARD");
45     }
46    
47     static void
48     ms_cmd_forward (sourceinfo_t *si, int parc, char *parv[])
49     {
50     /* Misc structs etc */
51     user_t *tu;
52     myuser_t *tmu;
53     mymemo_t *memo, *newmemo;
54     unsigned memonum = 0;
55     myuser_t::mzignore_vector::iterator miit, miit_end;
56    
57     /* Grab args */
58     char *target = parv[0];
59     char *arg = parv[1];
60    
61     /* Arg validator */
62     if (!target || !arg)
63     {
64 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FORWARD");
65 pippijn 1.1
66 pippijn 1.6 command_fail (si, fault::needmoreparams, "Syntax: FORWARD <account> <memo number>");
67 pippijn 1.1
68     return;
69     }
70     else
71     memonum = atoi (arg);
72    
73     /* user logged in? */
74     if (si->smu == NULL)
75     {
76 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not logged in."));
77 pippijn 1.1 return;
78     }
79    
80     if (si->smu->flags & MU_WAITAUTH)
81     {
82 pippijn 1.6 command_fail (si, fault::notverified, _("You need to verify your email address before you may send memos."));
83 pippijn 1.1 return;
84     }
85    
86     /* Check to see if any memos */
87     if (si->smu->memos.empty ())
88     {
89 pippijn 1.6 command_fail (si, fault::nosuch_key, _("You have no memos to forward."));
90 pippijn 1.1 return;
91     }
92    
93     /* Check to see if target user exists */
94 pippijn 1.5 if (!(tmu = myuser_t::find_ext (target)))
95 pippijn 1.1 {
96 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target);
97 pippijn 1.1 return;
98     }
99    
100     /* Make sure target isn't sender */
101     if (si->smu == tmu)
102     {
103 pippijn 1.6 command_fail (si, fault::noprivs, _("You cannot send yourself a memo."));
104 pippijn 1.1 return;
105     }
106    
107     /* Make sure arg is an int */
108     if (!memonum)
109     {
110 pippijn 1.6 command_fail (si, fault::badparams, _("Invalid message index."));
111 pippijn 1.1 return;
112     }
113    
114     /* check if targetuser has nomemo set */
115     if (tmu->flags & MU_NOMEMO)
116     {
117 pippijn 1.6 command_fail (si, fault::noprivs, "\2%s\2 does not wish to receive memos.", target);
118 pippijn 1.1
119     return;
120     }
121    
122     /* Check to see if memo n exists */
123     if (memonum > si->smu->memos.size ())
124     {
125 pippijn 1.6 command_fail (si, fault::nosuch_key, _("Invalid memo number."));
126 pippijn 1.1 return;
127     }
128    
129     /* Check to make sure target inbox not full */
130     if (tmu->memos.size () >= me.mdlimit)
131     {
132 pippijn 1.6 command_fail (si, fault::toomany, _("Target inbox is full."));
133 pippijn 1.1 logcommand (si, CMDLOG_SET, "failed FORWARD to %s (target inbox full)", tmu->name);
134     return;
135     }
136    
137     /* rate limit it -- jilles */
138     if (NOW - si->smu->memo_ratelimit_time > MEMO_MAX_TIME)
139     si->smu->memo_ratelimit_num = 0;
140     if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv (si, PRIV_FLOOD))
141     {
142 pippijn 1.6 command_fail (si, fault::toomany, _("Too many memos; please wait a while and try again"));
143 pippijn 1.1 return;
144     }
145     si->smu->memo_ratelimit_num++;
146     si->smu->memo_ratelimit_time = NOW;
147    
148     /* Make sure we're not on ignore */
149     for (miit = tmu->memo_ignores.begin (), miit_end = tmu->memo_ignores.end (); miit != miit_end; ++miit)
150     {
151     if (!strcasecmp (*miit, si->smu->name))
152     {
153     /* Lie... change this if you want it to fail silent */
154     logcommand (si, CMDLOG_SET, "failed FORWARD to %s (on ignore list)", tmu->name);
155     command_success_nodata (si, _("The memo has been successfully forwarded to \2%s\2."), target);
156     return;
157     }
158     }
159     logcommand (si, CMDLOG_SET, "FORWARD to %s", tmu->name);
160    
161     /* Go to forwarding memos */
162     memo = si->smu->memos[memonum - 1];
163 pippijn 1.4 newmemo = new mymemo_t;
164 pippijn 1.1
165     /* Create memo */
166     newmemo->sent = NOW;
167     newmemo->status = 0;
168     strlcpy (newmemo->sender, si->smu->name, NICKLEN);
169     strlcpy (newmemo->text, memo->text, MEMOLEN);
170    
171     /* Create node, add to their linked list of memos */
172     tmu->memos.insert (newmemo);
173     tmu->memoct_new++;
174    
175     /* Should we email this? */
176     if (tmu->flags & MU_EMAILMEMOS)
177     {
178     if (sendemail (si->su, EMAIL_MEMO, tmu, memo->text))
179     {
180     command_success_nodata (si, _("Your memo has been emailed to \2%s\2."), target);
181     return;
182     }
183     }
184    
185     /* Note: do not disclose other nicks they're logged in with
186     * -- jilles */
187     tu = user_find_named (target);
188     if (tu != NULL && tu->myuser == tmu)
189     command_success_nodata (si, _("%s is currently online, and you may talk directly, by sending a private message."), target);
190     if (si->su == NULL || !irccasecmp (si->su->nick, si->smu->name))
191 pippijn 1.4 tmu->notice (memosvs.nick, "You have a new forwarded memo from %s.", si->smu->name);
192 pippijn 1.1 else
193 pippijn 1.4 tmu->notice (memosvs.nick, "You have a new forwarded memo from %s (nick: %s).", si->smu->name, si->su->nick);
194 pippijn 1.1
195     command_success_nodata (si, _("The memo has been successfully forwarded to \2%s\2."), target);
196     return;
197     }