ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/clear_users.C
Revision: 1.3
Committed: Sat Jul 21 13:23:18 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -2 lines
Log Message:
- added rcsid to some files
- more documentation tweaks
- made most protocol commands local to phandler.C
- added ircd metadata (inspircd only for now)
- added inspircd swhois support

File Contents

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