Debian Codegraph @

modules/chanserv/kick.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the CService KICK functions.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "chanserv/kick", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void cs_cmd_kick(sourceinfo_t *si, int parc, char *parv[]);
19 static void cs_cmd_kickban(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t cs_kick = { "KICK", N_("Removes a user from a channel."),
22 AC_NONE, 3, cs_cmd_kick, { .path = "cservice/kick" } };
23 command_t cs_kickban = { "KICKBAN", N_("Removes and bans a user from a channel."),
24 AC_NONE, 3, cs_cmd_kickban, { .path = "cservice/kickban" } };
25
26 void _modinit(module_t *m)
27 {
28 service_named_bind_command("chanserv", &cs_kick);
29 service_named_bind_command("chanserv", &cs_kickban);
30 }
31
32 void _moddeinit(module_unload_intent_t intent)
33 {
34 service_named_unbind_command("chanserv", &cs_kick);
35 service_named_unbind_command("chanserv", &cs_kickban);
36 }
37
38 static void cs_cmd_kick(sourceinfo_t *si, int parc, char *parv[])
39 {
40 char *chan = parv[0];
41 char *nick = parv[1];
42 char *reason = parv[2];
43 mychan_t *mc;
44 user_t *tu;
45 chanuser_t *cu;
46 char reasonbuf[BUFSIZE];
47
48 if (!chan || !nick)
49 {
50 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "KICK");
51 command_fail(si, fault_needmoreparams, _("Syntax: KICK <#channel> <nickname> [reason]"));
52 return;
53 }
54
55 mc = mychan_find(chan);
56 if (!mc)
57 {
58 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), chan);
59 return;
60 }
61
62 if (!chanacs_source_has_flag(mc, si, CA_REMOVE))
63 {
64 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
65 return;
66 }
67
68 if (metadata_find(mc, "private:close:closer"))
69 {
70 command_fail(si, fault_noprivs, _("\2%s\2 is closed."), chan);
71 return;
72 }
73
74 /* figure out who we're going to kick */
75 if ((tu = user_find_named(nick)) == NULL)
76 {
77 command_fail(si, fault_nosuch_target, _("\2%s\2 is not online."), nick);
78 return;
79 }
80
81 /* if target is a service, bail. --nenolod */
82 if (is_service(tu))
83 {
84 command_fail(si, fault_noprivs, _("\2%s\2 is a network service; you cannot kick or deop them."), tu->nick);
85 return;
86 }
87
88 cu = chanuser_find(mc->chan, tu);
89 if (!cu)
90 {
91 command_fail(si, fault_nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
92 return;
93 }
94
95 if (cu->modes & CSTATUS_OWNER || cu->modes & CSTATUS_PROTECT)
96 {
97 command_fail(si, fault_noprivs, _("\2%s\2 is protected from kicks; you cannot kick them."), tu->nick);
98 return;
99 }
100
101 snprintf(reasonbuf, BUFSIZE, "(%s) %s", get_source_name(si), reason ? reason : "No reason given");
102 try_kick(chansvs.me->me, mc->chan, tu, reasonbuf);
103 logcommand(si, CMDLOG_DO, "KICK: \2%s!%s@%s\2 from \2%s\2", tu->nick, tu->user, tu->vhost, mc->name);
104 if (si->su == NULL ||
105 (si->su != tu && !chanuser_find(mc->chan, si->su)))
106 command_success_nodata(si, _("\2%s\2 has been kicked from \2%s\2."), tu->nick, mc->name);
107 }
108
109 static void cs_cmd_kickban(sourceinfo_t *si, int parc, char *parv[])
110 {
111 char *chan = parv[0];
112 char *nick = parv[1];
113 char *reason = parv[2];
114 mychan_t *mc;
115 user_t *tu;
116 chanuser_t *cu;
117 char reasonbuf[BUFSIZE];
118 int n;
119
120 if (!chan || !nick)
121 {
122 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "KICKBAN");
123 command_fail(si, fault_needmoreparams, _("Syntax: KICKBAN <#channel> <nickname> [reason]"));
124 return;
125 }
126
127 mc = mychan_find(chan);
128 if (!mc)
129 {
130 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), chan);
131 return;
132 }
133
134 if (!chanacs_source_has_flag(mc, si, CA_REMOVE))
135 {
136 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
137 return;
138 }
139
140 /* figure out who we're going to kick */
141 if ((tu = user_find_named(nick)) == NULL)
142 {
143 command_fail(si, fault_nosuch_target, _("\2%s\2 is not online."), nick);
144 return;
145 }
146
147 /* if target is a service, bail. --nenolod */
148 if (is_service(tu))
149 {
150 command_fail(si, fault_noprivs, _("\2%s\2 is a network service; you cannot kick or deop them."), tu->nick);
151 return;
152 }
153
154 cu = chanuser_find(mc->chan, tu);
155 if (!cu)
156 {
157 command_fail(si, fault_nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name);
158 return;
159 }
160
161 if (cu->modes & CSTATUS_OWNER || cu->modes & CSTATUS_PROTECT)
162 {
163 command_fail(si, fault_noprivs, _("\2%s\2 is protected from kicks; you cannot kick them."), tu->nick);
164 return;
165 }
166
167 snprintf(reasonbuf, BUFSIZE, "(%s) %s", get_source_name(si), reason ? reason : "No reason given");
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 try_kick(chansvs.me->me, mc->chan, tu, reasonbuf);
173 logcommand(si, CMDLOG_DO, "KICKBAN: \2%s!%s@%s\2 from \2%s\2", tu->nick, tu->user, tu->vhost, mc->name);
174 if (si->su == NULL ||
175 (si->su != tu && !chanuser_find(mc->chan, si->su)))
176 command_success_nodata(si, _("\2%s\2 has been kickbanned from \2%s\2."), tu->nick, mc->name);
177 }
178
179 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
180 * vim:ts=8
181 * vim:sw=8
182 * vim:noexpandtab
183 */