ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/kick.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 * kick.C: This file contains code for the ChanServ KICK 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 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: kick.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/mychan.h>
18 #include <account/chanacs.h>
19
20 static char const rcsid[] = "$Id: kick.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
21
22 REGISTER_MODULE ("chanserv/kick", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23
24 static void cs_cmd_kick (sourceinfo_t *si, int parc, char *parv[]);
25 static void cs_cmd_kickban (sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t const cs_kick = { "KICK", N_("Removes a user from a channel."), AC_NONE, 3, cs_cmd_kick };
28 command_t const cs_kickban = { "KICKBAN", N_("Removes and bans a user from a channel."), AC_NONE, 3, cs_cmd_kickban };
29
30 E cmdvec cs_cmdtree;
31 E helpvec cs_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 cs_cmdtree << cs_kick;
37 cs_cmdtree << cs_kickban;
38
39 help_addentry (cs_helptree, "KICK", "help/chanserv/kick", NULL);
40 help_addentry (cs_helptree, "KICKBAN", "help/chanserv/kickban", NULL);
41
42 return true;
43 }
44
45 void
46 _moddeinit ()
47 {
48 cs_cmdtree >> cs_kick;
49 cs_cmdtree >> cs_kickban;
50
51 help_delentry (cs_helptree, "KICK");
52 help_delentry (cs_helptree, "KICKBAN");
53 }
54
55 static void
56 cs_cmd_kick (sourceinfo_t *si, int parc, char *parv[])
57 {
58 char *chan = parv[0];
59 char *nick = parv[1];
60 char *reason = parv[2];
61 mychan_t *mc;
62 user_t *tu;
63 chanuser_t *cu;
64 char reasonbuf[BUFSIZE];
65
66 if (!chan || !nick)
67 {
68 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "KICK");
69 command_fail (si, fault::needmoreparams, _("Syntax: KICK <#channel> <nickname> [reason]"));
70 return;
71 }
72
73 mc = mychan_t::find (chan);
74 if (!mc)
75 {
76 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
77 return;
78 }
79
80 if (!chanacs_source_has_flag (mc, si, CA_REMOVE))
81 {
82 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
83 return;
84 }
85
86 if (mc->find_metadata ("private:close:closer"))
87 {
88 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan);
89 return;
90 }
91
92 /* figure out who we're going to kick */
93 if (!(tu = user_find_named (nick)))
94 {
95 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
96 return;
97 }
98
99 /* if target is a service, bail. --nenolod */
100 if (is_internal_client (tu))
101 return;
102
103 cu = chanuser_find (mc->chan, tu);
104 if (!cu)
105 {
106 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
107 return;
108 }
109
110 snprintf (reasonbuf, BUFSIZE, "%s (%s)", reason ? reason : "No reason given", get_source_name (si));
111 phandler->kick (chansvs.nick, chan, tu->nick, reasonbuf);
112 logcommand (si, CMDLOG_SET, "%s KICK %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost);
113 if (si->su != tu && !chanuser_find (mc->chan, si->su))
114 command_success_nodata (si, _("\2%s\2 has been kicked from \2%s\2."), tu->nick, mc->name);
115 }
116
117 static void
118 cs_cmd_kickban (sourceinfo_t *si, int parc, char *parv[])
119 {
120 char *chan = parv[0];
121 char *nick = parv[1];
122 char *reason = parv[2];
123 mychan_t *mc;
124 user_t *tu;
125 chanuser_t *cu;
126 char reasonbuf[BUFSIZE];
127 int n;
128
129 if (!chan || !nick)
130 {
131 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "KICKBAN");
132 command_fail (si, fault::needmoreparams, _("Syntax: KICKBAN <#channel> <nickname> [reason]"));
133 return;
134 }
135
136 mc = mychan_t::find (chan);
137 if (!mc)
138 {
139 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan);
140 return;
141 }
142
143 if (!chanacs_source_has_flag (mc, si, CA_REMOVE))
144 {
145 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
146 return;
147 }
148
149 /* figure out who we're going to kick */
150 if (!(tu = user_find_named (nick)))
151 {
152 command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick);
153 return;
154 }
155
156 /* if target is a service, bail. --nenolod */
157 if (is_internal_client (tu))
158 return;
159
160 cu = chanuser_find (mc->chan, tu);
161 if (!cu)
162 {
163 command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
164 return;
165 }
166
167 snprintf (reasonbuf, BUFSIZE, "%s (%s)", reason ? reason : "No reason given", get_source_name (si));
168 ban (si->service->me, mc->chan, tu);
169 n = remove_ban_exceptions (si->service->me, mc->chan, tu);
170 if (n > 0)
171 command_success_nodata (si, _("To avoid rejoin, %d ban exception(s) matching \2%s\2 have been removed from \2%s\2."), n, tu->nick, mc->name);
172 phandler->kick (chansvs.nick, chan, tu->nick, reasonbuf);
173 logcommand (si, CMDLOG_SET, "%s KICKBAN %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost);
174 if (si->su != tu && !chanuser_find (mc->chan, si->su))
175 command_success_nodata (si, _("\2%s\2 has been kickbanned from \2%s\2."), tu->nick, mc->name);
176 }