From 5651fc1cb13293d392a9c52aee1f9bf77bec8315 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 28 Feb 2014 20:39:59 +0100 Subject: [PATCH] Fixed level block and chunk sending --- src/API/PlayerAPI.php | 19 ------------------- src/Player.php | 9 +++++++-- src/entity/PlayerEntity.php | 9 ++++++++- src/pmf/PMFLevel.php | 10 +++++++--- src/world/Level.php | 8 +++----- 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index a1ac81b6e..f0ea1feb8 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -455,25 +455,6 @@ class PlayerAPI{ } } - public function remove($CID){ - if(isset($this->server->clients[$CID])){ - $player = $this->server->clients[$CID]; - unset($this->server->clients[$CID]); - $player->close(); - if($player->username != "" and ($player->data instanceof Config)){ - $this->saveOffline($player->data); - } - $this->server->query("DELETE FROM players WHERE name = '".$player->username."';"); - if($player->entity instanceof Entity){ - unset($player->entity->player); - //unset($player->entity); - $player->entity->close(); - } - $player = null; - unset($player); - } - } - public function getOffline($name){ $iname = strtolower($name); $default = array( diff --git a/src/Player.php b/src/Player.php index 5d75e41e8..6f34287c3 100644 --- a/src/Player.php +++ b/src/Player.php @@ -305,7 +305,11 @@ class Player extends PlayerEntity{ $this->receiveQueue = array(); $this->resendQueue = array(); $this->ackQueue = array(); - $this->server->api->player->remove($this->CID); + unset($this->server->clients[$this->CID]); + if($this->username != "" and ($this->data instanceof Config)){ + //TODO + //$this->saveOffline($player->data); + } if($msg === true and $this->username != "" and $this->spawned !== false){ $this->server->api->chat->broadcast($this->username." left the game"); } @@ -319,6 +323,7 @@ class Player extends PlayerEntity{ $this->chunkCount = array(); $this->craftingItems = array(); $this->received = array(); + parent::close(); } } @@ -1462,7 +1467,7 @@ class Player extends PlayerEntity{ //$this->server->api->player->spawnToAllPlayers($this); //TODO //$this->server->api->entity->spawnAll($this); - $this->spawnToAll(); + //$this->spawnToAll(); //$this->sendArmor(); $this->sendChat($this->server->motd."\n"); diff --git a/src/entity/PlayerEntity.php b/src/entity/PlayerEntity.php index 6ad89073d..6e8a8cf96 100644 --- a/src/entity/PlayerEntity.php +++ b/src/entity/PlayerEntity.php @@ -20,5 +20,12 @@ */ class PlayerEntity extends HumanEntity{ - + + protected function initEntity(){ + $this->level->players[$this->CID] = $this; + } + + public function close(){ + unset($this->level->players[$this->CID]); + } } \ No newline at end of file diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index b41d45823..44ad842f1 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -208,7 +208,8 @@ class PMFLevel extends PMF{ } $this->initCleanChunk($X, $Z); $ret = $this->level->generateChunk($X, $Z); - $this->saveChunk($X, $Z); + $this->saveChunk($X, $Z); + echo decbin($this->chunkInfo[self::getIndex($X, $Z)][0]).PHP_EOL; $this->populateChunk($X - 1, $Z); $this->populateChunk($X + 1, $Z); $this->populateChunk($X, $Z - 1); @@ -222,6 +223,7 @@ class PMFLevel extends PMF{ public function populateChunk($X, $Z){ if($this->isGenerating === 0 and + $this->isChunkLoaded($X, $Z) and !$this->isPopulated($X, $Z) and $this->isGenerated($X - 1, $Z) and $this->isGenerated($X, $Z - 1) and @@ -231,6 +233,7 @@ class PMFLevel extends PMF{ $this->isGenerated($X - 1, $Z - 1) and $this->isGenerated($X + 1, $Z - 1) and $this->isGenerated($X - 1, $Z + 1)){ + echo "pop $X $Z\n"; $this->level->populateChunk($X, $Z); $this->saveChunk($X, $Z); } @@ -240,6 +243,7 @@ class PMFLevel extends PMF{ if($this->isChunkLoaded($X, $Z)){ return true; } + echo "load $X $Z\n"; $index = self::getIndex($X, $Z); $path = $this->getChunkPath($X, $Z); if(!file_exists($path)){ @@ -644,6 +648,8 @@ class PMFLevel extends PMF{ } $this->chunkChange[$index][$Y] = 0; } + $this->chunkInfo[$index][0] = $bitmap; + $this->chunkChange[$index][-1] = false; $chunk = b""; $chunk .= chr($bitmap); $chunk .= Utils::writeInt($this->chunkInfo[$index][1]); @@ -657,8 +663,6 @@ class PMFLevel extends PMF{ } } file_put_contents($path, zlib_encode($chunk, PMFLevel::ZLIB_ENCODING, PMFLevel::ZLIB_LEVEL)); - $this->chunkChange[$index][-1] = false; - $this->chunkInfo[$index][0] = $bitmap; return true; } diff --git a/src/world/Level.php b/src/world/Level.php index 200c8ac55..20d5daf7b 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -64,9 +64,7 @@ class Level{ public function useChunk($X, $Z, Player $player){ $index = PMFLevel::getIndex($X, $Z); - if(!isset($this->usedChunks[$index])){ - $this->loadChunk($X, $Z); - } + $this->loadChunk($X, $Z); $this->usedChunks[$index][$player->CID] = true; } @@ -368,7 +366,7 @@ class Level{ public function getChunkEntities($X, $Z){ $index = PMFLevel::getIndex($X, $Z); - if(isset($this->usedChunks[$index]) or $this->level->loadChunk($X, $Z) === true){ + if(isset($this->usedChunks[$index]) or $this->loadChunk($X, $Z) === true){ return $this->chunkEntities[$index]; } return array(); @@ -376,7 +374,7 @@ class Level{ public function getChunkTiles($X, $Z){ $index = PMFLevel::getIndex($X, $Z); - if(isset($this->usedChunks[$index]) or $this->level->loadChunk($X, $Z) === true){ + if(isset($this->usedChunks[$index]) or $this->loadChunk($X, $Z) === true){ return $this->chunkTiles[$index]; } return array();