/
m_blockhighlight.cpp
138 lines (114 loc) · 4.06 KB
/
m_blockhighlight.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2017 Sadie Powell <sadie@witchery.services>
* Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $ModAuthor: Sadie Powell */
/* $ModAuthorMail: sadie@witchery.services */
/* $ModConfig: <blockhighlight ignoreextmsg="yes" minlen="50" minusernum="10" reason="Mass highlight spam is not allowed" stripcolor="yes"> */
/* $ModDesc: Adds a channel mode which kills clients that mass highlight spam. */
/* $ModDepends: core 2.0 */
#include "inspircd.h"
class ModuleBlockHighlight : public Module
{
SimpleChannelModeHandler mode;
bool ignoreextmsg;
unsigned int minlen;
unsigned int minusers;
std::string reason;
bool stripcolor;
public:
ModuleBlockHighlight()
: mode(this, "blockhighlight", 'V')
{
}
void init()
{
OnRehash(NULL);
Implementation eventList[] = { I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice };
ServerInstance->Modules->Attach(eventList, this, sizeof(eventList)/sizeof(Implementation));
ServerInstance->Modules->AddService(mode);
}
void OnRehash(User*)
{
ConfigTag* tag = ServerInstance->Config->ConfValue("blockhighlight");
ignoreextmsg = tag->getBool("ignoreextmsg", true);
minlen = tag->getInt("minlen", 50);
minusers = tag->getInt("minusernum", 10);
reason = tag->getString("reason", "Mass highlight spam is not allowed");
stripcolor = tag->getBool("stripcolor", true);
if (minlen < 1)
minlen = 1;
if (minusers < 2)
minusers = 2;
}
ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list)
{
if ((target_type != TYPE_CHANNEL) || (!IS_LOCAL(user)))
return MOD_RES_PASSTHRU;
// Must be at least minlen long
if (text.length() < minlen)
return MOD_RES_PASSTHRU;
Channel* const chan = static_cast<Channel*>(dest);
if (chan->GetUsers()->size() < minusers)
return MOD_RES_PASSTHRU;
// We only work if the channel mode is enabled.
if (!chan->IsModeSet(mode.GetModeChar()))
return MOD_RES_PASSTHRU;
// Exempt operators with the channels/mass-highlight privilege.
if (user->HasPrivPermission("channels/mass-highlight"))
return MOD_RES_PASSTHRU;
// Exempt users who match a blockhighlight entry.
if (ServerInstance->OnCheckExemption(user, chan, "blockhighlight") == MOD_RES_ALLOW)
return MOD_RES_PASSTHRU;
// Prevent the enumeration of channel members if enabled.
if (!chan->IsModeSet('n') && !chan->HasUser(user) && ignoreextmsg)
return MOD_RES_PASSTHRU;
std::string message = text;
if (stripcolor)
InspIRCd::StripColor(message);
irc::spacesepstream ss(message);
unsigned int count = 0;
for (std::string token; ss.GetToken(token); )
{
// Chop off trailing :
if ((token.length() > 1) && (token[token.length()-1] == ':'))
token.erase(token.length()-1);
User* const highlighted = ServerInstance->FindNickOnly(token);
if (!highlighted)
continue;
if (!chan->HasUser(highlighted))
continue;
// Highlighted someone
count++;
if (count >= minusers)
{
ServerInstance->Users->QuitUser(user, reason);
return MOD_RES_DENY;
}
}
return MOD_RES_PASSTHRU;
}
ModResult OnUserPreNotice(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list)
{
return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
}
Version GetVersion()
{
return Version("Adds a channel mode which kills clients that mass highlight spam.");
}
};
MODULE_INIT(ModuleBlockHighlight)