ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/forward.C
Revision: 1.4
Committed: Tue Aug 28 17:08:09 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +15 -23 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

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