UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

189 lines (188 loc) 8.47 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); const WorldLevelDat_1 = require("./WorldLevelDat"); var ServerGameMode; (function (ServerGameMode) { ServerGameMode["survival"] = "survival"; ServerGameMode["creative"] = "creative"; ServerGameMode["adventure"] = "adventure"; })(ServerGameMode || (ServerGameMode = {})); var ServerDifficulty; (function (ServerDifficulty) { ServerDifficulty["peaceful"] = "peaceful"; ServerDifficulty["easy"] = "easy"; ServerDifficulty["normal"] = "normal"; ServerDifficulty["hard"] = "hard"; })(ServerDifficulty || (ServerDifficulty = {})); var ServerContentLoggingLevel; (function (ServerContentLoggingLevel) { ServerContentLoggingLevel["verbose"] = "verbose"; ServerContentLoggingLevel["error"] = "error"; ServerContentLoggingLevel["warning"] = "warning"; ServerContentLoggingLevel["info"] = "info"; })(ServerContentLoggingLevel || (ServerContentLoggingLevel = {})); var ServerPermissionLevel; (function (ServerPermissionLevel) { ServerPermissionLevel["member"] = "member"; ServerPermissionLevel["visitor"] = "visitor"; ServerPermissionLevel["operator"] = "operator"; })(ServerPermissionLevel || (ServerPermissionLevel = {})); var ServerAuthoritativeness; (function (ServerAuthoritativeness) { ServerAuthoritativeness["clientAuth"] = "client-auth"; ServerAuthoritativeness["serverAuth"] = "server-auth"; ServerAuthoritativeness["serverAuthWithRewind"] = "server-auth-with-rewind"; })(ServerAuthoritativeness || (ServerAuthoritativeness = {})); class ServerPropertiesManager { _serverFolder; name = "Dedicated Server"; gameMode = ServerGameMode.survival; forceGameMode = false; difficulty = ServerDifficulty.easy; allowCheats = true; maxPlayers = 10; onlineMode = false; emitServerTelemetry = false; whiteList = false; serverPort = 19132; serverPortV6 = 19133; viewDistance = 32; tickDistance = 4; playerIdleTimeout = 30; maxThreads = 8; levelName = "Bedrock level"; levelSeed = ""; allowInboundScriptDebugging = true; allowOutboundScriptDebugging = true; defaultPlayerPermissionLevel = ServerPermissionLevel.member; contentLogLevel = ServerContentLoggingLevel.verbose; contentLogConsoleOutputEnabled = true; texturePackRequired = false; contentLogFileEnabled = true; compressionThreshold = 1; serverAuthoritativeMovement = ServerAuthoritativeness.serverAuth; playerMovementScoreThreshold = 20; playerMovementDistanceThreshold = 0.3; playerMovementDurationThresholdInMs = 500; correctPlayerMovement = true; serverAuthoritativeBlockBreaking = false; get serverFolder() { return this._serverFolder; } set serverFolder(newFolder) { this._serverFolder = newFolder; } applyFromWorldSettings(worldSettings) { if (worldSettings.playerPermissionLevel) { switch (worldSettings.playerPermissionLevel) { case WorldLevelDat_1.PlayerPermissionsLevel.member: this.defaultPlayerPermissionLevel = ServerPermissionLevel.member; break; case WorldLevelDat_1.PlayerPermissionsLevel.operator: this.defaultPlayerPermissionLevel = ServerPermissionLevel.operator; break; } } if (worldSettings.difficulty !== undefined) { switch (worldSettings.difficulty) { case WorldLevelDat_1.Difficulty.easy: this.difficulty = ServerDifficulty.easy; break; case WorldLevelDat_1.Difficulty.normal: this.difficulty = ServerDifficulty.normal; break; case WorldLevelDat_1.Difficulty.peaceful: this.difficulty = ServerDifficulty.peaceful; break; case WorldLevelDat_1.Difficulty.hard: this.difficulty = ServerDifficulty.hard; break; } } if (worldSettings.gameType !== undefined) { switch (worldSettings.gameType) { case WorldLevelDat_1.GameType.survival: this.gameMode = ServerGameMode.survival; this.forceGameMode = true; break; case WorldLevelDat_1.GameType.creative: this.gameMode = ServerGameMode.creative; this.forceGameMode = true; break; case WorldLevelDat_1.GameType.adventure: this.gameMode = ServerGameMode.adventure; this.forceGameMode = true; break; } } if (worldSettings.onlineMode !== undefined) { this.onlineMode = worldSettings.onlineMode; } if (worldSettings.emitServerTelemetry !== undefined) { this.emitServerTelemetry = worldSettings.emitServerTelemetry; } } async writeFile() { if (this._serverFolder === undefined) { return; } const file = this._serverFolder.ensureFile("server.properties"); await file.loadContent(true); const text = file.content; // backup the server properties file if it's not generated if (text && text.indexOf("# Generated") < 0) { const now = new Date(); const fileCopy = this._serverFolder.ensureFile("server.properties." + now.getFullYear() + "." + (now.getMonth() + 1) + "." + now.getDate() + "." + now.getHours() + "." + now.getMinutes() + ".cartobackup"); fileCopy.setContent(text); await fileCopy.saveContent(); } const content = []; content.push("# Generated by Minecraft Creator Tools"); content.push("server-name=" + this.name); content.push("gamemode=" + this.gameMode); content.push("force-gamemode=" + this.forceGameMode); content.push("difficulty=" + this.difficulty); content.push("allow-cheats=" + this.allowCheats); content.push("max-players=" + this.maxPlayers); content.push("online-mode=" + this.onlineMode); content.push("emit-server-telemetry=" + this.emitServerTelemetry); content.push("white-list=" + this.whiteList); content.push("server-port=" + this.serverPort); content.push("server-portv6=" + this.serverPortV6); content.push("view-distance=" + this.viewDistance); content.push("tick-distance=" + this.tickDistance); content.push("player-idle-timeout=" + this.playerIdleTimeout); content.push("max-threads=" + this.maxThreads); content.push("level-name=" + this.levelName); content.push("level-seed=" + this.levelSeed); content.push("allow-inbound-script-debugging=" + this.allowInboundScriptDebugging); content.push("allow-outbound-script-debugging=" + this.allowOutboundScriptDebugging); content.push("default-player-permission-level=" + this.defaultPlayerPermissionLevel); content.push("texturepack-required=" + this.texturePackRequired); content.push("content-log-file-enabled=" + this.contentLogFileEnabled); content.push("content-log-console-output=" + this.contentLogConsoleOutputEnabled); content.push("content-log-level=" + this.contentLogLevel); content.push("compression-threshold=" + this.compressionThreshold); content.push("server-authoritative-movement=" + this.serverAuthoritativeMovement); content.push("player-movement-score-threshold=" + this.playerMovementScoreThreshold); content.push("player-movement-distance-threshold=" + this.playerMovementDistanceThreshold); content.push("player-movement-duration-threshold-in-ms=" + this.playerMovementDurationThresholdInMs); content.push("correct-player-movement=" + this.correctPlayerMovement); content.push("server-authoritative-block-breaking=" + this.serverAuthoritativeBlockBreaking); file.setContent(content.join("\n")); file.saveContent(); } } exports.default = ServerPropertiesManager;