mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 15:35:52 +00:00
Fixed ChunkData, faster, action queue, NACK
This commit is contained in:
parent
a7ec472ef4
commit
22ef626c4f
@ -165,7 +165,7 @@ class ConsoleAPI{
|
||||
break;
|
||||
case "block":
|
||||
foreach($this->server->clients as $client){
|
||||
$b = $this->server->map->getBlock($client->entity->position["x"], $client->entity->position["y"] - 2, $client->entity->position["z"]);
|
||||
$b = $this->server->map->getBlock(round($client->entity->position["x"] - 0.5), round($client->entity->position["y"] - 1), round($client->entity->position["z"] - 0.5));
|
||||
console("[INFO] EID ".$client->eid." is over block ".$b[0].":".$b[1]);
|
||||
}
|
||||
break;
|
||||
|
@ -60,7 +60,7 @@ class LevelAPI{
|
||||
for($i = 0;$i < 0xff; ){
|
||||
$ordered[$i] = str_repeat("\x00", $i);
|
||||
for($j = 0; $j < $columnsPerPacket; ++$j){
|
||||
if(($i + $j) >= 0xff){
|
||||
if(($i + $j) > 0xff){
|
||||
break;
|
||||
}
|
||||
$ordered[$i] .= "\xff";
|
||||
|
@ -164,7 +164,6 @@ class ChunkParser{
|
||||
$aZ = $z - ($Z << 4);
|
||||
$index = $aX + ($aZ << 4);
|
||||
console("[DEBUG] $x $y $z | $X $Z $index", true, true, 2);
|
||||
var_dump($this->map[$X][$Z][0][$index]);
|
||||
$block = ord($this->map[$X][$Z][0][$index]{$y});
|
||||
//$meta = $this->getOffset($X, $Z) + 4 + (($x << 6) + $y + ($z << 10));
|
||||
return array($block, 0);
|
||||
|
@ -27,10 +27,11 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
|
||||
class Session{
|
||||
private $server, $timeout, $connected, $evid, $queue;
|
||||
private $server, $timeout, $connected, $evid, $queue, $buffer;
|
||||
var $clientID, $ip, $port, $counter, $username, $eid, $data, $entity, $auth, $CID, $MTU;
|
||||
function __construct($server, $clientID, $eid, $ip, $port, $MTU){
|
||||
$this->queue = array();
|
||||
$this->buffer = array();
|
||||
$this->MTU = $MTU;
|
||||
$this->server = $server;
|
||||
$this->clientID = $clientID;
|
||||
@ -55,10 +56,21 @@ class Session{
|
||||
$this->close("timeout");
|
||||
}else{
|
||||
if(count($this->queue) > 0){
|
||||
$limit = $time + 0.1;
|
||||
while($limit > microtime(true)){
|
||||
$cnt = 0;
|
||||
while($cnt < 4){
|
||||
$p = array_shift($this->queue);
|
||||
$this->dataPacket($p[0], $p[1]);
|
||||
if($p === null){
|
||||
break;
|
||||
}
|
||||
switch($p[0]){
|
||||
case 0:
|
||||
$this->dataPacket($p[1], $p[2], false, $p[3]);
|
||||
break;
|
||||
case 1:
|
||||
eval($p[1]);
|
||||
break;
|
||||
}
|
||||
++$cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,6 +203,22 @@ class Session{
|
||||
if($this->connected === true){
|
||||
$this->timeout = microtime(true) + 25;
|
||||
switch($pid){
|
||||
case 0xa0: //NACK
|
||||
if(isset($this->buffer[$data[2]])){
|
||||
array_unshift($this->queue, array(0, $this->buffer[$data[2]][0], $this->buffer[$data[2]][1], $data[2]));
|
||||
}
|
||||
if(isset($data[3])){
|
||||
if(isset($this->buffer[$data[3]])){
|
||||
array_unshift($this->queue, array(0, $this->buffer[$data[3]][0], $this->buffer[$data[3]][1], $data[3]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xc0: //ACK
|
||||
unset($this->buffer[$data[2]]);
|
||||
if(isset($data[3])){
|
||||
unset($this->buffer[$data[3]]);
|
||||
}
|
||||
break;
|
||||
case 0x07:
|
||||
$this->send(0x08, array(
|
||||
MAGIC,
|
||||
@ -321,16 +349,18 @@ class Session{
|
||||
console("[DEBUG] EID ".$this->eid." has now ".$data["block"].":".$data["meta"]." in their hands!", true, true, 2);
|
||||
break;
|
||||
case MC_REQUEST_CHUNK:
|
||||
$this->actionQueue('
|
||||
$max = floor(($this->MTU - 16 - 255) / 192);
|
||||
$chunk = $this->server->api->level->getOrderedChunk($data["x"], $data["z"], $max);
|
||||
$chunk = $this->server->api->level->getOrderedChunk('.$data["x"].', '.$data["z"].', $max);
|
||||
foreach($chunk as $d){
|
||||
$this->dataPacket(MC_CHUNK_DATA, array(
|
||||
"x" => $data["x"],
|
||||
"z" => $data["z"],
|
||||
"x" => '.$data["x"].',
|
||||
"z" => '.$data["z"].',
|
||||
"data" => $d,
|
||||
), true);
|
||||
}
|
||||
console("[DEBUG] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 2);
|
||||
');
|
||||
console("[DEBUG] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 2);
|
||||
break;
|
||||
case MC_REMOVE_BLOCK:
|
||||
console("[DEBUG] EID ".$this->eid." broke block at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
|
||||
@ -383,17 +413,28 @@ class Session{
|
||||
}
|
||||
}
|
||||
|
||||
public function dataPacket($id, $data = array(), $queue = false){
|
||||
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($id, $data);
|
||||
$this->queue[] = array(0, $id, $data, $count);
|
||||
}else{
|
||||
if($count === false){
|
||||
$count = $this->counter[0];
|
||||
++$this->counter[0];
|
||||
if(count($this->buffer) >= 512){
|
||||
array_shift($this->buffer);
|
||||
}
|
||||
$this->buffer[$count] = array($id, $data);
|
||||
}
|
||||
$data["id"] = $id;
|
||||
$this->send(0x84, array(
|
||||
$this->counter[0],
|
||||
$count,
|
||||
0x00,
|
||||
$data,
|
||||
));
|
||||
++$this->counter[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user