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