improved geometry debloating, also apply on skin changes

This commit is contained in:
Dylan K. Taylor 2017-10-29 12:14:16 +00:00
parent 600d80331a
commit 991d321928
3 changed files with 16 additions and 12 deletions

View File

@ -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");

View File

@ -126,6 +126,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
}
$this->skin = $skin;
$this->skin->debloatGeometryData();
}
/**

View File

@ -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));
}
}
}