From 31d8cc1cb556c9a95960e56de0fffbef13833b72 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 25 Aug 2023 13:23:38 +0100 Subject: [PATCH] Generate and use constants for pocketmine.yml constant names a couple of usages of properties that no longer exist couldn't be migrated. in addition, this revealed a couple of dead properties in the default file. this is not an ideal solution (I'd much rather model the configs using classes and map them) but in the absence of a good and reliable library to do that, this is the next best thing. --- .github/workflows/main.yml | 3 + ...enerate-pocketmine-yml-property-consts.php | 76 +++++++++++++ src/MemoryManager.php | 29 ++--- src/Server.php | 59 +++++----- src/YmlServerProperties.php | 107 ++++++++++++++++++ src/command/defaults/TimingsCommand.php | 3 +- src/crash/CrashDump.php | 7 +- src/network/mcpe/NetworkSession.php | 3 +- src/network/mcpe/raklib/RakLibInterface.php | 3 +- src/network/query/QueryInfo.php | 3 +- src/player/Player.php | 7 +- src/stats/SendUsageTask.php | 3 +- src/updater/UpdateChecker.php | 7 +- src/world/World.php | 9 +- 14 files changed, 258 insertions(+), 61 deletions(-) create mode 100644 build/generate-pocketmine-yml-property-consts.php create mode 100644 src/YmlServerProperties.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 022e0ab3a..a888d4254 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -158,6 +158,9 @@ jobs: - name: Regenerate BedrockData available files constants run: php build/generate-bedrockdata-path-consts.php + - name: Regenerate YmlServerProperties constants + run: php build/generate-pocketmine-yml-property-consts.php + - name: Verify code is unchanged run: | git diff diff --git a/build/generate-pocketmine-yml-property-consts.php b/build/generate-pocketmine-yml-property-consts.php new file mode 100644 index 000000000..b0e79519a --- /dev/null +++ b/build/generate-pocketmine-yml-property-consts.php @@ -0,0 +1,76 @@ + $constants + * @phpstan-param-out array $constants + */ +function collectProperties(string $prefix, array $properties, array &$constants) : void{ + foreach($properties as $propertyName => $property){ + $fullPropertyName = ($prefix !== "" ? $prefix . "." : "") . $propertyName; + + $constName = str_replace([".", "-"], "_", strtoupper($fullPropertyName)); + $constants[$constName] = $fullPropertyName; + + if(is_array($property)){ + collectProperties($fullPropertyName, $property, $constants); + } + } +} + +collectProperties("", $defaultConfig, $constants); +ksort($constants, SORT_STRING); + +$file = fopen(dirname(__DIR__) . '/src/YmlServerProperties.php', 'wb'); +if($file === false){ + fwrite(STDERR, "Failed to open output file\n"); + exit(1); +} +fwrite($file, " $propertyName){ + fwrite($file, "\tpublic const $constName = '$propertyName';\n"); +} +fwrite($file, "}\n"); + +fclose($file); + +echo "Done. Don't forget to run CS fixup after generating code.\n"; diff --git a/src/MemoryManager.php b/src/MemoryManager.php index 0e8502ff8..053498e7e 100644 --- a/src/MemoryManager.php +++ b/src/MemoryManager.php @@ -30,6 +30,7 @@ use pocketmine\scheduler\GarbageCollectionTask; use pocketmine\timings\Timings; use pocketmine\utils\Process; use pocketmine\utils\Utils; +use pocketmine\YmlServerProperties as Yml; use Symfony\Component\Filesystem\Path; use function arsort; use function count; @@ -109,7 +110,7 @@ class MemoryManager{ } private function init(ServerConfigGroup $config) : void{ - $this->memoryLimit = $config->getPropertyInt("memory.main-limit", 0) * 1024 * 1024; + $this->memoryLimit = $config->getPropertyInt(Yml::MEMORY_MAIN_LIMIT, 0) * 1024 * 1024; $defaultMemory = 1024; @@ -127,7 +128,7 @@ class MemoryManager{ } } - $hardLimit = $config->getPropertyInt("memory.main-hard-limit", $defaultMemory); + $hardLimit = $config->getPropertyInt(Yml::MEMORY_MAIN_HARD_LIMIT, $defaultMemory); if($hardLimit <= 0){ ini_set("memory_limit", '-1'); @@ -135,22 +136,22 @@ class MemoryManager{ ini_set("memory_limit", $hardLimit . "M"); } - $this->globalMemoryLimit = $config->getPropertyInt("memory.global-limit", 0) * 1024 * 1024; - $this->checkRate = $config->getPropertyInt("memory.check-rate", self::DEFAULT_CHECK_RATE); - $this->continuousTrigger = $config->getPropertyBool("memory.continuous-trigger", true); - $this->continuousTriggerRate = $config->getPropertyInt("memory.continuous-trigger-rate", self::DEFAULT_CONTINUOUS_TRIGGER_RATE); + $this->globalMemoryLimit = $config->getPropertyInt(Yml::MEMORY_GLOBAL_LIMIT, 0) * 1024 * 1024; + $this->checkRate = $config->getPropertyInt(Yml::MEMORY_CHECK_RATE, self::DEFAULT_CHECK_RATE); + $this->continuousTrigger = $config->getPropertyBool(Yml::MEMORY_CONTINUOUS_TRIGGER, true); + $this->continuousTriggerRate = $config->getPropertyInt(Yml::MEMORY_CONTINUOUS_TRIGGER_RATE, self::DEFAULT_CONTINUOUS_TRIGGER_RATE); - $this->garbageCollectionPeriod = $config->getPropertyInt("memory.garbage-collection.period", self::DEFAULT_TICKS_PER_GC); - $this->garbageCollectionTrigger = $config->getPropertyBool("memory.garbage-collection.low-memory-trigger", true); - $this->garbageCollectionAsync = $config->getPropertyBool("memory.garbage-collection.collect-async-worker", true); + $this->garbageCollectionPeriod = $config->getPropertyInt(Yml::MEMORY_GARBAGE_COLLECTION_PERIOD, self::DEFAULT_TICKS_PER_GC); + $this->garbageCollectionTrigger = $config->getPropertyBool(Yml::MEMORY_GARBAGE_COLLECTION_LOW_MEMORY_TRIGGER, true); + $this->garbageCollectionAsync = $config->getPropertyBool(Yml::MEMORY_GARBAGE_COLLECTION_COLLECT_ASYNC_WORKER, true); - $this->lowMemChunkRadiusOverride = $config->getPropertyInt("memory.max-chunks.chunk-radius", 4); - $this->lowMemChunkGC = $config->getPropertyBool("memory.max-chunks.trigger-chunk-collect", true); + $this->lowMemChunkRadiusOverride = $config->getPropertyInt(Yml::MEMORY_MAX_CHUNKS_CHUNK_RADIUS, 4); + $this->lowMemChunkGC = $config->getPropertyBool(Yml::MEMORY_MAX_CHUNKS_TRIGGER_CHUNK_COLLECT, true); - $this->lowMemDisableChunkCache = $config->getPropertyBool("memory.world-caches.disable-chunk-cache", true); - $this->lowMemClearWorldCache = $config->getPropertyBool("memory.world-caches.low-memory-trigger", true); + $this->lowMemDisableChunkCache = $config->getPropertyBool(Yml::MEMORY_WORLD_CACHES_DISABLE_CHUNK_CACHE, true); + $this->lowMemClearWorldCache = $config->getPropertyBool(Yml::MEMORY_WORLD_CACHES_LOW_MEMORY_TRIGGER, true); - $this->dumpWorkers = $config->getPropertyBool("memory.memory-dump.dump-async-worker", true); + $this->dumpWorkers = $config->getPropertyBool(Yml::MEMORY_MEMORY_DUMP_DUMP_ASYNC_WORKER, true); gc_enable(); } diff --git a/src/Server.php b/src/Server.php index 77d2ae393..00951c10a 100644 --- a/src/Server.php +++ b/src/Server.php @@ -120,6 +120,7 @@ use pocketmine\world\Position; use pocketmine\world\World; use pocketmine\world\WorldCreationOptions; use pocketmine\world\WorldManager; +use pocketmine\YmlServerProperties as Yml; use Ramsey\Uuid\UuidInterface; use Symfony\Component\Filesystem\Path; use function array_fill; @@ -496,7 +497,7 @@ class Server{ } public function shouldSavePlayerData() : bool{ - return $this->configGroup->getPropertyBool("player.save-player-data", true); + return $this->configGroup->getPropertyBool(Yml::PLAYER_SAVE_PLAYER_DATA, true); } public function getOfflinePlayer(string $name) : Player|OfflinePlayer|null{ @@ -736,7 +737,7 @@ class Server{ * @return string[][] */ public function getCommandAliases() : array{ - $section = $this->configGroup->getProperty("aliases"); + $section = $this->configGroup->getProperty(YmlServerProperties::ALIASES); $result = []; if(is_array($section)){ foreach($section as $key => $value){ @@ -834,12 +835,12 @@ class Server{ ]) ); - $debugLogLevel = $this->configGroup->getPropertyInt("debug.level", 1); + $debugLogLevel = $this->configGroup->getPropertyInt(Yml::DEBUG_LEVEL, 1); if($this->logger instanceof MainLogger){ $this->logger->setLogDebug($debugLogLevel > 1); } - $this->forceLanguage = $this->configGroup->getPropertyBool("settings.force-language", false); + $this->forceLanguage = $this->configGroup->getPropertyBool(Yml::SETTINGS_FORCE_LANGUAGE, false); $selectedLang = $this->configGroup->getConfigString(ServerProperties::LANGUAGE, $this->configGroup->getPropertyString("settings.language", Language::FALLBACK_LANGUAGE)); try{ $this->language = new Language($selectedLang); @@ -856,11 +857,11 @@ class Server{ $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::language_selected($this->getLanguage()->getName(), $this->getLanguage()->getLang()))); if(VersionInfo::IS_DEVELOPMENT_BUILD){ - if(!$this->configGroup->getPropertyBool("settings.enable-dev-builds", false)){ + if(!$this->configGroup->getPropertyBool(Yml::SETTINGS_ENABLE_DEV_BUILDS, false)){ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error1(VersionInfo::NAME))); $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error2())); $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error3())); - $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error4("settings.enable-dev-builds"))); + $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error4(YmlServerProperties::SETTINGS_ENABLE_DEV_BUILDS))); $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error5("https://github.com/pmmp/PocketMine-MP/releases"))); $this->forceShutdownExit(); @@ -878,7 +879,7 @@ class Server{ $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_start(TextFormat::AQUA . $this->getVersion() . TextFormat::RESET))); - if(($poolSize = $this->configGroup->getPropertyString("settings.async-workers", "auto")) === "auto"){ + if(($poolSize = $this->configGroup->getPropertyString(Yml::SETTINGS_ASYNC_WORKERS, "auto")) === "auto"){ $poolSize = 2; $processors = Utils::getCoreCount() - 2; @@ -889,32 +890,32 @@ class Server{ $poolSize = max(1, (int) $poolSize); } - $this->asyncPool = new AsyncPool($poolSize, max(-1, $this->configGroup->getPropertyInt("memory.async-worker-hard-limit", 256)), $this->autoloader, $this->logger, $this->tickSleeper); + $this->asyncPool = new AsyncPool($poolSize, max(-1, $this->configGroup->getPropertyInt(Yml::MEMORY_ASYNC_WORKER_HARD_LIMIT, 256)), $this->autoloader, $this->logger, $this->tickSleeper); $netCompressionThreshold = -1; - if($this->configGroup->getPropertyInt("network.batch-threshold", 256) >= 0){ - $netCompressionThreshold = $this->configGroup->getPropertyInt("network.batch-threshold", 256); + if($this->configGroup->getPropertyInt(Yml::NETWORK_BATCH_THRESHOLD, 256) >= 0){ + $netCompressionThreshold = $this->configGroup->getPropertyInt(Yml::NETWORK_BATCH_THRESHOLD, 256); } if($netCompressionThreshold < 0){ $netCompressionThreshold = null; } - $netCompressionLevel = $this->configGroup->getPropertyInt("network.compression-level", 6); + $netCompressionLevel = $this->configGroup->getPropertyInt(Yml::NETWORK_COMPRESSION_LEVEL, 6); if($netCompressionLevel < 1 || $netCompressionLevel > 9){ $this->logger->warning("Invalid network compression level $netCompressionLevel set, setting to default 6"); $netCompressionLevel = 6; } ZlibCompressor::setInstance(new ZlibCompressor($netCompressionLevel, $netCompressionThreshold, ZlibCompressor::DEFAULT_MAX_DECOMPRESSION_SIZE)); - $this->networkCompressionAsync = $this->configGroup->getPropertyBool("network.async-compression", true); + $this->networkCompressionAsync = $this->configGroup->getPropertyBool(Yml::NETWORK_ASYNC_COMPRESSION, true); $this->networkCompressionAsyncThreshold = max( - $this->configGroup->getPropertyInt("network.async-compression-threshold", self::DEFAULT_ASYNC_COMPRESSION_THRESHOLD), + $this->configGroup->getPropertyInt(Yml::NETWORK_ASYNC_COMPRESSION_THRESHOLD, self::DEFAULT_ASYNC_COMPRESSION_THRESHOLD), $netCompressionThreshold ?? self::DEFAULT_ASYNC_COMPRESSION_THRESHOLD ); - EncryptionContext::$ENABLED = $this->configGroup->getPropertyBool("network.enable-encryption", true); + EncryptionContext::$ENABLED = $this->configGroup->getPropertyBool(Yml::NETWORK_ENABLE_ENCRYPTION, true); - $this->doTitleTick = $this->configGroup->getPropertyBool("console.title-tick", true) && Terminal::hasFormattingCodes(); + $this->doTitleTick = $this->configGroup->getPropertyBool(Yml::CONSOLE_TITLE_TICK, true) && Terminal::hasFormattingCodes(); $this->operators = new Config(Path::join($this->dataPath, "ops.txt"), Config::ENUM); $this->whitelist = new Config(Path::join($this->dataPath, "white-list.txt"), Config::ENUM); @@ -963,8 +964,8 @@ class Server{ ))); $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_license($this->getName()))); - TimingsHandler::setEnabled($this->configGroup->getPropertyBool("settings.enable-profiling", false)); - $this->profilingTickRate = $this->configGroup->getPropertyInt("settings.profile-report-trigger", self::TARGET_TICKS_PER_SECOND); + TimingsHandler::setEnabled($this->configGroup->getPropertyBool(Yml::SETTINGS_ENABLE_PROFILING, false)); + $this->profilingTickRate = $this->configGroup->getPropertyInt(Yml::SETTINGS_PROFILE_REPORT_TRIGGER, self::TARGET_TICKS_PER_SECOND); DefaultPermissions::registerCorePermissions(); @@ -986,13 +987,13 @@ class Server{ $this->forceShutdownExit(); return; } - $this->pluginManager = new PluginManager($this, $this->configGroup->getPropertyBool("plugins.legacy-data-dir", true) ? null : Path::join($this->getDataPath(), "plugin_data"), $pluginGraylist); + $this->pluginManager = new PluginManager($this, $this->configGroup->getPropertyBool(Yml::PLUGINS_LEGACY_DATA_DIR, true) ? null : Path::join($this->getDataPath(), "plugin_data"), $pluginGraylist); $this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader)); $this->pluginManager->registerInterface(new ScriptPluginLoader()); $providerManager = new WorldProviderManager(); if( - ($format = $providerManager->getProviderByName($formatName = $this->configGroup->getPropertyString("level-settings.default-format", ""))) !== null && + ($format = $providerManager->getProviderByName($formatName = $this->configGroup->getPropertyString(Yml::LEVEL_SETTINGS_DEFAULT_FORMAT, ""))) !== null && $format instanceof WritableWorldProviderManagerEntry ){ $providerManager->setDefault($format); @@ -1002,9 +1003,9 @@ class Server{ $this->worldManager = new WorldManager($this, Path::join($this->dataPath, "worlds"), $providerManager); $this->worldManager->setAutoSave($this->configGroup->getConfigBool(ServerProperties::AUTO_SAVE, $this->worldManager->getAutoSave())); - $this->worldManager->setAutoSaveInterval($this->configGroup->getPropertyInt("ticks-per.autosave", $this->worldManager->getAutoSaveInterval())); + $this->worldManager->setAutoSaveInterval($this->configGroup->getPropertyInt(Yml::TICKS_PER_AUTOSAVE, $this->worldManager->getAutoSaveInterval())); - $this->updater = new UpdateChecker($this, $this->configGroup->getPropertyString("auto-updater.host", "update.pmmp.io")); + $this->updater = new UpdateChecker($this, $this->configGroup->getPropertyString(Yml::AUTO_UPDATER_HOST, "update.pmmp.io")); $this->queryInfo = new QueryInfo($this); @@ -1041,7 +1042,7 @@ class Server{ return; } - if($this->configGroup->getPropertyBool("anonymous-statistics.enabled", true)){ + if($this->configGroup->getPropertyBool(Yml::ANONYMOUS_STATISTICS_ENABLED, true)){ $this->sendUsageTicker = self::TICKS_PER_STATS_REPORT; $this->sendUsage(SendUsageTask::TYPE_OPEN); } @@ -1057,7 +1058,7 @@ class Server{ $this->subscribeToBroadcastChannel(self::BROADCAST_CHANNEL_USERS, $forwarder); //TODO: move console parts to a separate component - if($this->configGroup->getPropertyBool("console.enable-input", true)){ + if($this->configGroup->getPropertyBool(Yml::CONSOLE_ENABLE_INPUT, true)){ $this->console = new ConsoleReaderChildProcessDaemon($this->logger); } @@ -1092,7 +1093,7 @@ class Server{ $anyWorldFailedToLoad = false; - foreach((array) $this->configGroup->getProperty("worlds", []) as $name => $options){ + foreach((array) $this->configGroup->getProperty(Yml::WORLDS, []) as $name => $options){ if($options === null){ $options = []; }elseif(!is_array($options)){ @@ -1238,7 +1239,7 @@ class Server{ $this->network->blockAddress($entry->getName(), -1); } - if($this->configGroup->getPropertyBool("network.upnp-forwarding", false)){ + if($this->configGroup->getPropertyBool(Yml::NETWORK_UPNP_FORWARDING, false)){ $this->network->registerInterface(new UPnPNetworkInterface($this->logger, Internet::getInternalIP(), $this->getPort())); } @@ -1458,7 +1459,7 @@ class Server{ } if(isset($this->network)){ - $this->network->getSessionManager()->close($this->configGroup->getPropertyString("settings.shutdown-message", "Server closed")); + $this->network->getSessionManager()->close($this->configGroup->getPropertyString(YmlServerProperties::SETTINGS_SHUTDOWN_MESSAGE, "Server closed")); } if(isset($this->worldManager)){ @@ -1595,7 +1596,7 @@ class Server{ $this->logger->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_crash_submit($crashDumpPath))); - if($this->configGroup->getPropertyBool("auto-report.enabled", true)){ + if($this->configGroup->getPropertyBool(Yml::AUTO_REPORT_ENABLED, true)){ $report = true; $stamp = Path::join($this->getDataPath(), "crashdumps", ".last_crash"); @@ -1625,7 +1626,7 @@ class Server{ } if($report){ - $url = ($this->configGroup->getPropertyBool("auto-report.use-https", true) ? "https" : "http") . "://" . $this->configGroup->getPropertyString("auto-report.host", "crash.pmmp.io") . "/submit/api"; + $url = ($this->configGroup->getPropertyBool(Yml::AUTO_REPORT_USE_HTTPS, true) ? "https" : "http") . "://" . $this->configGroup->getPropertyString(Yml::AUTO_REPORT_HOST, "crash.pmmp.io") . "/submit/api"; $postUrlError = "Unknown error"; $reply = Internet::postURL($url, [ "report" => "yes", @@ -1736,7 +1737,7 @@ class Server{ } public function sendUsage(int $type = SendUsageTask::TYPE_STATUS) : void{ - if($this->configGroup->getPropertyBool("anonymous-statistics.enabled", true)){ + if($this->configGroup->getPropertyBool(Yml::ANONYMOUS_STATISTICS_ENABLED, true)){ $this->asyncPool->submitTask(new SendUsageTask($this, $type, $this->uniquePlayers)); } $this->uniquePlayers = []; diff --git a/src/YmlServerProperties.php b/src/YmlServerProperties.php new file mode 100644 index 000000000..920f0797a --- /dev/null +++ b/src/YmlServerProperties.php @@ -0,0 +1,107 @@ +getServer()->getConfigGroup()->getPropertyString("timings.host", "timings.pmmp.io"); + $host = $sender->getServer()->getConfigGroup()->getPropertyString(YmlServerProperties::TIMINGS_HOST, "timings.pmmp.io"); $sender->getServer()->getAsyncPool()->submitTask(new BulkCurlTask( [new BulkCurlTaskOperation( diff --git a/src/crash/CrashDump.php b/src/crash/CrashDump.php index ded1e5d88..9d2eb39e9 100644 --- a/src/crash/CrashDump.php +++ b/src/crash/CrashDump.php @@ -34,6 +34,7 @@ use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\Filesystem; use pocketmine\utils\Utils; use pocketmine\VersionInfo; +use pocketmine\YmlServerProperties; use Symfony\Component\Filesystem\Path; use function array_map; use function base64_encode; @@ -152,7 +153,7 @@ class CrashDump{ private function extraData() : void{ global $argv; - if($this->server->getConfigGroup()->getPropertyBool("auto-report.send-settings", true)){ + if($this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_REPORT_SEND_SETTINGS, true)){ $this->data->parameters = (array) $argv; if(($serverDotProperties = @file_get_contents(Path::join($this->server->getDataPath(), "server.properties"))) !== false){ $this->data->serverDotProperties = preg_replace("#^rcon\\.password=(.*)$#m", "rcon.password=******", $serverDotProperties) ?? throw new AssumptionFailedError("Pattern is valid"); @@ -170,7 +171,7 @@ class CrashDump{ $this->data->jit_mode = Utils::getOpcacheJitMode(); - if($this->server->getConfigGroup()->getPropertyBool("auto-report.send-phpinfo", true)){ + if($this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_REPORT_SEND_PHPINFO, true)){ ob_start(); phpinfo(); $this->data->phpinfo = ob_get_contents(); // @phpstan-ignore-line @@ -225,7 +226,7 @@ class CrashDump{ } } - if($this->server->getConfigGroup()->getPropertyBool("auto-report.send-code", true) && file_exists($error["fullFile"])){ + if($this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_REPORT_SEND_CODE, true) && file_exists($error["fullFile"])){ $file = @file($error["fullFile"], FILE_IGNORE_NEW_LINES); if($file !== false){ for($l = max(0, $error["line"] - 10); $l < $error["line"] + 10 && isset($file[$l]); ++$l){ diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 100d9c989..5b65ca1b5 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -108,6 +108,7 @@ use pocketmine\utils\BinaryStream; use pocketmine\utils\ObjectSet; use pocketmine\utils\TextFormat; use pocketmine\world\Position; +use pocketmine\YmlServerProperties; use function array_map; use function array_values; use function base64_encode; @@ -740,7 +741,7 @@ class NetworkSession{ } $this->logger->debug("Xbox Live authenticated: " . ($this->authenticated ? "YES" : "NO")); - $checkXUID = $this->server->getConfigGroup()->getPropertyBool("player.verify-xuid", true); + $checkXUID = $this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::PLAYER_VERIFY_XUID, true); $myXUID = $this->info instanceof XboxLivePlayerInfo ? $this->info->getXuid() : ""; $kickForXUIDMismatch = function(string $xuid) use ($checkXUID, $myXUID) : bool{ if($checkXUID && $myXUID !== $xuid){ diff --git a/src/network/mcpe/raklib/RakLibInterface.php b/src/network/mcpe/raklib/RakLibInterface.php index 4bf8ffb15..759a992e8 100644 --- a/src/network/mcpe/raklib/RakLibInterface.php +++ b/src/network/mcpe/raklib/RakLibInterface.php @@ -42,6 +42,7 @@ use pocketmine\Server; use pocketmine\thread\ThreadCrashException; use pocketmine\timings\Timings; use pocketmine\utils\Utils; +use pocketmine\YmlServerProperties; use raklib\generic\DisconnectReason; use raklib\generic\SocketException; use raklib\protocol\EncapsulatedPacket; @@ -125,7 +126,7 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{ $threadToMainBuffer, new InternetAddress($ip, $port, $ipV6 ? 6 : 4), $this->rakServerId, - $this->server->getConfigGroup()->getPropertyInt("network.max-mtu-size", 1492), + $this->server->getConfigGroup()->getPropertyInt(YmlServerProperties::NETWORK_MAX_MTU_SIZE, 1492), self::MCPE_RAKNET_PROTOCOL_VERSION, $sleeperEntry ); diff --git a/src/network/query/QueryInfo.php b/src/network/query/QueryInfo.php index 2d36ac7e6..cdb1c66db 100644 --- a/src/network/query/QueryInfo.php +++ b/src/network/query/QueryInfo.php @@ -29,6 +29,7 @@ use pocketmine\plugin\Plugin; use pocketmine\Server; use pocketmine\utils\Binary; use pocketmine\utils\Utils; +use pocketmine\YmlServerProperties; use function array_map; use function chr; use function count; @@ -66,7 +67,7 @@ final class QueryInfo{ public function __construct(Server $server){ $this->serverName = $server->getMotd(); - $this->listPlugins = $server->getConfigGroup()->getPropertyBool("settings.query-plugins", true); + $this->listPlugins = $server->getConfigGroup()->getPropertyBool(YmlServerProperties::SETTINGS_QUERY_PLUGINS, true); $this->plugins = $server->getPluginManager()->getPlugins(); $this->players = array_map(fn(Player $p) => $p->getName(), $server->getOnlinePlayers()); diff --git a/src/player/Player.php b/src/player/Player.php index 33f9e16f4..2059613ad 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -135,6 +135,7 @@ use pocketmine\world\sound\FireExtinguishSound; use pocketmine\world\sound\ItemBreakSound; use pocketmine\world\sound\Sound; use pocketmine\world\World; +use pocketmine\YmlServerProperties; use Ramsey\Uuid\UuidInterface; use function abs; use function array_filter; @@ -318,8 +319,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $rootPermissions[DefaultPermissions::ROOT_OPERATOR] = true; } $this->perm = new PermissibleBase($rootPermissions); - $this->chunksPerTick = $this->server->getConfigGroup()->getPropertyInt("chunk-sending.per-tick", 4); - $this->spawnThreshold = (int) (($this->server->getConfigGroup()->getPropertyInt("chunk-sending.spawn-radius", 4) ** 2) * M_PI); + $this->chunksPerTick = $this->server->getConfigGroup()->getPropertyInt(YmlServerProperties::CHUNK_SENDING_PER_TICK, 4); + $this->spawnThreshold = (int) (($this->server->getConfigGroup()->getPropertyInt(YmlServerProperties::CHUNK_SENDING_SPAWN_RADIUS, 4) ** 2) * M_PI); $this->chunkSelector = new ChunkSelector(); $this->chunkLoader = new class implements ChunkLoader{}; @@ -584,7 +585,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $this->viewDistance = $newViewDistance; - $this->spawnThreshold = (int) (min($this->viewDistance, $this->server->getConfigGroup()->getPropertyInt("chunk-sending.spawn-radius", 4)) ** 2 * M_PI); + $this->spawnThreshold = (int) (min($this->viewDistance, $this->server->getConfigGroup()->getPropertyInt(YmlServerProperties::CHUNK_SENDING_SPAWN_RADIUS, 4)) ** 2 * M_PI); $this->nextChunkOrderRun = 0; diff --git a/src/stats/SendUsageTask.php b/src/stats/SendUsageTask.php index 08c17c73a..d218774b5 100644 --- a/src/stats/SendUsageTask.php +++ b/src/stats/SendUsageTask.php @@ -31,6 +31,7 @@ use pocketmine\utils\Internet; use pocketmine\utils\Process; use pocketmine\utils\Utils; use pocketmine\VersionInfo; +use pocketmine\YmlServerProperties; use Ramsey\Uuid\Uuid; use function array_map; use function array_values; @@ -57,7 +58,7 @@ class SendUsageTask extends AsyncTask{ * @phpstan-param array $playerList */ public function __construct(Server $server, int $type, array $playerList = []){ - $endpoint = "http://" . $server->getConfigGroup()->getPropertyString("anonymous-statistics.host", "stats.pocketmine.net") . "/"; + $endpoint = "http://" . $server->getConfigGroup()->getPropertyString(YmlServerProperties::ANONYMOUS_STATISTICS_HOST, "stats.pocketmine.net") . "/"; $data = []; $data["uniqueServerId"] = $server->getServerUniqueId()->toString(); diff --git a/src/updater/UpdateChecker.php b/src/updater/UpdateChecker.php index ddb0f4d66..4a3ee3444 100644 --- a/src/updater/UpdateChecker.php +++ b/src/updater/UpdateChecker.php @@ -27,6 +27,7 @@ use pocketmine\event\server\UpdateNotifyEvent; use pocketmine\Server; use pocketmine\utils\VersionString; use pocketmine\VersionInfo; +use pocketmine\YmlServerProperties; use function date; use function strtolower; use function ucfirst; @@ -43,7 +44,7 @@ class UpdateChecker{ $this->logger = new \PrefixedLogger($server->getLogger(), "Update Checker"); $this->endpoint = "http://$endpoint/api/"; - if($server->getConfigGroup()->getPropertyBool("auto-updater.enabled", true)){ + if($server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_UPDATER_ENABLED, true)){ $this->doCheck(); } } @@ -59,7 +60,7 @@ class UpdateChecker{ $this->checkUpdate($updateInfo); if($this->hasUpdate()){ (new UpdateNotifyEvent($this))->call(); - if($this->server->getConfigGroup()->getPropertyBool("auto-updater.on-update.warn-console", true)){ + if($this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_UPDATER_ON_UPDATE_WARN_CONSOLE, true)){ $this->showConsoleUpdate(); } }else{ @@ -157,7 +158,7 @@ class UpdateChecker{ * Returns the channel used for update checking (stable, beta, dev) */ public function getChannel() : string{ - return strtolower($this->server->getConfigGroup()->getPropertyString("auto-updater.preferred-channel", "stable")); + return strtolower($this->server->getConfigGroup()->getPropertyString(YmlServerProperties::AUTO_UPDATER_PREFERRED_CHANNEL, "stable")); } /** diff --git a/src/world/World.php b/src/world/World.php index d917a3e82..903cc60e2 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -104,6 +104,7 @@ use pocketmine\world\particle\Particle; use pocketmine\world\sound\BlockPlaceSound; use pocketmine\world\sound\Sound; use pocketmine\world\utils\SubChunkExplorer; +use pocketmine\YmlServerProperties; use function abs; use function array_filter; use function array_key_exists; @@ -513,14 +514,14 @@ class World implements ChunkManager{ $this->time = $this->provider->getWorldData()->getTime(); $cfg = $this->server->getConfigGroup(); - $this->chunkTickRadius = min($this->server->getViewDistance(), max(0, $cfg->getPropertyInt("chunk-ticking.tick-radius", 4))); + $this->chunkTickRadius = min($this->server->getViewDistance(), max(0, $cfg->getPropertyInt(YmlServerProperties::CHUNK_TICKING_TICK_RADIUS, 4))); if($cfg->getPropertyInt("chunk-ticking.per-tick", 40) <= 0){ //TODO: this needs l10n $this->logger->warning("\"chunk-ticking.per-tick\" setting is deprecated, but you've used it to disable chunk ticking. Set \"chunk-ticking.tick-radius\" to 0 in \"pocketmine.yml\" instead."); $this->chunkTickRadius = 0; } - $this->tickedBlocksPerSubchunkPerTick = $cfg->getPropertyInt("chunk-ticking.blocks-per-subchunk-per-tick", self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK); - $this->maxConcurrentChunkPopulationTasks = $cfg->getPropertyInt("chunk-generation.population-queue-size", 2); + $this->tickedBlocksPerSubchunkPerTick = $cfg->getPropertyInt(YmlServerProperties::CHUNK_TICKING_BLOCKS_PER_SUBCHUNK_PER_TICK, self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK); + $this->maxConcurrentChunkPopulationTasks = $cfg->getPropertyInt(YmlServerProperties::CHUNK_GENERATION_POPULATION_QUEUE_SIZE, 2); $this->initRandomTickBlocksFromConfig($cfg); @@ -541,7 +542,7 @@ class World implements ChunkManager{ private function initRandomTickBlocksFromConfig(ServerConfigGroup $cfg) : void{ $dontTickBlocks = []; $parser = StringToItemParser::getInstance(); - foreach($cfg->getProperty("chunk-ticking.disable-block-ticking", []) as $name){ + foreach($cfg->getProperty(YmlServerProperties::CHUNK_TICKING_DISABLE_BLOCK_TICKING, []) as $name){ $name = (string) $name; $item = $parser->parse($name); if($item !== null){