Debian Codegraph @

modules/memoserv/sendgroup.c

raw
1 /*
2 * Copyright (c) 2005-2007 Atheme Development Group
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the Memoserv SENDGROUP function
6 *
7 */
8
9 #include "atheme.h"
10 #include "../groupserv/groupserv.h"
11
12 DECLARE_MODULE_V1
13 (
14 "memoserv/sendgroup", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void ms_cmd_sendgroup(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t ms_sendgroup = { "SENDGROUP", N_("Sends a memo to all members on a group."),
22 AC_AUTHENTICATED, 2, ms_cmd_sendgroup, { .path = "memoserv/sendgroup" } };
23 static unsigned int *maxmemos;
24
25 void _modinit(module_t *m)
26 {
27 service_named_bind_command("memoserv", &ms_sendgroup);
28 MODULE_TRY_REQUEST_SYMBOL(m, maxmemos, "memoserv/main", "maxmemos");
29 }
30
31 void _moddeinit(module_unload_intent_t intent)
32 {
33 service_named_unbind_command("memoserv", &ms_sendgroup);
34 }
35
36 static void ms_cmd_sendgroup(sourceinfo_t *si, int parc, char *parv[])
37 {
38 /* misc structs etc */
39 myuser_t *tmu;
40 mowgli_node_t *n, *tn;
41 mymemo_t *memo;
42 mygroup_t *mg;
43 int sent = 0, tried = 0;
44 bool ignored, operoverride = false;
45 service_t *memoserv;
46
47 /* Grab args */
48 char *target = parv[0];
49 char *m = parv[1];
50
51 /* Arg validation */
52 if (!target || !m)
53 {
54 command_fail(si, fault_needmoreparams,
55 STR_INSUFFICIENT_PARAMS, "SENDGROUP");
56
57 command_fail(si, fault_needmoreparams,
58 _("Syntax: SENDGROUP <group> <memo>"));
59
60 return;
61 }
62
63 if (si->smu->flags & MU_WAITAUTH)
64 {
65 command_fail(si, fault_notverified, _("You need to verify your email address before you may send memos."));
66 return;
67 }
68
69 /* rate limit it -- jilles */
70 if (CURRTIME - si->smu->memo_ratelimit_time > MEMO_MAX_TIME)
71 si->smu->memo_ratelimit_num = 0;
72 if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv(si, PRIV_FLOOD))
73 {
74 command_fail(si, fault_toomany, _("You have used this command too many times; please wait a while and try again."));
75 return;
76 }
77
78 /* Check for memo text length -- includes/common.h */
79 if (strlen(m) >= MEMOLEN)
80 {
81 command_fail(si, fault_badparams,
82 "Please make sure your memo is less than %d characters", MEMOLEN);
83
84 return;
85 }
86
87 /* Check to make sure the memo doesn't contain hostile CTCP responses.
88 * realistically, we'll probably want to check the _entire_ message for this... --nenolod
89 */
90 if (*m == '\001')
91 {
92 command_fail(si, fault_badparams, _("Your memo contains invalid characters."));
93 return;
94 }
95
96 mg = group(myentity_find(target));
97 if (mg == NULL)
98 {
99 command_fail(si, fault_nosuch_target, "Group \2%s\2 is not registered.", target);
100 return;
101 }
102
103 si->smu->memo_ratelimit_num++;
104 si->smu->memo_ratelimit_time = CURRTIME;
105
106 MOWGLI_ITER_FOREACH(tn, mg->acs.head)
107 {
108 groupacs_t *ga = (groupacs_t *) tn->data;
109 tmu = user(ga->mt);
110
111 if (!(ga->flags & GA_MEMOS) || tmu == NULL || tmu == si->smu)
112 continue;
113
114 tried++;
115
116 /* Does the user allow memos? --pfish */
117 if (tmu->flags & MU_NOMEMO)
118 continue;
119
120 /* Check to make sure target inbox not full */
121 if (tmu->memos.count >= *maxmemos)
122 continue;
123
124 /* As in SEND to a single user, make ignore fail silently */
125 sent++;
126
127 /* Make sure we're not on ignore */
128 ignored = false;
129 MOWGLI_ITER_FOREACH(n, tmu->memo_ignores.head)
130 {
131 mynick_t *mn;
132 myuser_t *mu;
133
134 if (nicksvs.no_nick_ownership)
135 mu = myuser_find((const char *)n->data);
136 else
137 {
138 mn = mynick_find((const char *)n->data);
139 mu = mn != NULL ? mn->owner : NULL;
140 }
141 if (mu == si->smu)
142 ignored = true;
143 }
144 if (ignored)
145 continue;
146
147 /* Malloc and populate struct */
148 memo = smalloc(sizeof(mymemo_t));
149 memo->sent = CURRTIME;
150 memo->status = MEMO_CHANNEL;
151 mowgli_strlcpy(memo->sender,entity(si->smu)->name,NICKLEN);
152 snprintf(memo->text, MEMOLEN, "%s %s", entity(mg)->name, m);
153
154 /* Create a linked list node and add to memos */
155 n = mowgli_node_create();
156 mowgli_node_add(memo, n, &tmu->memos);
157 tmu->memoct_new++;
158
159 /* Should we email this? */
160 if (tmu->flags & MU_EMAILMEMOS)
161 {
162 sendemail(si->su, tmu, EMAIL_MEMO, tmu->email, memo->text);
163 }
164
165 memoserv = service_find("memoserv");
166 if (memoserv == NULL)
167 memoserv = si->service;
168
169 /* Is the user online? If so, tell them about the new memo. */
170 if (si->su == NULL || !irccasecmp(si->su->nick, entity(si->smu)->name))
171 myuser_notice(memoserv->nick, tmu, "You have a new memo from %s (%zu).", entity(si->smu)->name, MOWGLI_LIST_LENGTH(&tmu->memos));
172 else
173 myuser_notice(memoserv->nick, tmu, "You have a new memo from %s (nick: %s) (%zu).", entity(si->smu)->name, si->su->nick, MOWGLI_LIST_LENGTH(&tmu->memos));
174 myuser_notice(memoserv->nick, tmu, _("To read it, type /%s%s READ %zu"),
175 ircd->uses_rcommand ? "" : "msg ", memoserv->disp, MOWGLI_LIST_LENGTH(&tmu->memos));
176 }
177
178 /* Tell user memo sent, return */
179 if (sent > 4)
180 command_add_flood(si, FLOOD_HEAVY);
181 else if (sent > 1)
182 command_add_flood(si, FLOOD_MODERATE);
183 if (operoverride)
184 logcommand(si, CMDLOG_ADMIN, "SENDGROUP: to \2%s\2 (%d/%d sent) (oper override)", entity(mg)->name, sent, tried);
185 else
186 logcommand(si, CMDLOG_SET, "SENDGROUP: to \2%s\2 (%d/%d sent)", entity(mg)->name, sent, tried);
187 command_success_nodata(si, _("The memo has been successfully sent to %d members on \2%s\2."), sent, entity(mg)->name);
188 return;
189 }
190
191 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
192 * vim:ts=8
193 * vim:sw=8
194 * vim:noexpandtab
195 */