1
0
Fork 0

When Client sends message longer than 256 bytes, kick him instead of handling message (#4514)

* Wrong overload of function push() got called when pushing a cEntity*.
Using a const cEntity * fixes this.

* Fixed accidental wrong indentation

* Compiler didn't like old style cast

* Kicking player when writing chat message longer than 2048

* Accounted for Astrings size() method returning bits, not bytes

* Fixed typo

* Changed MAX_STRING_SIZE to 1024, removed unnecessary division by 8

* Handling message length check in cClientHandle:HandleChat

* Guard clause instead of if else

* Remove stale changes

* Fixed formatting

Co-authored-by: mluchterhand <mluchterhand@max.de>
Co-authored-by: Peter Bell <peterbell10@live.co.uk>
Co-authored-by: Mattes D <github@xoft.cz>
This commit is contained in:
Max Luchterhand 2020-03-24 09:39:54 +01:00 committed by GitHub
parent 0d0d019bbe
commit 08a9991b5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -43,6 +43,9 @@
/** Maximum number of block change interactions a player can perform per tick - exceeding this causes a kick */
#define MAX_BLOCK_CHANGE_INTERACTIONS 20
/** Maximum number of bytes that a chat message sent by a player may consist of */
#define MAX_CHAT_MSG_LENGTH 1024
/** The interval for sending pings to clients.
Vanilla sends one ping every 1 second. */
static const std::chrono::milliseconds PING_TIME_MS = std::chrono::milliseconds(1000);
@ -1549,6 +1552,13 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
void cClientHandle::HandleChat(const AString & a_Message)
{
if ((a_Message.size()) > MAX_CHAT_MSG_LENGTH)
{
this->Kick(std::string("Please don't exceed the maximum message length of ")
+ std::to_string(MAX_CHAT_MSG_LENGTH)
);
return;
}
// We no longer need to postpone message processing, because the messages already arrive in the Tick thread
// If a command, perform it: