ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/sendops.C
Revision: 1.2
Committed: Sat Jul 21 01:29:09 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -2 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005-2007 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 SENDOPS function
6     *
7 pippijn 1.2 * $Id: sendops.C,v 1.1 2007-07-19 08:24:54 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11     #include <account/chanacs.h>
12     #include <account/mychan.h>
13     #include <account/myuser.h>
14     #include <account/mymemo.h>
15    
16     static char const rcsid[] = "$Id";
17    
18     struct ms_sendops_listeners : callback::has_listeners
19     {
20     };
21    
22     ms_sendops_listeners listeners;
23    
24     DECLARE_MODULE_V1 ("memoserv/sendops", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
25    
26     static void ms_cmd_sendops (sourceinfo_t *si, int parc, char *parv[]);
27    
28     command_t ms_sendops = { "SENDOPS", N_("Sends a memo to all ops on a channel."),
29     AC_NONE, 2, ms_cmd_sendops
30     };
31    
32     cmdvec *ms_cmdtree;
33     helpvec *ms_helptree;
34    
35     void
36     _modinit (module_t *m)
37     {
38     MODULE_USE_SYMBOL_T (ms_cmdtree, cmdvec, "memoserv/main", "ms_cmdtree");
39     MODULE_USE_SYMBOL_T (ms_helptree, helpvec, "memoserv/main", "ms_helptree");
40    
41     ms_cmdtree << ms_sendops;
42     help_addentry (ms_helptree, "SENDOPS", "help/memoserv/sendops", NULL);
43     }
44    
45     void
46     _moddeinit ()
47     {
48     ms_cmdtree >> ms_sendops;
49     help_delentry (ms_helptree, "SENDOPS");
50     }
51    
52     static void
53     ms_cmd_sendops (sourceinfo_t *si, int parc, char *parv[])
54     {
55     /* misc structs etc */
56     myuser_t *tmu;
57     node_t *tn;
58     mymemo_t *memo;
59     mychan_t *mc;
60     int sent = 0, tried = 0;
61     bool ignored;
62     myuser_t::mzignore_vector::iterator miit, miit_end;
63    
64     /* Grab args */
65     char *target = parv[0];
66     char *m = parv[1];
67    
68     /* Arg validation */
69     if (!target || !m)
70     {
71     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SENDOPS");
72    
73     command_fail (si, fault_needmoreparams, "Syntax: SENDOPS <channel> <memo>");
74    
75     return;
76     }
77    
78     /* user logged in? */
79     if (!si->smu)
80     {
81     command_fail (si, fault_noprivs, _("You are not logged in."));
82     return;
83     }
84    
85     if (si->smu->flags & MU_WAITAUTH)
86     {
87     command_fail (si, fault_notverified, _("You need to verify your email address before you may send memos."));
88     return;
89     }
90    
91     /* rate limit it -- jilles */
92     if (NOW - si->smu->memo_ratelimit_time > MEMO_MAX_TIME)
93     si->smu->memo_ratelimit_num = 0;
94     if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv (si, PRIV_FLOOD))
95     {
96     command_fail (si, fault_toomany, _("You have used this command too many times; please wait a while and try again."));
97     return;
98     }
99     si->smu->memo_ratelimit_num++;
100     si->smu->memo_ratelimit_time = NOW;
101    
102     /* Check for memo text length -- includes/common.h */
103     if (strlen (m) >= MEMOLEN)
104     {
105     command_fail (si, fault_badparams, "Please make sure your memo is less than %d characters", MEMOLEN);
106    
107     return;
108     }
109    
110     /* Check to make sure the memo doesn't contain hostile CTCP responses.
111     * realistically, we'll probably want to check the _entire_ message for this... --nenolod
112     */
113     if (*m == '\001')
114     {
115     command_fail (si, fault_badparams, _("Your memo contains invalid characters."));
116     return;
117     }
118    
119     mc = mychan_find (target);
120    
121     if (mc == NULL)
122     {
123     command_fail (si, fault_nosuch_target, "\2%s\2 is not registered.", target);
124     return;
125     }
126    
127     if (!chanacs_user_has_flag (mc, si->su, CA_ACLVIEW))
128     {
129     command_fail (si, fault_noprivs, _("You are not authorized to perform this operation."));
130     return;
131     }
132    
133     LIST_FOREACH (tn, mc->chanacs.head)
134     {
135     chanacs_t *ca = (chanacs_t *) tn->data;
136     tmu = ca->myuser;
137    
138     if (!(ca->level & (CA_OP | CA_AUTOOP)) || tmu == NULL || tmu == si->smu)
139     continue;
140    
141     tried++;
142    
143     /* Does the user allow memos? --pfish */
144     if (tmu->flags & MU_NOMEMO)
145     continue;
146    
147     /* Check to make sure target inbox not full */
148     if (tmu->memos.size () >= me.mdlimit)
149     continue;
150    
151     /* As in SEND to a single user, make ignore fail silently */
152     sent++;
153    
154     /* Make sure we're not on ignore */
155     ignored = false;
156     for (miit = tmu->memo_ignores.begin (), miit_end = tmu->memo_ignores.end (); miit != miit_end; ++miit)
157     {
158     if (!strcasecmp (*miit, si->smu->name))
159     ignored = true;
160     }
161     if (ignored)
162     continue;
163    
164     /* Malloc and populate struct */
165     memo = static_cast<mymemo_t *> (smalloc (sizeof (mymemo_t)));
166     memo->sent = NOW;
167     memo->status = MEMO_CHANNEL;
168     strlcpy (memo->sender, si->smu->name, NICKLEN);
169     snprintf (memo->text, MEMOLEN, "%s %s", mc->name, m);
170    
171     /* Create a linked list node and add to memos */
172     tmu->memos.insert (memo);
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     continue;
180     }
181    
182     /* Is the user online? If so, tell them about the new memo. */
183     if (si->su == NULL || !irccasecmp (si->su->nick, si->smu->name))
184     myuser_notice (memosvs.nick, tmu, _("You have a new memo from %s."), si->smu->name);
185     else
186     myuser_notice (memosvs.nick, tmu, _("You have a new memo from %s (nick: %s)."), si->smu->name, si->su->nick);
187     }
188    
189     /* Tell user memo sent, return */
190     logcommand (si, CMDLOG_SET, "SENDOPS to %s (%d/%d sent)", mc->name, sent, tried);
191     command_success_nodata (si, _("The memo has been successfully sent to %d ops on \2%s\2."), sent, mc->name);
192     return;
193     }