mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
improved geometry debloating, also apply on skin changes
This commit is contained in:
parent
600d80331a
commit
991d321928
@ -2002,24 +2002,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Mojang, some stupid reason, send every single model for every single skin in the selected skin-pack.
|
||||
* Not only that, they are pretty-printed. This decode/encode is to get rid of the pretty-print, which cuts down
|
||||
* significantly on the amount of wasted bytes.
|
||||
* TODO: find out what model crap can be safely dropped from the packet (unless it gets fixed first)
|
||||
*/
|
||||
|
||||
$geometryJsonEncoded = base64_decode($packet->clientData["SkinGeometry"] ?? "");
|
||||
if($geometryJsonEncoded !== ""){
|
||||
$geometryJsonEncoded = json_encode(json_decode($geometryJsonEncoded));
|
||||
}
|
||||
|
||||
$skin = new Skin(
|
||||
$packet->clientData["SkinId"],
|
||||
base64_decode($packet->clientData["SkinData"] ?? ""),
|
||||
base64_decode($packet->clientData["CapeData"] ?? ""),
|
||||
$packet->clientData["SkinGeometryName"],
|
||||
$geometryJsonEncoded
|
||||
base64_decode($packet->clientData["SkinGeometry"] ?? "")
|
||||
);
|
||||
$skin->debloatGeometryData();
|
||||
|
||||
if(!$skin->isValid()){
|
||||
$this->close("", "disconnectionScreen.invalidSkin");
|
||||
|
@ -126,6 +126,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
}
|
||||
|
||||
$this->skin = $skin;
|
||||
$this->skin->debloatGeometryData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,4 +87,17 @@ class Skin{
|
||||
return $this->geometryData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hack to cut down on network overhead due to skins, by un-pretty-printing geometry JSON.
|
||||
*
|
||||
* Mojang, some stupid reason, send every single model for every single skin in the selected skin-pack.
|
||||
* Not only that, they are pretty-printed.
|
||||
* TODO: find out what model crap can be safely dropped from the packet (unless it gets fixed first)
|
||||
*/
|
||||
public function debloatGeometryData() : void{
|
||||
if($this->geometryData !== ""){
|
||||
$this->geometryData = (string) json_encode(json_decode($this->geometryData));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user