diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index a1e872cb3..beff79f6a 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -29,7 +29,7 @@ namespace pocketmine\network; use pocketmine\event\server\NetworkInterfaceRegisterEvent; use pocketmine\event\server\NetworkInterfaceUnregisterEvent; use pocketmine\network\mcpe\protocol\PacketPool; -use function bin2hex; +use function base64_encode; use function get_class; use function preg_match; use function spl_object_id; @@ -248,7 +248,7 @@ class Network{ } } if(!$handled){ - $this->logger->debug("Unhandled raw packet from /$address:$port: " . bin2hex($packet)); + $this->logger->debug("Unhandled raw packet from /$address:$port: " . base64_encode($packet)); } } } diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 8f1cc66a5..943b8584a 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -80,6 +80,7 @@ use pocketmine\utils\BinaryDataException; use pocketmine\utils\Utils; use pocketmine\world\Position; use function array_map; +use function base64_encode; use function bin2hex; use function count; use function get_class; @@ -265,7 +266,7 @@ class NetworkSession{ try{ $payload = $this->cipher->decrypt($payload); }catch(\UnexpectedValueException $e){ - $this->logger->debug("Encrypted packet: " . bin2hex($payload)); + $this->logger->debug("Encrypted packet: " . base64_encode($payload)); throw new BadPacketException("Packet decryption error: " . $e->getMessage(), 0, $e); }finally{ Timings::$playerNetworkReceiveDecryptTimer->stopTiming(); @@ -276,7 +277,7 @@ class NetworkSession{ try{ $stream = new PacketBatch(NetworkCompression::decompress($payload)); }catch(\ErrorException $e){ - $this->logger->debug("Failed to decompress packet: " . bin2hex($payload)); + $this->logger->debug("Failed to decompress packet: " . base64_encode($payload)); //TODO: this isn't incompatible game version if we already established protocol version throw new BadPacketException("Compressed packet batch decode error: " . $e->getMessage(), 0, $e); }finally{ @@ -291,14 +292,14 @@ class NetworkSession{ try{ $pk = $stream->getPacket(); }catch(BinaryDataException $e){ - $this->logger->debug("Packet batch: " . bin2hex($stream->getBuffer())); + $this->logger->debug("Packet batch: " . base64_encode($stream->getBuffer())); throw new BadPacketException("Packet batch decode error: " . $e->getMessage(), 0, $e); } try{ $this->handleDataPacket($pk); }catch(BadPacketException $e){ - $this->logger->debug($pk->getName() . ": " . bin2hex($pk->getBuffer())); + $this->logger->debug($pk->getName() . ": " . base64_encode($pk->getBuffer())); throw new BadPacketException("Error processing " . $pk->getName() . ": " . $e->getMessage(), 0, $e); } } @@ -327,7 +328,7 @@ class NetworkSession{ $ev = new DataPacketReceiveEvent($this, $packet); $ev->call(); if(!$ev->isCancelled() and !$packet->handle($this->handler)){ - $this->logger->debug("Unhandled " . $packet->getName() . ": " . bin2hex($packet->getBuffer())); + $this->logger->debug("Unhandled " . $packet->getName() . ": " . base64_encode($packet->getBuffer())); } }finally{ $timings->stopTiming(); diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 542b1a79f..08e824fd2 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -44,7 +44,6 @@ use function file; use function file_exists; use function file_get_contents; use function function_exists; -use function get_class; use function get_current_user; use function get_loaded_extensions; use function getenv; @@ -76,7 +75,6 @@ use function str_split; use function stripos; use function strlen; use function strpos; -use function strval; use function substr; use function sys_get_temp_dir; use function trim; @@ -405,10 +403,11 @@ class Utils{ /** * @param array $trace + * @param int $maxStringLength * * @return array */ - public static function printableTrace(array $trace) : array{ + public static function printableTrace(array $trace, int $maxStringLength = 80) : array{ $messages = []; for($i = 0; isset($trace[$i]); ++$i){ $params = ""; @@ -419,8 +418,17 @@ class Utils{ $args = $trace[$i]["params"]; } - $params = implode(", ", array_map(function($value){ - return (is_object($value) ? get_class($value) . " object" : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value)))); + $params = implode(", ", array_map(function($value) use($maxStringLength){ + if(is_object($value)){ + return "object " . self::getNiceClassName($value); + } + if(is_array($value)){ + return "array[" . count($value) . "]"; + } + if(is_string($value)){ + return "string[" . strlen($value) . "] " . substr(Utils::printable($value), 0, $maxStringLength); + } + return gettype($value) . " " . Utils::printable((string) $value); }, $args)); } $messages[] = "#$i " . (isset($trace[$i]["file"]) ? self::cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable($params) . ")";