| 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 |
|
|
* This file contains code for the ChanServ CLEAR USERS function. |
| 6 |
|
|
* |
| 7 |
pippijn |
1.6 |
* $Id: clear_users.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/chanacs.h> |
| 13 |
|
|
#include <account/mychan.h> |
| 14 |
|
|
|
| 15 |
pippijn |
1.6 |
static char const rcsid[] = "$Id: clear_users.C,v 1.5 2007-08-28 17:08:07 pippijn Exp $"; |
| 16 |
pippijn |
1.1 |
|
| 17 |
pippijn |
1.5 |
REGISTER_MODULE ("chanserv/clear_users", false, "The Ermyth Team <http://ermyth.schmorp.de>"); |
| 18 |
pippijn |
1.1 |
|
| 19 |
|
|
static void cs_cmd_clear_users (sourceinfo_t *si, int parc, char *parv[]); |
| 20 |
|
|
|
| 21 |
pippijn |
1.5 |
command_t const cs_clear_users = { "USERS", N_("Kicks all users from a channel."), AC_NONE, 2, cs_cmd_clear_users }; |
| 22 |
pippijn |
1.1 |
|
| 23 |
pippijn |
1.5 |
E cmdvec cs_clear_cmds; |
| 24 |
|
|
E helpvec cs_helptree; |
| 25 |
pippijn |
1.1 |
|
| 26 |
pippijn |
1.5 |
bool |
| 27 |
|
|
_modinit (module *m) |
| 28 |
pippijn |
1.1 |
{ |
| 29 |
|
|
cs_clear_cmds << cs_clear_users; |
| 30 |
pippijn |
1.4 |
help_addentry (cs_helptree, "CLEAR USERS", "help/chanserv/clear_users", NULL); |
| 31 |
pippijn |
1.5 |
|
| 32 |
|
|
return true; |
| 33 |
pippijn |
1.1 |
} |
| 34 |
|
|
|
| 35 |
|
|
void |
| 36 |
|
|
_moddeinit () |
| 37 |
|
|
{ |
| 38 |
|
|
cs_clear_cmds >> cs_clear_users; |
| 39 |
|
|
|
| 40 |
|
|
help_delentry (cs_helptree, "CLEAR USERS"); |
| 41 |
|
|
} |
| 42 |
|
|
|
| 43 |
|
|
static void |
| 44 |
|
|
cs_cmd_clear_users (sourceinfo_t *si, int parc, char *parv[]) |
| 45 |
|
|
{ |
| 46 |
|
|
char fullreason[200]; |
| 47 |
|
|
channel_t *c; |
| 48 |
|
|
char *channel = parv[0]; |
| 49 |
pippijn |
1.6 |
mychan_t *mc = mychan_t::find (channel); |
| 50 |
pippijn |
1.1 |
chanuser_t *cu; |
| 51 |
|
|
node_t *n, *tn; |
| 52 |
|
|
int oldlimit; |
| 53 |
|
|
|
| 54 |
|
|
if (parc >= 2) |
| 55 |
|
|
snprintf (fullreason, sizeof fullreason, "CLEAR USERS used by %s: %s", get_source_name (si), parv[1]); |
| 56 |
|
|
else |
| 57 |
|
|
snprintf (fullreason, sizeof fullreason, "CLEAR USERS used by %s", get_source_name (si)); |
| 58 |
|
|
|
| 59 |
|
|
if (!mc) |
| 60 |
|
|
{ |
| 61 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), channel); |
| 62 |
pippijn |
1.1 |
return; |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
|
if (!(c = channel_find (channel))) |
| 66 |
|
|
{ |
| 67 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), channel); |
| 68 |
pippijn |
1.1 |
return; |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
|
if (!chanacs_source_has_flag (mc, si, CA_RECOVER)) |
| 72 |
|
|
{ |
| 73 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
| 74 |
pippijn |
1.1 |
return; |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
if (mc->find_metadata ("private:close:closer")) |
| 78 |
|
|
{ |
| 79 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), channel); |
| 80 |
pippijn |
1.1 |
return; |
| 81 |
|
|
} |
| 82 |
|
|
|
| 83 |
|
|
/* stop a race condition where users can rejoin */ |
| 84 |
|
|
oldlimit = c->limit; |
| 85 |
|
|
if (oldlimit != 1) |
| 86 |
|
|
modestack_mode_limit (chansvs.nick, c, MTYPE_ADD, 1); |
| 87 |
|
|
modestack_flush_channel (c); |
| 88 |
|
|
|
| 89 |
|
|
LIST_FOREACH_SAFE (n, tn, c->members.head) |
| 90 |
|
|
{ |
| 91 |
|
|
cu = static_cast<chanuser_t *> (n->data); |
| 92 |
|
|
|
| 93 |
|
|
/* don't kick the user who requested the masskick */ |
| 94 |
|
|
if (cu->user == si->su || is_internal_client (cu->user)) |
| 95 |
|
|
continue; |
| 96 |
|
|
|
| 97 |
pippijn |
1.5 |
phandler->kick (chansvs.nick, c->name, cu->user->nick, fullreason); |
| 98 |
pippijn |
1.1 |
} |
| 99 |
|
|
|
| 100 |
|
|
/* the channel may be empty now, so our pointer may be bogus! */ |
| 101 |
|
|
c = channel_find (channel); |
| 102 |
|
|
if (c != NULL) |
| 103 |
|
|
{ |
| 104 |
|
|
if ((mc->flags & MC_GUARD) && !config_options.leave_chans && c != NULL && !chanuser_find (c, si->su)) |
| 105 |
|
|
{ |
| 106 |
|
|
/* Always cycle it if the requester is not on channel |
| 107 |
|
|
* -- jilles */ |
| 108 |
|
|
part (channel, chansvs.nick); |
| 109 |
|
|
} |
| 110 |
|
|
/* could be permanent channel, blah */ |
| 111 |
|
|
c = channel_find (channel); |
| 112 |
|
|
if (c != NULL) |
| 113 |
|
|
{ |
| 114 |
|
|
if (oldlimit == 0) |
| 115 |
|
|
modestack_mode_limit (chansvs.nick, c, MTYPE_DEL, 0); |
| 116 |
|
|
else if (oldlimit != 1) |
| 117 |
|
|
modestack_mode_limit (chansvs.nick, c, MTYPE_ADD, oldlimit); |
| 118 |
|
|
} |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
logcommand (si, CMDLOG_DO, "%s CLEAR USERS", mc->name); |
| 122 |
|
|
|
| 123 |
|
|
command_success_nodata (si, _("Cleared users from \2%s\2."), channel); |
| 124 |
|
|
} |