Removed Math_BigInteger dependency

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-15 20:04:21 +01:00
parent 39df588dd9
commit b3db08a370
6 changed files with 22 additions and 3646 deletions

View File

@ -41,6 +41,5 @@ The entire server is done in PHP, and has been tested, profiled and optimized to
* __[Zlib](http://www.zlib.net/)__: A Massively Spiffy Yet Delicately Unobtrusive Compression Library
* __[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).
* __[Math_BigInteger](http://phpseclib.sourceforge.net/math/intro.html)__ by _[phpseclib](http://phpseclib.sourceforge.net/)_: Pure-PHP arbitrary precission integer arithmetic library
* __[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.

View File

@ -64,14 +64,12 @@ class ServerAPI{
$test .= Utils::writeInt(Utils::readInt("\xff\xff\xff\xff"));
$test .= Utils::writeInt(1);
$test .= Utils::writeInt(-1);
$test .= Utils::writeFloat(Utils::readfloat("\xff\xff\xff\xff"));
$test .= Utils::writeFloat(Utils::readFloat("\xff\xff\xff\xff"));
$test .= Utils::writeFloat(-1.584563155838E+29);
$test .= Utils::writeFloat(1);
$test .= Utils::writeLDouble(Utils::readLDouble("\xff\xff\xff\xff\xff\xff\xff\xff"));
$test .= Utils::writeLong("-1152921504606846977");
$test .= Utils::writeLong("-1152921504606846976");
$test .= Utils::writeTriad(16777215);
$test .= Utils::writeTriad(16777216);
$str = new Java_String("TESTING\x00\n\r\t\xff");
$test .= Utils::writeLong($str->hashCode());
$test .= Utils::writeDataArray(array("a", "b", "c", "\xff\xff\xff\xff"));

View File

@ -37,7 +37,7 @@ set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH);
ini_set("memory_limit", "256M");
define("LOG", true);
define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78");
define("TEST_MD5", "d0ca3786e53b615bb4fb9f5094d5c9a7");
define("TEST_MD5", "2c25fb29459162c2a865b370ef0cdfcf");
define("MAJOR_VERSION", "Alpha_1.2dev");
define("CURRENT_STRUCTURE", 5);
define("CURRENT_PROTOCOL", 9);

View File

@ -80,6 +80,11 @@ 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 GMP extension", true, true, 0);
++$errors;
}
if($errors > 0){
exit(1); //Exit with error
}

File diff suppressed because it is too large Load Diff

View File

@ -104,7 +104,7 @@ class Utils extends Thread{
public static function readTriad($str){
list(,$unpacked) = unpack("N", "\x00".$str);
return (int) $unpacked;
return $unpacked;
}
public static function writeTriad($value){
@ -344,11 +344,11 @@ class Utils extends Thread{
return array("yaw" => $hAngle, "pitch" => $vAngle);
}
public static function sha1($input){
/*public static function sha1($input){
$number = new Math_BigInteger(sha1($input, true), -256);
$zero = new Math_BigInteger(0);
return ($zero->compare($number) <= 0 ? "":"-") . ltrim($number->toHex(), "0");
}
}*/
public static function microtime(){
return microtime(true);
@ -526,25 +526,29 @@ class Utils extends Thread{
}
public static function readLong($str){
$long = new Math_BigInteger($str, -256);
return $long->toString();
$n = gmp_init(Utils::strToHex($str));
if(gmp_testbit($n, 63)){
$n = gmp_xor($n, "0xffffffffffffffff"); //flip the bits
$n = gmp_neg(gmp_add($n, 1)); // add one and negate
}
return gmp_strval($n);
}
public static function writeLong($value){
$long = new Math_BigInteger($value, -10);
return str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT);
$long = gmp_init($value, 10);
$long = gmp_and($long, "0xffffffffffffffff");
return Utils::hexToStr(str_pad(gmp_strval($long, -16), 16, "00", STR_PAD_LEFT));
}
public static function readLLong($str){
$long = new Math_BigInteger(strrev($str), -256);
return $long->toString();
return Utils::readLong(strrev($str));
}
public static function writeLLong($value){
$long = new Math_BigInteger($value, -10);
return strrev(str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT));
return strrev(Utils::writeLong($str));
}
}
if(Utils::isOnline() === false){