コード例 #1
0
        public void UpdateInstalledJavaVersion(bool ignoreWarnings = false)
        {
            InstalledJavaVersion = JavaVersionUtils.GetInstalledJavaVersion();
            if (InstalledJavaVersion == null)
            {
                ShowJavaWarning    = !ignoreWarnings;
                JavaWarningMessage =
                    "No Java installation detected!" +
                    "\nMinecraft Servers require Java to be installed on your system";
                return;
            }

            if (!InstalledJavaVersion.Is64Bit)
            {
                ShowJavaWarning    = !ignoreWarnings;
                JavaWarningMessage =
                    "32-Bit Java installation detected!" +
                    "\nThis will cause issues if you want to use more than 1GB of RAM";
                return;
            }

            if (InstalledJavaVersion.VersionComputed < 16)
            {
                ShowJavaWarning    = !ignoreWarnings;
                JavaWarningMessage =
                    "Old Java installation detected (Version " + InstalledJavaVersion.VersionComputed + ")!" +
                    "\nOlder Java versions will cause problems from Minecraft 1.17 onwards." +
                    "\nWe recommend installing Java version 16 or higher for full support";
                return;
            }

            ShowJavaWarning    = false;
            JavaWarningMessage = "";
        }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: yenandrew/Fork
        public void UpdateInstalledJavaVersion(bool ignoreWarnings = false)
        {
            InstalledJavaVersion = JavaVersionUtils.GetInstalledJavaVersion();
            if (InstalledJavaVersion == null)
            {
                ShowJavaWarning    = !ignoreWarnings;
                JavaWarningMessage =
                    "No Java installation detected!" +
                    "\nMinecraft Servers require Java to be installed on your system";
                return;
            }

            if (!InstalledJavaVersion.Is64Bit)
            {
                ShowJavaWarning    = !ignoreWarnings;
                JavaWarningMessage =
                    "32-Bit Java installation detected!" +
                    "\nThis will cause issues if you want to use more than 1GB of RAM";
                return;
            }


            //TODO enable this at a latest point when new java versions don't cause issues anymore

            /*if (InstalledJavaVersion.VersionComputed < 11)
             * {
             *  ShowJavaWarning = !ignoreWarnings;
             *  JavaWarningMessage =
             *      "Old Java installation detected (Version "+InstalledJavaVersion.VersionComputed+")!" +
             *      "\nOlder Java versions will cause problems in the near future" +
             *      "\nWe recommend installing Java version 11 or higher for full support";
             *  return;
             * }*/

            ShowJavaWarning    = false;
            JavaWarningMessage = "";
        }
コード例 #3
0
        public async Task <bool> StartNetworkAsync(NetworkViewModel viewModel, bool startServers)
        {
            ConsoleWriter.Write("\n Starting network " + viewModel.Entity.Name, viewModel);
            Console.WriteLine("Starting network " + viewModel.Entity.Name);
            if (startServers)
            {
                if (viewModel.Servers.Count == 0)
                {
                    ConsoleWriter.Write("WARNING: This network contains no Servers. Players will not be able to join.", viewModel);
                }
                else
                {
                    ConsoleWriter.Write("Starting all " + viewModel.Servers.Count + " servers of this network...", viewModel);
                    foreach (NetworkServer networkServer in viewModel.Servers)
                    {
                        if (networkServer is NetworkForkServer networkForkServer)
                        {
                            ServerViewModel serverViewModel = networkForkServer.ServerViewModel;
                            if (serverViewModel.CurrentStatus == ServerStatus.STOPPED)
                            {
                                ConsoleWriter.Write("\nStarting server " + serverViewModel.Server + " on world: " +
                                                    serverViewModel.Server.ServerSettings.LevelName, viewModel);
                                ServerManager.Instance.StartServerAsync(serverViewModel);
                            }
                            else if (serverViewModel.CurrentStatus == ServerStatus.STARTING)
                            {
                                ConsoleWriter.Write("Server " + serverViewModel.Server + " is already starting.", viewModel);
                            }
                            else if (serverViewModel.CurrentStatus == ServerStatus.RUNNING)
                            {
                                ConsoleWriter.Write("Server " + serverViewModel.Server + " is already running.", viewModel);
                            }
                        }
                        else
                        {
                            ConsoleWriter.Write("Server " + networkServer.Name + " can't be started automatically because it is no Fork server.", viewModel);
                        }
                    }
                }
            }
            else
            {
                ConsoleWriter.Write("Make sure that at least one server configured in the settings is running, else Players won't be able to join this network.", viewModel);
            }

            ConsoleWriter.Write("\n", viewModel);
            if (!viewModel.SettingsSavingTask.IsCompleted)
            {
                ConsoleWriter.Write("Saving settings files before starting proxy server...", viewModel);
                await viewModel.SettingsSavingTask;
            }

            //Start proxy server
            ConsoleWriter.Write("Starting proxy server...", viewModel);
            DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(App.ServerPath, viewModel.Network.Name));

            if (!directoryInfo.Exists)
            {
                ConsoleWriter.Write("ERROR: Can't find network directory: " + directoryInfo.FullName, viewModel);
                return(false);
            }
            JavaVersion javaVersion = JavaVersionUtils.GetInstalledJavaVersion(viewModel.Network.JavaSettings.JavaPath);

            if (javaVersion == null)
            {
                ConsoleWriter.Write("ERROR: Java is not installed! Minecraft networks require Java!", viewModel);
                return(false);
            }
            if (!javaVersion.Is64Bit)
            {
                ConsoleWriter.Write("WARN: The Java installation selected for this network is a 32-bit version, which can cause errors.", viewModel);
            }
            if (javaVersion.VersionComputed < 11)
            {
                ConsoleWriter.Write("WARN: The Java installation selected for this network is outdated. Please update Java to version 11 or higher.", viewModel);
            }

            Process          process   = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo
            {
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                FileName         = viewModel.Network.JavaSettings.JavaPath,
                WorkingDirectory = directoryInfo.FullName,
                Arguments        = "-Xmx" + viewModel.Network.JavaSettings.MaxRam + "m " + viewModel.Network.JavaSettings.StartupParameters + " -jar server.jar nogui",
                WindowStyle      = ProcessWindowStyle.Hidden,
                CreateNoWindow   = true
            };

            process.StartInfo = startInfo;
            process.Start();
            Task.Run(() =>
            {
                viewModel.TrackPerformance(process);
            });
            viewModel.CurrentStatus = ServerStatus.STARTING;
            ConsoleWriter.RegisterApplication(viewModel, process.StandardOutput, process.StandardError);
            ConsoleReader consoleReader = new ConsoleReader(process.StandardInput);

            viewModel.ConsoleReader = consoleReader;
            Task.Run(async() =>
            {
                await process.WaitForExitAsync();
                ApplicationManager.Instance.ActiveEntities.Remove(viewModel.Entity);
                viewModel.CurrentStatus = ServerStatus.STOPPED;
            });
            ApplicationManager.Instance.ActiveEntities[viewModel.Network] = process;
            Console.WriteLine("Started network " + viewModel.Network);

            return(true);
        }
コード例 #4
0
        public async Task <bool> StartServerAsync(ServerViewModel viewModel)
        {
            ConsoleWriter.Write("\n", viewModel);
            //if (!viewModel.SettingsSavingTask.IsCompleted)
            //{
            ConsoleWriter.Write("Saving settings files before starting server ...", viewModel);
            await Task.Run(async() => await viewModel.SettingsSavingTask);

            //}

            ConsoleWriter.Write(
                "Starting server " + viewModel.Server + " on world: " + viewModel.Server.ServerSettings.LevelName,
                viewModel);
            Console.WriteLine("Starting server " + viewModel.Server.Name + " on world: " +
                              viewModel.Server.ServerSettings.LevelName);
            DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(App.ServerPath, viewModel.Server.Name));

            if (!directoryInfo.Exists)
            {
                return(false);
            }

            JavaVersion javaVersion = JavaVersionUtils.GetInstalledJavaVersion(viewModel.Server.JavaSettings.JavaPath);

            if (javaVersion == null)
            {
                ConsoleWriter.Write("ERROR: Java is not installed! Minecraft servers require Java!", viewModel);
                return(false);
            }

            if (!javaVersion.Is64Bit)
            {
                ConsoleWriter.Write(
                    "WARN: The Java installation selected for this server is a 32-bit version, which can cause errors.",
                    viewModel);
            }

            if (javaVersion.VersionComputed < 16)
            {
                if (new ServerVersion {
                    Version = "1.17"
                }.CompareTo(viewModel.Entity.Version) <= 0)
                {
                    ConsoleWriter.Write("ERROR: The Java installation selected for this server is outdated. Please update Java to version 16 or higher.", viewModel);
                    return(false);
                }
                else
                {
                    ConsoleWriter.Write("WARN: The Java installation selected for this server is outdated. Please update Java to version 16 or higher.", viewModel);
                }
            }

            if (!viewModel.Server.ServerSettings.ResourcePack.Equals("") && viewModel.Server.AutoSetSha1)
            {
                ConsoleWriter.Write(new ConsoleMessage("Generating Resource Pack hash...",
                                                       ConsoleMessage.MessageLevel.INFO), viewModel);
                string resourcePackUrl = viewModel.Server.ServerSettings.ResourcePack.Replace("\\", "");
                bool   isHashUpToDate  = await IsHashUpToDate(viewModel.Server.ResourcePackHashAge, resourcePackUrl);

                if (!string.IsNullOrEmpty(viewModel.Server.ServerSettings.ResourcePackSha1) && isHashUpToDate)
                {
                    ConsoleWriter.Write(new ConsoleMessage("Resource Pack hash is still up to date. Staring server...",
                                                           ConsoleMessage.MessageLevel.SUCCESS), viewModel);
                }
                else
                {
                    ConsoleWriter.Write(new ConsoleMessage("Resource Pack hash is outdated. Updating it...",
                                                           ConsoleMessage.MessageLevel.WARN), viewModel);
                    DateTime           hashAge          = DateTime.Now;
                    IProgress <double> downloadProgress = new Progress <double>();
                    string             hash             = await HashResourcePack(resourcePackUrl, downloadProgress);

                    if (!string.IsNullOrEmpty(hash))
                    {
                        viewModel.Server.ServerSettings.ResourcePackSha1 = hash;
                        viewModel.Server.ResourcePackHashAge             = hashAge;
                        await viewModel.SaveProperties();

                        ConsoleWriter.Write(new ConsoleMessage("Successfully updated Resource Pack hash to: " + hash,
                                                               ConsoleMessage.MessageLevel.SUCCESS), viewModel);
                        ConsoleWriter.Write(new ConsoleMessage("Starting the server...",
                                                               ConsoleMessage.MessageLevel.INFO), viewModel);
                    }
                    else
                    {
                        ConsoleWriter.Write(new ConsoleMessage(
                                                "Error updating the Resource Pack hash! Continuing with no hash...",
                                                ConsoleMessage.MessageLevel.ERROR), viewModel);
                    }
                }
            }

            Process          process   = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo
            {
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                FileName         = viewModel.Server.JavaSettings.JavaPath,
                WorkingDirectory = directoryInfo.FullName,
                Arguments        = "-Xmx" + viewModel.Server.JavaSettings.MaxRam + "m " +
                                   viewModel.Server.JavaSettings.StartupParameters + " -jar server.jar nogui",
                WindowStyle    = ProcessWindowStyle.Hidden,
                CreateNoWindow = true
            };

            process.StartInfo = startInfo;
            process.Start();
            Task.Run(() => { viewModel.TrackPerformance(process); });
            viewModel.CurrentStatus = ServerStatus.STARTING;
            ConsoleWriter.RegisterApplication(viewModel, process.StandardOutput, process.StandardError);
            ConsoleReader consoleReader = new ConsoleReader(process.StandardInput);

            ServerAutomationManager.Instance.UpdateAutomation(viewModel);

            Task.Run(async() =>
            {
                await process.WaitForExitAsync();
                ApplicationManager.Instance.ActiveEntities.Remove(viewModel.Server);
                viewModel.CurrentStatus = ServerStatus.STOPPED;
                ServerAutomationManager.Instance.UpdateAutomation(viewModel);
            });
            viewModel.ConsoleReader = consoleReader;
            ApplicationManager.Instance.ActiveEntities[viewModel.Server] = process;
            Task.Run(async() =>
            {
                var worker = new QueryStatsWorker(viewModel);
                await process.WaitForExitAsync();
                worker.Dispose();
            });
            Console.WriteLine("Started server " + viewModel.Server);

            //Register new world if created
            Task.Run(async() =>
            {
                while (!viewModel.ServerRunning)
                {
                    await Task.Delay(500);
                }

                viewModel.InitializeWorldsList();
            });
            return(true);
        }
コード例 #5
0
    public async Task StartServerAsync(Server server)
    {
        if (server.Status != EntityStatus.Stopped)
        {
            await _console.WriteError(server, "Can't start server that was not properly stopped");

            throw new ForkException("Only stopped servers can be started");
        }
        await ChangeServerStatusAsync(server, EntityStatus.Starting);

        _logger.LogInformation($"Starting server {server.Name} on world {server.VanillaSettings.LevelName}");

        // Get server directory
        DirectoryInfo serverDirectory = new DirectoryInfo(server.GetPath(_application));

        if (!serverDirectory.Exists)
        {
            await ChangeServerStatusAsync(server, EntityStatus.Stopped);

            await _console.WriteError(server,
                                      $"This server has no directory for some reason. The path that was searched was:\n{server.GetPath(_application)}");

            throw new ForkException($"Supplied server \"{server.Name}\" has no directory!");
        }

        JavaVersion javaVersion = JavaVersionUtils.GetInstalledJavaVersion(server.JavaSettings.JavaPath);

        if (javaVersion == null)
        {
            await ChangeServerStatusAsync(server, EntityStatus.Stopped);

            await _console.WriteError(server,
                                      $"No valid Java installation was found for the configured java path:\n{server.JavaSettings.JavaPath}");

            throw new ForkException(
                      $"No valid Java installation was found for the configured java path:\n{server.JavaSettings.JavaPath}");
        }

        if (!javaVersion.Is64Bit)
        {
            await _console.WriteWarning(server,
                                        "The Java installation selected for this server is a 32-bit version, which can cause errors and limits the RAM usage to 2GB");
        }

        if (javaVersion.VersionComputed < 16)
        {
            if (new ServerVersion {
                Version = "1.17"
            }.CompareTo(server.Version) <= 0)
            {
                await ChangeServerStatusAsync(server, EntityStatus.Stopped);

                await _console.WriteError(server,
                                          "The Java installation selected for this server is outdated. Please update Java to version 16 or higher.");

                throw new ForkException(
                          "The Java installation selected for this server is outdated. Please update Java to version 16 or higher.");
            }

            await _console.WriteWarning(server,
                                        "WARN: The Java installation selected for this server is outdated. Please update Java to version 16 or higher.");
        }

        if (server.VanillaSettings.ResourcePack != "" && server.AutoSetSha1)
        {
            await UpdateResourcePackHash(server);
        }

        Process          process   = new Process();
        ProcessStartInfo startInfo = new ProcessStartInfo
        {
            UseShellExecute        = false,
            RedirectStandardError  = true,
            RedirectStandardInput  = true,
            RedirectStandardOutput = true,
            FileName         = server.JavaSettings.JavaPath ?? "java",
            WorkingDirectory = serverDirectory.FullName,
            Arguments        = "-Xmx" + server.JavaSettings.MaxRam + "m " +
                               server.JavaSettings.StartupParameters + " -jar server.jar nogui",
            WindowStyle    = ProcessWindowStyle.Hidden,
            CreateNoWindow = true
        };

        process.StartInfo = startInfo;
        process.Start();
        CancellationTokenSource serverStoppedTokenSource = new CancellationTokenSource();

        Task.Run(() => TrackServerPerformance(server, process, serverStoppedTokenSource));
        await _console.BindProcessToConsole(server, process.StandardOutput, process.StandardError,
                                            status => _ = ChangeServerStatusAsync(server, status));

        server.ConsoleHandler = delegate(string line)
        {
            _console.WriteLine(server, line, ConsoleMessageType.UserInput);
            process.StandardInput.WriteLineAsync(line);
        };

        //TODO CKE add server automation
        //ServerAutomationManager.Instance.UpdateAutomation(viewModel);

        _ = Task.Run(async() =>
        {
            //TODO CKE start performance tracker here
            // var worker = new QueryStatsWorker(viewModel);

            await process.WaitForExitAsync();
            //TODO determine crash and normal stop
            await ChangeServerStatusAsync(server, EntityStatus.Stopped);

            serverStoppedTokenSource.Cancel();
            //TODO CKE stop automation here
            //ServerAutomationManager.Instance.UpdateAutomation(viewModel);
        });
        _logger.LogInformation("Started server " + server.Name);

        //Register new world if created
        _ = Task.Run(async() =>
        {
            while (server.Status == EntityStatus.Starting)
            {
                await Task.Delay(500);
            }

            if (server.Status == EntityStatus.Started)
            {
                // TODO CKE update Worlds as a new one might have been created
                // viewModel.InitializeWorldsList();
            }
        });
    }