Debian Codegraph @

modules/operserv/clearchan.c

raw
1 /*
2 * Copyright (c) 2006 Robin Burchell <[email protected]>
3 * Rights to this code are documented in doc/LICENCE.
4 *
5 * This file contains functionality implementing OperServ CLEARCHAN.
6 *
7 *
8 * Default AKILL time is 7 days (604800 seconds)
9 *
10 */
11
12 #include "atheme.h"
13
14 DECLARE_MODULE_V1
15 (
16 "operserv/clearchan", false, _modinit, _moddeinit,
17 PACKAGE_STRING,
18 "Robin Burchell <[email protected]>"
19 );
20
21 #define CLEAR_KICK 1
22 #define CLEAR_KILL 2
23 #define CLEAR_AKILL 3
24
25 static void os_cmd_clearchan(sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t os_clearchan = { "CLEARCHAN", N_("Clears a channel via KICK, KILL or AKILL"), PRIV_CHAN_ADMIN, 3, os_cmd_clearchan, { .path = "oservice/clearchan" } };
28
29 void _modinit(module_t *m)
30 {
31 service_named_bind_command("operserv", &os_clearchan);
32 }
33
34 void _moddeinit(module_unload_intent_t intent)
35 {
36 service_named_unbind_command("operserv", &os_clearchan);
37 }
38
39 static void os_cmd_clearchan(sourceinfo_t *si, int parc, char *parv[])
40 {
41 chanuser_t *cu = NULL;
42 mowgli_node_t *n, *tn;
43 channel_t *c = NULL;
44 int action;
45 char *actionstr = parv[0];
46 char *targchan = parv[1];
47 char *treason = parv[2];
48 char reason[512];
49 int matches = 0;
50 int ignores = 0;
51 kline_t *k;
52
53 if (!actionstr || !targchan || !treason)
54 {
55 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "CLEARCHAN");
56 command_fail(si, fault_needmoreparams, _("Syntax: CLEARCHAN KICK|KILL|AKILL <#channel> <reason>"));
57 return;
58 }
59
60 c = channel_find(targchan);
61
62 if (!c)
63 {
64 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 does not exist."), targchan);
65 return;
66 }
67
68 /* check what they are doing is valid */
69 if (!strcasecmp(actionstr, "KICK"))
70 action = CLEAR_KICK;
71 else if (!strcasecmp(actionstr, "KILL"))
72 action = CLEAR_KILL;
73 else if (!strcasecmp(actionstr, "AKILL") || !strcasecmp(actionstr, "GLINE") || !strcasecmp(actionstr, "KLINE"))
74 action = CLEAR_AKILL;
75 else
76 {
77 /* not valid! */
78 command_fail(si, fault_badparams, _("\2%s\2 is not a valid action"), actionstr);
79 return;
80 }
81
82 if (action != CLEAR_KICK && !has_priv(si, PRIV_MASS_AKILL))
83 {
84 command_fail(si, fault_noprivs, STR_NO_PRIVILEGE, PRIV_MASS_AKILL);
85 return;
86 }
87
88 if (action == CLEAR_KICK)
89 snprintf(reason, sizeof reason, "(Clearing) %s", treason);
90 else
91 snprintf(reason, sizeof reason, "(Clearing %s) %s", targchan, treason);
92
93 wallops("\2%s\2 is clearing channel %s with %s",
94 get_oper_name(si), targchan, actionstr);
95 command_success_nodata(si, _("Clearing \2%s\2 with \2%s\2"), targchan, actionstr);
96
97 /* iterate over the users in channel */
98 MOWGLI_ITER_FOREACH_SAFE(n, tn, c->members.head)
99 {
100 cu = n->data;
101
102 if (is_internal_client(cu->user))
103 ;
104 else if (is_ircop(cu->user))
105 {
106 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);
107 ignores++;
108 }
109 else
110 {
111 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);
112 matches++;
113
114 switch (action)
115 {
116 case CLEAR_KICK:
117 kick(si->service->me, c, cu->user, reason);
118 break;
119 case CLEAR_KILL:
120 kill_user(si->service->me, cu->user, "%s", reason);
121 break;
122 case CLEAR_AKILL:
123 if (is_autokline_exempt(cu->user)) {
124 command_success_nodata(si, _("\2CLEARCHAN\2: Not klining exempt user %s!%s@%s"),
125 cu->user->nick, cu->user->user, cu->user->host);
126 } else {
127 if (! (cu->user->flags & UF_KLINESENT)) {
128 k = kline_add(cu->user->user, cu->user->host, reason, 604800, "*");
129 cu->user->flags |= UF_KLINESENT;
130 }
131 }
132 }
133 }
134 }
135
136 command_success_nodata(si, _("\2%d\2 matches, \2%d\2 ignores for \2%s\2 on \2%s\2"), matches, ignores, actionstr, targchan);
137 logcommand(si, CMDLOG_ADMIN, "CLEARCHAN: \2%s\2 \2%s\2 (reason: \2%s\2) (\2%d\2 matches, \2%d\2 ignores)", actionstr, targchan, treason, matches, ignores);
138 }
139
140 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
141 * vim:ts=8
142 * vim:sw=8
143 * vim:noexpandtab
144 */