From 732591f174fb5ec220a8bf9162387ba61cfe4797 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sun, 28 Aug 2022 12:24:20 +0300 Subject: [PATCH] emojis cant be send in chat anymore --- src/Player.php | 4 ++++ src/utils/Utils.php | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Player.php b/src/Player.php index 7f0b3200..25dc4ca5 100755 --- a/src/Player.php +++ b/src/Player.php @@ -2042,6 +2042,10 @@ class Player{ $this->server->api->console->run(substr($message, 1), $this); }else{ $data = ["player" => $this, "message" => $message]; + if(Utils::hasEmoji($data["message"])){ + $this->sendChat("Your message contains illegal characters"); + break; + } if($this->server->api->handle("player.chat", $data) !== false){ $this->server->send2Discord("<" . $this->username . "> " . $message); if(isset($data["message"])){ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 7e07ad39..80499b6e 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -12,7 +12,7 @@ class Utils{ /*public static function isOnline(){ return ((@fsockopen("8.8.8.8", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.linux.org", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.php.net", 80, $e = null, $n = null, 2) !== false) ? true:false); }*/ - + const emojiRegex = "([*#0-9](?>\\xEF\\xB8\\x8F)?\\xE2\\x83\\xA3|\\xC2[\\xA9\\xAE]|\\xE2..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?(?>\\xEF\\xB8\\x8F)?|\\xE3(?>\\x80[\\xB0\\xBD]|\\x8A[\\x97\\x99])(?>\\xEF\\xB8\\x8F)?|\\xF0\\x9F(?>[\\x80-\\x86].(?>\\xEF\\xB8\\x8F)?|\\x87.\\xF0\\x9F\\x87.|..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?|(((?\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k\\xF0\\x9F..(\k\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))"; public static function getEntityTypeByID($id){ switch($id){ case 10: @@ -38,7 +38,9 @@ class Utils{ } return $id; } - + public static function hasEmoji($s){ + return preg_match(Utils::emojiRegex, $s, $matches); + } public static function getCallableIdentifier(callable $variable){ if(is_array($variable)){ return sha1(strtolower(get_class($variable[0])) . "::" . strtolower($variable[1])); @@ -662,6 +664,7 @@ class Utils{ } return $x; } + } //if(Utils::isOnline() === false){