From 801e924783b1154543e564563a5de136ad5e95bb Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 6 Mar 2014 23:38:46 +0100 Subject: [PATCH] Comments --- src/utils/Utils.php | 55 +++++++++++++++++++++++++++++++------ src/utils/VersionString.php | 6 ++++ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 5703d24bc..6131c81f2 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -601,6 +601,14 @@ class Utils{ return Utils::writeByte($b === true ? 1 : 0); } + /** + * Reads an unsigned/signed byte + * + * @param $c + * @param bool $signed + * + * @return int + */ public static function readByte($c, $signed = true){ $b = ord($c{0}); if($signed === true and ($b & 0x80) === 0x80){ //calculate Two's complement @@ -610,6 +618,13 @@ class Utils{ return $b; } + /** + * Writes an unsigned/signed byte + * + * @param $c + * + * @return bool|string + */ public static function writeByte($c){ if($c > 0xff){ return false; @@ -621,6 +636,14 @@ class Utils{ return chr($c); } + /** + * Reads a 16-bit signed/unsigned big-endian number + * + * @param $str + * @param bool $signed + * + * @return int + */ public static function readShort($str, $signed = true){ list(, $unpacked) = @unpack("n", $str); if($unpacked > 0x7fff and $signed === true){ @@ -630,6 +653,13 @@ class Utils{ return $unpacked; } + /** + * Writes a 16-bit signed/unsigned big-endian number + * + * @param $value + * + * @return string + */ public static function writeShort($value){ if($value < 0){ $value += 0x10000; @@ -638,6 +668,14 @@ class Utils{ return pack("n", $value); } + /** + * Reads a 16-bit signed/unsigned little-endian number + * + * @param $str + * @param bool $signed + * + * @return int + */ public static function readLShort($str, $signed = true){ list(, $unpacked) = @unpack("v", $str); if($unpacked > 0x7fff and $signed === true){ @@ -647,6 +685,13 @@ class Utils{ return $unpacked; } + /** + * Writes a 16-bit signed/unsigned little-endian number + * + * @param $value + * + * @return string + */ public static function writeLShort($value){ if($value < 0){ $value += 0x10000; @@ -657,7 +702,7 @@ class Utils{ public static function readInt($str){ list(, $unpacked) = @unpack("N", $str); - if($unpacked >= 2147483648){ + if($unpacked > 2147483647){ $unpacked -= 4294967296; } @@ -665,10 +710,6 @@ class Utils{ } public static function writeInt($value){ - if($value < 0){ - $value += 0x100000000; - } - return pack("N", $value); } @@ -682,10 +723,6 @@ class Utils{ } public static function writeLInt($value){ - if($value < 0){ - $value += 0x100000000; - } - return pack("V", $value); } diff --git a/src/utils/VersionString.php b/src/utils/VersionString.php index 820d83f84..406fcad84 100644 --- a/src/utils/VersionString.php +++ b/src/utils/VersionString.php @@ -23,6 +23,12 @@ namespace PocketMine\Utils; use PocketMine; +/** + * Class VersionString + * Manages PocketMine-MP Version strings, and compares them + * + * @package PocketMine\Utils + */ class VersionString{ public static $stageOrder = array( "alpha" => 0,