Player: move max chat length to constant

This commit is contained in:
Dylan K. Taylor 2021-12-27 17:06:19 +00:00
parent f5144d49b1
commit 74ac0f5862
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -160,6 +160,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
private const MOVES_PER_TICK = 2;
private const MOVE_BACKLOG_SIZE = 100 * self::MOVES_PER_TICK; //100 ticks backlog (5 seconds)
/** Max length of a chat message (UTF-8 codepoints, not bytes) */
private const MAX_CHAT_CHAR_LENGTH = 512;
/**
* Validates the given username.
*/
@ -1335,7 +1338,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$message = TextFormat::clean($message, false);
foreach(explode("\n", $message) as $messagePart){
if(trim($messagePart) !== "" and mb_strlen($messagePart, 'UTF-8') <= 512 and $this->messageCounter-- > 0){
if(trim($messagePart) !== "" and mb_strlen($messagePart, 'UTF-8') <= self::MAX_CHAT_CHAR_LENGTH and $this->messageCounter-- > 0){
if(strpos($messagePart, './') === 0){
$messagePart = substr($messagePart, 1);
}