diff --git a/README.md b/README.md index aeb1b3d13..82c844961 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,10 @@ The entire server is done in PHP, and has been tested, profiled and optimized to ## Third-party Libraries Used * __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__ * __[PHP SQLite3](http://php.net/manual/en/book.sqlite3.php)__ -* __[cURL](http://curl.haxx.se/)__: cURL is a command line tool for transferring data with URL syntax -* __[GMP](http://gmplib.org/)__: Arithmetic without limitations -* __[Zlib](http://www.zlib.net/)__: A Massively Spiffy Yet Delicately Unobtrusive Compression Library +* __[PHP BCMath](http://php.net/manual/en/book.bc.php)__ * __[PHP pthreads](https://github.com/krakjoe/pthreads)__ by _[krakjoe](https://github.com/krakjoe)_: Threading for PHP - Share Nothing, Do Everything. * __[PHP NBT](https://github.com/TheFrozenFire/PHP-NBT-Decoder-Encoder/blob/master/nbt.class.php)__ by _[TheFrozenFire](https://github.com/TheFrozenFire)_: Class for reading in NBT-format files (modified to handle Little-Endian files). * __[Spyc](https://github.com/mustangostang/spyc/blob/master/Spyc.php)__ by _[Vlad Andersen](https://github.com/mustangostang)_: A simple YAML loader/dumper class for PHP. * __[ANSICON](https://github.com/adoxa/ansicon)__ by _[Jason Hood](https://github.com/adoxa)_: Process ANSI escape sequences for Windows console programs. +* __[cURL](http://curl.haxx.se/)__: cURL is a command line tool for transferring data with URL syntax +* __[Zlib](http://www.zlib.net/)__: A Massively Spiffy Yet Delicately Unobtrusive Compression Library diff --git a/compile_php.sh b/compile_php.sh index 84531237e..d73ebf676 100644 --- a/compile_php.sh +++ b/compile_php.sh @@ -1,14 +1,12 @@ #!/bin/bash -COMPILER_VERSION="0.10" +COMPILER_VERSION="0.11" PHP_VERSION="5.4.13" ZEND_VM="GOTO" ZLIB_VERSION="1.2.7" -GMP_VERSION="5.1.1" PTHREADS_VERSION="24cecf484105e0d6972c2767a9501c6a72d48090" CURL_VERSION="curl-7_29_0" -#READLINE_VERSION="6.2" echo "[PocketMine] PHP installer and compiler for Linux & Mac - by @shoghicp v$COMPILER_VERSION" DIR=`pwd` @@ -53,44 +51,6 @@ cd .. rm -r -f ./zlib echo " done!" -#Readline -#echo -n "[Readline] downloading $READLINE_VERSION..." -#wget ftp://ftp.cwru.edu/pub/bash/readline-$READLINE_VERSION.tar.gz -q -O - | tar -xz >> "$DIR/install.log" 2>&1 -#mv readline-$READLINE_VERSION readline -#echo -n " checking..." -#cd readline -#./configure --prefix="$DIR/install_data/php/ext/readline" \ -#--disable-shared >> "$DIR/install.log" 2>&1 -#echo -n " compiling..." -#make >> "$DIR/install.log" 2>&1 -#echo -n " installing..." -#make install >> "$DIR/install.log" 2>&1 -#echo -n " cleaning..." -#cd .. -#rm -r -f ./readine -#echo " done!" - -#--with-readline=$DIR/install_data/php/ext/readline - -#GMP -echo -n "[GMP] downloading $GMP_VERSION..." -wget ftp://ftp.gmplib.org/pub/gmp-$GMP_VERSION/gmp-$GMP_VERSION.tar.bz2 -q -O - | tar -xj >> "$DIR/install.log" 2>&1 -mv gmp-$GMP_VERSION gmp -echo -n " checking..." -cd gmp -./configure --prefix="$DIR/install_data/php/ext/gmp" \ ---disable-assembly \ ---disable-shared >> "$DIR/install.log" 2>&1 -echo -n " compiling..." -make >> "$DIR/install.log" 2>&1 -echo -n " installing..." -make install >> "$DIR/install.log" 2>&1 -echo -n " cleaning..." -cd .. -rm -r -f ./gmp -echo " done!" - - echo -n "[cURL] downloading $CURL_VERSION..." wget https://github.com/bagder/curl/archive/$CURL_VERSION.tar.gz --no-check-certificate -q -O - | tar -zx >> "$DIR/install.log" 2>&1 mv curl-$CURL_VERSION curl @@ -139,7 +99,6 @@ rm -f ./configure >> "$DIR/install.log" 2>&1 --exec-prefix="$DIR/php5" \ --enable-embedded-mysqli \ --enable-bcmath \ ---with-gmp="$DIR/install_data/php/ext/gmp" \ --with-curl="$DIR/install_data/php/ext/curl" \ --with-zlib="$DIR/install_data/php/ext/zlib" \ --disable-libxml \ diff --git a/src/dependencies.php b/src/dependencies.php index 9505727af..ad2c48e67 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -48,9 +48,7 @@ if(version_compare("5.4.0", PHP_VERSION) > 0){ if(version_compare(CURRENT_PHP_VERSION, PHP_VERSION) > 0){ console("[NOTICE] This PocketMine-MP version has not been tested with PHP < ".CURRENT_PHP_VERSION, true, true, 0); -}/*elseif(version_compare(CURRENT_PHP_VERSION, PHP_VERSION) < 0){ - console("[NOTICE] This PocketMine-MP version has not been tested with PHP > ".CURRENT_PHP_VERSION, true, true, 0); -}*/ +} if(php_sapi_name() !== "cli"){ console("[ERROR] You must run PocketMine-MP using the CLI.", true, true, 0); @@ -82,11 +80,6 @@ if(!extension_loaded("zlib") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . ++$errors; } -if(!extension_loaded("gmp") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "gmp." . PHP_SHLIB_SUFFIX) === false){ - console("[ERROR] Unable to find the GMP extension.", true, true, 0); - ++$errors; -} - if($errors > 0){ console("[ERROR] Please use the installer provided on the homepage.", true, true, 0); exit(1); //Exit with error diff --git a/src/utils/Utils.php b/src/utils/Utils.php index a0f9ab658..c4a0aabc1 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -529,19 +529,45 @@ class Utils extends Thread{ return ENDIANNESS === BIG_ENDIAN ? strrev(pack("d", $value)):pack("d", $value); } - public static function readLong($str){ - $n = gmp_init(Utils::strToHex($str), 16); - if(gmp_testbit($n, "63")){ - $n = gmp_xor($n, "0xffffffffffffffff"); //flip the bits - $n = gmp_neg(gmp_add($n, "1")); // add one and negate + public static function readLong($x, $signed = true){ + $value = "0"; + if($signed === true){ + $negative = ((ord($x{0}) & 0x80) === 0x80) ? true:false; + if($negative){ + $x = ~$x; + } + }else{ + $negative = false; } - return gmp_strval($n); + + for($i = 0; $i < 8; $i += 4){ + $value = bcmul($value, "4294967296", 0); //4294967296 == 2^32 + $value = bcadd($value, 0x1000000 * ord($x{$i}) + ((ord($x{$i + 1}) << 16) | (ord($x{$i + 2}) << 8) | ord($x{$i + 3})), 0); + } + return ($negative === true ? "-".$value:$value); } public static function writeLong($value){ - $long = gmp_init($value, 10); - $long = gmp_and($long, "0xffffffffffffffff"); - return Utils::hexToStr(str_pad(gmp_strval($long, -16), 16, "00", STR_PAD_LEFT)); + $x = ""; + if($value{0} === "-"){ + $negative = true; + $value = bcadd($value, "1"); + if($value{0} === "-"){ + $value = substr($value, 1); + } + }else{ + $negative = false; + } + while(bccomp($value, '0', 0) > 0){ + $temp = bcmod($value, "16777216"); + $x = chr($temp >> 16) . chr($temp >> 8) . chr($temp) . $x; + $value = bcdiv($value, "16777216", 0); + } + $x = str_pad(substr($x, 0, 8), 8, "\x00", STR_PAD_LEFT); + if($negative === true){ + $x = ~$x; + } + return $x; } public static function readLLong($str){