Make use of BadPacketException::wrap()

This commit is contained in:
Dylan K. Taylor 2020-03-23 21:28:38 +00:00
parent 2d46ae4476
commit 3e5d3a646b
5 changed files with 10 additions and 10 deletions

View File

@ -271,7 +271,7 @@ class NetworkSession{
$payload = $this->cipher->decrypt($payload);
}catch(\UnexpectedValueException $e){
$this->logger->debug("Encrypted packet: " . base64_encode($payload));
throw new BadPacketException("Packet decryption error: " . $e->getMessage(), 0, $e);
throw BadPacketException::wrap($e, "Packet decryption error");
}finally{
Timings::$playerNetworkReceiveDecryptTimer->stopTiming();
}
@ -283,7 +283,7 @@ class NetworkSession{
}catch(\ErrorException $e){
$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);
throw BadPacketException::wrap($e, "Compressed packet batch decode error");
}finally{
Timings::$playerNetworkReceiveDecompressTimer->stopTiming();
}
@ -297,14 +297,14 @@ class NetworkSession{
$pk = $stream->getPacket();
}catch(BinaryDataException $e){
$this->logger->debug("Packet batch: " . base64_encode($stream->getBuffer()));
throw new BadPacketException("Packet batch decode error: " . $e->getMessage(), 0, $e);
throw BadPacketException::wrap($e, "Packet batch decode error");
}
try{
$this->handleDataPacket($pk);
}catch(BadPacketException $e){
$this->logger->debug($pk->getName() . ": " . base64_encode($pk->getBinaryStream()->getBuffer()));
throw new BadPacketException("Error processing " . $pk->getName() . ": " . $e->getMessage(), 0, $e);
throw BadPacketException::wrap($e, "Error processing " . $pk->getName());
}
}
}

View File

@ -544,7 +544,7 @@ class InGamePacketHandler extends PacketHandler{
$offset = 0;
$nbt = (new NetworkNbtSerializer())->read($packet->namedtag, $offset, 512)->mustGetCompoundTag();
}catch(NbtDataException $e){
throw new BadPacketException($e->getMessage(), 0, $e);
throw BadPacketException::wrap($e);
}
if($block instanceof Sign){
@ -552,7 +552,7 @@ class InGamePacketHandler extends PacketHandler{
try{
$text = SignText::fromBlob($nbt->getString("Text"));
}catch(\InvalidArgumentException $e){
throw new BadPacketException("Invalid sign text update: " . $e->getMessage(), 0, $e);
throw BadPacketException::wrap($e, "Invalid sign text update");
}
try{
@ -560,7 +560,7 @@ class InGamePacketHandler extends PacketHandler{
$this->player->getWorld()->sendBlocks([$this->player], [$pos]);
}
}catch(\UnexpectedValueException $e){
throw new BadPacketException($e->getMessage(), 0, $e);
throw BadPacketException::wrap($e);
}
return true;

View File

@ -198,7 +198,7 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{
$attr->setMaxValue($max);
$attr->setValue($current);
}catch(\InvalidArgumentException $e){
throw new BadPacketException($e->getMessage(), 0, $e); //TODO: address this properly
throw BadPacketException::wrap($e); //TODO: address this properly
}
$this->attributes[] = $attr;
}else{

View File

@ -128,7 +128,7 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{
try{
$entry["input"] = ItemFactory::get($inputId, $inputData);
}catch(\InvalidArgumentException $e){
throw new BadPacketException($e->getMessage(), 0, $e);
throw BadPacketException::wrap($e);
}
$entry["output"] = $out = $in->getSlot();
if($out->getMeta() === 0x7fff){

View File

@ -82,7 +82,7 @@ abstract class DataPacket implements Packet{
$this->decodeHeader($this->buf);
$this->decodePayload($this->buf);
}catch(BinaryDataException | BadPacketException $e){
throw new BadPacketException($this->getName() . ": " . $e->getMessage(), 0, $e);
throw BadPacketException::wrap($e, $this->getName());
}
}