Exemple #1
0
        /// <summary>
        /// Saves current config out of the form
        /// </summary>
        private void saveConfig()
        {
            toolstripStatusLabelValue = "Try to save configuration ...";
            if (currentConfig == null)
            {
                currentConfig = new GameServerConfiguration();
            }

            //Full Server Name
            if (this.full_server_name_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(this.full_server_name_textbox, "The value of \"Full Server Name\" is not set.");
                return;
            }
            currentConfig.ServerName = this.full_server_name_textbox.Text;

            //Short Server Name
            if (this.short_server_name_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(this.short_server_name_textbox, "The value of \"Short Server Name\" is not set.");
                return;
            }
            currentConfig.ServerNameShort = this.short_server_name_textbox.Text;

            switch (this.game_type_selectbox.SelectedItem.ToString().ToLower())
            {
            case "pvp":
                currentConfig.ServerType = DOL.eGameServerType.GST_PvP;
                break;

            case "pve":
                currentConfig.ServerType = DOL.eGameServerType.GST_PvE;
                break;

            case "roleplay":
                currentConfig.ServerType = DOL.eGameServerType.GST_Roleplay;
                break;

            case "casual":
                currentConfig.ServerType = DOL.eGameServerType.GST_Casual;
                break;

            case "test":
                currentConfig.ServerType = DOL.eGameServerType.GST_Test;
                break;

            case "normal":
            default:
                currentConfig.ServerType = DOL.eGameServerType.GST_Normal;
                break;
            }

            //Parse Auto Account creation
            currentConfig.AutoAccountCreation = this.auto_account_creation_checkbox.Checked;

            //Ip
            if (ip_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(this.ip_textbox, "The value of \"IP\" is not set.");
                return;
            }
            try
            {
                currentConfig.IP = new System.Net.IPAddress(ipToByteArray(this.ip_textbox.Text));
            }
            catch (Exception)
            {
                addWrongValueErrorHandler(this.ip_textbox, "The value of \"IP\" is not allowed.");
                return;
            }

            //currentConfig.Ip = new System.Net.IPAddress();
            //Port
            if (this.port_textbox.Text.Length == 0 || Convert.ToUInt16(this.port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(this.port_textbox, "The value of \"TCP Port\" is not allowed.");
                return;
            }
            currentConfig.Port = Convert.ToUInt16(this.port_textbox.Text);

            //UDP port
            if (this.udp_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.udp_port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(this.udp_port_textbox, "The value of \"UDP Port\" is not allowed.");
                return;
            }
            currentConfig.UDPPort = Convert.ToUInt16(this.udp_port_textbox.Text);

            //Detect Region IPs
            currentConfig.DetectRegionIP = this.detect_region_ip_checkbox.Checked;

            //Region IP
            if (region_ip_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(this.region_ip_textbox, "The value of \"Region IP\" is not set.");
                return;
            }
            try
            {
                currentConfig.RegionIP = new System.Net.IPAddress(ipToByteArray(this.region_ip_textbox.Text));
            }
            catch (Exception)
            {
                addWrongValueErrorHandler(this.region_ip_textbox, "The value of \"Region IP\" is not allowed.");
                return;
            }


            //Region port
            if (this.region_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.region_port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(this.region_port_textbox, "The value of \"Region Port\" is not allowed.");
                return;
            }
            currentConfig.RegionPort = Convert.ToUInt16(this.region_port_textbox.Text);

            //Database Settings
            currentConfig.AutoSave = this.database_autosave_checkbox.Checked;

            //Auto database save interval
            if (this.database_autosave_interval_textbox.Text.Length == 0 || Convert.ToInt32(this.database_autosave_interval_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(this.database_autosave_interval_textbox, "The value of \"Autosave Interval\" is not allowed.");
                return;
            }
            currentConfig.SaveInterval = Convert.ToInt32(this.database_autosave_interval_textbox.Text);

            //Database settings
            switch (this.database_type_selectbox.SelectedItem.ToString().ToLower())
            {
            case "xml":
                currentConfig.DBType = ConnectionType.DATABASE_XML;
                if (xml_path_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(this.xml_path_textbox, "The value of \"Directory\" in \"XML Database settings\" is not set.");
                    return;
                }
                currentConfig.DBConnectionString = xml_path_textbox.Text;
                break;

            case "sqlite":
                currentConfig.DBType = ConnectionType.DATABASE_SQLITE;
                break;

            case "mysql":
                currentConfig.DBType = ConnectionType.DATABASE_MYSQL;

                //Mysql connection string builder
                MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder();

                //Host
                if (this.mysql_host_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(this.mysql_host_textbox, "The value of \"Server Address\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                sb.Server = this.mysql_host_textbox.Text;

                //Port
                if (this.mysql_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.mysql_port_textbox.Text) == 0)
                {
                    addWrongValueErrorHandler(this.mysql_port_textbox, "The value of \"Port\" in \"MySQL Database settings\" is not allowed.");
                    return;
                }
                sb.Port = Convert.ToUInt16(this.mysql_port_textbox.Text);

                //Database Name
                if (this.mysql_database_name_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(this.mysql_database_name_textbox, "The value of \"Database Name\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                sb.Database = this.mysql_database_name_textbox.Text;

                //Username
                if (this.mysql_username_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(this.mysql_username_textbox, "The value of \"Username\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                sb.UserID = this.mysql_username_textbox.Text;

                //Password
                sb.Password = this.mysql_password_textbox.Text;

                //Treat tiny as boolean
                sb.TreatTinyAsBoolean = false;

                //Set generated connection string
                currentConfig.DBConnectionString = sb.ConnectionString;

                //Just for fun: Test the connection
                mysql_test_button_Click(null, null);

                break;

            default:
                addWrongValueErrorHandler(this.database_type_selectbox, "There is no database connection selected.");
                return;
            }

            //Finally save all configuration
            DOLConfigParser.saveCurrentConfiguration(currentConfig);

            //And write extra properties
            if (this.extraOptions != null)
            {
                DOLConfigParser.saveExtraOptions(this.extraOptions);
            }

            toolstripStatusLabelValue = "Configuration saved.";
            toolstripTimer.Start();
        }
Exemple #2
0
        private void saveConfig()
        {
            toolstripStatusLabelValue = "Try to save configuration ...";
            if (currentConfig == null)
            {
                currentConfig = new GameServerConfiguration();
            }

            //Full Server Name
            if (full_server_name_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(full_server_name_textbox, "The value of \"Full Server Name\" is not set.");
                return;
            }
            currentConfig.ServerName = full_server_name_textbox.Text;

            //Short Server Name
            if (short_server_name_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(short_server_name_textbox, "The value of \"Short Server Name\" is not set.");
                return;
            }
            currentConfig.ServerNameShort = short_server_name_textbox.Text;

            switch (game_type_selectbox.SelectedItem.ToString().ToLower())
            {
            case "pvp":
                currentConfig.ServerType = DOL.eGameServerType.GST_PvP;
                break;

            case "pve":
                currentConfig.ServerType = DOL.eGameServerType.GST_PvE;
                break;

            case "roleplay":
                currentConfig.ServerType = DOL.eGameServerType.GST_Roleplay;
                break;

            case "casual":
                currentConfig.ServerType = DOL.eGameServerType.GST_Casual;
                break;

            case "test":
                currentConfig.ServerType = DOL.eGameServerType.GST_Test;
                break;

            case "normal":
            default:
                currentConfig.ServerType = DOL.eGameServerType.GST_Normal;
                break;
            }

            //Parse Auto Account creation
            currentConfig.AutoAccountCreation = auto_account_creation_checkbox.Checked;

            //Ip
            if (ip_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(ip_textbox, "The value of \"IP\" is not set.");
                return;
            }
            try
            {
                currentConfig.IP = new System.Net.IPAddress(ipToByteArray(ip_textbox.Text));
            }
            catch (Exception)
            {
                addWrongValueErrorHandler(ip_textbox, "The value of \"IP\" is not allowed.");
                return;
            }

            //currentConfig.Ip = new System.Net.IPAddress();
            //Port
            if (port_textbox.Text.Length == 0 || Convert.ToUInt16(port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(port_textbox, "The value of \"TCP Port\" is not allowed.");
                return;
            }
            currentConfig.Port = Convert.ToUInt16(port_textbox.Text);

            //UDP port
            if (udp_port_textbox.Text.Length == 0 || Convert.ToUInt16(udp_port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(udp_port_textbox, "The value of \"UDP Port\" is not allowed.");
                return;
            }
            currentConfig.UDPPort = Convert.ToUInt16(udp_port_textbox.Text);

            //Detect Region IPs
            currentConfig.DetectRegionIP = detect_region_ip_checkbox.Checked;

            //Region IP
            if (region_ip_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(region_ip_textbox, "The value of \"Region IP\" is not set.");
                return;
            }
            try
            {
                currentConfig.RegionIP = new System.Net.IPAddress(ipToByteArray(region_ip_textbox.Text));
            }
            catch (Exception)
            {
                addWrongValueErrorHandler(region_ip_textbox, "The value of \"Region IP\" is not allowed.");
                return;
            }


            //Region port
            if (region_port_textbox.Text.Length == 0 || Convert.ToUInt16(region_port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(region_port_textbox, "The value of \"Region Port\" is not allowed.");
                return;
            }
            currentConfig.RegionPort = Convert.ToUInt16(region_port_textbox.Text);

            //Database Settings
            currentConfig.AutoSave = database_autosave_checkbox.Checked;

            //Auto database save interval
            if (database_autosave_interval_textbox.Text.Length == 0 || Convert.ToInt32(database_autosave_interval_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(database_autosave_interval_textbox, "The value of \"Autosave Interval\" is not allowed.");
                return;
            }
            currentConfig.SaveInterval = Convert.ToInt32(database_autosave_interval_textbox.Text);

            //Database settings
            switch (database_type_selectbox.SelectedItem.ToString().ToLower())
            {
            case "xml":
                currentConfig.DBType = ConnectionType.DATABASE_XML;
                if (xml_path_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(xml_path_textbox, "The value of \"Directory\" in \"XML Database settings\" is not set.");
                    return;
                }
                currentConfig.DBConnectionString = xml_path_textbox.Text;
                break;

            case "sqlite":
                currentConfig.DBType             = ConnectionType.DATABASE_SQLITE;
                currentConfig.DBConnectionString = xml_path_textbox.Text;
                break;

            case "mysql":
                currentConfig.DBType = ConnectionType.DATABASE_MYSQL;

                var dbConfig = new DbConfig();

                if (mysql_host_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(mysql_host_textbox, "The value of \"Server Address\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                dbConfig.SetOption("Server", mysql_host_textbox.Text);

                if (mysql_port_textbox.Text.Length == 0 || Convert.ToUInt16(mysql_port_textbox.Text) == 0)
                {
                    addWrongValueErrorHandler(mysql_port_textbox, "The value of \"Port\" in \"MySQL Database settings\" is not allowed.");
                    return;
                }
                dbConfig.SetOption("Port", Convert.ToUInt16(mysql_port_textbox.Text).ToString());

                if (mysql_database_name_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(mysql_database_name_textbox, "The value of \"Database Name\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                dbConfig.SetOption("Database", mysql_database_name_textbox.Text);

                if (mysql_username_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(mysql_username_textbox, "The value of \"Username\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                dbConfig.SetOption("UserID", mysql_username_textbox.Text);
                dbConfig.SetOption("Password", mysql_password_textbox.Text);
                currentConfig.DBConnectionString = dbConfig.ConnectionString;

                mysql_test_button_Click(null, null);

                break;

            default:
                addWrongValueErrorHandler(database_type_selectbox, "There is no database connection selected.");
                return;
            }

            //Finally save all configuration
            DOLConfigParser.saveCurrentConfiguration(currentConfig);

            //And write extra properties
            if (extraOptions != null)
            {
                DOLConfigParser.saveExtraOptions(extraOptions);
            }

            toolstripStatusLabelValue = "Configuration saved.";
            toolstripTimer.Start();
        }