New extra.properties and ClientRenderFix

This commit is contained in:
kotyaralih 2022-01-31 15:43:13 +00:00
parent c3954dbdae
commit a6aa36bbba
5 changed files with 175 additions and 10 deletions

View file

@ -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();
}
}
}

View file

@ -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;

View file

@ -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"){

View file

@ -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]);

View file

@ -0,0 +1,143 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class ClientRenderFix {
public $player;
private $server, $startingFromX, $startingFromZ, $sideLength = 1, $doing = 0, $nUpdated = 0,$sideIndex = 0, $spiralDone = false,$startChunkX, $startChunkZ;
public function __construct($player, $freq) {
if(!$player instanceof Player) return;
$this->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);
}
}