Skip to content

Commit 0891116

Browse files
rubenwardynerzhul
authored andcommittedJan 25, 2017
Block spam messages before calling on_chatmessage callbacks (#4805)
Fixes #4799
1 parent 33e0eed commit 0891116

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed
 

Diff for: ‎src/server.cpp

+20-19
Original file line numberDiff line numberDiff line change
@@ -2790,40 +2790,41 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
27902790
RollbackScopeActor rollback_scope(m_rollback,
27912791
std::string("player:") + name);
27922792

2793-
// Line to send
2794-
std::wstring line;
2795-
// Whether to send line to the player that sent the message, or to all players
2796-
bool broadcast_line = true;
2797-
2798-
// Run script hook
2799-
bool ate = m_script->on_chat_message(name,
2800-
wide_to_utf8(wmessage));
2801-
// If script ate the message, don't proceed
2802-
if (ate)
2803-
return L"";
2804-
28052793
if (player) {
28062794
switch (player->canSendChatMessage()) {
28072795
case RPLAYER_CHATRESULT_FLOODING: {
28082796
std::wstringstream ws;
28092797
ws << L"You cannot send more messages. You are limited to "
2810-
<< g_settings->getFloat("chat_message_limit_per_10sec")
2811-
<< L" messages per 10 seconds.";
2798+
<< g_settings->getFloat("chat_message_limit_per_10sec")
2799+
<< L" messages per 10 seconds.";
28122800
return ws.str();
28132801
}
28142802
case RPLAYER_CHATRESULT_KICK:
2815-
DenyAccess_Legacy(player->peer_id, L"You have been kicked due to message flooding.");
2803+
DenyAccess_Legacy(player->peer_id,
2804+
L"You have been kicked due to message flooding.");
28162805
return L"";
2817-
case RPLAYER_CHATRESULT_OK: break;
2818-
default: FATAL_ERROR("Unhandled chat filtering result found.");
2806+
case RPLAYER_CHATRESULT_OK:
2807+
break;
2808+
default:
2809+
FATAL_ERROR("Unhandled chat filtering result found.");
28192810
}
28202811
}
28212812

2822-
if (m_max_chatmessage_length > 0 && wmessage.length() > m_max_chatmessage_length) {
2813+
if (m_max_chatmessage_length > 0
2814+
&& wmessage.length() > m_max_chatmessage_length) {
28232815
return L"Your message exceed the maximum chat message limit set on the server. "
2824-
L"It was refused. Send a shorter message";
2816+
L"It was refused. Send a shorter message";
28252817
}
28262818

2819+
// Run script hook, exit if script ate the chat message
2820+
if (m_script->on_chat_message(name, wide_to_utf8(wmessage)))
2821+
return L"";
2822+
2823+
// Line to send
2824+
std::wstring line;
2825+
// Whether to send line to the player that sent the message, or to all players
2826+
bool broadcast_line = true;
2827+
28272828
// Commands are implemented in Lua, so only catch invalid
28282829
// commands that were not "eaten" and send an error back
28292830
if (wmessage[0] == L'/') {

0 commit comments

Comments
 (0)
Please sign in to comment.