ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/kick.C
Revision: 1.6
Committed: Thu Aug 30 19:56:22 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +17 -17 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

File Contents

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