Пример #1
0
 public static VoteFile FromLoad(string path, ServerSettings settings)
 {
     return(LoadOrCreate(path, settings));
 }
Пример #2
0
        private void buttonSaveServer_Click(object sender, EventArgs e)
        {
            bool isPortValid = int.TryParse(textBoxServerPort.Text, out _);

            if (string.IsNullOrWhiteSpace(textBoxServerIP.Text))
            {
                MessageBox.Show("Server IP cannot be blank!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (string.IsNullOrWhiteSpace(textBoxServerPort.Text))
            {
                MessageBox.Show("InfoServer Port cannot be blank!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!IsValidIPAddress(textBoxServerIP.Text))
            {
                MessageBox.Show("Server IP must be valid!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!isPortValid)
            {
                MessageBox.Show("InfoServer Port must be valid!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                textBoxCommandsToSendUponConnection.Text = textBoxCommandsToSendUponConnection.Text.StandardizeLineBreaks();
                List <string> onConnectCommands = new List <string>(textBoxCommandsToSendUponConnection.Text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries));

                string serverLanguage;
                string selectedLanguage = (string)comboBoxServerLanguage.SelectedItem;
                if (Translation.LanguageCodesByEnglishLanguageNameString.ContainsKey(selectedLanguage))
                {
                    serverLanguage = Translation.LanguageCodesByEnglishLanguageNameString[selectedLanguage];
                }
                else
                {
                    serverLanguage = "en";
                }

                if (isEditing)
                {
                    listbox.Items.Remove(listbox.SelectedItem);
                    connection.Settings.Ip                        = textBoxServerIP.Text;
                    connection.Settings.InfoPort                  = textBoxServerPort.Text;
                    connection.Settings.ServerPassword            = textBoxServerPassword.Text;
                    connection.Settings.RconPassword              = textBoxRconPassword.Text;
                    connection.Settings.RconPort                  = textBoxRconPort.Text;
                    connection.Settings.Name                      = textBoxName.Text;
                    connection.Settings.SendOnConnectCommands     = onConnectCommands;
                    connection.Settings.ServerLanguage            = serverLanguage;
                    connection.Settings.AutoTranslateChatMessages = checkBoxEnableAutoTranslate.Checked;
                    connection.Settings.UseLocalFiles             = checkBoxUseLocalData.Checked;
                    connection.Settings.UseServerHook             = checkBoxUseServerHook.Checked;

                    if (gameExecutableDirectoryInfo?.Exists ?? false)
                    {
                        // Add Server Directory Path
                        connection.Settings.ServerExecutableDirectoryPath =
                            gameExecutableDirectoryInfo.FullName;
                        // Add Map Variants folder if found
                        if (Directory.Exists(gameExecutableDirectoryInfo.FullName + "\\mods\\maps"))
                        {
                            connection.Settings.MapVariantsDirectoryPath =
                                gameExecutableDirectoryInfo.FullName + "\\mods\\maps";
                        }
                        else
                        {
                            connection.Settings.MapVariantsDirectoryPath = "";
                        }
                        // Add Game Variants folder if found
                        if (Directory.Exists(gameExecutableDirectoryInfo.FullName + "\\mods\\variants"))
                        {
                            connection.Settings.GameVariantsDirectoryPath =
                                gameExecutableDirectoryInfo.FullName + "\\mods\\variants";
                        }
                        else
                        {
                            connection.Settings.GameVariantsDirectoryPath = "";
                        }
                        // Add Vote Files folder if found
                        if (Directory.Exists(gameExecutableDirectoryInfo.FullName + "\\mods\\server"))
                        {
                            connection.Settings.VoteFilesDirectoryPath =
                                gameExecutableDirectoryInfo.FullName + "\\mods\\server";
                        }
                        else
                        {
                            connection.Settings.VoteFilesDirectoryPath = "";
                        }
                    }
                    else
                    {
                        connection.Settings.ServerExecutableDirectoryPath = "";
                        connection.Settings.MapVariantsDirectoryPath      = "";
                        connection.Settings.GameVariantsDirectoryPath     = "";
                        connection.Settings.VoteFilesDirectoryPath        = "";
                    }
                    int serverItemIndex =
                        listbox.Items.Add(new ServerManagerListBoxItem
                    {
                        ServerDisplayName = connection.Settings.DisplayName,
                        Connection        = connection
                    });
                    listbox.SetSelected(serverItemIndex, true);
                    connection.ResetRconConnection();
                    if (checkBoxIncludeDefaultFilteredPhrases.Checked && !alreadyHasFilteredPhrases)
                    {
                        foreach (string item in Translation.DefaultFilteredEnglishPhrases)
                        {
                            if (!connection.Settings.AutoTranslateIgnoredPhrasesList.Contains(item))
                            {
                                connection.Settings.AutoTranslateIgnoredPhrasesList.Add(item);
                            }
                        }
                        connection.SaveSettings();
                    }

                    connection.UpdateDisplay = true;
                }
                else
                {
                    //ServerSettings newServerSettings = new ServerSettings(
                    //    GetNextConnectionId(),
                    //    textBoxServerIP.Text,
                    //    textBoxServerPort.Text,
                    //    textBoxServerPassword.Text,
                    //    textBoxRconPassword.Text,
                    //    textBoxRconPort.Text,
                    //    serverLanguage,
                    //    textBoxName.Text,
                    //    onConnectCommands
                    //);

                    ServerSettings newServerSettings = new ServerSettings()
                    {
                        Id                    = GetNextConnectionId(),
                        Ip                    = textBoxServerIP.Text,
                        InfoPort              = textBoxServerPort.Text,
                        RconPort              = textBoxRconPort.Text,
                        ServerPassword        = textBoxServerPassword.Text,
                        RconPassword          = textBoxRconPassword.Text,
                        Name                  = textBoxName.Text,
                        ServerLanguage        = serverLanguage,
                        SendOnConnectCommands = onConnectCommands,
                        UseLocalFiles         = checkBoxUseLocalData.Checked,
                        UseServerHook         = checkBoxUseServerHook.Checked
                    };

                    if (newServerSettings.UseLocalFiles)
                    {
                        if (gameExecutableDirectoryInfo?.Exists ?? false)
                        {
                            newServerSettings.ServerExecutableDirectoryPath =
                                gameExecutableDirectoryInfo.FullName;

                            // Add Map Variants folder if found
                            if (Directory.Exists(gameExecutableDirectoryInfo.FullName + "\\mods\\maps"))
                            {
                                newServerSettings.MapVariantsDirectoryPath =
                                    gameExecutableDirectoryInfo.FullName + "\\mods\\maps";
                            }
                            // Add Game Variants folder if found
                            if (Directory.Exists(gameExecutableDirectoryInfo.FullName + "\\mods\\variants"))
                            {
                                newServerSettings.GameVariantsDirectoryPath =
                                    gameExecutableDirectoryInfo.FullName + "\\mods\\variants";
                            }
                            // Add Vote Files folder if found
                            if (Directory.Exists(gameExecutableDirectoryInfo.FullName + "\\mods\\server"))
                            {
                                newServerSettings.VoteFilesDirectoryPath =
                                    gameExecutableDirectoryInfo.FullName + "\\mods\\server";
                            }
                        }
                    }

                    Connection newConnection = new Connection(newServerSettings.Id, newServerSettings);

                    int serverItemIndex =
                        listbox.Items.Add(new ServerManagerListBoxItem
                    {
                        ServerDisplayName = newServerSettings.DisplayName,
                        Connection        = newConnection
                    });
                    listbox.SetSelected(serverItemIndex, true);

                    newConnection.Settings.AutoTranslateChatMessages = checkBoxEnableAutoTranslate.Checked;
                    if (checkBoxIncludeDefaultFilteredPhrases.Checked)
                    {
                        foreach (string item in Translation.DefaultFilteredEnglishPhrases)
                        {
                            if (!newConnection.Settings.AutoTranslateIgnoredPhrasesList.Contains(item))
                            {
                                newConnection.Settings.AutoTranslateIgnoredPhrasesList.Add(item);
                            }
                        }
                    }

                    newConnection.SaveSettings();
                }

                SaveSettings();
                Close();
            }
        }