ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/memoserv/forward.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months 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

# Content
1 /**
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 * Copyright © 2005 Atheme Development Group
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: forward.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <libermyth.h>
17 #include <ermyth/module.h>
18 #include <account/myuser.h>
19 #include <account/mymemo.h>
20
21 static char const rcsid[] = "$Id: forward.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
22
23 REGISTER_MODULE ("memoserv/forward", false, "The Ermyth Team <http://ermyth.xinutec.org>");
24
25 static void ms_cmd_forward (sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t const ms_forward = { "FORWARD", N_(N_("Forwards a memo.")), AC_NONE, 2, ms_cmd_forward };
28
29 E cmdvec ms_cmdtree;
30 E helpvec ms_helptree;
31
32 bool
33 _modinit (module *m)
34 {
35 ms_cmdtree << ms_forward;
36 help_addentry (ms_helptree, "forward", "help/memoserv/forward", NULL);
37
38 return true;
39 }
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 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FORWARD");
66
67 command_fail (si, fault::needmoreparams, "Syntax: FORWARD <account> <memo number>");
68
69 return;
70 }
71 else
72 memonum = atoi (arg);
73
74 /* user logged in? */
75 if (si->smu == NULL)
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 /* Check to see if any memos */
88 if (si->smu->memos.empty ())
89 {
90 command_fail (si, fault::nosuch_key, _("You have no memos to forward."));
91 return;
92 }
93
94 /* Check to see if target user exists */
95 if (!(tmu = myuser_t::find_ext (target)))
96 {
97 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target);
98 return;
99 }
100
101 /* Make sure target isn't sender */
102 if (si->smu == tmu)
103 {
104 command_fail (si, fault::noprivs, _("You cannot send yourself a memo."));
105 return;
106 }
107
108 /* Make sure arg is an int */
109 if (!memonum)
110 {
111 command_fail (si, fault::badparams, _("Invalid message index."));
112 return;
113 }
114
115 /* check if targetuser has nomemo set */
116 if (tmu->flags & MU_NOMEMO)
117 {
118 command_fail (si, fault::noprivs, "\2%s\2 does not wish to receive memos.", target);
119
120 return;
121 }
122
123 /* Check to see if memo n exists */
124 if (memonum > si->smu->memos.size ())
125 {
126 command_fail (si, fault::nosuch_key, _("Invalid memo number."));
127 return;
128 }
129
130 /* Check to make sure target inbox not full */
131 if (tmu->memos.size () >= me.mdlimit)
132 {
133 command_fail (si, fault::toomany, _("Target inbox is full."));
134 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 command_fail (si, fault::toomany, _("Too many memos; please wait a while and try again"));
144 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 newmemo = new mymemo_t;
165
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 tmu->notice (memosvs.nick, "You have a new forwarded memo from %s.", si->smu->name);
193 else
194 tmu->notice (memosvs.nick, "You have a new forwarded memo from %s (nick: %s).", si->smu->name, si->su->nick);
195
196 command_success_nodata (si, _("The memo has been successfully forwarded to \2%s\2."), target);
197 return;
198 }