Exemplo n.º 1
0
 /// <summary>
 /// Form onload event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DOLConfig_Load(object sender, EventArgs e)
 {
     //load data from current config file
     try
     {
         toolstripStatusLabelValue = "Loading current configuration ...";
         currentConfig             = DOLConfigParser.getCurrentConfiguration();
         loadConfig();
         toolstripStatusLabelValue = null;
     }
     catch (System.IO.FileNotFoundException)
     {
         DialogResult result = MessageBox.Show("There is no configuration file present." + Environment.NewLine + "Do you want me to create the default configuration?" + Environment.NewLine + "Otherwise: Start the GameServer first.", "Config file not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
         if (result == DialogResult.Yes)
         {
             saveConfig();
             DOLConfig_Load(sender, e);
             return;
         }
         else
         {
             this.Close();
         }
     }
     catch (FormatException ex)
     {
         MessageBox.Show("There are not allowed values in the config file. Please edit them manually." + Environment.NewLine + "Exception: " + ex.Message, "Error in config file", MessageBoxButtons.OK, MessageBoxIcon.Error);
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 2
0
        private void delete_property_button_Click(object sender, EventArgs e)
        {
            if (extra_options_datagrid.CurrentRow == null)
            {
                return;
            }

            DOLConfigParser.removeExtraOptionsRow(this.extraOptions, extra_options_datagrid.Rows[extra_options_datagrid.CurrentRow.Index].Cells["property"].Value);
        }
Exemplo n.º 3
0
        private void add_property_button_Click(object sender, EventArgs e)
        {
            ExtraPropertiesEditor property_editor = new ExtraPropertiesEditor("", "", "", "");
            DialogResult          result          = property_editor.ShowDialog();

            if (result == DialogResult.OK)
            {
                //Add a new Row
                DOLConfigParser.addExtraOptionsRow(this.extraOptions, property_editor.propertyName, property_editor.propertyType, (object)property_editor.propertyValue, "");
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads data vom current config to the form
        /// </summary>
        private void loadConfig()
        {
            if (currentConfig == null)
            {
                return;
            }

            //Full Server Name and Short Server Name
            this.full_server_name_textbox.Text  = currentConfig.ServerName;
            this.short_server_name_textbox.Text = currentConfig.ServerNameShort;

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

            case DOL.eGameServerType.GST_PvE:
                this.game_type_selectbox.SelectedItem = "PvE";
                break;

            case DOL.eGameServerType.GST_Roleplay:
                this.game_type_selectbox.SelectedItem = "Roleplay";
                break;

            case DOL.eGameServerType.GST_Casual:
                this.game_type_selectbox.SelectedItem = "Casual";
                break;

            case DOL.eGameServerType.GST_Test:
                this.game_type_selectbox.SelectedItem = "Test";
                break;

            case DOL.eGameServerType.GST_Normal:
            default:
                this.game_type_selectbox.SelectedItem = "Normal";
                break;
            }

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

            //Ip and Port settings
            this.ip_textbox.Text                   = currentConfig.IP.ToString();
            this.port_textbox.Text                 = currentConfig.Port.ToString();
            this.udp_port_textbox.Text             = currentConfig.UDPPort.ToString();
            this.detect_region_ip_checkbox.Checked = currentConfig.DetectRegionIP;
            this.region_ip_textbox.Text            = currentConfig.RegionIP.ToString();
            this.region_port_textbox.Text          = currentConfig.RegionPort.ToString();

            //Database Settings
            this.database_autosave_checkbox.Checked      = currentConfig.AutoSave;
            this.database_autosave_interval_textbox.Text = currentConfig.SaveInterval.ToString();

            switch (currentConfig.DBType)
            {
            case ConnectionType.DATABASE_XML:
                this.database_type_selectbox.SelectedItem = "XML";
                this.xml_path_textbox.Text = currentConfig.DBConnectionString;
                break;

            case ConnectionType.DATABASE_SQLITE:
                this.database_type_selectbox.SelectedItem = "SQLITE";
                this.xml_path_textbox.Text = currentConfig.DBConnectionString;
                break;

            case ConnectionType.DATABASE_MYSQL:
            default:
                this.database_type_selectbox.SelectedItem = "MySQL";
                MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder(currentConfig.DBConnectionString);
                this.mysql_host_textbox.Text          = sb.Server;
                this.mysql_port_textbox.Text          = sb.Port.ToString();
                this.mysql_database_name_textbox.Text = sb.Database;
                this.mysql_username_textbox.Text      = sb.UserID;
                this.mysql_password_textbox.Text      = sb.Password;

                break;
            }

            //Load extra options
            this.extraOptions = DOLConfigParser.loadExtraOptions();
            if (this.extraOptions != null)
            {
                extra_options_datagrid.DataSource = this.extraOptions;
            }
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
        private void loadConfig()
        {
            if (currentConfig == null)
            {
                return;
            }

            //Full Server Name and Short Server Name
            full_server_name_textbox.Text  = currentConfig.ServerName;
            short_server_name_textbox.Text = currentConfig.ServerNameShort;

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

            case DOL.eGameServerType.GST_PvE:
                game_type_selectbox.SelectedItem = "PvE";
                break;

            case DOL.eGameServerType.GST_Roleplay:
                game_type_selectbox.SelectedItem = "Roleplay";
                break;

            case DOL.eGameServerType.GST_Casual:
                game_type_selectbox.SelectedItem = "Casual";
                break;

            case DOL.eGameServerType.GST_Test:
                game_type_selectbox.SelectedItem = "Test";
                break;

            case DOL.eGameServerType.GST_Normal:
            default:
                game_type_selectbox.SelectedItem = "Normal";
                break;
            }

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

            //Ip and Port settings
            ip_textbox.Text                   = currentConfig.IP.ToString();
            port_textbox.Text                 = currentConfig.Port.ToString();
            udp_port_textbox.Text             = currentConfig.UDPPort.ToString();
            detect_region_ip_checkbox.Checked = currentConfig.DetectRegionIP;
            region_ip_textbox.Text            = currentConfig.RegionIP.ToString();
            region_port_textbox.Text          = currentConfig.RegionPort.ToString();

            //Database Settings
            database_autosave_checkbox.Checked      = currentConfig.AutoSave;
            database_autosave_interval_textbox.Text = currentConfig.SaveInterval.ToString();

            switch (currentConfig.DBType)
            {
            case ConnectionType.DATABASE_XML:
                database_type_selectbox.SelectedItem = "XML";
                xml_path_textbox.Text = currentConfig.DBConnectionString;
                break;

            case ConnectionType.DATABASE_SQLITE:
                database_type_selectbox.SelectedItem = "SQLite";
                xml_path_textbox.Text = currentConfig.DBConnectionString;
                break;

            case ConnectionType.DATABASE_MYSQL:
            default:
                database_type_selectbox.SelectedItem = "MySQL";
                var dbConfig = new DbConfig(currentConfig.DBConnectionString);
                mysql_host_textbox.Text          = dbConfig.GetValueOf("Server");
                mysql_port_textbox.Text          = dbConfig.GetValueOf("Port");
                mysql_database_name_textbox.Text = dbConfig.GetValueOf("Database");
                mysql_username_textbox.Text      = dbConfig.GetValueOf("UserID");
                mysql_password_textbox.Text      = dbConfig.GetValueOf("Password");
                break;
            }

            //Load extra options
            extraOptions = DOLConfigParser.loadExtraOptions();
            if (extraOptions != null)
            {
                extra_options_datagrid.DataSource = extraOptions;
            }
        }