diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 2a3a2bb1..cee34f0f 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -479,13 +479,15 @@ class PlayerAPI{ ); if(!file_exists(DATA_PATH."players/".$iname.".yml")){ - console("[NOTICE] Player data not found for \"".$iname."\", creating new profile"); - $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); - $data->save(); - }else{ - $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); + if($this->server->extraprops->get("save-player-data")) { + console("[NOTICE] Player data not found for \"".$iname."\", creating new profile"); + $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); + $data->save(); + } } + $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); + if(($data->get("gamemode") & 0x01) === 1){ $data->set("health", 20); } @@ -494,7 +496,9 @@ class PlayerAPI{ } public function saveOffline(Config $data){ - $this->server->handle("player.offline.save", $data); - $data->save(); + if($this->server->extraprops->get("save-player-data")) { + $this->server->handle("player.offline.save", $data); + $data->save(); + } } } diff --git a/src/Player.php b/src/Player.php index a56b15c7..e6de0cb0 100644 --- a/src/Player.php +++ b/src/Player.php @@ -939,6 +939,12 @@ class Player{ } } + if($pos->level->getName() !== $this->level->getName()) { // we're switching levels. + $rf = new ClientRenderFix($this); + if($this->server->extraprops->get("update-client-on-world-switch")) { + $rf = new ClientRenderFix($this, $this->server->extraprops->get("update-frequency")); + } + } $this->level->freeAllChunks($this); $this->level = $pos->level; diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 3a2cca37..fc99d49b 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -21,7 +21,7 @@ class PocketMinecraftServer{ public $tCnt; - public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; + public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = array(), $asyncID = 0; /** @@ -30,6 +30,7 @@ class PocketMinecraftServer{ public $api; private function load(){ + global $dolog; $this->version = new VersionString(); /*if(defined("DEBUG") and DEBUG >= 0){ @cli_set_process_title("PocketMine-MP ".MAJOR_VERSION); @@ -70,6 +71,15 @@ class PocketMinecraftServer{ if(!defined("NO_THREADS")){ $this->asyncThread = new AsyncMultipleQueue(); } + console("[NostalgiaCore] Loading extra.properties..."); + $this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, array( + "update-client-on-world-switch" => true, + "update-frequency" => 8, + "save-player-data" => true, + "save-console-data" => true + )); + + $dolog = $this->extraprops->get("save-console-data"); } function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){ diff --git a/src/functions.php b/src/functions.php index 720d8062..f032f83b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -245,7 +245,7 @@ function error_handler($errno, $errstr, $errfile, $errline){ } function logg($message, $name, $EOL = true, $level = 2, $close = false){ - global $fpointers; + global $fpointers, $dolog; if((!defined("DEBUG") or DEBUG >= $level) and (!defined("LOG") or LOG === true)){ $message .= $EOL === true ? PHP_EOL:""; if(!isset($fpointers)){ @@ -254,7 +254,9 @@ function logg($message, $name, $EOL = true, $level = 2, $close = false){ if(!isset($fpointers[$name]) or $fpointers[$name] === false){ $fpointers[$name] = @fopen(DATA_PATH."/".$name.".log", "ab"); } - @fwrite($fpointers[$name], $message); + if($dolog) { + @fwrite($fpointers[$name], $message); + } if($close === true){ fclose($fpointers[$name]); unset($fpointers[$name]); diff --git a/src/world/ClientRenderFix.php b/src/world/ClientRenderFix.php new file mode 100644 index 00000000..72f4bf70 --- /dev/null +++ b/src/world/ClientRenderFix.php @@ -0,0 +1,143 @@ +server = ServerAPI::request(); + $this->player = $player; + $this->startingFromX = round($player->entity->x,0); + $this->startChunkX = $this->block2Chunk($this->startingFromX); + $this->lowerLeftChunkX = $this->startChunkX; + $this->startingFromZ = round($player->entity->z,0); + $this->startChunkZ = $this->block2Chunk($this->startingFromZ); + $this->lowerLeftChunkZ = $this->startChunkZ; + $this->server->schedule($freq, array($this,"updateSpiral"),array(),true); + // Doing 0 = bottom, 1 = left side, 2 = top, 3 = right side. + } + + private function block2Chunk($inputBlock) { + $output = intval($inputBlock / 16); + return $output; + } + private function chunk2MidBlock($inputChunk) { + $output = $inputChunk * 16 + 8; + return $output; + } + + // Given x and y chunks, see if these chunks lie within the world. + // If they do, send out the packet and increase our nupdated. Otherwise, return false. + // Also, check to see if we are done. + private function try2Update($xChunk, $zChunk) { + if($xChunk < 0) return false; + if($xChunk > 15) return false; + if($zChunk < 0) return false; + if($zChunk > 15) return false; + $this->mkPacket($this->chunk2MidBlock($xChunk), $this->chunk2MidBlock($zChunk)); + $this->nUpdated++; + if($this->nUpdated > 255) { + $this->spiralDone = true; + } + + return true; + } + + // Send a spiral, which is really a box that grows around the starting chunk x, z. + // This function should be called set up for whatever chunk it expects to try next. + // For each growing box it sends the bottom, left side, top, right side. + public function updateSpiral() { + if(!$this->player instanceof Player) return false; + $sentPacket = false; + $maxSideIndex = $this->sideLength - 1; + + // Keep try to send chunks until we succeed in sending one. + while(!$sentPacket) { + // Prevent problem is updating from locking up server. Should never happen: + if ($this->sideLength > 32) return false; + + switch($this->doing) { + case 0: // Sending bottom. Send index 0 to sideLength; + $sentPacket = $this->try2Update($this->lowerLeftChunkX + $this->sideIndex, $this->lowerLeftChunkZ); + // Look for special case of first chunk sent. If so, move the lowerLeft down and left one. + if($this->sideLength === 1) { + $this->lowerLeftChunkX--; + $this->lowerLeftChunkZ--; + $this->sideLength += 2; + $this->sideIndex = 0; + $this->doing = 0; + break; + } + // Check to see if we are done sending bottom: + $this->sideIndex++; + if($this->sideIndex > $maxSideIndex) { + $this->doing = 1; // Set up to start sending left side. + $this->sideIndex = 1; // start with index 1, not zero. + } + break; + case 1: // Sending left side + $sentPacket = $this->try2Update($this->lowerLeftChunkX, $this->lowerLeftChunkZ + $this->sideIndex); + // Done sending left? + $this->sideIndex++; + if($this->sideIndex >= $this->sideLength) { + $this->sideIndex = 1; + $this->doing = 2; + } + break; + case 2: // Sending top + $sentPacket = $this->try2Update($this->lowerLeftChunkX + $this->sideIndex, $this->lowerLeftChunkZ + $maxSideIndex); + $this->sideIndex++; + // Done sending top? + if($this->sideIndex >= $this->sideLength) { + $this->sideIndex = 1; + $this->doing = 3; + } + break; + case 3: // Sending right + $sentPacket = $this->try2Update( $this->lowerLeftChunkX + $maxSideIndex, $this->lowerLeftChunkZ + $this->sideIndex); + $this->sideIndex++; + // Done sending top? If so, move the lower left down and left a chunk, increase sideLength by 2. + if ($this->sideIndex >= $maxSideIndex) { + $this->lowerLeftChunkX--; + $this->lowerLeftChunkZ--; + $this->sideLength += 2; + $this->sideIndex = 0; + $this->doing = 0; + } + break; + } + } + + if($this->spiralDone === false) return true; + if($this->spiralDone === true) return false; + } + + + public function mkPacket($x,$z) { + $pk = new UpdateBlockPacket(); + $pk->x = $x; + $pk->z = $z; + $pk->y = 127; + $pk->block = GLOWSTONE_BLOCK; + $pk->meta = 0; + $this->player->dataPacket($pk); + } +} \ No newline at end of file