Merge branch 'stable'

# Conflicts:
#	resources/vanilla
#	src/pocketmine/Server.php
#	src/pocketmine/item/Item.php
#	src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php
#	src/pocketmine/network/mcpe/RakLibInterface.php
#	src/pocketmine/network/query/QueryHandler.php
#	src/pocketmine/utils/Utils.php
This commit is contained in:
Dylan K. Taylor 2019-06-06 15:04:05 +01:00
commit 32c832c87e
3 changed files with 21 additions and 12 deletions

View File

@ -29,7 +29,7 @@ namespace pocketmine\network;
use pocketmine\event\server\NetworkInterfaceRegisterEvent; use pocketmine\event\server\NetworkInterfaceRegisterEvent;
use pocketmine\event\server\NetworkInterfaceUnregisterEvent; use pocketmine\event\server\NetworkInterfaceUnregisterEvent;
use pocketmine\network\mcpe\protocol\PacketPool; use pocketmine\network\mcpe\protocol\PacketPool;
use function bin2hex; use function base64_encode;
use function get_class; use function get_class;
use function preg_match; use function preg_match;
use function spl_object_id; use function spl_object_id;
@ -248,7 +248,7 @@ class Network{
} }
} }
if(!$handled){ 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));
} }
} }
} }

View File

@ -80,6 +80,7 @@ use pocketmine\utils\BinaryDataException;
use pocketmine\utils\Utils; use pocketmine\utils\Utils;
use pocketmine\world\Position; use pocketmine\world\Position;
use function array_map; use function array_map;
use function base64_encode;
use function bin2hex; use function bin2hex;
use function count; use function count;
use function get_class; use function get_class;
@ -265,7 +266,7 @@ class NetworkSession{
try{ try{
$payload = $this->cipher->decrypt($payload); $payload = $this->cipher->decrypt($payload);
}catch(\UnexpectedValueException $e){ }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); throw new BadPacketException("Packet decryption error: " . $e->getMessage(), 0, $e);
}finally{ }finally{
Timings::$playerNetworkReceiveDecryptTimer->stopTiming(); Timings::$playerNetworkReceiveDecryptTimer->stopTiming();
@ -276,7 +277,7 @@ class NetworkSession{
try{ try{
$stream = new PacketBatch(NetworkCompression::decompress($payload)); $stream = new PacketBatch(NetworkCompression::decompress($payload));
}catch(\ErrorException $e){ }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 //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); throw new BadPacketException("Compressed packet batch decode error: " . $e->getMessage(), 0, $e);
}finally{ }finally{
@ -291,14 +292,14 @@ class NetworkSession{
try{ try{
$pk = $stream->getPacket(); $pk = $stream->getPacket();
}catch(BinaryDataException $e){ }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); throw new BadPacketException("Packet batch decode error: " . $e->getMessage(), 0, $e);
} }
try{ try{
$this->handleDataPacket($pk); $this->handleDataPacket($pk);
}catch(BadPacketException $e){ }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); throw new BadPacketException("Error processing " . $pk->getName() . ": " . $e->getMessage(), 0, $e);
} }
} }
@ -327,7 +328,7 @@ class NetworkSession{
$ev = new DataPacketReceiveEvent($this, $packet); $ev = new DataPacketReceiveEvent($this, $packet);
$ev->call(); $ev->call();
if(!$ev->isCancelled() and !$packet->handle($this->handler)){ 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{ }finally{
$timings->stopTiming(); $timings->stopTiming();

View File

@ -44,7 +44,6 @@ use function file;
use function file_exists; use function file_exists;
use function file_get_contents; use function file_get_contents;
use function function_exists; use function function_exists;
use function get_class;
use function get_current_user; use function get_current_user;
use function get_loaded_extensions; use function get_loaded_extensions;
use function getenv; use function getenv;
@ -76,7 +75,6 @@ use function str_split;
use function stripos; use function stripos;
use function strlen; use function strlen;
use function strpos; use function strpos;
use function strval;
use function substr; use function substr;
use function sys_get_temp_dir; use function sys_get_temp_dir;
use function trim; use function trim;
@ -405,10 +403,11 @@ class Utils{
/** /**
* @param array $trace * @param array $trace
* @param int $maxStringLength
* *
* @return array * @return array
*/ */
public static function printableTrace(array $trace) : array{ public static function printableTrace(array $trace, int $maxStringLength = 80) : array{
$messages = []; $messages = [];
for($i = 0; isset($trace[$i]); ++$i){ for($i = 0; isset($trace[$i]); ++$i){
$params = ""; $params = "";
@ -419,8 +418,17 @@ class Utils{
$args = $trace[$i]["params"]; $args = $trace[$i]["params"];
} }
$params = implode(", ", array_map(function($value){ $params = implode(", ", array_map(function($value) use($maxStringLength){
return (is_object($value) ? get_class($value) . " object" : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value)))); 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)); }, $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) . ")"; $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) . ")";