@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
174 lines (172 loc) • 7.94 kB
JavaScript
"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 {
constructor() {
this.name = "Dedicated Server";
this.gameMode = ServerGameMode.survival;
this.forceGameMode = false;
this.difficulty = ServerDifficulty.easy;
this.allowCheats = true;
this.maxPlayers = 10;
this.onlineMode = true;
this.whiteList = false;
this.serverPort = 19132;
this.serverPortV6 = 19133;
this.viewDistance = 32;
this.tickDistance = 4;
this.playerIdleTimeout = 30;
this.maxThreads = 8;
this.levelName = "Bedrock level";
this.levelSeed = "";
this.allowInboundScriptDebugging = true;
this.allowOutboundScriptDebugging = true;
this.defaultPlayerPermissionLevel = ServerPermissionLevel.member;
this.contentLogLevel = ServerContentLoggingLevel.verbose;
this.contentLogConsoleOutputEnabled = true;
this.texturePackRequired = false;
this.contentLogFileEnabled = true;
this.compressionThreshold = 1;
this.serverAuthoritativeMovement = ServerAuthoritativeness.serverAuth;
this.playerMovementScoreThreshold = 20;
this.playerMovementDistanceThreshold = 0.3;
this.playerMovementDurationThresholdInMs = 500;
this.correctPlayerMovement = false;
this.serverAuthoritativeBlockBreaking = false;
}
get serverFolder() {
return this._serverFolder;
}
set serverFolder(newFolder) {
this._serverFolder = newFolder;
}
applyFromWorldSettings(worldSettings) {
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;
}
}
}
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("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;
//# sourceMappingURL=../maps/minecraft/ServerPropertiesManager.js.map