ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/sendops.C
Revision: 1.6
Committed: Sun Sep 16 18:54:43 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +10 -5 lines
Log Message:
#defines to enum

File Contents

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