ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/clear_users.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (19 years 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

# User Rev Content
1 pippijn 1.7 /**
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 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: clear_users.C,v 1.7 2007-09-16 18:54:42 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/chanacs.h>
18     #include <account/mychan.h>
19    
20 pippijn 1.8 static char const rcsid[] = "$Id: clear_users.C,v 1.7 2007-09-16 18:54:42 pippijn Exp $";
21 pippijn 1.1
22 pippijn 1.8 REGISTER_MODULE ("chanserv/clear_users", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23 pippijn 1.1
24     static void cs_cmd_clear_users (sourceinfo_t *si, int parc, char *parv[]);
25    
26 pippijn 1.5 command_t const cs_clear_users = { "USERS", N_("Kicks all users from a channel."), AC_NONE, 2, cs_cmd_clear_users };
27 pippijn 1.1
28 pippijn 1.5 E cmdvec cs_clear_cmds;
29     E helpvec cs_helptree;
30 pippijn 1.1
31 pippijn 1.5 bool
32     _modinit (module *m)
33 pippijn 1.1 {
34     cs_clear_cmds << cs_clear_users;
35 pippijn 1.4 help_addentry (cs_helptree, "CLEAR USERS", "help/chanserv/clear_users", NULL);
36 pippijn 1.5
37     return true;
38 pippijn 1.1 }
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 pippijn 1.6 mychan_t *mc = mychan_t::find (channel);
55 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), channel);
67 pippijn 1.1 return;
68     }
69    
70     if (!(c = channel_find (channel)))
71     {
72 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), channel);
73 pippijn 1.1 return;
74     }
75    
76     if (!chanacs_source_has_flag (mc, si, CA_RECOVER))
77     {
78 pippijn 1.6 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
79 pippijn 1.1 return;
80     }
81    
82     if (mc->find_metadata ("private:close:closer"))
83     {
84 pippijn 1.6 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), channel);
85 pippijn 1.1 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 pippijn 1.5 phandler->kick (chansvs.nick, c->name, cu->user->nick, fullreason);
103 pippijn 1.1 }
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     }