ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/unban_self.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 * unban_self.C: Do not load chanserv/ban and chanserv/unban_self together.
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-2007 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * This file contains a ChanServ UNBAN which can only unbans the source
13 *
14 * $Id: unban_self.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
15 */
16
17 #include "atheme.h"
18 #include <ermyth/module.h>
19 #include <account/mychan.h>
20 #include <account/chanacs.h>
21
22 static char const rcsid[] = "$Id: unban_self.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
23
24 REGISTER_MODULE ("chanserv/unban_self", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25
26 static void cs_cmd_unban (sourceinfo_t *si, int parc, char *parv[]);
27
28 command_t const cs_unban = { "UNBAN", N_("Unbans you on a channel."), AC_NONE, 2, cs_cmd_unban };
29
30 E cmdvec cs_cmdtree;
31 E helpvec cs_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 cs_cmdtree << cs_unban;
37
38 help_addentry (cs_helptree, "UNBAN", "help/chanserv/unban", NULL);
39
40 return true;
41 }
42
43 void
44 _moddeinit ()
45 {
46 cs_cmdtree >> cs_unban;
47
48 help_delentry (cs_helptree, "UNBAN");
49 }
50
51 static void
52 cs_cmd_unban (sourceinfo_t *si, int parc, char *parv[])
53 {
54 char *channel = parv[0];
55 char *target = parv[1];
56 channel_t *c = channel_find (channel);
57 mychan_t *mc = mychan_t::find (channel);
58 user_t *tu;
59 chanban_t *cb;
60
61 if (si->su == NULL)
62 {
63 command_fail (si, fault::noprivs, _("\2%s\2 can only be executed via IRC."), "UNBAN");
64 return;
65 }
66
67 if (!channel)
68 {
69 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "UNBAN");
70 command_fail (si, fault::needmoreparams, _("Syntax: UNBAN <#channel>"));
71 return;
72 }
73
74 if (target && irccasecmp (target, si->su->nick))
75 {
76 command_fail (si, fault::noprivs, _("You may only unban yourself via %s."), si->service->name);
77 if (validhostmask (target))
78 command_fail (si, fault::noprivs, _("Try \2/mode %s -b %s\2"), channel, target);
79 return;
80 }
81
82 if (!mc)
83 {
84 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), channel);
85 return;
86 }
87
88 if (!c)
89 {
90 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), channel);
91 return;
92 }
93
94 if (!si->smu)
95 {
96 command_fail (si, fault::noprivs, _("You are not logged in."));
97 return;
98 }
99
100 if (!chanacs_source_has_flag (mc, si, CA_REMOVE))
101 {
102 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
103 return;
104 }
105
106 tu = si->su;
107 {
108 node_t *n, *tn;
109 char hostbuf2[BUFSIZE];
110 int count = 0;
111
112 snprintf (hostbuf2, BUFSIZE, "%s!%s@%s", tu->nick, tu->user, tu->vhost);
113 for (n = phandler->next_matching_ban (c, tu, 'b', c->bans.head); n != NULL; n = phandler->next_matching_ban (c, tu, 'b', tn))
114 {
115 tn = n->next;
116 cb = static_cast<chanban_t *> (n->data);
117
118 logcommand (si, CMDLOG_DO, "%s UNBAN %s (for user %s)", mc->name, cb->mask, hostbuf2);
119 modestack_mode_param (chansvs.nick, c, MTYPE_DEL, cb->type, cb->mask);
120 chanban_delete (cb);
121 count++;
122 }
123 if (count > 0)
124 command_success_nodata (si, _("Unbanned \2%s\2 on \2%s\2 (%d ban%s removed)."), target, channel, count, (count != 1 ? "s" : ""));
125 else
126 command_success_nodata (si, _("No bans found matching \2%s\2 on \2%s\2."), target, channel);
127 return;
128 }
129 }