mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
Fixed TABS
This commit is contained in:
parent
b3b38605b5
commit
aa1a39adfc
41 changed files with 549 additions and 549 deletions
|
|
@ -60,7 +60,7 @@ class Async extends Thread {
|
|||
/**
|
||||
* Do whatever, result stored in $this->result, don't try to join twice
|
||||
**/
|
||||
public function __toString(){
|
||||
public function __toString(){
|
||||
if(!$this->joined) {
|
||||
$this->joined = true;
|
||||
$this->join();
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the
|
||||
* {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the
|
||||
* {@link MATH_BIGINTEGER_MODE_INTERNAL MATH_BIGINTEGER_MODE_INTERNAL} mode)
|
||||
*
|
||||
* Math_BigInteger uses base-2**26 to perform operations such as multiplication and division and
|
||||
|
|
@ -53,10 +53,10 @@
|
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
|
@ -234,7 +234,7 @@ class Math_BigInteger {
|
|||
/**
|
||||
* Mode independant value used for serialization.
|
||||
*
|
||||
* If the bcmath or gmp extensions are installed $this->value will be a non-serializable resource, hence the need for
|
||||
* If the bcmath or gmp extensions are installed $this->value will be a non-serializable resource, hence the need for
|
||||
* a variable that'll be serializable regardless of whether or not extensions are being used. Unlike $this->value,
|
||||
* however, $this->hex is only calculated when $this->__sleep() is called.
|
||||
*
|
||||
|
|
@ -750,7 +750,7 @@ class Math_BigInteger {
|
|||
$vars[] = 'precision';
|
||||
}
|
||||
return $vars;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2237,7 +2237,7 @@ class Math_BigInteger {
|
|||
/**
|
||||
* Montgomery Multiply
|
||||
*
|
||||
* Interleaves the montgomery reduction and long multiplication algorithms together as described in
|
||||
* Interleaves the montgomery reduction and long multiplication algorithms together as described in
|
||||
* {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=13 HAC 14.36}
|
||||
*
|
||||
* @see _prepMontgomery()
|
||||
|
|
@ -2317,7 +2317,7 @@ class Math_BigInteger {
|
|||
* {@link http://groups.google.com/group/sci.crypt/msg/7a137205c1be7d85}
|
||||
*
|
||||
* As for why we do all the bitmasking... strange things can happen when converting from floats to ints. For
|
||||
* instance, on some computers, var_dump((int) -4294967297) yields int(-1) and on others, it yields
|
||||
* instance, on some computers, var_dump((int) -4294967297) yields int(-1) and on others, it yields
|
||||
* int(-2147483648). To avoid problems stemming from this, we use bitmasks to guarantee that ints aren't
|
||||
* auto-converted to floats. The outermost bitmask is present because without it, there's no guarantee that
|
||||
* the "residue" returned would be the so-called "common residue". We use fmod, in the last step, because the
|
||||
|
|
@ -3217,7 +3217,7 @@ class Math_BigInteger {
|
|||
* @return Boolean
|
||||
* @access public
|
||||
* @internal Uses the
|
||||
* {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See
|
||||
* {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See
|
||||
* {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=8 HAC 4.24}.
|
||||
*/
|
||||
function isPrime($t = false)
|
||||
|
|
@ -3266,16 +3266,16 @@ class Math_BigInteger {
|
|||
|
||||
if (!isset($primes)) {
|
||||
$primes = array(
|
||||
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
|
||||
61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
|
||||
139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
|
||||
229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
|
||||
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
|
||||
421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
|
||||
521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617,
|
||||
619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
|
||||
733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
|
||||
839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947,
|
||||
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
|
||||
61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
|
||||
139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
|
||||
229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
|
||||
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
|
||||
421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
|
||||
521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617,
|
||||
619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
|
||||
733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
|
||||
839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947,
|
||||
953, 967, 971, 977, 983, 991, 997
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,11 +30,11 @@ class ChunkParser{
|
|||
var $sectorLength = 4096; //16 * 16 * 16
|
||||
var $chunkLength = 86016; //21 * $sectorLength
|
||||
var $map;
|
||||
|
||||
|
||||
function __construct(){
|
||||
$map = array();
|
||||
}
|
||||
|
||||
|
||||
private function loadLocationTable(){
|
||||
$this->location = array();
|
||||
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
||||
|
|
@ -57,7 +57,7 @@ class ChunkParser{
|
|||
++$chunkCnt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function loadFile($file){
|
||||
if(ZLIB_EXTENSION === true and file_exists($file.".gz")){
|
||||
$this->raw = gzinflate(file_get_contents($file.".gz"));
|
||||
|
|
@ -69,40 +69,40 @@ class ChunkParser{
|
|||
file_put_contents($file, $this->raw);
|
||||
}elseif(!file_exists($file)){
|
||||
return false;
|
||||
}else{
|
||||
}else{
|
||||
$this->raw = file_get_contents($file);
|
||||
}
|
||||
$this->file = $file;
|
||||
$this->chunkLength = $this->sectorLength * ord($this->raw{0});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function loadRaw($raw, $file){
|
||||
$this->file = $file;
|
||||
$this->raw = $raw;
|
||||
$this->chunkLength = $this->sectorLength * ord($this->raw{0});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function getOffsetPosition($X, $Z){
|
||||
$data = substr($this->raw, ($X << 2) + ($Z << 7), 4); //$X * 4 + $Z * 128
|
||||
return array(ord($data{0}), ord($data{1}), ord($data{2}), ord($data{3}));
|
||||
}
|
||||
|
||||
|
||||
private function getOffset($X, $Z, $sectors = 21){
|
||||
return 0x1000 + (($X * $sectors) << 12) + (($Z * $sectors) << 16);
|
||||
}
|
||||
|
||||
|
||||
private function getOffsetLocation($X, $Z){
|
||||
return $X << 2 + $Z << 7;
|
||||
}
|
||||
|
||||
|
||||
public function getChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
return substr($this->raw, $this->getOffset($X, $Z), $this->chunkLength);
|
||||
}
|
||||
|
||||
|
||||
public function writeChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
|
|
@ -117,7 +117,7 @@ class ChunkParser{
|
|||
}
|
||||
return Utils::writeLInt(strlen($chunk)).$chunk;
|
||||
}
|
||||
|
||||
|
||||
public function parseChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
|
|
@ -139,7 +139,7 @@ class ChunkParser{
|
|||
}
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
|
||||
public function loadMap(){
|
||||
if($this->raw == ""){
|
||||
return false;
|
||||
|
|
@ -155,10 +155,10 @@ class ChunkParser{
|
|||
$this->raw = b"";
|
||||
console("[DEBUG] Chunks loaded!", true, true, 2);
|
||||
}
|
||||
|
||||
|
||||
public function saveMap($final = false){
|
||||
console("[DEBUG] Saving chunks...", true, true, 2);
|
||||
|
||||
|
||||
$fp = fopen($this->file, "r+b");
|
||||
flock($fp, LOCK_EX);
|
||||
foreach($this->map as $x => $d){
|
||||
|
|
@ -179,7 +179,7 @@ class ChunkParser{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getFloor($x, $z){
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
|
|
@ -193,7 +193,7 @@ class ChunkParser{
|
|||
}
|
||||
return $y;
|
||||
}
|
||||
|
||||
|
||||
public function getBlock($x, $y, $z){
|
||||
$x = (int) $x;
|
||||
$y = (int) $y;
|
||||
|
|
@ -212,12 +212,12 @@ class ChunkParser{
|
|||
}
|
||||
return array($block, $meta);
|
||||
}
|
||||
|
||||
|
||||
public function getChunkColumn($X, $Z, $x, $z, $type = 0){
|
||||
$index = $z + ($x << 4);
|
||||
return $this->map[$X][$Z][$type][$index];
|
||||
}
|
||||
|
||||
|
||||
public function setBlock($x, $y, $z, $block, $meta = 0){
|
||||
$x = (int) $x;
|
||||
$y = (int) $y;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class CustomPacketHandler{
|
|||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function __construct($pid, $raw = "", $data = array(), $create = false){
|
||||
$this->raw = $raw;
|
||||
$this->data = $data;
|
||||
|
|
@ -54,7 +54,7 @@ class CustomPacketHandler{
|
|||
$this->data["payload"] = Utils::readLong($this->get(8));
|
||||
}else{
|
||||
$this->raw .= Utils::writeLong($this->data["payload"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x03:
|
||||
if($this->c === false){
|
||||
|
|
@ -63,10 +63,10 @@ class CustomPacketHandler{
|
|||
}else{
|
||||
$this->raw .= Utils::writeLong($this->data["unknown1"]);
|
||||
$this->raw .= Utils::writeLong($this->data["unknown2"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_CLIENT_CONNECT:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["clientID"] = Utils::readLong($this->get(8));
|
||||
$this->data["session"] = Utils::readLong($this->get(8));
|
||||
$this->data["unknown2"] = $this->get(1);
|
||||
|
|
@ -105,7 +105,7 @@ class CustomPacketHandler{
|
|||
$this->raw .= "\x00\x00";
|
||||
$this->raw .= Utils::writeLong($this->data["session"]);
|
||||
$this->raw .= Utils::writeLong($this->data["session2"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_CLIENT_HANDSHAKE:
|
||||
if($this->c === false){
|
||||
|
|
@ -137,7 +137,7 @@ class CustomPacketHandler{
|
|||
//null
|
||||
break;
|
||||
case MC_LOGIN:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
$this->data["maxX"] = Utils::readInt($this->get(4));
|
||||
$this->data["maxY"] = Utils::readInt($this->get(4));
|
||||
|
|
@ -147,35 +147,35 @@ class CustomPacketHandler{
|
|||
}
|
||||
break;
|
||||
case MC_LOGIN_STATUS:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["status"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["status"]);
|
||||
}
|
||||
break;
|
||||
case MC_READY:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["status"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= chr($this->data["status"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_CHAT:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["message"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
}else{
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"];
|
||||
}
|
||||
break;
|
||||
case MC_SET_TIME:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["time"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["time"]);
|
||||
}
|
||||
break;
|
||||
case MC_START_GAME:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["seed"] = Utils::readInt($this->get(4));
|
||||
$this->data["unknown1"] = Utils::readInt($this->get(4));
|
||||
$this->data["gamemode"] = Utils::readInt($this->get(4));
|
||||
|
|
@ -191,9 +191,9 @@ class CustomPacketHandler{
|
|||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_ADD_MOB:
|
||||
case MC_ADD_MOB:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["type"] = Utils::readInt($this->get(4));
|
||||
|
|
@ -214,7 +214,7 @@ class CustomPacketHandler{
|
|||
));
|
||||
}
|
||||
break;
|
||||
case MC_ADD_PLAYER:
|
||||
case MC_ADD_PLAYER:
|
||||
if($this->c === false){
|
||||
$this->data["clientID"] = Utils::readLong($this->get(8));
|
||||
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
|
|
@ -298,7 +298,7 @@ class CustomPacketHandler{
|
|||
}
|
||||
break;
|
||||
case MC_MOVE_ENTITY:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
|
|
@ -311,7 +311,7 @@ class CustomPacketHandler{
|
|||
}
|
||||
break;
|
||||
case MC_MOVE_ENTITY_POSROT:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
|
|
@ -328,7 +328,7 @@ class CustomPacketHandler{
|
|||
}
|
||||
break;
|
||||
case MC_MOVE_PLAYER:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
|
|
@ -345,7 +345,7 @@ class CustomPacketHandler{
|
|||
}
|
||||
break;
|
||||
case MC_PLACE_BLOCK:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
|
|
@ -361,10 +361,10 @@ class CustomPacketHandler{
|
|||
$this->raw .= chr($this->data["block"]);
|
||||
$this->raw .= chr($this->data["meta"]);
|
||||
$this->raw .= chr($this->data["face"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_REMOVE_BLOCK:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
|
|
@ -374,7 +374,7 @@ class CustomPacketHandler{
|
|||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
$this->raw .= chr($this->data["y"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_UPDATE_BLOCK:
|
||||
if($this->c === false){
|
||||
|
|
@ -389,10 +389,10 @@ class CustomPacketHandler{
|
|||
$this->raw .= chr($this->data["y"]);
|
||||
$this->raw .= chr($this->data["block"]);
|
||||
$this->raw .= chr($this->data["meta"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_REQUEST_CHUNK:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
|
|
@ -401,7 +401,7 @@ class CustomPacketHandler{
|
|||
}
|
||||
break;
|
||||
case MC_CHUNK_DATA:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
$this->data["data"] = $this->get(true);
|
||||
|
|
@ -412,7 +412,7 @@ class CustomPacketHandler{
|
|||
}
|
||||
break;
|
||||
case MC_PLAYER_EQUIPMENT:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["block"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["meta"] = Utils::readShort($this->get(2), false);
|
||||
|
|
@ -420,10 +420,10 @@ class CustomPacketHandler{
|
|||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeShort($this->data["block"]);
|
||||
$this->raw .= Utils::writeShort($this->data["meta"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_INTERACT:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["action"] = Utils::readByte($this->get(1));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["target"] = Utils::readInt($this->get(4));
|
||||
|
|
@ -431,10 +431,10 @@ class CustomPacketHandler{
|
|||
$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["target"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_USE_ITEM:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["y"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
|
|
@ -449,33 +449,33 @@ class CustomPacketHandler{
|
|||
/*$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["target"]);*/
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_SET_ENTITY_DATA:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeMetadata(array(
|
||||
|
||||
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_SET_HEALTH:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["health"] = Utils::readByte($this->get(1));
|
||||
}else{
|
||||
$this->raw .= Utils::writeByte($this->data["health"]);
|
||||
}
|
||||
break;
|
||||
case MC_ANIMATE:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["action"] = Utils::readByte($this->get(1));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_RESPAWN:
|
||||
if($this->c === false){
|
||||
|
|
@ -516,14 +516,14 @@ class CustomPacketHandler{
|
|||
$this->raw .= chr($this->data["type"]);
|
||||
$this->raw .= Utils::writeShort($this->data["slots"]);
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["title"])).$this->data["title"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_CONTAINER_CLOSE:
|
||||
if($this->c === false){
|
||||
$this->data["windowid"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= chr($this->data["windowid"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_CONTAINER_SET_SLOT:
|
||||
if($this->c === false){
|
||||
|
|
@ -538,17 +538,17 @@ class CustomPacketHandler{
|
|||
$this->raw .= Utils::writeShort($this->data["block"]);
|
||||
$this->raw .= chr($this->data["stack"]);
|
||||
$this->raw .= Utils::writeShort($this->data["meta"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_CLIENT_MESSAGE:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["message"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
}else{
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"];
|
||||
}
|
||||
break;
|
||||
case MC_SIGN_UPDATE:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readShort($this->get(2));
|
||||
$this->data["y"] = ord($this->get(1));
|
||||
$this->data["z"] = Utils::readShort($this->get(2));
|
||||
|
|
@ -565,7 +565,7 @@ class CustomPacketHandler{
|
|||
}
|
||||
break;
|
||||
case MC_ADVENTURE_SETTINGS:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readShort($this->get(2));
|
||||
$this->data["y"] = ord($this->get(1));
|
||||
$this->data["z"] = Utils::readShort($this->get(2));
|
||||
|
|
@ -575,10 +575,10 @@ class CustomPacketHandler{
|
|||
}else{
|
||||
$this->raw .= $this->data["unknown1"];
|
||||
$this->raw .= $this->data["unknown2"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($this->c === false){
|
||||
if($this->c === false){
|
||||
console("[DEBUG] Received unknown Data Packet ID 0x".dechex($pid), true, true, 2);
|
||||
}else{
|
||||
console("[DEBUG] Sent unknown Data Packet ID 0x".dechex($pid), true, true, 2);
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class Material{
|
|||
102 => true,
|
||||
105 => true,
|
||||
107 => true,
|
||||
108 => true,
|
||||
108 => true,
|
||||
);
|
||||
static $replaceable = array(
|
||||
0 => true,
|
||||
|
|
@ -130,7 +130,7 @@ class Material{
|
|||
11 => true,
|
||||
31 => true,
|
||||
51 => true,
|
||||
78 => true,
|
||||
78 => true,
|
||||
);
|
||||
static $activable = array(
|
||||
2 => true,
|
||||
|
|
@ -234,7 +234,7 @@ class Material{
|
|||
4 => "Cobblestone",
|
||||
5 => "Wooden Planks",
|
||||
6 => "Sapling",
|
||||
7 => "Bedrock",
|
||||
7 => "Bedrock",
|
||||
);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class Entity extends stdClass{
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function update(){
|
||||
if($this->class === ENTITY_ITEM and $this->closed === false){
|
||||
$this->server->api->dhandle("entity.move", $this);
|
||||
|
|
@ -86,12 +86,12 @@ class Entity extends stdClass{
|
|||
"meta" => $this->meta,
|
||||
"target" => $this->eid
|
||||
)) !== false){
|
||||
$this->close();
|
||||
$this->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDirection(){
|
||||
$rotation = ($this->yaw - 90) % 360;
|
||||
if ($rotation < 0) {
|
||||
|
|
@ -111,7 +111,7 @@ class Entity extends stdClass{
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function spawn($player){
|
||||
if(!is_object($player)){
|
||||
$player = $this->server->api->player->get($player);
|
||||
|
|
@ -145,7 +145,7 @@ class Entity extends stdClass{
|
|||
"meta" => $this->meta,
|
||||
"stack" => $this->stack,
|
||||
));
|
||||
break;
|
||||
break;
|
||||
case ENTITY_MOB:
|
||||
$player->dataPacket(MC_ADD_MOB, array(
|
||||
"type" => $this->type,
|
||||
|
|
@ -160,7 +160,7 @@ class Entity extends stdClass{
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function close(){
|
||||
if($this->closed === false){
|
||||
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
|
||||
|
|
@ -169,24 +169,24 @@ class Entity extends stdClass{
|
|||
$this->__destruct();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
}
|
||||
|
||||
|
||||
public function getEID(){
|
||||
return $this->eid;
|
||||
}
|
||||
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
public function setName($name){
|
||||
$this->name = $name;
|
||||
$this->server->query("UPDATE entities SET name = '".str_replace("'", "", $this->name)."' WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
|
||||
public function look($pos2){
|
||||
$pos = $this->getPosition();
|
||||
$angle = Utils::angle3D($pos2, $pos);
|
||||
|
|
@ -194,14 +194,14 @@ class Entity extends stdClass{
|
|||
$this->pitch = $angle["pitch"];
|
||||
$this->server->query("UPDATE entities SET pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
|
||||
public function setCoords($x, $y, $z){
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->z = $z;
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z." WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
|
||||
public function move($x, $y, $z, $yaw = 0, $pitch = 0){
|
||||
$this->x += $x;
|
||||
$this->y += $y;
|
||||
|
|
@ -212,22 +212,22 @@ class Entity extends stdClass{
|
|||
$this->pitch %= 90;
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
|
||||
public function setPosition($x, $y, $z, $yaw, $pitch){
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->z = $z;
|
||||
$this->yaw = $yaw;
|
||||
$this->pitch = $pitch;
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function getPosition($round = false){
|
||||
return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position);
|
||||
}
|
||||
|
||||
public function setHealth($health, $cause = ""){
|
||||
|
||||
public function setHealth($health, $cause = ""){
|
||||
$this->health = (int) $health;
|
||||
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
|
||||
$this->server->api->dhandle("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause));
|
||||
|
|
@ -245,7 +245,7 @@ class Entity extends stdClass{
|
|||
$this->dead = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getHealth(){
|
||||
return $this->health;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@ class WorldGenerator{
|
|||
$this->genName = $genName;
|
||||
$this->gen = new $genName($this->seed);
|
||||
}
|
||||
|
||||
|
||||
public function getSpawn(){
|
||||
return $this->gen->getSpawn();
|
||||
}
|
||||
|
||||
|
||||
public function set($name, $value){
|
||||
$this->gen->set($name, $value);
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->raw = "\x15\x01\x00\x00\x15\x16\x00\x00\x15\x2b\x00\x00\x15\x40\x00\x00". //Location Header
|
||||
"\x15\x55\x00\x00\x15\x6a\x00\x00\x15\x7f\x00\x00\x15\x94\x00\x00".
|
||||
|
|
@ -301,18 +301,18 @@ class WorldGenerator{
|
|||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
$this->gen->init();
|
||||
}
|
||||
|
||||
|
||||
public function generate(){
|
||||
for($Z = 0; $Z < 16; ++$Z){
|
||||
for($X = 0; $X < 16; ++$X){
|
||||
$chunk = str_pad($this->getChunk($X, $Z), 86012, "\x00", STR_PAD_RIGHT);
|
||||
$this->raw .= Utils::writeLInt(strlen($chunk)) . $chunk;
|
||||
$this->raw .= Utils::writeLInt(strlen($chunk)) . $chunk;
|
||||
}
|
||||
console("[DEBUG] Generating level ".ceil(($Z + 1)/0.16)."%", true, true, 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function getChunk($X, $Z){
|
||||
$chunk = b"";
|
||||
$columns = array();
|
||||
|
|
@ -333,7 +333,7 @@ class WorldGenerator{
|
|||
unset($columns);
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
|
||||
public function save($dir, $name){
|
||||
@mkdir($dir, 0777, true);
|
||||
file_put_contents($dir."chunks.dat", $this->raw);
|
||||
|
|
|
|||
|
|
@ -28,26 +28,26 @@ the Free Software Foundation, either version 3 of the License, or
|
|||
|
||||
class Java_String{
|
||||
private $value = "", $count = 0, $hash = 0;
|
||||
|
||||
|
||||
public function __construct($string = false){
|
||||
if($string !== false){
|
||||
$this->value = (string) $string;
|
||||
$this->count = strlen($this->value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function __toString(){
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
||||
public function lenght(){
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
|
||||
public function isEmpty(){
|
||||
return $this->count === 0;
|
||||
}
|
||||
|
||||
|
||||
public function charAt($index){
|
||||
$index = (int) $index;
|
||||
if($index < 0 or $index >= $this->count){
|
||||
|
|
@ -56,7 +56,7 @@ class Java_String{
|
|||
}
|
||||
return $this->value{$index};
|
||||
}
|
||||
|
||||
|
||||
public function hashCode(){
|
||||
$h = $this->hash;
|
||||
if($h === 0 and $this->count > 0){
|
||||
|
|
@ -68,13 +68,13 @@ class Java_String{
|
|||
$this->hash = $h;
|
||||
}
|
||||
return $h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Java_Random{
|
||||
private $haveNextNextGaussian, $nextNextGaussian, $seed, $n1, $n2, $n3, $zero;
|
||||
|
||||
|
||||
public function __construct($seed = false){
|
||||
$this->n1 = new Math_BigInteger(0x5DEECE66D);
|
||||
$this->n2 = new Math_BigInteger(1);
|
||||
|
|
@ -86,19 +86,19 @@ class Java_Random{
|
|||
}
|
||||
$this->setSeed($seed);
|
||||
}
|
||||
|
||||
|
||||
public function setSeed($seed){
|
||||
$seed = new Math_BigInteger($seed);
|
||||
$this->seed = $seed->bitwise_xor($this->n1)->bitwise_and($this->n2);
|
||||
$this->haveNextNextGaussian = false;
|
||||
}
|
||||
|
||||
|
||||
protected function next($bits){
|
||||
$bits = (int) $bits;
|
||||
$this->seed = $this->seed->multiply($this->n1)->add($this->n3)->bitwise_and($this->n2);
|
||||
return $this->_tripleRightShift($this->seed, (48 - $bits));
|
||||
}
|
||||
|
||||
|
||||
private function _tripleRightShift($number, $places){
|
||||
if($number->compare($this->zero) >= 0){
|
||||
return $number->bitwise_rightShift($places);
|
||||
|
|
@ -106,7 +106,7 @@ class Java_Random{
|
|||
$n1 = new Math_BigInteger(2);
|
||||
return $number->bitwise_rightShift($places)->add($n1->bitwise_leftShift(~$places));
|
||||
}
|
||||
|
||||
|
||||
public function nextBytes($bytes){
|
||||
$bytes = (int) $bytes;
|
||||
$b = b"";
|
||||
|
|
|
|||
|
|
@ -41,18 +41,18 @@ class MinecraftInterface{
|
|||
$this->client = (bool) $client;
|
||||
$this->start = microtime(true);
|
||||
}
|
||||
|
||||
|
||||
public function close(){
|
||||
return $this->socket->close();
|
||||
}
|
||||
|
||||
|
||||
protected function getStruct($pid){
|
||||
if(isset($this->pstruct[$pid])){
|
||||
return $this->pstruct[$pid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
|
||||
if(LOG === true and DEBUG >= 3){
|
||||
$p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".(isset($data["id"]) ? "MC Packet ".$this->dataName[$pid]:$this->name[$pid])." (0x".Utils::strTohex(chr($pid)).") [length ".strlen($raw)."]".PHP_EOL;
|
||||
|
|
@ -65,9 +65,9 @@ class MinecraftInterface{
|
|||
$p .= PHP_EOL;
|
||||
logg($p, "packets", false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function readPacket(){
|
||||
$p = $this->popPacket();
|
||||
if($p !== false){
|
||||
|
|
@ -90,13 +90,13 @@ class MinecraftInterface{
|
|||
logg($p, "packets", true, 2);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$packet = new Packet($pid, $struct, $data[0]);
|
||||
$packet->parse();
|
||||
$this->data[] = array($pid, $packet->data, $data[0], $data[1], $data[2]);
|
||||
return $this->popPacket();
|
||||
}
|
||||
|
||||
|
||||
public function popPacket(){
|
||||
if(count($this->data) > 0){
|
||||
$p = array_shift($this->data);
|
||||
|
|
@ -112,7 +112,7 @@ class MinecraftInterface{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function writePacket($pid, $data = array(), $raw = false, $dest = false, $port = false){
|
||||
$struct = $this->getStruct($pid);
|
||||
if($raw === false){
|
||||
|
|
@ -124,10 +124,10 @@ class MinecraftInterface{
|
|||
}else{
|
||||
$write = $this->socket->write($data, $dest, $port);
|
||||
$this->writeDump($pid, $data, false, "client", $dest, $port);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for reading in NBT-format files.
|
||||
*
|
||||
*
|
||||
* @author Justin Martin <frozenfire@thefrozenfire.com>
|
||||
* @version 1.0
|
||||
* MODIFIED BY @shoghicp
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
class NBT {
|
||||
public $root = array();
|
||||
|
||||
|
||||
const TAG_END = 0;
|
||||
const TAG_BYTE = 1;
|
||||
const TAG_SHORT = 2;
|
||||
|
|
@ -24,7 +24,7 @@ class NBT {
|
|||
const TAG_STRING = 8;
|
||||
const TAG_LIST = 9;
|
||||
const TAG_COMPOUND = 10;
|
||||
|
||||
|
||||
public function loadFile($filename) {
|
||||
if(is_file($filename)) {
|
||||
$fp = fopen($filename, "rb");
|
||||
|
|
@ -44,7 +44,7 @@ class NBT {
|
|||
$this->traverseTag($fp, $this->root);
|
||||
return end($this->root);
|
||||
}
|
||||
|
||||
|
||||
public function traverseTag($fp, &$tree) {
|
||||
if(feof($fp)) {
|
||||
return false;
|
||||
|
|
@ -59,7 +59,7 @@ class NBT {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function readType($fp, $tagType) {
|
||||
switch($tagType) {
|
||||
case self::TAG_BYTE: // Signed byte (8 bit)
|
||||
|
|
|
|||
|
|
@ -33,19 +33,19 @@ class NormalGenerator{
|
|||
"seed" => (int) $seed,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function set($name, $value){
|
||||
$this->config[$name] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->spawn = array(128, 128, 128);
|
||||
}
|
||||
|
||||
|
||||
public function getSpawn(){
|
||||
return $this->spawn;
|
||||
}
|
||||
|
||||
|
||||
public function getColumn($x, $z){
|
||||
$x = (int) $x;
|
||||
$z = (int) $z;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class Packet{
|
|||
private $struct, $sock;
|
||||
protected $pid, $packet;
|
||||
public $data, $raw;
|
||||
|
||||
|
||||
function __construct($pid, $struct, $data = ""){
|
||||
$this->pid = $pid;
|
||||
$this->offset = 1;
|
||||
|
|
@ -42,7 +42,7 @@ class Packet{
|
|||
$this->struct = $struct;
|
||||
$this->sock = $sock;
|
||||
}
|
||||
|
||||
|
||||
public function create($raw = false){
|
||||
foreach($this->struct as $field => $type){
|
||||
if(!isset($this->data[$field])){
|
||||
|
|
@ -83,7 +83,7 @@ class Packet{
|
|||
$reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true);
|
||||
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
|
||||
$this->addRaw(chr($this->data[$field]["id"]));
|
||||
$this->addRaw($reply->raw);
|
||||
$this->addRaw($reply->raw);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
@ -136,10 +136,10 @@ class Packet{
|
|||
default:
|
||||
$this->addRaw(Utils::writeByte($this->data[$field]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function get($len = true){
|
||||
if($len === true){
|
||||
$data = substr($this->raw, $this->offset);
|
||||
|
|
@ -150,12 +150,12 @@ class Packet{
|
|||
$this->offset += $len;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function addRaw($str){
|
||||
$this->raw .= $str;
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
public function parse(){
|
||||
$continue = true;
|
||||
foreach($this->struct as $field => $type){
|
||||
|
|
@ -205,7 +205,7 @@ class Packet{
|
|||
break;
|
||||
case "byte":
|
||||
$this->data[] = Utils::readByte($this->get(1));
|
||||
break;
|
||||
break;
|
||||
case "ubyte":
|
||||
$this->data[] = ord($this->get(1));
|
||||
break;
|
||||
|
|
@ -231,8 +231,8 @@ class Packet{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ class Player{
|
|||
$this->auth = false;
|
||||
$this->counter = array(0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
public function onTick($time, $event){
|
||||
if($event !== "server.tick"){
|
||||
return;
|
||||
|
|
@ -80,7 +80,7 @@ class Player{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function save(){
|
||||
if(is_object($this->entity)){
|
||||
$this->data["spawn"] = array(
|
||||
|
|
@ -90,7 +90,7 @@ class Player{
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function close($reason = "", $msg = true){
|
||||
$reason = $reason == "" ? "server stop":$reason;
|
||||
$this->save();
|
||||
|
|
@ -110,14 +110,14 @@ class Player{
|
|||
console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason);
|
||||
$this->server->api->player->remove($this->CID);
|
||||
}
|
||||
|
||||
public function eventHandler($data, $event){
|
||||
|
||||
public function eventHandler($data, $event){
|
||||
switch($event){
|
||||
case "player.item.pick":
|
||||
if($data["eid"] === $this->eid){
|
||||
$data["eid"] = 0;
|
||||
}
|
||||
$this->dataPacket(MC_TAKE_ITEM_ENTITY, $data);
|
||||
$this->dataPacket(MC_TAKE_ITEM_ENTITY, $data);
|
||||
break;
|
||||
case "player.equipment.change":
|
||||
if($data["eid"] === $this->eid){
|
||||
|
|
@ -170,7 +170,7 @@ class Player{
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function handle($pid, $data){
|
||||
if($this->connected === true){
|
||||
$this->timeout = microtime(true) + 25;
|
||||
|
|
@ -210,7 +210,7 @@ class Player{
|
|||
$data[3],
|
||||
0,
|
||||
));
|
||||
break;
|
||||
break;
|
||||
case 0x80:
|
||||
case 0x81:
|
||||
case 0x82:
|
||||
|
|
@ -240,12 +240,12 @@ class Player{
|
|||
$this->send(0xc0, array(1, true, $data[0]));
|
||||
}
|
||||
switch($data["id"]){
|
||||
|
||||
|
||||
case MC_KEEP_ALIVE:
|
||||
|
||||
|
||||
break;
|
||||
case 0x03:
|
||||
|
||||
|
||||
break;
|
||||
case MC_DISCONNECT:
|
||||
$this->connected = false;
|
||||
|
|
@ -259,13 +259,13 @@ class Player{
|
|||
));
|
||||
break;
|
||||
case MC_CLIENT_HANDSHAKE:
|
||||
|
||||
|
||||
break;
|
||||
case MC_LOGIN:
|
||||
$this->username = str_replace(array("\x00", "/", " ", "\r", "\n"), array("", "-", "_", "", ""), $data["username"]);
|
||||
if($this->username == ""){
|
||||
$this->close("bad username", false);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
$o = $this->server->api->player->getOffline($this->username);
|
||||
if($this->server->whitelist !== false and (!in_array($this->username, $this->server->whitelist)/* or ($o["lastID"] != 0 and $o["lastID"] != $this->clientID)*/)){
|
||||
|
|
@ -298,7 +298,7 @@ class Player{
|
|||
"eid" => 0,
|
||||
));
|
||||
break;
|
||||
case MC_READY:
|
||||
case MC_READY:
|
||||
switch($data["status"]){
|
||||
case 1:
|
||||
if($this->spawned !== false){
|
||||
|
|
@ -321,7 +321,7 @@ class Player{
|
|||
$this->evid[] = $this->server->event("player.item.pick", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("world.block.change", array($this, "eventHandler"));
|
||||
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
|
||||
|
||||
|
||||
$this->eventHandler($this->server->motd, "server.chat");
|
||||
if($this->MTU <= 548){
|
||||
$this->eventHandler("Your connection is bad, you may experience lag and slow map loading.", "server.chat");
|
||||
|
|
@ -337,7 +337,7 @@ class Player{
|
|||
$this->server->api->dhandle("entity.move", $this->entity);
|
||||
}
|
||||
break;
|
||||
case MC_PLAYER_EQUIPMENT:
|
||||
case MC_PLAYER_EQUIPMENT:
|
||||
$data["eid"] = $this->eid;
|
||||
if($this->server->handle("player.equipment.change", $data) !== false){
|
||||
$this->equipment[0] = $data["block"];
|
||||
|
|
@ -353,7 +353,7 @@ class Player{
|
|||
$this->dataPacket(MC_CHUNK_DATA, array(
|
||||
"x" => '.$data["x"].',
|
||||
"z" => '.$data["z"].',
|
||||
"data" => $d,
|
||||
"data" => $d,
|
||||
), true);
|
||||
}
|
||||
');
|
||||
|
|
@ -376,7 +376,7 @@ class Player{
|
|||
case MC_INTERACT:
|
||||
if(isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
||||
console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2);
|
||||
if($this->server->gamemode !== 1 and $this->server->difficulty > 0){
|
||||
if($this->server->gamemode !== 1 and $this->server->difficulty > 0){
|
||||
$this->server->api->entity->harm($data["target"], $this->server->difficulty, $this->eid);
|
||||
}
|
||||
}
|
||||
|
|
@ -405,17 +405,17 @@ class Player{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function send($pid, $data = array(), $raw = false){
|
||||
if($this->connected === true){
|
||||
$this->server->send($pid, $data, $raw, $this->ip, $this->port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function actionQueue($code){
|
||||
$this->queue[] = array(1, $code);
|
||||
}
|
||||
|
||||
|
||||
public function dataPacket($id, $data = array(), $queue = false, $count = false){
|
||||
if($queue === true){
|
||||
$this->queue[] = array(0, $id, $data, $count);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->timePerSecond = 10;
|
||||
$this->tickMeasure = array_fill(0, 40, 0);
|
||||
$this->setType("normal");
|
||||
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false);
|
||||
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false);
|
||||
$this->reloadConfig();
|
||||
console("[INFO] Server Name: ".$this->name);
|
||||
console("[INFO] Server GUID: ".$this->serverID);
|
||||
|
|
@ -79,17 +79,17 @@ class PocketMinecraftServer extends stdClass{
|
|||
console("[INFO] Max Clients: ".$this->maxClients);
|
||||
$this->stop = false;
|
||||
}
|
||||
|
||||
|
||||
public function getTPS(){
|
||||
$v = array_values($this->tickMeasure);
|
||||
$tps = 40 / ($v[39] - $v[0]);
|
||||
return round($tps, 4);
|
||||
}
|
||||
|
||||
public function loadEvents(){
|
||||
|
||||
public function loadEvents(){
|
||||
$this->event("server.chat", array($this, "eventHandler"));
|
||||
$this->event("player.new", array($this, "eventHandler"));
|
||||
|
||||
|
||||
$this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->api->dhandle("server.time.change", $this->time);');
|
||||
$this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}');
|
||||
$this->action(1000000 * 60, '$this->reloadConfig();');
|
||||
|
|
@ -103,7 +103,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
public function startDatabase(){
|
||||
$this->preparedSQL = new stdClass();
|
||||
$this->database = new SQLite3(":memory:");
|
||||
//$this->query("PRAGMA journal_mode = OFF;");
|
||||
//$this->query("PRAGMA journal_mode = OFF;");
|
||||
//$this->query("PRAGMA encoding = \"UTF-8\";");
|
||||
//$this->query("PRAGMA secure_delete = OFF;");
|
||||
$this->query("CREATE TABLE players (clientID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE);");
|
||||
|
|
@ -118,7 +118,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);");
|
||||
$this->preparedSQL->updateActions = $this->database->prepare("UPDATE actions SET last = :time WHERE last <= (:time - interval);");
|
||||
}
|
||||
|
||||
|
||||
public function query($sql, $fetch = false){
|
||||
console("[INTERNAL] [SQL] ".$sql, true, true, 3);
|
||||
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0);
|
||||
|
|
@ -127,14 +127,14 @@ class PocketMinecraftServer extends stdClass{
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function reloadConfig(){
|
||||
if($this->whitelist === true or is_array($this->whitelist)){
|
||||
$this->whitelist = explode("\n", str_replace(array("\t","\r"), "", file_get_contents(FILE_PATH."white-list.txt")));
|
||||
}
|
||||
$this->bannedIPs = explode("\n", str_replace(array(" ","\t","\r"), "", file_get_contents(FILE_PATH."banned-ips.txt")));
|
||||
}
|
||||
|
||||
|
||||
public function debugInfo($console = false){
|
||||
$info = array();
|
||||
$info["tps"] = $this->getTPS();
|
||||
|
|
@ -152,7 +152,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
public function close($reason = "stop"){
|
||||
if($this->stop !== true){
|
||||
$this->chat(false, "Stopping server...");
|
||||
|
|
@ -162,7 +162,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->interface->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function chat($owner, $text, $target = true){
|
||||
$message = "";
|
||||
if($owner !== false){
|
||||
|
|
@ -171,7 +171,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
$message .= $text;
|
||||
$this->handle("server.chat", $message);
|
||||
}
|
||||
|
||||
|
||||
public function setType($type = "normal"){
|
||||
switch($type){
|
||||
case "normal":
|
||||
|
|
@ -181,9 +181,9 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->serverType = "MCCPP;MINECON;";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function addHandler($event, $callable, $priority = 5){
|
||||
if(!is_callable($callable)){
|
||||
return false;
|
||||
|
|
@ -194,14 +194,14 @@ class PocketMinecraftServer extends stdClass{
|
|||
console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$this->handCnt.")", true, true, 3);
|
||||
return $this->handCnt++;
|
||||
}
|
||||
|
||||
|
||||
public function handle($event, &$data){
|
||||
$this->preparedSQL->selectHandlers->reset();
|
||||
$this->preparedSQL->selectHandlers->clear();
|
||||
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
|
||||
$handlers = $this->preparedSQL->selectHandlers->execute();
|
||||
$result = true;
|
||||
if($handlers !== false and $handlers !== true){
|
||||
if($handlers !== false and $handlers !== true){
|
||||
while(false !== ($hn = $handlers->fetchArray(SQLITE3_ASSOC)) and $result !== false){
|
||||
$handler = $this->handlers[(int) $hn["ID"]];
|
||||
if(is_array($handler)){
|
||||
|
|
@ -210,7 +210,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
}else{
|
||||
$result = $handler($data, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$handlers->finalize();
|
||||
if($result !== false){
|
||||
|
|
@ -218,7 +218,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function eventHandler($data, $event){
|
||||
switch($event){
|
||||
case "player.new":
|
||||
|
|
@ -229,14 +229,14 @@ class PocketMinecraftServer extends stdClass{
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function loadMap(){
|
||||
if($this->mapName !== false and trim($this->mapName) !== ""){
|
||||
if($this->mapName !== false and trim($this->mapName) !== ""){
|
||||
$this->level = unserialize(file_get_contents($this->mapDir."level.dat"));
|
||||
console("[INFO] Map: ".$this->level["LevelName"]);
|
||||
$this->time = (int) $this->level["Time"];
|
||||
$this->seed = (int) $this->level["RandomSeed"];
|
||||
if(isset($this->level["SpawnX"])){
|
||||
if(isset($this->level["SpawnX"])){
|
||||
$this->spawn = array("x" => $this->level["SpawnX"], "y" => $this->level["SpawnY"], "z" => $this->level["SpawnZ"]);
|
||||
}else{
|
||||
$this->level["SpawnX"] = $this->spawn["x"];
|
||||
|
|
@ -264,7 +264,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function loadEntities(){
|
||||
if($this->map !== false){
|
||||
console("[INFO] Loading entities...");
|
||||
|
|
@ -288,26 +288,26 @@ class PocketMinecraftServer extends stdClass{
|
|||
$e = $this->api->entity->add(ENTITY_MOB, $entity["id"]);
|
||||
$e->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]);
|
||||
$e->setHealth($entity["Health"]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
console("[DEBUG] Loaded ".count($this->entities)." Entities", true, true, 2);
|
||||
$this->action(1000000 * 60 * 15, '$this->chat(false, "Forcing save...");$this->save();$this->chat(false, "Done");');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function save($final = false){
|
||||
if($this->mapName !== false){
|
||||
if($this->mapName !== false){
|
||||
file_put_contents($this->mapDir."level.dat", serialize($this->level));
|
||||
$this->map->saveMap($final);
|
||||
console("[INFO] Saving entities...");
|
||||
foreach($this->entities as $entity){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
if($this->mapName !== false and $this->map === false){
|
||||
$this->loadMap();
|
||||
|
|
@ -322,21 +322,21 @@ class PocketMinecraftServer extends stdClass{
|
|||
console("[INFO] Server started!");
|
||||
$this->process();
|
||||
}
|
||||
|
||||
|
||||
public function tick(){
|
||||
$time = microtime(true);
|
||||
if($this->lastTick <= ($time - 0.05)){
|
||||
array_shift($this->tickMeasure);
|
||||
$this->tickMeasure[] = $this->lastTick = $time;
|
||||
$this->tickMeasure[] = $this->lastTick = $time;
|
||||
$this->tickerFunction($time);
|
||||
$this->trigger("server.tick", $time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function clientID($ip, $port){
|
||||
return md5($ip . $port, true);
|
||||
}
|
||||
|
||||
|
||||
public function packetHandler($packet){
|
||||
$data =& $packet["data"];
|
||||
$CID = $this->clientID($packet["ip"], $packet["port"]);
|
||||
|
|
@ -351,7 +351,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->serverID,
|
||||
MAGIC,
|
||||
$this->serverType,
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
break;
|
||||
}
|
||||
if(in_array($packet["ip"], $this->bannedIPs)){
|
||||
|
|
@ -441,11 +441,11 @@ class PocketMinecraftServer extends stdClass{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function send($pid, $data = array(), $raw = false, $dest = false, $port = false){
|
||||
$this->interface->writePacket($pid, $data, $raw, $dest, $port);
|
||||
}
|
||||
|
||||
|
||||
public function process(){
|
||||
while($this->stop === false){
|
||||
$packet = @$this->interface->readPacket();
|
||||
|
|
@ -453,10 +453,10 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->packetHandler($packet);
|
||||
}else{
|
||||
usleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function trigger($event, $data = ""){
|
||||
$this->preparedSQL->selectEvents->reset();
|
||||
$this->preparedSQL->selectEvents->clear();
|
||||
|
|
@ -486,7 +486,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function schedule($ticks, $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){
|
||||
if(!is_callable($callback)){
|
||||
return false;
|
||||
|
|
@ -499,7 +499,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.'if(!is_callable($schedule[0])){unset($this->schedule['.$this->scheduleCnt.']);return;} call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat);
|
||||
return $this->scheduleCnt++;
|
||||
}
|
||||
|
||||
|
||||
public function action($microseconds, $code, $repeat = true){
|
||||
$this->query("INSERT INTO actions (interval, last, code, repeat) VALUES(".($microseconds / 1000000).", ".microtime(true).", '".base64_encode($code)."', ".($repeat === true ? 1:0).");");
|
||||
console("[INTERNAL] Attached to action ".$microseconds, true, true, 3);
|
||||
|
|
@ -511,7 +511,7 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->preparedSQL->selectActions->clear();
|
||||
$this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$actions = $this->preparedSQL->selectActions->execute();
|
||||
|
||||
|
||||
if($actions === false or $actions === true){
|
||||
return;
|
||||
}
|
||||
|
|
@ -526,8 +526,8 @@ class PocketMinecraftServer extends stdClass{
|
|||
$this->preparedSQL->updateActions->clear();
|
||||
$this->preparedSQL->updateActions->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$this->preparedSQL->updateActions->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function event($event, $func){
|
||||
if(!is_callable($func)){
|
||||
return false;
|
||||
|
|
@ -537,11 +537,11 @@ class PocketMinecraftServer extends stdClass{
|
|||
console("[INTERNAL] Attached ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)." to event ".$event." (ID ".$this->evCnt.")", true, true, 3);
|
||||
return $this->evCnt++;
|
||||
}
|
||||
|
||||
|
||||
public function deleteEvent($id){
|
||||
$id = (int) $id;
|
||||
unset($this->events[$id]);
|
||||
$this->query("DELETE FROM events WHERE ID = ".$id.";");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class SerializedPacketHandler{
|
|||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function __construct($pid, $raw = "", $data = array(), $create = false){
|
||||
$this->raw = $raw;
|
||||
$this->data = $data;
|
||||
|
|
@ -54,12 +54,12 @@ class SerializedPacketHandler{
|
|||
case 0x00:
|
||||
if($this->c === false){
|
||||
$this->data["packets"] = array();
|
||||
$i = 0;
|
||||
$i = 0;
|
||||
while($this->offset < strlen($this->raw)){
|
||||
if($i > 0){
|
||||
$pid = ord($this->get(1));
|
||||
}
|
||||
|
||||
|
||||
$len = ceil(Utils::readShort($this->get(2), false) / 8); //Utils::readShort($this->get(2), false) >> 3;
|
||||
if($pid !== 0x00){
|
||||
$c = Utils::readTriad(strrev($this->get(3)));
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class Spyc {
|
|||
/**
|
||||
* Setting this to true will force YAMLDump to enclose any string value in
|
||||
* quotes. False by default.
|
||||
*
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $setting_dump_force_quotes = false;
|
||||
|
|
@ -168,7 +168,7 @@ class Spyc {
|
|||
/**
|
||||
* Load a string of YAML into a PHP array statically
|
||||
*
|
||||
* The load method, when supplied with a YAML string, will do its best
|
||||
* The load method, when supplied with a YAML string, will do its best
|
||||
* to convert YAML in a string into a PHP array. Pretty simple.
|
||||
*
|
||||
* Note: use this function if you don't want files from the file system
|
||||
|
|
@ -257,7 +257,7 @@ class Spyc {
|
|||
|
||||
// Start at the base of the array and move through it.
|
||||
if ($array) {
|
||||
$array = (array)$array;
|
||||
$array = (array)$array;
|
||||
$previous_key = -1;
|
||||
foreach ($array as $key => $value) {
|
||||
if (!isset($first_key)) $first_key = $key;
|
||||
|
|
@ -346,7 +346,7 @@ class Spyc {
|
|||
if (is_bool($value)) {
|
||||
$value = ($value) ? "true" : "false";
|
||||
}
|
||||
|
||||
|
||||
if ($value === null) $value = 'null';
|
||||
if ($value === "'" . self::REMPTY . "'") $value = null;
|
||||
|
||||
|
|
@ -438,7 +438,7 @@ class Spyc {
|
|||
$cnt = count($Source);
|
||||
for ($i = 0; $i < $cnt; $i++) {
|
||||
$line = $Source[$i];
|
||||
|
||||
|
||||
$this->indent = strlen($line) - strlen(ltrim($line));
|
||||
$tempPath = $this->getParentPathByIndent($this->indent);
|
||||
$line = self::stripIndent($line, $this->indent);
|
||||
|
|
@ -530,9 +530,9 @@ class Spyc {
|
|||
return $this->returnArrayElement($line);
|
||||
|
||||
if ($this->isPlainArray($line))
|
||||
return $this->returnPlainArray($line);
|
||||
|
||||
|
||||
return $this->returnPlainArray($line);
|
||||
|
||||
|
||||
return $this->returnKeyValuePair($line);
|
||||
|
||||
}
|
||||
|
|
@ -558,7 +558,7 @@ class Spyc {
|
|||
|
||||
if ($is_quoted)
|
||||
return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\'\'' => '\'', '\\\'' => '\''));
|
||||
|
||||
|
||||
if (strpos($value, ' #') !== false && !$is_quoted)
|
||||
$value = preg_replace('/\s+#(.+)$/','',$value);
|
||||
|
||||
|
|
@ -585,7 +585,7 @@ class Spyc {
|
|||
$value = $this->_toType($value);
|
||||
return array($key => $value);
|
||||
}
|
||||
|
||||
|
||||
if ($first_character == '{' && $last_character == '}') {
|
||||
$innerValue = trim(substr ($value, 1, -1));
|
||||
if ($innerValue === '') return array();
|
||||
|
|
@ -632,7 +632,7 @@ class Spyc {
|
|||
$value = (float)$value;
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
|
@ -735,7 +735,7 @@ class Spyc {
|
|||
if ($finished) break;
|
||||
|
||||
$i++;
|
||||
if ($i > 10)
|
||||
if ($i > 10)
|
||||
break; // Prevent infinite loops.
|
||||
}
|
||||
|
||||
|
|
@ -763,7 +763,7 @@ class Spyc {
|
|||
private function addArrayInline ($array, $indent) {
|
||||
$CommonGroupPath = $this->path;
|
||||
if (empty ($array)) return false;
|
||||
|
||||
|
||||
foreach ($array as $k => $_) {
|
||||
$this->addArray(array($k => $_), $indent);
|
||||
$this->path = $CommonGroupPath;
|
||||
|
|
@ -777,7 +777,7 @@ class Spyc {
|
|||
|
||||
if (count ($incoming_data) > 1)
|
||||
return $this->addArrayInline ($incoming_data, $incoming_indent);
|
||||
|
||||
|
||||
$key = key ($incoming_data);
|
||||
$value = isset($incoming_data[$key]) ? $incoming_data[$key] : null;
|
||||
if ($key === '__!YAMLZero') $key = '0';
|
||||
|
|
@ -793,7 +793,7 @@ class Spyc {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$history = array();
|
||||
// Unfolding inner array tree.
|
||||
$history[] = $_arr = $this->result;
|
||||
|
|
@ -940,7 +940,7 @@ class Spyc {
|
|||
if ($line[0] != '-') return false;
|
||||
if (strlen ($line) > 3)
|
||||
if (substr($line,0,3) == '---') return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -985,14 +985,14 @@ class Spyc {
|
|||
private function startsMappedValue ($line) {
|
||||
return (substr ($line, -1, 1) == ':');
|
||||
}
|
||||
|
||||
|
||||
private function isPlainArray ($line) {
|
||||
return ($line[0] == '[' && substr ($line, -1, 1) == ']');
|
||||
}
|
||||
|
||||
|
||||
private function returnPlainArray ($line) {
|
||||
return $this->_toType($line);
|
||||
}
|
||||
return $this->_toType($line);
|
||||
}
|
||||
|
||||
private function returnKeyValuePair ($line) {
|
||||
$array = array();
|
||||
|
|
@ -1032,7 +1032,7 @@ class Spyc {
|
|||
}
|
||||
|
||||
|
||||
private function nodeContainsGroup ($line) {
|
||||
private function nodeContainsGroup ($line) {
|
||||
$symbolsForReference = 'A-z0-9_\-';
|
||||
if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-)
|
||||
if ($line[0] == '&' && preg_match('/^(&['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1];
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ class SuperflatGenerator{
|
|||
);
|
||||
$this->parsePreset();
|
||||
}
|
||||
|
||||
|
||||
public function set($name, $value){
|
||||
$this->config[$name] = $value;
|
||||
if($name === "preset"){
|
||||
$this->parsePreset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function parsePreset(){
|
||||
$this->structure = array(
|
||||
0 => "",
|
||||
|
|
@ -53,7 +53,7 @@ class SuperflatGenerator{
|
|||
2 => str_repeat("\x00", 64),
|
||||
3 => str_repeat("\x00", 64),
|
||||
);
|
||||
$preset = explode(";", trim($this->config["preset"]));
|
||||
$preset = explode(";", trim($this->config["preset"]));
|
||||
foreach($preset as $i => $data){
|
||||
$num = 1;
|
||||
if(preg_match('#([a-zA-Z\-_]*)\((.*)\)#', $data, $matches) > 0){ //Property
|
||||
|
|
@ -78,15 +78,15 @@ class SuperflatGenerator{
|
|||
$this->structure[2] = substr($this->structure[2], 0, 64);
|
||||
$this->structure[3] = substr($this->structure[3], 0, 64);
|
||||
}
|
||||
|
||||
|
||||
public function init(){
|
||||
$this->spawn = array(128, strlen($this->structure[0]), 128);
|
||||
}
|
||||
|
||||
|
||||
public function getSpawn(){
|
||||
return $this->spawn;
|
||||
}
|
||||
|
||||
|
||||
public function getColumn($x, $z){
|
||||
$x = (int) $x;
|
||||
$z = (int) $z;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
|
|||
class TileEntity extends stdClass{
|
||||
private $server;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class UDPSocket{
|
|||
$this->unblock();
|
||||
}else{
|
||||
$this->sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
socket_set_option($this->sock, SOL_SOCKET, SO_BROADCAST, 1);
|
||||
socket_set_option($this->sock, SOL_SOCKET, SO_BROADCAST, 1);
|
||||
if($listen !== true){
|
||||
$this->connected = true;
|
||||
$this->buffer = array();
|
||||
|
|
@ -57,7 +57,7 @@ class UDPSocket{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function listenSocket(){
|
||||
$sock = @socket_accept($this->sock);
|
||||
if($sock !== false){
|
||||
|
|
@ -67,7 +67,7 @@ class UDPSocket{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function close($error = 125){
|
||||
$this->connected = false;
|
||||
if($error === false){
|
||||
|
|
@ -77,7 +77,7 @@ class UDPSocket{
|
|||
}
|
||||
return @socket_close($this->sock);
|
||||
}
|
||||
|
||||
|
||||
public function block(){
|
||||
socket_set_block($this->sock);
|
||||
}
|
||||
|
|
@ -85,18 +85,18 @@ class UDPSocket{
|
|||
public function unblock(){
|
||||
socket_set_nonblock($this->sock);
|
||||
}
|
||||
|
||||
|
||||
public function read(){
|
||||
$source = false;
|
||||
$port = 1;
|
||||
$len = @socket_recvfrom($this->sock, $buf, 65536, 0, $source, $port);
|
||||
return array($buf, $source, $port, $len);
|
||||
}
|
||||
|
||||
|
||||
public function write($data, $dest = false, $port = false){
|
||||
return @socket_sendto($this->sock, $data, strlen($data), 0, ($dest === false ? $this->server:$dest), ($port === false ? $this->port:$port));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -36,7 +36,7 @@ define("LITTLE_ENDIAN", 0x01);
|
|||
define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN));
|
||||
|
||||
abstract class Utils{
|
||||
|
||||
|
||||
public static function getOS(){
|
||||
$uname = strtoupper(php_uname("s"));
|
||||
if(strpos($uname, "WIN") !== false){
|
||||
|
|
@ -47,22 +47,22 @@ abstract class Utils{
|
|||
return "linux";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function hexdump($bin){
|
||||
$output = "";
|
||||
$bin = str_split($bin, 16);
|
||||
foreach($bin as $counter => $line){
|
||||
$hex = chunk_split(chunk_split(str_pad(bin2hex($line), 32, " ", STR_PAD_RIGHT), 2, " "), 24, " ");
|
||||
$ascii = preg_replace('#([^\x20-\x7E])#', ".", $line);
|
||||
$output .= str_pad(dechex($counter << 4), 4, "0", STR_PAD_LEFT). " " . $hex . " " . $ascii . PHP_EOL;
|
||||
$output .= str_pad(dechex($counter << 4), 4, "0", STR_PAD_LEFT). " " . $hex . " " . $ascii . PHP_EOL;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
public static function printable($str){
|
||||
return preg_replace('#([^\x20-\x7E])#', '.', $str);
|
||||
}
|
||||
|
||||
|
||||
public static function readTriad($str){
|
||||
list(,$unpacked) = unpack("N", "\x00".$str);
|
||||
return (int) $unpacked;
|
||||
|
|
@ -103,18 +103,18 @@ abstract class Utils{
|
|||
$m .= Utils::writeLInt($data["value"][$i]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
$m .= "\x7f";
|
||||
return $m;
|
||||
return $m;
|
||||
}
|
||||
|
||||
|
||||
public static function readMetadata($value, $types = false){
|
||||
$offset = 0;
|
||||
$m = array();
|
||||
$b = ord($value{$offset});
|
||||
++$offset;
|
||||
++$offset;
|
||||
while($b !== 127){
|
||||
$bottom = $b & 0x1F;
|
||||
$type = $b >> 5;
|
||||
|
|
@ -157,7 +157,7 @@ abstract class Utils{
|
|||
$offset += 4;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
if($types === true){
|
||||
$m[$bottom] = array($r, $type);
|
||||
|
|
@ -167,9 +167,9 @@ abstract class Utils{
|
|||
$b = ord($value{$offset});
|
||||
++$offset;
|
||||
}
|
||||
return $m;
|
||||
return $m;
|
||||
}
|
||||
|
||||
|
||||
public static function readDataArray($str, $len = 10, &$offset = null){
|
||||
$data = array();
|
||||
$offset = 0;
|
||||
|
|
@ -181,7 +181,7 @@ abstract class Utils{
|
|||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public static function writeDataArray($data){
|
||||
$raw = "";
|
||||
foreach($data as $v){
|
||||
|
|
@ -190,7 +190,7 @@ abstract class Utils{
|
|||
}
|
||||
return $raw;
|
||||
}
|
||||
|
||||
|
||||
public static function getRandomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0){
|
||||
$output = b"";
|
||||
$length = abs((int) $length);
|
||||
|
|
@ -227,7 +227,7 @@ abstract class Utils{
|
|||
(string) disk_total_space("."),
|
||||
uniqid(microtime(),true),
|
||||
);
|
||||
|
||||
|
||||
shuffle($weakEntropy);
|
||||
$value = hash("sha256", implode($weakEntropy), true);
|
||||
foreach($weakEntropy as $k => $c){ //mixing entropy values with XOR and hash randomness extractor
|
||||
|
|
@ -237,7 +237,7 @@ abstract class Utils{
|
|||
$value ^= hash("sha256", $c . microtime() . $k, true);
|
||||
}
|
||||
unset($weakEntropy);
|
||||
|
||||
|
||||
if($secure === true){
|
||||
$strongEntropy = array(
|
||||
is_array($startEntropy) ? $startEntropy[($rounds + $drop) % count($startEntropy)]:$startEntropy, //Get a random index of the startEntropy, or just read it
|
||||
|
|
@ -275,15 +275,15 @@ abstract class Utils{
|
|||
}
|
||||
return $raw === false ? bin2hex($output):$output;
|
||||
}
|
||||
|
||||
|
||||
public static function round($number){
|
||||
return round($number, 0, PHP_ROUND_HALF_DOWN);
|
||||
}
|
||||
|
||||
|
||||
public static function distance($pos1, $pos2){
|
||||
return sqrt(pow($pos1["x"] - $pos2["x"], 2) + pow($pos1["y"] - $pos2["y"], 2) + pow($pos1["z"] - $pos2["z"], 2));
|
||||
}
|
||||
|
||||
|
||||
public static function angle3D($pos1, $pos2){
|
||||
$X = $pos1["x"] - $pos2["x"];
|
||||
$Z = $pos1["z"] - $pos2["z"];
|
||||
|
|
@ -293,17 +293,17 @@ abstract class Utils{
|
|||
$vAngle = rad2deg(-atan2($Y, $dXZ));
|
||||
return array("yaw" => $hAngle, "pitch" => $vAngle);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public static function curl_get($page){
|
||||
$ch = curl_init($page);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Minecraft PHP Client 2"));
|
||||
|
|
@ -317,7 +317,7 @@ abstract class Utils{
|
|||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public static function curl_post($page, $args, $timeout = 10){
|
||||
$ch = curl_init($page);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
|
|
@ -331,26 +331,26 @@ abstract class Utils{
|
|||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public static function strToHex($str){
|
||||
return bin2hex($str);
|
||||
}
|
||||
|
||||
|
||||
public static function hexToStr($hex){
|
||||
if(HEX2BIN === true){
|
||||
return hex2bin($hex);
|
||||
}
|
||||
}
|
||||
return pack("H*" , $hex);
|
||||
}
|
||||
|
||||
public static function readBool($b){
|
||||
return Utils::readByte($b, false) === 0 ? false:true;
|
||||
}
|
||||
|
||||
|
||||
public static function writeBool($b){
|
||||
return Utils::writeByte($b === true ? 1:0);
|
||||
}
|
||||
|
||||
|
||||
public static function readByte($c, $signed = true){
|
||||
$b = ord($c{0});
|
||||
if($signed === true and ($b & 0x80) === 0x80){ //calculate Two's complement
|
||||
|
|
@ -358,7 +358,7 @@ abstract class Utils{
|
|||
}
|
||||
return $b;
|
||||
}
|
||||
|
||||
|
||||
public static function writeByte($c){
|
||||
if($c > 0xff){
|
||||
return false;
|
||||
|
|
@ -376,14 +376,14 @@ abstract class Utils{
|
|||
}
|
||||
return $unpacked;
|
||||
}
|
||||
|
||||
|
||||
public static function writeShort($value){
|
||||
if($value < 0){
|
||||
$value += 0x10000;
|
||||
$value += 0x10000;
|
||||
}
|
||||
return pack("n", $value);
|
||||
}
|
||||
|
||||
|
||||
public static function readLShort($str, $signed = true){
|
||||
list(,$unpacked) = unpack("v", $str);
|
||||
if($unpacked > 0x7fff and $signed === true){
|
||||
|
|
@ -391,10 +391,10 @@ abstract class Utils{
|
|||
}
|
||||
return $unpacked;
|
||||
}
|
||||
|
||||
|
||||
public static function writeLShort($value){
|
||||
if($value < 0){
|
||||
$value += 0x10000;
|
||||
$value += 0x10000;
|
||||
}
|
||||
return pack("v", $value);
|
||||
}
|
||||
|
|
@ -406,14 +406,14 @@ abstract class Utils{
|
|||
}
|
||||
return (int) $unpacked;
|
||||
}
|
||||
|
||||
|
||||
public static function writeInt($value){
|
||||
if($value < 0){
|
||||
$value += 0x100000000;
|
||||
$value += 0x100000000;
|
||||
}
|
||||
return pack("N", $value);
|
||||
}
|
||||
|
||||
|
||||
public static function readLInt($str){
|
||||
list(,$unpacked) = unpack("V", $str);
|
||||
if($unpacked >= 2147483648){
|
||||
|
|
@ -421,50 +421,50 @@ abstract class Utils{
|
|||
}
|
||||
return (int) $unpacked;
|
||||
}
|
||||
|
||||
|
||||
public static function writeLInt($value){
|
||||
if($value < 0){
|
||||
$value += 0x100000000;
|
||||
$value += 0x100000000;
|
||||
}
|
||||
return pack("V", $value);
|
||||
}
|
||||
|
||||
|
||||
public static function readFloat($str){
|
||||
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", $str):unpack("f", strrev($str));
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
public static function writeFloat($value){
|
||||
return ENDIANNESS === BIG_ENDIAN ? pack("f", $value):strrev(pack("f", $value));
|
||||
}
|
||||
|
||||
|
||||
public static function readLFloat($str){
|
||||
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", strrev($str)):unpack("f", $str);
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
public static function writeLFloat($value){
|
||||
return ENDIANNESS === BIG_ENDIAN ? strrev(pack("f", $value)):pack("f", $value);
|
||||
}
|
||||
|
||||
|
||||
public static function printFloat($value){
|
||||
return preg_replace("/(\.\d+?)0+$/", "$1", sprintf("%F", $value));
|
||||
}
|
||||
|
||||
|
||||
public static function readDouble($str){
|
||||
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", $str):unpack("d", strrev($str));
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
public static function writeDouble($value){
|
||||
return ENDIANNESS === BIG_ENDIAN ? pack("d", $value):strrev(pack("d", $value));
|
||||
}
|
||||
|
||||
|
||||
public static function readLDouble($str){
|
||||
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", strrev($str)):unpack("d", $str);
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
public static function writeLDouble($value){
|
||||
return ENDIANNESS === BIG_ENDIAN ? strrev(pack("d", $value)):pack("d", $value);
|
||||
}
|
||||
|
|
@ -473,20 +473,20 @@ abstract class Utils{
|
|||
$long = new Math_BigInteger($str, -256);
|
||||
return $long->toString();
|
||||
}
|
||||
|
||||
|
||||
public static function writeLong($value){
|
||||
$long = new Math_BigInteger($value, -10);
|
||||
return str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
|
||||
public static function readLLong($str){
|
||||
$long = new Math_BigInteger(strrev($str), -256);
|
||||
return $long->toString();
|
||||
}
|
||||
|
||||
|
||||
public static function writeLLong($value){
|
||||
$long = new Math_BigInteger($value, -10);
|
||||
return strrev(str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ define("WINDOW_FURNACE", 2);
|
|||
class Window{
|
||||
private $server;
|
||||
public function __construct(PocketMinecraftServer $server){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue