mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Merge branch 'mcpe-1.6' into mcpe-1.6-master
This commit is contained in:
@ -103,6 +103,13 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
*/
|
||||
public $commandData = [];
|
||||
|
||||
/**
|
||||
* @var CommandEnum[]
|
||||
* List of dynamic command enums, also referred to as "soft" enums. These can by dynamically updated mid-game
|
||||
* without resending this packet.
|
||||
*/
|
||||
public $softEnums = [];
|
||||
|
||||
protected function decodePayload() : void{
|
||||
for($i = 0, $this->enumValuesCount = $this->getUnsignedVarInt(); $i < $this->enumValuesCount; ++$i){
|
||||
$this->enumValues[] = $this->getString();
|
||||
@ -119,6 +126,10 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
||||
$this->commandData[] = $this->getCommandData();
|
||||
}
|
||||
|
||||
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
||||
$this->softEnums[] = $this->getSoftEnum();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getEnum() : CommandEnum{
|
||||
@ -133,6 +144,18 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
return $retval;
|
||||
}
|
||||
|
||||
protected function getSoftEnum() : CommandEnum{
|
||||
$retval = new CommandEnum();
|
||||
$retval->enumName = $this->getString();
|
||||
|
||||
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){
|
||||
//Get the enum value from the initial pile of mess
|
||||
$retval->enumValues[] = $this->getString();
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
protected function putEnum(CommandEnum $enum) : void{
|
||||
$this->putString($enum->enumName);
|
||||
|
||||
@ -147,6 +170,15 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
}
|
||||
}
|
||||
|
||||
protected function putSoftEnum(CommandEnum $enum) : void{
|
||||
$this->putString($enum->enumName);
|
||||
|
||||
$this->putUnsignedVarInt(count($enum->enumValues));
|
||||
foreach($enum->enumValues as $value){
|
||||
$this->putString($value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getEnumValueIndex() : int{
|
||||
if($this->enumValuesCount < 256){
|
||||
return $this->getByte();
|
||||
@ -185,13 +217,17 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
if($parameter->paramType & self::ARG_FLAG_ENUM){
|
||||
$index = ($parameter->paramType & 0xffff);
|
||||
$parameter->enum = $this->enums[$index] ?? null;
|
||||
|
||||
assert($parameter->enum !== null, "expected enum at $index, but got none");
|
||||
}elseif(($parameter->paramType & self::ARG_FLAG_VALID) === 0){ //postfix (guessing)
|
||||
if($parameter->enum === null){
|
||||
throw new \UnexpectedValueException("expected enum at $index, but got none");
|
||||
}
|
||||
}elseif($parameter->paramType & self::ARG_FLAG_POSTFIX){
|
||||
$index = ($parameter->paramType & 0xffff);
|
||||
$parameter->postfix = $this->postfixes[$index] ?? null;
|
||||
|
||||
assert($parameter->postfix !== null, "expected postfix at $index, but got none");
|
||||
if($parameter->postfix === null){
|
||||
throw new \UnexpectedValueException("expected postfix at $index, but got none");
|
||||
}
|
||||
}elseif(($parameter->paramType & self::ARG_FLAG_VALID) === 0){
|
||||
throw new \UnexpectedValueException("Invalid parameter type 0x" . dechex($parameter->paramType));
|
||||
}
|
||||
|
||||
$retval->overloads[$overloadIndex][$paramIndex] = $parameter;
|
||||
@ -227,7 +263,7 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
if($key === false){
|
||||
throw new \InvalidStateException("Postfix '$parameter->postfix' not in postfixes array");
|
||||
}
|
||||
$type = $parameter->paramType << 24 | $key;
|
||||
$type = self::ARG_FLAG_POSTFIX | $key;
|
||||
}else{
|
||||
$type = $parameter->paramType;
|
||||
}
|
||||
@ -266,13 +302,12 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
case self::ARG_TYPE_COMMAND:
|
||||
return "command";
|
||||
}
|
||||
}elseif($argtype !== 0){
|
||||
//guessed
|
||||
$baseType = $argtype >> 24;
|
||||
$typeName = $this->argTypeToString(self::ARG_FLAG_VALID | $baseType);
|
||||
}elseif($argtype & self::ARG_FLAG_POSTFIX){
|
||||
$postfix = $this->postfixes[$argtype & 0xffff];
|
||||
|
||||
return $typeName . " (postfix $postfix)";
|
||||
return "int (postfix $postfix)";
|
||||
}else{
|
||||
throw new \UnexpectedValueException("Unknown arg type 0x" . dechex($argtype));
|
||||
}
|
||||
|
||||
return "unknown ($argtype)";
|
||||
@ -334,6 +369,11 @@ class AvailableCommandsPacket extends DataPacket{
|
||||
foreach($this->commandData as $data){
|
||||
$this->putCommandData($data);
|
||||
}
|
||||
|
||||
$this->putUnsignedVarInt(count($this->softEnums));
|
||||
foreach($this->softEnums as $enum){
|
||||
$this->putSoftEnum($enum);
|
||||
}
|
||||
}
|
||||
|
||||
public function handle(SessionHandler $handler) : bool{
|
||||
|
Reference in New Issue
Block a user