ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/forward.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +4 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

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