Skip to content

Commit

Permalink
Fix #320 - Parameters type names are now visible
Browse files Browse the repository at this point in the history
  • Loading branch information
kvetinac97 authored Aug 13, 2017
1 parent a10f4b0 commit 6093966
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/pocketmine/network/protocol/AvailableCommandsPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public function encode($playerProtocol){
}
}

const ARG_FLAG_VALID = 0x100000;
const ARG_TYPE_INT = 0x01;
const ARG_TYPE_FLOAT = 0x02;
const ARG_TYPE_VALUE = 0x03;
const ARG_TYPE_TARGET = 0x04;
const ARG_TYPE_STRING = 0x0c;
const ARG_TYPE_POSITION = 0x0d;
const ARG_TYPE_RAWTEXT = 0x10;
const ARG_TYPE_TEXT = 0x12;
const ARG_TYPE_JSON = 0x15;
const ARG_TYPE_COMMAND = 0x1c;

public static function prepareCommands($commands) {
self::$commandsBuffer['default'] = json_encode($commands);

Expand Down Expand Up @@ -87,7 +99,7 @@ public static function prepareCommands($commands) {
$commandsStream->putVarInt(count($overloadData['input']['parameters']));
foreach ($overloadData['input']['parameters'] as $paramData) {
$commandsStream->putString($paramData['name']);
$commandsStream->putLInt(0);
$commandsStream->putLInt(self::ARG_FLAG_VALID | self::getFlag($paramData['type']));
$commandsStream->putByte(isset($paramData['optional']) && $paramData['optional']);
}
}
Expand Down Expand Up @@ -120,4 +132,34 @@ public static function prepareCommands($commands) {
$additionalDataStream->put($commandsStream->buffer);
self::$commandsBuffer[Info::PROTOCOL_120] = $additionalDataStream->buffer;
}
}

/**
* @param string $paramName
* @return int
*/
private static function getFlag($paramName){
switch ($paramName){
case "int":
return self::ARG_TYPE_INT;
case "float":
return self::ARG_TYPE_FLOAT;
case "mixed":
return self::ARG_TYPE_VALUE;
case "target":
return self::ARG_TYPE_TARGET;
case "string":
return self::ARG_TYPE_STRING;
case "xyz":
return self::ARG_TYPE_POSITION;
case "rawtext":
return self::ARG_TYPE_RAWTEXT;
case "text":
return self::ARG_TYPE_TEXT;
case "json":
return self::ARG_TYPE_JSON;
case "command":
return self::ARG_TYPE_COMMAND;
}
return 0;
}
}

2 comments on commit 6093966

@sn3akrr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ur ghey

@Sandertv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yo, you forgot to copy+paste the comments that explained those constants. You might want to do that too.

Please sign in to comment.