/// <summary> /// Restores the server from a previous backup, then resumes starting /// </summary> private void Restore() { Console.Clear(); string[] allFiles = Directory.GetFiles(ServerDir); Dictionary <int, string> backups = new Dictionary <int, string>(); int fileCount = -1; foreach (string file in allFiles) { if (Path.GetExtension(file) == ".zip") { fileCount++; backups.Add(fileCount, file); } } Console.WriteLine("Enter the number for the backup you want to restore with"); // PrettyPrints each backup file without path or extension preceded by its key in the dictionary `files` Funcs.PrettyPrint(backups.Select(i => i.Key + " " + Path.GetFileNameWithoutExtension(i.Value)).ToList <string>()); Console.Write($"Backup [{fileCount}]: "); // The backup to use int backup = Funcs.GetInt(0, fileCount, fileCount); // Only attempt to backup and delete the source directory if it exists if (Directory.Exists(WorldDir)) { Backup("pre-restore"); Directory.Delete(WorldDir, true); Console.WriteLine($"Deleted {ServerName}"); } // Extracts specified backup to the source directory ZipFile.ExtractToDirectory(backups[backup], ServerDir); Console.WriteLine($"Extracted {Path.GetFileNameWithoutExtension(backups[backup])}"); Console.WriteLine($"{ServerName} restored from {Path.GetFileNameWithoutExtension(backups[backup])}"); Backup("post-restore"); }
/// <summary> /// Creates the server.properties file /// </summary> /// <param name="changes">True to make changes, False to use defaults</param> private void ServerProperties(bool changes) { int gamemode = 0; int difficulty = 1; bool hardcore = false; bool whitelist = false; string motd = GetMotd("Max\'s Minecraft Server"); if (changes) { Console.WriteLine("Gamemodes\n0: Survival, 1: Creative, 2: Adventure, 3: Spectator"); Console.Write("Gamemode (0-3) [0]: "); gamemode = Funcs.GetInt(0, 3, 0); Console.WriteLine("Difficulties\n0: Peaceful, 1:Easy, 2: Normal, 3: Hard"); Console.Write("Difficulty (0-3) [1]: "); difficulty = Funcs.GetInt(0, 3, 1); Console.Write("Hardcore true/[false]: "); hardcore = Funcs.ValidateBool(false); Console.Write("Whitelist true/[false]: "); whitelist = Funcs.ValidateBool(false); } string properties = "spawn-protection=0" + "max-tick-time=60000\n" + "generator-settings=\n" + "allow-nether=true\n" + "force-gamemode=false\n" + "enforce-whitelist=false\n" + $"gamemode={gamemode}\n" + "broadcast-console-to-ops=true\n" + "enable-query=true\n" + "player-idle-timeout=5\n" + $"difficulty={difficulty}\n" + "spawn-monsters=true\n" + "op-permission-level=3\n" + "pvp=true\n" + "snooper-enabled=true\n" + "level-type=DEFAULT\n" + $"hardcore={hardcore}\n" + "enable-command-block=true\n" + "max-players=20\n" + "network-compression-threshold=256\n" + "resource-pack-sha1=\n" + "max-world-size=29999984\n" + "server-port=25565\n" + "server-ip=\n" + "spawn-npcs=true\n" + "allow-flight=false\n" + $"level-name={ServerName}\n" + "view-distance=10\n" + "resource-pack=\n" + "spawn-animals=true\n" + $"white-list={whitelist}\n" + "generate-structures=true\n" + "online-mode=true\n" + "max-build-height=256\n" + "level-seed=\n" + "prevent-proxy-connections=false\n" + $"motd={@motd}\n" + "enable-rcon=false"; Write("server.properties", properties); }