Fixed the disaster of packet receive error handling

This commit is contained in:
Dylan K. Taylor
2019-01-16 19:52:41 +00:00
parent ddc2bed63f
commit 23269da1a6
19 changed files with 126 additions and 55 deletions

View File

@ -28,6 +28,7 @@ use pocketmine\inventory\transaction\CraftingTransaction;
use pocketmine\inventory\transaction\InventoryTransaction;
use pocketmine\inventory\transaction\TransactionValidationException;
use pocketmine\math\Vector3;
use pocketmine\network\BadPacketException;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
@ -454,6 +455,7 @@ class SimpleSessionHandler extends SessionHandler{
* @param bool $assoc
*
* @return mixed
* @throws BadPacketException
*/
private static function stupid_json_decode(string $json, bool $assoc = false){
if(preg_match('/^\[(.+)\]$/s', $json, $matches) > 0){
@ -468,7 +470,7 @@ class SimpleSessionHandler extends SessionHandler{
$fixed = "[" . implode(",", $parts) . "]";
if(($ret = json_decode($fixed, $assoc)) === null){
throw new \InvalidArgumentException("Failed to fix JSON: " . json_last_error_msg() . "(original: $json, modified: $fixed)");
throw new BadPacketException("Failed to fix JSON: " . json_last_error_msg() . "(original: $json, modified: $fixed)");
}
return $ret;