ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/forward.C
Revision: 1.3
Committed: Sat Jul 21 13:23:20 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -2 lines
Log Message:
- added rcsid to some files
- more documentation tweaks
- made most protocol commands local to phandler.C
- added ircd metadata (inspircd only for now)
- added inspircd swhois support

File Contents

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