Example #1
0
		/// <summary>
		/// Saves a single configuration element to an XML stream.
		/// </summary>
		/// <param name="writer">the xml writer to save to</param>
		/// <param name="name">the name for this element</param>
		/// <param name="element">the element to save</param>
		private static void SaveElement(XmlWriter writer, string name, ConfigElement element)
		{
			bool badName = IsBadXMLElementName(name);

			if (element.HasChildren)
			{
				if (name == null)
					name = "root";

				if (badName)
				{
					writer.WriteStartElement("param");
					writer.WriteAttributeString("name", name);
				}
				else
				{
					writer.WriteStartElement(name);
				}

				foreach (var entry in element.Children)
				{
					SaveElement(writer, entry.Key, entry.Value);
				}

				writer.WriteEndElement();
			}
			else
			{
				if (name != null)
				{
					if (badName)
					{
						writer.WriteStartElement("param");
						writer.WriteAttributeString("name", name);
						writer.WriteString(element.GetString());
						writer.WriteEndElement();
					}
					else
					{
						writer.WriteElementString(name, element.GetString());
					}
				}
			}
		}
		/// <summary>
		/// Saves the values into a specific config element
		/// </summary>
		/// <param name="root">the root config element</param>
		protected override void SaveToConfig(ConfigElement root)
		{
			base.SaveToConfig(root);
			root["Server"]["ServerName"].Set(m_ServerName);
			root["Server"]["ServerNameShort"].Set(m_ServerNameShort);
			// Removed to not confuse users
//			root["Server"]["RootDirectory"].Set(m_rootDirectory);
			root["Server"]["LogConfigFile"].Set(m_logConfigFile);

			root["Server"]["ScriptCompilationTarget"].Set(m_scriptCompilationTarget);
			root["Server"]["ScriptAssemblies"].Set(m_scriptAssemblies);
			root["Server"]["AutoAccountCreation"].Set(m_autoAccountCreation);

			string serverType = "Normal";

			switch (m_serverType)
			{
				case eGameServerType.GST_Normal:
					serverType = "Normal";
					break;
				case eGameServerType.GST_Casual:
					serverType = "Casual";
					break;
				case eGameServerType.GST_Roleplay:
					serverType = "Roleplay";
					break;
				case eGameServerType.GST_PvE:
					serverType = "PvE";
					break;
				case eGameServerType.GST_PvP:
					serverType = "PvP";
					break;
				case eGameServerType.GST_Test:
					serverType = "Test";
					break;
				default:
					serverType = "Normal";
					break;
			}
			root["Server"]["GameType"].Set(serverType);

			root["Server"]["CheatLoggerName"].Set(m_cheatLoggerName);
			root["Server"]["GMActionLoggerName"].Set(m_gmActionsLoggerName);
			root["Server"]["InvalidNamesFile"].Set(m_invalidNamesFile);

			string db = "XML";
			
			switch (m_dbType)
			{
			case ConnectionType.DATABASE_XML:
				db = "XML";
					break;
			case ConnectionType.DATABASE_MYSQL:
				db = "MYSQL";
					break;
			case ConnectionType.DATABASE_SQLITE:
				db = "SQLITE";
					break;
			case ConnectionType.DATABASE_MSSQL:
				db = "MSSQL";
					break;
			case ConnectionType.DATABASE_ODBC:
				db = "ODBC";
					break;
			case ConnectionType.DATABASE_OLEDB:
				db = "OLEDB";
					break;
				default:
					m_dbType = ConnectionType.DATABASE_XML;
					break;
			}
			root["Server"]["DBType"].Set(db);
			root["Server"]["DBConnectionString"].Set(m_dbConnectionString);
			root["Server"]["DBAutosave"].Set(m_autoSave);
			root["Server"]["DBAutosaveInterval"].Set(m_saveInterval);
			root["Server"]["CpuUse"].Set(m_cpuUse);

			// Store UDP out endpoint
			if (m_udpOutEndpoint != null)
			{
				root["Server"]["UDPOutIP"].Set(m_udpOutEndpoint.Address.ToString());
				root["Server"]["UDPOutPort"].Set(m_udpOutEndpoint.Port.ToString());
			}
		}
		/// <summary>
		/// Loads the config values from a specific config element
		/// </summary>
		/// <param name="root">the root config element</param>
		protected override void LoadFromConfig(ConfigElement root)
		{
			base.LoadFromConfig(root);

			// Removed to not confuse users
//			m_rootDirectory = root["Server"]["RootDirectory"].GetString(m_rootDirectory);

			m_logConfigFile = root["Server"]["LogConfigFile"].GetString(m_logConfigFile);

			m_scriptCompilationTarget = root["Server"]["ScriptCompilationTarget"].GetString(m_scriptCompilationTarget);
			m_scriptAssemblies = root["Server"]["ScriptAssemblies"].GetString(m_scriptAssemblies);
			m_autoAccountCreation = root["Server"]["AutoAccountCreation"].GetBoolean(m_autoAccountCreation);

			string serverType = root["Server"]["GameType"].GetString("Normal");
			switch (serverType.ToLower())
			{
				case "normal":
					m_serverType = eGameServerType.GST_Normal;
					break;
				case "casual":
					m_serverType = eGameServerType.GST_Casual;
					break;
				case "roleplay":
					m_serverType = eGameServerType.GST_Roleplay;
					break;
				case "pve":
					m_serverType = eGameServerType.GST_PvE;
					break;
				case "pvp":
					m_serverType = eGameServerType.GST_PvP;
					break;
				case "test":
					m_serverType = eGameServerType.GST_Test;
					break;
				default:
					m_serverType = eGameServerType.GST_Normal;
					break;
			}

			m_ServerName = root["Server"]["ServerName"].GetString(m_ServerName);
			m_ServerNameShort = root["Server"]["ServerNameShort"].GetString(m_ServerNameShort);

			m_cheatLoggerName = root["Server"]["CheatLoggerName"].GetString(m_cheatLoggerName);
			m_gmActionsLoggerName = root["Server"]["GMActionLoggerName"].GetString(m_gmActionsLoggerName);
			m_invalidNamesFile = root["Server"]["InvalidNamesFile"].GetString(m_invalidNamesFile);

			string db = root["Server"]["DBType"].GetString("XML");
			switch (db.ToLower())
			{
				case "xml":
					m_dbType = ConnectionType.DATABASE_XML;
					break;
				case "mysql":
					m_dbType = ConnectionType.DATABASE_MYSQL;
					break;
				case "sqlite":
					m_dbType = ConnectionType.DATABASE_SQLITE;
					break;
				case "mssql":
					m_dbType = ConnectionType.DATABASE_MSSQL;
					break;
				case "odbc":
					m_dbType = ConnectionType.DATABASE_ODBC;
					break;
				case "oledb":
					m_dbType = ConnectionType.DATABASE_OLEDB;
					break;
				default:
					m_dbType = ConnectionType.DATABASE_XML;
					break;
			}
			m_dbConnectionString = root["Server"]["DBConnectionString"].GetString(m_dbConnectionString);
			m_autoSave = root["Server"]["DBAutosave"].GetBoolean(m_autoSave);
			m_saveInterval = root["Server"]["DBAutosaveInterval"].GetInt(m_saveInterval);
			m_maxClientCount = root["Server"]["MaxClientCount"].GetInt(m_maxClientCount);
			m_cpuCount = root["Server"]["CpuCount"].GetInt(m_cpuCount);
			
			if (m_cpuCount < 1)
				m_cpuCount = 1;
			
			m_cpuUse = root["Server"]["CpuUse"].GetInt(m_cpuUse);
			if (m_cpuUse < 1)
				m_cpuUse = 1; 
			
			// Parse UDP out endpoint
			IPAddress	address = null;
			int			port = -1;
			string		addressStr = root["Server"]["UDPOutIP"].GetString(string.Empty);
			string		portStr = root["Server"]["UDPOutPort"].GetString(string.Empty);
			if (IPAddress.TryParse(addressStr, out address)
				&& int.TryParse(portStr, out port)
				&& IPEndPoint.MaxPort >= port
				&& IPEndPoint.MinPort <= port)
			{
				m_udpOutEndpoint = new IPEndPoint(address, port);
			}
		}
Example #4
0
		/// <summary>
		/// Loads the xml configuration from a file
		/// </summary>
		/// <param name="configFile">The config file</param>
		/// <returns>The parsed config</returns>
		public static XMLConfigFile ParseXMLFile(FileInfo configFile)
		{
			if (configFile == null)
				throw new ArgumentNullException("configFile");

			var root = new XMLConfigFile();

			if (!configFile.Exists)
				return root;

			ConfigElement current = root;
			using(var reader = new XmlTextReader(configFile.OpenRead()))
			{
				while (reader.Read())
				{
					if (reader.NodeType == XmlNodeType.Element)
					{
						if (reader.Name == "root")
							continue;

						if (reader.Name == "param")
						{
							string name = reader.GetAttribute("name");

							if (name != null && name != "root")
							{
								var newElement = new ConfigElement(current);
								current[name] = newElement;
								current = newElement;
							}
						}
						else
						{
							var newElement = new ConfigElement(current);
							current[reader.Name] = newElement;
							current = newElement;
						}
					}
					else if (reader.NodeType == XmlNodeType.Text)
					{
						current.Set(reader.Value);
					}
					else if (reader.NodeType == XmlNodeType.EndElement)
					{
						if (reader.Name != "root")
						{
							current = current.Parent;
						}
					}
				}
			}

			return root;
		}
Example #5
0
		/// <summary>
		/// Creates and returns a new configuration element.
		/// </summary>
		/// <param name="parent">the parent element of the newly created element</param>
		/// <returns>the newly created config element</returns>
		private static ConfigElement GetNewConfigElement(ConfigElement parent)
		{
			return new ConfigElement(parent);
		}
Example #6
0
		/// <summary>
		/// Constructs a new config element with the given parent.
		/// </summary>
		/// <param name="parent">the parent element of the newly created element</param>
		public ConfigElement(ConfigElement parent)
		{
			_parent = parent;
		}
Example #7
0
		/// <summary>
		/// Saves the values to the given configuration element.
		/// </summary>
		/// <param name="root">the configuration element to save to</param>
		protected virtual void SaveToConfig(ConfigElement root)
		{
			root["Server"]["Port"].Set(_port);
			root["Server"]["IP"].Set(_ip);
			root["Server"]["RegionIP"].Set(_regionIP);
			root["Server"]["RegionPort"].Set(_regionPort);
			root["Server"]["UdpIP"].Set(_udpIP);
			root["Server"]["UdpPort"].Set(_udpPort);
			root["Server"]["EnableUPnP"].Set(_enableUPnP);
			root["Server"]["DetectRegionIP"].Set(_detectRegionIP);
		}
Example #8
0
		/// <summary>
		/// Loads the configuration values from the given configuration element.
		/// </summary>
		/// <param name="root">the root config element</param>
		protected virtual void LoadFromConfig(ConfigElement root)
		{
			string ip = root["Server"]["IP"].GetString("any");
			_ip = ip == "any" ? IPAddress.Any : IPAddress.Parse(ip);
			_port = (ushort) root["Server"]["Port"].GetInt(_port);

			ip = root["Server"]["RegionIP"].GetString("any");
			_regionIP = ip == "any" ? IPAddress.Any : IPAddress.Parse(ip);
			_regionPort = (ushort) root["Server"]["RegionPort"].GetInt(_regionPort);

			ip = root["Server"]["UdpIP"].GetString("any");

			_udpIP = ip == "any" ? IPAddress.Any : IPAddress.Parse(ip);
			_udpPort = (ushort) root["Server"]["UdpPort"].GetInt(_udpPort);

			_enableUPnP = root["Server"]["EnableUPnP"].GetBoolean(_enableUPnP);
			_detectRegionIP = root["Server"]["DetectRegionIP"].GetBoolean(_detectRegionIP);
		}
Example #9
0
 /// <summary>
 /// Constructs a new config element with the given parent.
 /// </summary>
 /// <param name="parent">the parent element of the newly created element</param>
 public ConfigElement(ConfigElement parent)
 {
     _parent = parent;
 }
Example #10
0
 /// <summary>
 /// Creates and returns a new configuration element.
 /// </summary>
 /// <param name="parent">the parent element of the newly created element</param>
 /// <returns>the newly created config element</returns>
 private static ConfigElement GetNewConfigElement(ConfigElement parent)
 {
     return(new ConfigElement(parent));
 }
Example #11
0
        /// <summary>
        /// Loads the xml configuration from a file
        /// </summary>
        /// <param name="configFile">The config file</param>
        /// <returns>The parsed config</returns>
        public static XMLConfigFile ParseXMLFile(FileInfo configFile)
        {
            if (configFile == null)
            {
                throw new ArgumentNullException("configFile");
            }

            var root = new XMLConfigFile();

            if (!configFile.Exists)
            {
                return(root);
            }

            ConfigElement current = root;

            using (var reader = new XmlTextReader(configFile.OpenRead()))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == "root")
                        {
                            continue;
                        }

                        if (reader.Name == "param")
                        {
                            string name = reader.GetAttribute("name");

                            if (name != null && name != "root")
                            {
                                var newElement = new ConfigElement(current);
                                current[name] = newElement;
                                current       = newElement;
                            }
                        }
                        else
                        {
                            var newElement = new ConfigElement(current);
                            current[reader.Name] = newElement;
                            current = newElement;
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.Text)
                    {
                        current.Set(reader.Value);
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (reader.Name != "root")
                        {
                            current = current.Parent;
                        }
                    }
                }
            }

            return(root);
        }