Пример #1
0
 private void loadBtn_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         ControlPanelForm controlPanel = new ControlPanelForm(openFileDialog1.FileName);
         controlPanel.Show();
         this.Visible = false;
     }
 }
Пример #2
0
        void CreateServManager()
        {
            if (serverPathBox.Text != "" && serverEngineCB.Text != "" && serverVersionCB.Text != "" && serverNameBox.Text != "")
            {
                Server server = new Server();
                server.Name    = serverNameBox.Text;
                server.Path    = serverPathBox.Text;
                server.Engine  = serverEngineCB.Text;
                server.Version = serverVersionCB.Text;
                StreamWriter configWriter = new StreamWriter(serverPathBox.Text + "\\servmanager.srv");
                configWriter.Write(JsonConvert.SerializeObject(server));
                configWriter.Close();
                MessageBox.Show("Server " + serverNameBox.Text + " has been added. You'll be moved to Control Panel", "Server added", MessageBoxButtons.OK, MessageBoxIcon.Information);

                ControlPanelForm controlPanel = new ControlPanelForm(serverPathBox.Text + "\\servmanager.srv");
                controlPanel.Show();

                this.Visible = false;
            }
            else
            {
                MessageBox.Show("The required fields have not been completed! Complete them and try again.", "Required fields are empty", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void createServer(object sender, EventArgs e)
        {
            try
            {
                if (serverEngineCB.Text != "" && serverNameTB.Text != "" && serverPathTB.Text != "" && serverVersionCB.Text != "" && minRAM.Value <= maxRAM.Value && maxRAM.Value >= minRAM.Value && minRAM.Value != 0)
                {
                    if (eulaBox.Checked)
                    {
                        groupBox1.Enabled = false;
                        groupBox2.Enabled = false;
                        groupBox3.Enabled = false;
                        groupBox4.Enabled = false;

                        // Pobieranie pliku serwerowego
                        progressBar1.Visible = true;
                        WebClient downloader = new WebClient();
                        downloader.DownloadProgressChanged += (s, v) => { progressBar1.Value = v.ProgressPercentage; };
                        downloader.DownloadFileAsync(new Uri("https://file.siemv.pl/gry/minecraft/server/" + serverVersionCB.Text + "/" + serverEngineCB.Text + "/" + "server.jar"), serverPathTB.Text + "\\server.jar");

                        // Tworzenie pliku EULA
                        StreamWriter eulaWriter = new StreamWriter(serverPathTB.Text + "\\eula.txt");
                        eulaWriter.Write("#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula)." + Environment.NewLine + "#" + DateTime.Now + Environment.NewLine + "eula=true");
                        eulaWriter.Close();

                        // Tworzenie pliku startowego serwera
                        StreamWriter startWriter = new StreamWriter(serverPathTB.Text + "\\start.bat");
                        startWriter.Write("@echo off" + Environment.NewLine + "java -Xms" + minRAM.Value + "M -Xmx" + maxRAM.Value + "M " + argumentsTB.Text + " -jar server.jar nogui");
                        startWriter.Close();

                        // Tworzenie pliku dla ServManager
                        Server server = new Server();
                        server.Name    = serverNameTB.Text;
                        server.Path    = serverPathTB.Text;
                        server.Engine  = serverEngineCB.Text;
                        server.Version = serverVersionCB.Text;
                        StreamWriter configWriter = new StreamWriter(serverPathTB.Text + "\\servmanager.srv");
                        configWriter.Write(JsonConvert.SerializeObject(server));
                        configWriter.Close();

                        // Tworzenie pliku server.properties
                        var nowalinia = Environment.NewLine;

                        StreamWriter writer           = new StreamWriter(serverPathTB.Text + "\\server.properties");
                        string       serverproperties =
                            "#Minecraft server properties" + nowalinia +
                            "#" + DateTime.Now + nowalinia +
                            "spawn-protection=" + spawnProtection.Value + nowalinia +
                            "generator-settings=" + generatorSettings.Text + nowalinia +
                            "force-gamemode=" + forceGamemode.Checked.ToString().ToLower() + nowalinia +
                            "allow-nether=" + allowNether.Checked.ToString().ToLower() + nowalinia +
                            "gamemode=" + gamemode.SelectedIndex.ToString() + nowalinia +
                            "difficulty=" + difficulty.SelectedIndex.ToString() + nowalinia +
                            "spawn-monstars=" + spawnMonsters.Checked.ToString().ToLower() + nowalinia +
                            "pvp=" + enablePvp.Checked.ToString().ToLower() + nowalinia +
                            "level-type=default" + nowalinia +
                            "hardcore=" + hardcore.Checked.ToString().ToLower() + nowalinia +
                            "enable-status=" + enableStatus.Checked.ToString().ToLower() + nowalinia +
                            "enable-command-block=" + enableCommandBlocks.Checked.ToString().ToLower() + nowalinia +
                            "max-players=" + maxPlayers.Value + nowalinia +
                            "max-world-size=" + maxWorldSize.Value + nowalinia +
                            "server-port=" + serverPort.Value + nowalinia +
                            "server-ip=" + serverIp.Text + nowalinia +
                            "max-build-height=" + maxBuildingHeight.Value.ToString() + nowalinia +
                            "spawn-npcs=" + spawnNpcs.Checked.ToString().ToLower() + nowalinia +
                            "allow-flight=" + allowFlight.Checked.ToString().ToLower() + nowalinia +
                            "level-name=" + levelName.Text + nowalinia +
                            "view-distance=" + viewDistance.Value + nowalinia +
                            "spawn-animals=" + spawnAnimals.Checked.ToString().ToLower() + nowalinia +
                            "white-list=" + whiteList.Checked.ToString().ToLower() + nowalinia +
                            "generate-structures=" + generateStructures.Checked.ToString().ToLower() + nowalinia +
                            "online-mode=" + onlineMode.Checked.ToString().ToLower() + nowalinia +
                            "motd=" + motd.Text + nowalinia;
                        writer.Write(serverproperties);
                        writer.Close();

                        downloader.DownloadFileCompleted += (s, v) =>
                        {
                            progressBar1.Visible = false;
                            MessageBox.Show("Server " + serverNameTB.Text + " has been created in: " + serverPathTB.Text + ". After pressing the OK button you'll be taken to the control panel.", "Server Created", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            ControlPanelForm controlPanel = new ControlPanelForm(serverPathTB.Text + "\\servmanager.srv");
                            controlPanel.Show();

                            this.Visible = false;
                        };
                    }
                    else
                    {
                        MessageBox.Show("You have to accept an EULA, to run a server.", "Accept EULA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("The required fields have not been completed! Complete them and try again.", "Required fields are empty", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }