Пример #1
0
        private bool CreateServer(string serverName, ServerVersion serverVersion, ServerSettings serverSettings,
                                  JavaSettings javaSettings, string worldPath = null)
        {
            serverName = RefineName(serverName);
            string serverPath = Path.Combine(App.ServerPath, serverName);

            serverNames.Add(serverName);
            if (string.IsNullOrEmpty(serverSettings.LevelName))
            {
                serverSettings.LevelName = "world";
            }
            DirectoryInfo   directoryInfo = Directory.CreateDirectory(serverPath);
            Server          server        = new Server(serverName, serverVersion, serverSettings, javaSettings);
            ServerViewModel viewModel     = new ServerViewModel(server);

            Application.Current.Dispatcher.Invoke(() => Entities.Add(viewModel));
            //Select Server
            ApplicationManager.Instance.MainViewModel.SelectedEntity = viewModel;

            //Download server.jar
            Downloader.DownloadJarAsync(viewModel, directoryInfo);

            //Move World Files
            if (worldPath != null)
            {
                new FileImporter().DirectoryCopy(worldPath, Path.Combine(directoryInfo.FullName, server.ServerSettings.LevelName), true);
            }

            //Writing necessary files
            new FileWriter().WriteEula(Path.Combine(App.ServerPath, directoryInfo.Name));
            new FileWriter().WriteServerSettings(Path.Combine(App.ServerPath, directoryInfo.Name),
                                                 serverSettings.SettingsDictionary);

            return(true);
        }
Пример #2
0
        public async Task <bool> CreateNetworkAsync(string networkName, ServerVersion.VersionType networkType,
                                                    JavaSettings javaSettings)
        {
            Task <bool> t = new Task <bool>(() =>
                                            networkController.CreateNetwork(networkName, networkType, javaSettings, serverNames));

            t.Start();
            bool r = await t;

            return(r);
        }
Пример #3
0
        public async Task <bool> CreateServerAsync(string serverName, ServerVersion serverVersion, ServerSettings serverSettings,
                                                   JavaSettings javaSettings, string worldPath = null)
        {
            Task <bool> t = new Task <bool>(() =>
                                            CreateServer(serverName, serverVersion, serverSettings, javaSettings, worldPath));

            t.Start();
            bool r = await t;

            return(r);
        }
Пример #4
0
        private async void BtnApply_Click(object sender, RoutedEventArgs e)
        {
            if (isProxy)
            {
                string networkName = NetworkName.Text;
                if (networkName == null || networkName.Equals(""))
                {
                    networkName = "Network";
                }

                //TODO replace this with int value verifier
                int minRam, maxRam;
                if (!int.TryParse(NetworkMaxRam.Text, out maxRam))
                {
                    maxRam = 1024;
                }

                if (!int.TryParse(NetworkMinRam.Text, out minRam))
                {
                    minRam = 512;
                }

                JavaSettings javaSettings = new JavaSettings {
                    MinRam = minRam, MaxRam = maxRam
                };
                bool createNetworkSuccess = await ServerManager.Instance.CreateNetworkAsync(networkName, proxyType, javaSettings);
            }
            else
            {
                ServerVersion selectedVersion = (ServerVersion)versionComboBox.SelectedValue;
                //TODO check if inputs are valid / server not existing

                string serverName = ServerName.Text;
                if (serverName == null || serverName.Equals(""))
                {
                    serverName = "Server";
                }

                string worldPath = null;
                if (lastPath != null)
                {
                    WorldValidationInfo valInfo = DirectoryValidator.ValidateWorldDirectory(new DirectoryInfo(lastPath));
                    if (valInfo.IsValid)
                    {
                        worldPath = lastPath;
                    }
                }
                bool createServerSuccess = await ServerManager.Instance.CreateServerAsync(serverName, selectedVersion, viewModel.ServerSettings, new JavaSettings(), worldPath);
            }
            viewModel.GenerateNewSettings();

            //TODO Do something if creating fails
        }
Пример #5
0
    public async Task <ulong> CreateServerAsync(string serverName, ServerVersion serverVersion, VanillaSettings settings,
                                                JavaSettings javaSettings, string worldPath)
    {
        serverName = RefineName(serverName);
        string serverPath = Path.Combine(_application.EntityPath, serverName);

        if (string.IsNullOrEmpty(settings.LevelName))
        {
            settings.LevelName = "world";
        }

        DirectoryInfo directoryInfo = Directory.CreateDirectory(serverPath);
        // TODO CKE serverVersion.Build = await VersionManager.Instance.GetLatestBuild(serverVersion);
        Server server = new Server(serverName, serverVersion, settings, javaSettings);

        _context.ServerSet.Add(server);

        //Download server.jar
        var downloadProgress = new Progress <float>();

        downloadProgress.ProgressChanged += (_, f) =>
        {
            // TODO CKE send notification update
        };
        await _download.DownloadJarAsync(server, downloadProgress, CancellationToken.None);

        //Move World Files
        if (worldPath != null)
        {
            //TODO CKE add world import
            //new FileImporter().DirectoryCopy(worldPath,
            //   Path.Combine(directoryInfo.FullName, server.VanillaSettings.LevelName), true);
        }

        //Writing necessary files
        await _fileWriter.WriteEula(Path.Combine(_application.EntityPath, directoryInfo.Name));

        await _fileWriter.WriteServerSettings(Path.Combine(_application.EntityPath, directoryInfo.Name),
                                              settings.SettingsDictionary);

        await _context.SaveChangesAsync();

        return(server.Id);
    }
Пример #6
0
        public bool CreateNetwork(string networkName, ServerVersion.VersionType networkType, JavaSettings javaSettings, List <string> usedServerNames)
        {
            if (networkType != ServerVersion.VersionType.Waterfall)
            {
                return(false);
            }
            networkName = RefineName(networkName, usedServerNames);
            string           serverPath    = Path.Combine(App.ServerPath, networkName);
            DirectoryInfo    directoryInfo = Directory.CreateDirectory(serverPath);
            Network          network       = new Network(networkName, networkType, javaSettings, VersionManager.Instance.WaterfallVersion);
            NetworkViewModel viewModel     = new NetworkViewModel(network);

            ServerManager.Instance.AddEntity(viewModel);
            //Select Server
            ApplicationManager.Instance.MainViewModel.SelectedEntity = viewModel;

            //Download server.jar
            Downloader.DownloadJarAsync(viewModel, directoryInfo);

            //Writing necessary files
            //TODO write settings
            //new FileWriter().WriteServerSettings(Path.Combine(App.ServerPath, directoryInfo.Name), serverSettings.SettingsDictionary);

            return(true);
        }
Пример #7
0
        private async void BtnApply_Click(object sender, RoutedEventArgs e)
        {
            CreateBtn.IsEnabled = false;
            char[] illegalDirChars = Path.GetInvalidFileNameChars();
            if (isProxy)
            {
                string networkName        = NetworkName.Text;
                string refinedNetworkName = networkName;
                foreach (char c in networkName)
                {
                    if (illegalDirChars.Contains(c))
                    {
                        refinedNetworkName = refinedNetworkName.Replace(c + "", "");
                    }
                }
                if (refinedNetworkName.Equals(""))
                {
                    refinedNetworkName = "Network";
                }

                //TODO replace this with int value verifier
                int maxRam;
                if (!int.TryParse(NetworkMaxRam.Text, out maxRam))
                {
                    maxRam = 1024;
                }

                JavaSettings javaSettings = new JavaSettings {
                    MaxRam = maxRam
                };
                bool createNetworkSuccess = await ServerManager.Instance.CreateNetworkAsync(refinedNetworkName, proxyType, javaSettings);
            }
            else
            {
                ServerVersion selectedVersion = (ServerVersion)versionComboBox.SelectedValue;
                //TODO check if inputs are valid / server not existing

                string serverName        = ServerName.Text;
                string refinedServerName = serverName;
                foreach (char c in serverName)
                {
                    if (illegalDirChars.Contains(c))
                    {
                        refinedServerName = refinedServerName.Replace(c + "", "");
                    }
                }
                if (refinedServerName.Equals(""))
                {
                    refinedServerName = "Server";
                }

                string worldPath = null;
                if (lastPath != null)
                {
                    WorldValidationInfo valInfo = DirectoryValidator.ValidateWorldDirectory(new DirectoryInfo(lastPath));
                    if (valInfo.IsValid)
                    {
                        worldPath = lastPath;
                    }
                }
                bool createServerSuccess = await ServerManager.Instance.CreateServerAsync(refinedServerName, selectedVersion, viewModel.ServerSettings, new JavaSettings(), worldPath);
            }
            viewModel.GenerateNewSettings();
            CreateBtn.IsEnabled = true;

            //TODO Do something if creating fails
        }