mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Fixed extremely stupid zero-length bug in BinaryStream
pls don't kill me 😢
This commit is contained in:
parent
4765242397
commit
2024e9ecdf
@ -46,7 +46,7 @@ class BatchPacket extends DataPacket{
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->payload = $this->get(0);
|
||||
$this->payload = $this->getRemaining();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
@ -38,7 +38,7 @@ class BlockEntityDataPacket extends DataPacket{
|
||||
|
||||
public function decode(){
|
||||
$this->getBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->namedtag = $this->get(0);
|
||||
$this->namedtag = $this->getRemaining();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
@ -49,7 +49,7 @@ class CommandStepPacket extends DataPacket{
|
||||
$this->inputJson = json_decode($this->getString());
|
||||
$this->outputJson = json_decode($this->getString());
|
||||
|
||||
$this->get(0); //TODO: read command origin data
|
||||
$this->getRemaining(); //TODO: read command origin data
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
@ -45,7 +45,7 @@ class UnknownPacket extends DataPacket{
|
||||
|
||||
public function decode(){
|
||||
$this->offset -= 1; //Rewind one byte so we can read the PID
|
||||
$this->payload = $this->get(0);
|
||||
$this->payload = $this->getRemaining();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
@ -53,7 +53,7 @@ class UpdateTradePacket extends DataPacket{
|
||||
$this->traderEid = $this->getEntityUniqueId();
|
||||
$this->playerEid = $this->getEntityUniqueId();
|
||||
$this->displayName = $this->getString();
|
||||
$this->offers = $this->get(0);
|
||||
$this->offers = $this->getRemaining();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
@ -57,19 +57,32 @@ class BinaryStream{
|
||||
return $this->buffer;
|
||||
}
|
||||
|
||||
public function get(int $len) : string{
|
||||
if($len < 0){
|
||||
$this->offset = strlen($this->buffer) - 1;
|
||||
return "";
|
||||
}elseif($len === 0){
|
||||
/**
|
||||
* @param int|bool $len
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get($len) : string{
|
||||
if($len === true){
|
||||
$str = substr($this->buffer, $this->offset);
|
||||
$this->offset = strlen($this->buffer);
|
||||
return $str;
|
||||
}elseif($len < 0){
|
||||
$this->offset = strlen($this->buffer) - 1;
|
||||
return "";
|
||||
}elseif($len === 0){
|
||||
return "";
|
||||
}
|
||||
|
||||
return $len === 1 ? $this->buffer{$this->offset++} : substr($this->buffer, ($this->offset += $len) - $len, $len);
|
||||
}
|
||||
|
||||
public function getRemaining() : string{
|
||||
$str = substr($this->buffer, $this->offset);
|
||||
$this->offset = strlen($this->buffer);
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function put(string $str){
|
||||
$this->buffer .= $str;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user