Use base64 instead of hex to display binary in some places

base64 takes less space than hex, which is beneficial for logging larger payloads.
This commit is contained in:
Dylan K. Taylor 2019-06-06 14:43:20 +01:00
parent 80f8a27094
commit eb161f8e1c
5 changed files with 8 additions and 9 deletions

View File

@ -112,7 +112,6 @@ use function array_sum;
use function asort;
use function assert;
use function base64_encode;
use function bin2hex;
use function class_exists;
use function count;
use function define;
@ -2528,7 +2527,7 @@ class Server{
if(strlen($payload) > 2 and substr($payload, 0, 2) === "\xfe\xfd" and $this->queryHandler instanceof QueryHandler){
$this->queryHandler->handle($interface, $address, $port, $payload);
}else{
$this->logger->debug("Unhandled raw packet from $address $port: " . bin2hex($payload));
$this->logger->debug("Unhandled raw packet from $address $port: " . base64_encode($payload));
}
}catch(\Throwable $e){
$this->logger->logException($e);

View File

@ -46,7 +46,6 @@ use pocketmine\utils\Binary;
use function array_map;
use function base64_decode;
use function base64_encode;
use function bin2hex;
use function file_get_contents;
use function get_class;
use function hex2bin;
@ -874,7 +873,7 @@ class Item implements ItemIds, \JsonSerializable{
* @return string
*/
final public function __toString() : string{
return "Item " . $this->name . " (" . $this->id . ":" . ($this->hasAnyDamageValue() ? "?" : $this->meta) . ")x" . $this->count . ($this->hasCompoundTag() ? " tags:0x" . bin2hex($this->getCompoundTag()) : "");
return "Item " . $this->name . " (" . $this->id . ":" . ($this->hasAnyDamageValue() ? "?" : $this->meta) . ")x" . $this->count . ($this->hasCompoundTag() ? " tags:" . base64_encode($this->getCompoundTag()) : "");
}
/**

View File

@ -68,6 +68,7 @@ use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\timings\Timings;
use function base64_encode;
use function bin2hex;
use function implode;
use function json_decode;
@ -107,7 +108,7 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
$ev = new DataPacketReceiveEvent($this->player, $packet);
$ev->call();
if(!$ev->isCancelled() and !$packet->handle($this)){
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer));
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": " . base64_encode($packet->buffer));
}
$timings->stopTiming();

View File

@ -40,7 +40,7 @@ use raklib\server\ServerHandler;
use raklib\server\ServerInstance;
use raklib\utils\InternetAddress;
use function addcslashes;
use function bin2hex;
use function base64_encode;
use function get_class;
use function implode;
use function rtrim;
@ -170,7 +170,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
}
}catch(\Throwable $e){
$logger = $this->server->getLogger();
$logger->debug("Packet " . (isset($pk) ? get_class($pk) : "unknown") . " 0x" . bin2hex($packet->buffer));
$logger->debug("Packet " . (isset($pk) ? get_class($pk) : "unknown") . ": " . base64_encode($packet->buffer));
$logger->logException($e);
$player->close($player->getLeaveMessage(), "Internal server error");

View File

@ -30,7 +30,7 @@ namespace pocketmine\network\query;
use pocketmine\network\AdvancedSourceInterface;
use pocketmine\Server;
use pocketmine\utils\Binary;
use function bin2hex;
use function base64_encode;
use function chr;
use function hash;
use function microtime;
@ -134,7 +134,7 @@ class QueryHandler{
$interface->sendRawPacket($address, $port, $reply);
break;
default:
$this->debug("Unhandled packet from $address $port: 0x" . bin2hex($packet));
$this->debug("Unhandled packet from $address $port: " . base64_encode($packet));
break;
}
}