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