mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 23:15:29 +00:00
New Player::directBigRawPacket() method
This commit is contained in:
parent
db97c0c5f7
commit
295363a381
@ -39,7 +39,7 @@ class Player{
|
|||||||
private $clientID;
|
private $clientID;
|
||||||
private $ip;
|
private $ip;
|
||||||
private $port;
|
private $port;
|
||||||
private $counter = array(0, 0, 0);
|
private $counter = array(0, 0, 0, 0, 0);
|
||||||
private $username;
|
private $username;
|
||||||
private $iusername;
|
private $iusername;
|
||||||
private $eid = false;
|
private $eid = false;
|
||||||
@ -65,6 +65,7 @@ class Player{
|
|||||||
private $freedChunks = true;
|
private $freedChunks = true;
|
||||||
public $itemEnforcement;
|
public $itemEnforcement;
|
||||||
public $lastCorrect;
|
public $lastCorrect;
|
||||||
|
private $bigCnt;
|
||||||
|
|
||||||
public function __get($name){
|
public function __get($name){
|
||||||
if(isset($this->{$name})){
|
if(isset($this->{$name})){
|
||||||
@ -74,6 +75,7 @@ class Player{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function __construct($clientID, $ip, $port, $MTU){
|
public function __construct($clientID, $ip, $port, $MTU){
|
||||||
|
$this->bigCnt = 0;
|
||||||
$this->MTU = $MTU;
|
$this->MTU = $MTU;
|
||||||
$this->server = ServerAPI::request();
|
$this->server = ServerAPI::request();
|
||||||
$this->lastBreak = microtime(true);
|
$this->lastBreak = microtime(true);
|
||||||
@ -163,18 +165,10 @@ class Player{
|
|||||||
$x = $X << 4;
|
$x = $X << 4;
|
||||||
$z = $Z << 4;
|
$z = $Z << 4;
|
||||||
$y = $Y << 4;
|
$y = $Y << 4;
|
||||||
$MTU = $this->MTU - 16;
|
|
||||||
$this->level->useChunk($X, $Z, $this);
|
$this->level->useChunk($X, $Z, $this);
|
||||||
$chunk = $this->level->getOrderedMiniChunk($X, $Z, $Y, $MTU);
|
$this->directBigRawPacket(MC_CHUNK_DATA, Utils::writeInt($X) . Utils::writeInt($Z) . $this->level->getOrderedMiniChunk($X, $Z, $Y));
|
||||||
foreach($chunk as $d){
|
|
||||||
$this->dataPacket(MC_CHUNK_DATA, array(
|
|
||||||
"x" => $X,
|
|
||||||
"z" => $Z,
|
|
||||||
"data" => $d,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$tiles = $this->server->query("SELECT ID FROM tileentities WHERE spawnable = 1 AND x >= ".($x - 1)." AND x < ".($x + 17)." AND z >= ".($z - 1)." AND z < ".($z + 17)." AND y >= ".($y - 1)." AND y < ".($y + 17).";");
|
$tiles = $this->server->query("SELECT ID FROM tileentities WHERE spawnable = 1 AND level = '".$this->level->getName()."' AND x >= ".($x - 1)." AND x < ".($x + 17)." AND z >= ".($z - 1)." AND z < ".($z + 17)." AND y >= ".($y - 1)." AND y < ".($y + 17).";");
|
||||||
if($tiles !== false and $tiles !== true){
|
if($tiles !== false and $tiles !== true){
|
||||||
while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
|
while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
$this->server->api->tileentity->spawnTo($tile["ID"], $this);
|
$this->server->api->tileentity->spawnTo($tile["ID"], $this);
|
||||||
@ -1368,6 +1362,40 @@ class Player{
|
|||||||
$this->nextBuffer = microtime(true) + 0.1;
|
$this->nextBuffer = microtime(true) + 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function directBigRawPacket($id, $buffer){
|
||||||
|
if($this->connected === false){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$data = array(
|
||||||
|
"id" => false,
|
||||||
|
"sendtime" => microtime(true),
|
||||||
|
"raw" => "",
|
||||||
|
);
|
||||||
|
$size = $this->MTU - 32;
|
||||||
|
$buffer = str_split(chr($id).$buffer, $size);
|
||||||
|
$h = strrev(Utils::writeTriad($this->counter[4]++))."\x00".Utils::writeInt(count($buffer)).Utils::writeShort($this->bigCnt);
|
||||||
|
$this->counter[4] %= 0x1000000;
|
||||||
|
$this->bigCnt = ($this->bigCnt + 1) % 0x10000;
|
||||||
|
foreach($buffer as $i => $buf){
|
||||||
|
$data["raw"] = Utils::writeShort(strlen($buf) << 3).strrev(Utils::writeTriad($this->counter[3]++)).$h.Utils::writeInt($i).$buf;
|
||||||
|
$this->counter[3] %= 0x1000000;
|
||||||
|
$count = $this->counter[0]++;
|
||||||
|
if(count($this->recovery) >= 1024){
|
||||||
|
reset($this->recovery);
|
||||||
|
$k = key($this->recovery);
|
||||||
|
$this->recovery[$k] = null;
|
||||||
|
unset($this->recovery[$k]);
|
||||||
|
end($this->recovery);
|
||||||
|
}
|
||||||
|
$this->recovery[$count] = $data;
|
||||||
|
$this->send(0x80, array(
|
||||||
|
$count,
|
||||||
|
0x70,
|
||||||
|
$data,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function directDataPacket($id, $data = array(), $count = false){
|
public function directDataPacket($id, $data = array(), $count = false){
|
||||||
if($this->connected === false){
|
if($this->connected === false){
|
||||||
return false;
|
return false;
|
||||||
@ -1375,8 +1403,7 @@ class Player{
|
|||||||
$data["id"] = $id;
|
$data["id"] = $id;
|
||||||
$data["sendtime"] = microtime(true);
|
$data["sendtime"] = microtime(true);
|
||||||
if($count === false){
|
if($count === false){
|
||||||
$count = $this->counter[0];
|
$count = $this->counter[0]++;
|
||||||
++$this->counter[0];
|
|
||||||
if(count($this->recovery) >= 1024){
|
if(count($this->recovery) >= 1024){
|
||||||
reset($this->recovery);
|
reset($this->recovery);
|
||||||
$k = key($this->recovery);
|
$k = key($this->recovery);
|
||||||
|
@ -25,9 +25,14 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class StillWaterBlock extends LiquidBlock{
|
|
||||||
|
/***REM_START***/
|
||||||
|
require_once("Water.php");
|
||||||
|
/***REM_END***/
|
||||||
|
|
||||||
|
class StillWaterBlock extends WaterBlock{
|
||||||
public function __construct($meta = 0){
|
public function __construct($meta = 0){
|
||||||
parent::__construct(STILL_WATER, $meta, "Still Water");
|
LiquidBlock::__construct(STILL_WATER, $meta, "Still Water");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -30,4 +30,26 @@ class WaterBlock extends LiquidBlock{
|
|||||||
parent::__construct(WATER, $meta, "Water");
|
parent::__construct(WATER, $meta, "Water");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
return false;
|
||||||
|
$level = $this->meta & 0x03;
|
||||||
|
if($type !== BLOCK_UPDATE_NORMAL or $level === 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$falling = $this->meta >> 3;
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->isFlowable){
|
||||||
|
$this->level->setBlock($down, new WaterBlock(9), true); //1001
|
||||||
|
return;
|
||||||
|
}elseif($down instanceof WaterBlock and $down->getMetadata() === 9){
|
||||||
|
$level = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$up = $this->getSide(1);
|
||||||
|
if($up instanceof WaterBlock){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -102,7 +102,7 @@ class Packet{
|
|||||||
case 0x40:
|
case 0x40:
|
||||||
$reply = new CustomPacketHandler($this->data[2]["id"], "", $this->data[2], true);
|
$reply = new CustomPacketHandler($this->data[2]["id"], "", $this->data[2], true);
|
||||||
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
|
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
|
||||||
$this->addRaw(Utils::writeTriad(strrev($this->data[2]["count"])));
|
$this->addRaw(strrev(Utils::writeTriad($this->data[2]["count"])));
|
||||||
$this->addRaw(chr($this->data[2]["id"]));
|
$this->addRaw(chr($this->data[2]["id"]));
|
||||||
$this->addRaw($reply->raw);
|
$this->addRaw($reply->raw);
|
||||||
break;
|
break;
|
||||||
@ -117,6 +117,11 @@ class Packet{
|
|||||||
$this->addRaw($this->data[2]["raw"]);
|
$this->addRaw($this->data[2]["raw"]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
if($this->data[2]["id"] === false){
|
||||||
|
$this->addRaw($this->data[2]["raw"]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "magic":
|
case "magic":
|
||||||
@ -251,6 +256,8 @@ class Packet{
|
|||||||
$offset += 2;
|
$offset += 2;
|
||||||
$splitIndex = Utils::readInt(substr($raw, $offset, 4));
|
$splitIndex = Utils::readInt(substr($raw, $offset, 4));
|
||||||
$offset += 4;
|
$offset += 4;
|
||||||
|
//error! no split packets allowed!
|
||||||
|
break;
|
||||||
}else{
|
}else{
|
||||||
$splitCount = 0;
|
$splitCount = 0;
|
||||||
$splitID = 0;
|
$splitID = 0;
|
||||||
|
@ -215,23 +215,15 @@ class Level{
|
|||||||
return $this->level->unloadChunk($X, $Z);
|
return $this->level->unloadChunk($X, $Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrderedMiniChunk($X, $Z, $Y, $MTU){
|
public function getOrderedMiniChunk($X, $Z, $Y){
|
||||||
$raw = $this->level->getMiniChunk($X, $Z, $Y);
|
$raw = $this->level->getMiniChunk($X, $Z, $Y);
|
||||||
$ordered = array();
|
$ordered = "";
|
||||||
$i = 0;
|
|
||||||
$ordered[$i] = "";
|
|
||||||
$cnt = 0;
|
|
||||||
$flag = chr(1 << $Y);
|
$flag = chr(1 << $Y);
|
||||||
for($j = 0; $j < 256; ++$j){
|
for($j = 0; $j < 256; ++$j){
|
||||||
if((strlen($ordered[$i]) + 16 + 8 + 1) > $MTU){
|
|
||||||
++$i;
|
|
||||||
$ordered[$i] = str_repeat("\x00", $cnt);
|
|
||||||
}
|
|
||||||
$index = $j << 5;
|
$index = $j << 5;
|
||||||
$ordered[$i] .= $flag;
|
$ordered .= $flag;
|
||||||
$ordered[$i] .= substr($raw, $index, 16);
|
$ordered .= substr($raw, $index, 16);
|
||||||
$ordered[$i] .= substr($raw, $index + 16, 8);
|
$ordered .= substr($raw, $index + 16, 8);
|
||||||
++$cnt;
|
|
||||||
}
|
}
|
||||||
return $ordered;
|
return $ordered;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user