AvailableCommandsPacket: deal with dynamic enums

somehow I missed this, thanks @NiclasOlofsson for pointing it out
This commit is contained in:
Dylan K. Taylor 2018-06-20 17:40:36 +01:00
parent 986077e03c
commit 0d05dcec08

View File

@ -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(){
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){
$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();
@ -334,6 +366,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(NetworkSession $session) : bool{