Fixed #3963, closes #3979, added hash for non-numeric seeds

This commit is contained in:
PEMapModder
2016-02-22 19:37:52 +08:00
parent 41a847567c
commit ed9888a2cb
6 changed files with 34 additions and 15 deletions

View File

@ -23,6 +23,7 @@
* Various Utilities used around the code
*/
namespace pocketmine\utils;
use pocketmine\ThreadManager;
/**
@ -462,8 +463,8 @@ class Utils{
/**
* GETs an URL using cURL
*
* @param $page
* @param int $timeout default 10
* @param $page
* @param int $timeout default 10
* @param array $extraHeaders
*
* @return bool|mixed
@ -496,7 +497,7 @@ class Utils{
* @param $page
* @param array|string $args
* @param int $timeout
* @param array $extraHeaders
* @param array $extraHeaders
*
* @return bool|mixed
*/
@ -524,4 +525,22 @@ class Utils{
return $ret;
}
public static function javaStringHash($string){
$hash = 0;
for($i = 0; $i < strlen($string); $i++){
$ord = ord($string{$i});
if($ord & 0x80){
$ord -= 0x100;
}
$hash = 31 * $hash + $ord;
while($hash > 0x7FFFFFFF){
$hash -= 0x100000000;
}
while($hash < -0x80000000){
$hash += 0x100000000;
}
$hash &= 0xFFFFFFFF;
}
return $hash;
}
}