| 1 |
pippijn |
1.7 |
/** |
| 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 |
pippijn |
1.5 |
* Copyright © 2005 William Pitcock, et al. |
| 10 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 11 |
pippijn |
1.1 |
* |
| 12 |
pippijn |
1.8 |
* $Id: kick.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $ |
| 13 |
pippijn |
1.1 |
*/ |
| 14 |
|
|
|
| 15 |
|
|
#include "atheme.h" |
| 16 |
pippijn |
1.5 |
#include <ermyth/module.h> |
| 17 |
pippijn |
1.1 |
#include <account/mychan.h> |
| 18 |
|
|
#include <account/chanacs.h> |
| 19 |
|
|
|
| 20 |
pippijn |
1.8 |
static char const rcsid[] = "$Id: kick.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $"; |
| 21 |
pippijn |
1.1 |
|
| 22 |
pippijn |
1.8 |
REGISTER_MODULE ("chanserv/kick", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
| 23 |
pippijn |
1.1 |
|
| 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 |
pippijn |
1.5 |
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 |
pippijn |
1.1 |
|
| 30 |
pippijn |
1.5 |
E cmdvec cs_cmdtree; |
| 31 |
|
|
E helpvec cs_helptree; |
| 32 |
pippijn |
1.1 |
|
| 33 |
pippijn |
1.5 |
bool |
| 34 |
|
|
_modinit (module *m) |
| 35 |
pippijn |
1.1 |
{ |
| 36 |
|
|
cs_cmdtree << cs_kick; |
| 37 |
|
|
cs_cmdtree << cs_kickban; |
| 38 |
|
|
|
| 39 |
pippijn |
1.4 |
help_addentry (cs_helptree, "KICK", "help/chanserv/kick", NULL); |
| 40 |
|
|
help_addentry (cs_helptree, "KICKBAN", "help/chanserv/kickban", NULL); |
| 41 |
pippijn |
1.5 |
|
| 42 |
|
|
return true; |
| 43 |
pippijn |
1.1 |
} |
| 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 |
pippijn |
1.6 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "KICK"); |
| 69 |
|
|
command_fail (si, fault::needmoreparams, _("Syntax: KICK <#channel> <nickname> [reason]")); |
| 70 |
pippijn |
1.1 |
return; |
| 71 |
|
|
} |
| 72 |
|
|
|
| 73 |
pippijn |
1.6 |
mc = mychan_t::find (chan); |
| 74 |
pippijn |
1.1 |
if (!mc) |
| 75 |
|
|
{ |
| 76 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
| 77 |
pippijn |
1.1 |
return; |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
|
|
if (!chanacs_source_has_flag (mc, si, CA_REMOVE)) |
| 81 |
|
|
{ |
| 82 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
| 83 |
pippijn |
1.1 |
return; |
| 84 |
|
|
} |
| 85 |
|
|
|
| 86 |
|
|
if (mc->find_metadata ("private:close:closer")) |
| 87 |
|
|
{ |
| 88 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); |
| 89 |
pippijn |
1.1 |
return; |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
|
/* figure out who we're going to kick */ |
| 93 |
|
|
if (!(tu = user_find_named (nick))) |
| 94 |
|
|
{ |
| 95 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); |
| 96 |
pippijn |
1.1 |
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 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name); |
| 107 |
pippijn |
1.1 |
return; |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
snprintf (reasonbuf, BUFSIZE, "%s (%s)", reason ? reason : "No reason given", get_source_name (si)); |
| 111 |
pippijn |
1.5 |
phandler->kick (chansvs.nick, chan, tu->nick, reasonbuf); |
| 112 |
pippijn |
1.1 |
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 |
pippijn |
1.6 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "KICKBAN"); |
| 132 |
|
|
command_fail (si, fault::needmoreparams, _("Syntax: KICKBAN <#channel> <nickname> [reason]")); |
| 133 |
pippijn |
1.1 |
return; |
| 134 |
|
|
} |
| 135 |
|
|
|
| 136 |
pippijn |
1.6 |
mc = mychan_t::find (chan); |
| 137 |
pippijn |
1.1 |
if (!mc) |
| 138 |
|
|
{ |
| 139 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
| 140 |
pippijn |
1.1 |
return; |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
|
if (!chanacs_source_has_flag (mc, si, CA_REMOVE)) |
| 144 |
|
|
{ |
| 145 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
| 146 |
pippijn |
1.1 |
return; |
| 147 |
|
|
} |
| 148 |
|
|
|
| 149 |
|
|
/* figure out who we're going to kick */ |
| 150 |
|
|
if (!(tu = user_find_named (nick))) |
| 151 |
|
|
{ |
| 152 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); |
| 153 |
pippijn |
1.1 |
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 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name); |
| 164 |
pippijn |
1.1 |
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 |
pippijn |
1.5 |
phandler->kick (chansvs.nick, chan, tu->nick, reasonbuf); |
| 173 |
pippijn |
1.1 |
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 |
|
|
} |