1 |
/** |
2 |
* clearchan.C: This file contains functionality implementing OperServ CLEARCHAN. |
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 © 2006 Robin Burchell <surreal.w00t@gmail.com> |
10 |
* Rights to this code are documented in doc/LICENCE. |
11 |
* |
12 |
* $Id: clearchan.C,v 1.5 2007-08-30 19:56:24 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <ermyth/module.h> |
17 |
|
18 |
static char const rcsid[] = "$Id: clearchan.C,v 1.5 2007-08-30 19:56:24 pippijn Exp $"; |
19 |
|
20 |
REGISTER_MODULE ("operserv/clearchan", false, "Robin Burchell <surreal.w00t@gmail.com>"); |
21 |
|
22 |
#define CLEAR_KICK 1 |
23 |
#define CLEAR_KILL 2 |
24 |
#define CLEAR_GLINE 3 |
25 |
|
26 |
static void os_cmd_clearchan (sourceinfo_t *si, int parc, char *parv[]); |
27 |
|
28 |
command_t const os_clearchan = { "CLEARCHAN", N_("Clears a channel via KICK, KILL or GLINE"), PRIV_CHAN_ADMIN, 3, os_cmd_clearchan }; |
29 |
|
30 |
E cmdvec os_cmdtree; |
31 |
E helpvec os_helptree; |
32 |
|
33 |
static void |
34 |
os_cmd_clearchan (sourceinfo_t *si, int parc, char *parv[]) |
35 |
{ |
36 |
chanuser_t *cu = NULL; |
37 |
node_t *n = NULL; |
38 |
channel_t *c = NULL; |
39 |
int action; |
40 |
char *actionstr = parv[0]; |
41 |
char *targchan = parv[1]; |
42 |
char *treason = parv[2]; |
43 |
char reason[512]; |
44 |
int matches = 0; |
45 |
int ignores = 0; |
46 |
|
47 |
if (!actionstr || !targchan || !treason) |
48 |
{ |
49 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "CLEARCHAN"); |
50 |
command_fail (si, fault::needmoreparams, _("Syntax: CLEARCHAN KICK|KILL|GLINE <#channel> <reason>")); |
51 |
return; |
52 |
} |
53 |
|
54 |
c = channel_find (targchan); |
55 |
|
56 |
if (!c) |
57 |
{ |
58 |
command_fail (si, fault::nosuch_target, _("Channel \2%s\2 does not exist."), targchan); |
59 |
return; |
60 |
} |
61 |
|
62 |
/* check what they are doing is valid */ |
63 |
if (!strcasecmp (actionstr, "KICK")) |
64 |
action = CLEAR_KICK; |
65 |
else if (!strcasecmp (actionstr, "KILL")) |
66 |
action = CLEAR_KILL; |
67 |
else if (!strcasecmp (actionstr, "GLINE") || !strcasecmp (actionstr, "KLINE")) |
68 |
action = CLEAR_GLINE; |
69 |
else |
70 |
{ |
71 |
/* not valid! */ |
72 |
command_fail (si, fault::badparams, _("\2%s\2 is not a valid action"), actionstr); |
73 |
return; |
74 |
} |
75 |
|
76 |
if (action != CLEAR_KICK && !has_priv (si, PRIV_MASS_AKILL)) |
77 |
{ |
78 |
command_fail (si, fault::noprivs, _("You do not have %s privilege."), PRIV_MASS_AKILL); |
79 |
return; |
80 |
} |
81 |
|
82 |
if (action == CLEAR_KICK) |
83 |
snprintf (reason, sizeof reason, "(Clearing) %s", treason); |
84 |
else |
85 |
snprintf (reason, sizeof reason, "(Clearing %s) %s", targchan, treason); |
86 |
|
87 |
wallops ("\2%s\2 is clearing channel %s with %s", get_oper_name (si), targchan, actionstr); |
88 |
snoop ("CLEARCHAN: %s on \2%s\2 by \2%s\2", actionstr, targchan, get_oper_name (si)); |
89 |
command_success_nodata (si, _("Clearing \2%s\2 with \2%s\2"), targchan, actionstr); |
90 |
|
91 |
/* iterate over the users in channel */ |
92 |
LIST_FOREACH (n, c->members.head) |
93 |
{ |
94 |
cu = static_cast < chanuser_t *>(n->data); |
95 |
|
96 |
if (is_internal_client (cu->user)) |
97 |
; |
98 |
else if (is_ircop (cu->user)) |
99 |
{ |
100 |
command_success_nodata (si, _("\2CLEARCHAN\2: Ignoring IRC Operator \2%s\2!%s@%s {%s}"), cu->user->nick, cu->user->user, cu->user->host, cu->user->gecos); |
101 |
ignores++; |
102 |
} |
103 |
else |
104 |
{ |
105 |
command_success_nodata (si, _("\2CLEARCHAN\2: \2%s\2 hit \2%s\2!%s@%s {%s}"), actionstr, cu->user->nick, cu->user->user, cu->user->host, cu->user->gecos); |
106 |
matches++; |
107 |
|
108 |
switch (action) |
109 |
{ |
110 |
case CLEAR_KICK: |
111 |
phandler->kick (opersvs.nick, targchan, cu->user->nick, reason); |
112 |
break; |
113 |
case CLEAR_KILL: |
114 |
phandler->skill (opersvs.nick, cu->user->nick, reason); |
115 |
user_delete (cu->user); |
116 |
break; |
117 |
case CLEAR_GLINE: |
118 |
phandler->kline_sts ("*", "*", cu->user->host, 604800, reason); |
119 |
} |
120 |
} |
121 |
} |
122 |
|
123 |
command_success_nodata (si, _("\2%d\2 matches, \2%d\2 ignores for \2%s\2 on \2%s\2"), matches, ignores, actionstr, targchan); |
124 |
logcommand (si, CMDLOG_ADMIN, "CLEARCHAN %s %s %s (%d matches, %d ignores)", actionstr, targchan, treason, matches, ignores); |
125 |
} |
126 |
|
127 |
bool |
128 |
_modinit (module *m) |
129 |
{ |
130 |
os_cmdtree << os_clearchan; |
131 |
help_addentry (os_helptree, "CLEARCHAN", "help/operserv/clearchan", NULL); |
132 |
|
133 |
return true; |
134 |
} |
135 |
|
136 |
void |
137 |
_moddeinit (void) |
138 |
{ |
139 |
os_cmdtree >> os_clearchan; |
140 |
help_delentry (os_helptree, "CLEARCHAN"); |
141 |
} |