ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/memoserv/ignore.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * ignore.C: This file contains code for the Memoserv IGNORE functions
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 * Copyright © 2005 Atheme Development Group
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: ignore.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/module.h>
17 #include <account/myuser.h>
18
19 static char const rcsid[] = "$Id: ignore.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
20
21 REGISTER_MODULE ("memoserv/ignore", false, "The Ermyth Team <http://ermyth.xinutec.org>");
22
23 static void ms_cmd_ignore (sourceinfo_t *si, int parc, char *parv[]);
24 static void ms_cmd_ignore_add (sourceinfo_t *si, int parc, char *parv[]);
25 static void ms_cmd_ignore_del (sourceinfo_t *si, int parc, char *parv[]);
26 static void ms_cmd_ignore_clear (sourceinfo_t *si, int parc, char *parv[]);
27 static void ms_cmd_ignore_list (sourceinfo_t *si, int parc, char *parv[]);
28
29 command_t const ms_ignore = { "IGNORE", N_(N_("Ignores memos.")), AC_NONE, 2, ms_cmd_ignore };
30 command_t const ms_ignore_add = { "ADD", N_(N_("Ignores memos from a user.")), AC_NONE, 1, ms_cmd_ignore_add };
31 command_t const ms_ignore_del = { "DEL", N_(N_("Stops ignoring memos from a user.")), AC_NONE, 1, ms_cmd_ignore_del };
32 command_t const ms_ignore_clear = { "CLEAR", N_(N_("Clears your memo ignore list.")), AC_NONE, 1, ms_cmd_ignore_clear };
33 command_t const ms_ignore_list = { "LIST", N_(N_("Shows all users you are ignoring memos from.")), AC_NONE, 1, ms_cmd_ignore_list };
34
35 E cmdvec ms_cmdtree;
36 E helpvec ms_helptree;
37 cmdvec ms_ignore_cmds;
38
39 bool
40 _modinit (module *m)
41 {
42 ms_cmdtree << ms_ignore;
43 help_addentry (ms_helptree, "IGNORE", "help/memoserv/ignore", NULL);
44
45 /* Add sub-commands */
46 ms_ignore_cmds << ms_ignore_add;
47 ms_ignore_cmds << ms_ignore_del;
48 ms_ignore_cmds << ms_ignore_clear;
49 ms_ignore_cmds << ms_ignore_list;
50
51 return true;
52 }
53
54 void
55 _moddeinit ()
56 {
57 ms_cmdtree >> ms_ignore;
58 help_delentry (ms_helptree, "IGNORE");
59
60 /* Delete sub-commands */
61 ms_ignore_cmds >> ms_ignore_add;
62 ms_ignore_cmds >> ms_ignore_del;
63 ms_ignore_cmds >> ms_ignore_clear;
64 ms_ignore_cmds >> ms_ignore_list;
65 }
66
67 static void
68 ms_cmd_ignore (sourceinfo_t *si, int parc, char *parv[])
69 {
70 /* Grab args */
71 char *cmd = parv[0];
72 command_t const *c;
73
74 /* Bad/missing arg */
75 if (!cmd)
76 {
77 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE");
78
79 command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR [account]"));
80 return;
81 }
82
83 /* User logged in? */
84 if (si->smu == NULL)
85 {
86 command_fail (si, fault::noprivs, _("You are not logged in."));
87 return;
88 }
89
90 c = ms_ignore_cmds.find (cmd);
91 if (c == NULL)
92 {
93 command_fail (si, fault::badparams, _("Invalid command. Use \2/%s%s help\2 for a command listing."), (ircd->uses_rcommand == false) ? "msg " : "", memosvs.me->disp);
94 return;
95 }
96
97 c->exec (si->service, si, parc - 1, parv + 1);
98 }
99
100 static void
101 ms_cmd_ignore_add (sourceinfo_t *si, int parc, char *parv[])
102 {
103 myuser_t *tmu;
104 myuser_t::mzignore_vector::iterator miit, miit_end;
105 char *temp;
106
107 /* Arg check */
108 if (parc < 1)
109 {
110 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE");
111
112 command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR <account>"));
113 return;
114 }
115
116 /* User attempting to ignore themself? */
117 if (!irccasecmp (parv[0], si->smu->name))
118 {
119 command_fail (si, fault::badparams, _("Silly wabbit, you can't ignore yourself."));
120 return;
121 }
122
123 /* Does the target account exist? */
124 if (!(tmu = myuser_t::find_ext (parv[0])))
125 {
126 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), parv[0]);
127 return;
128 }
129
130 /* Ignore list is full */
131 if (si->smu->memo_ignores.size () >= MAXMSIGNORES)
132 {
133 command_fail (si, fault::toomany, _("Your ignore list is full, please DEL an account."));
134 return;
135 }
136
137 /* Iterate through list, make sure target not in it, if last node append */
138 for (miit = si->smu->memo_ignores.begin (), miit_end = si->smu->memo_ignores.end (); miit != miit_end; ++miit)
139 {
140 temp = *miit;
141
142 /* Already in the list */
143 if (!irccasecmp (temp, parv[0]))
144 {
145 command_fail (si, fault::nochange, _("Account \2%s\2 is already in your ignore list."), temp);
146 return;
147 }
148 }
149
150 /* Add to ignore list */
151 si->smu->memo_ignores.insert (sstrdup (tmu->name));
152 logcommand (si, CMDLOG_SET, "IGNORE ADD %s", tmu->name);
153 command_success_nodata (si, _("Account \2%s\2 added to your ignore list."), tmu->name);
154 return;
155 }
156
157 static void
158 ms_cmd_ignore_del (sourceinfo_t *si, int parc, char *parv[])
159 {
160 int i = 0;
161 size_t ignorenum = 0;
162 myuser_t::mzignore_vector::iterator miit, miit_end;
163 char *temp;
164
165 /* Arg check */
166 if (parc < 1)
167 {
168 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE");
169 command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR <account>"));
170 return;
171 }
172
173 ignorenum = atoi (parv[0]);
174 if (ignorenum > si->smu->memo_ignores.size ())
175 {
176 command_fail (si, fault::badparams, _("Invalid ignore index"));
177 return;
178 }
179
180 if (ignorenum > 0)
181 {
182 temp = si->smu->memo_ignores[ignorenum - 1];
183 logcommand (si, CMDLOG_SET, "IGNORE DEL %s", temp);
184 command_success_nodata (si, _("Account \2%s\2 removed from ignore list."), temp);
185 si->smu->memo_ignores.erase (ignorenum - 1);
186 sfree (temp);
187
188 return;
189 }
190
191 /* Iterate through list, make sure they're not in it, if last node append */
192 for (miit = si->smu->memo_ignores.begin (), miit_end = si->smu->memo_ignores.end (); miit != miit_end; ++miit)
193 {
194 temp = *miit;
195
196 /* Not using list or clear, but we've found our target in the ignore list */
197 if (!irccasecmp (temp, parv[0]))
198 {
199 logcommand (si, CMDLOG_SET, "IGNORE DEL %s", temp);
200 command_success_nodata (si, _("Account \2%s\2 removed from ignore list."), temp);
201 si->smu->memo_ignores.erase (i);
202 sfree (temp);
203
204 return;
205 }
206
207 ++i;
208 }
209
210 command_fail (si, fault::nosuch_target, _("\2%s\2 is not in your ignore list."), parv[0]);
211 return;
212 }
213
214 static void
215 ms_cmd_ignore_clear (sourceinfo_t *si, int parc, char *parv[])
216 {
217 if (si->smu->memo_ignores.empty ())
218 {
219 command_fail (si, fault::nochange, _("Ignore list already empty."));
220 return;
221 }
222
223 while (!si->smu->memo_ignores.empty ())
224 {
225 sfree (si->smu->memo_ignores.back ());
226 si->smu->memo_ignores.pop_back ();
227 }
228
229 /* Let them know list is clear */
230 command_success_nodata (si, _("Ignore list cleared."));
231 logcommand (si, CMDLOG_SET, "IGNORE CLEAR");
232 return;
233 }
234
235 static void
236 ms_cmd_ignore_list (sourceinfo_t *si, int parc, char *parv[])
237 {
238 unsigned int i = 1;
239 myuser_t::mzignore_vector::iterator miit, miit_end;
240
241 /* Throw in list header */
242 command_success_nodata (si, _("Ignore list:"));
243 command_success_nodata (si, "-------------------------");
244
245 /* Iterate through list, make sure they're not in it, if last node append */
246 for (miit = si->smu->memo_ignores.begin (), miit_end = si->smu->memo_ignores.end (); miit != miit_end; ++miit)
247 {
248 command_success_nodata (si, "%d - %s", i, *miit);
249 i++;
250 }
251
252 /* Ignore list footer */
253 if (i == 1)
254 command_success_nodata (si, _("list empty"));
255
256 command_success_nodata (si, "-------------------------");
257 return;
258 }