ConfigurationLoader.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using System.Threading;
  31. using System.IO;
  32. using OpenSim.Framework;
  33. using Nini;
  34. using Nini.Config;
  35. namespace OpenSim
  36. {
  37. public class ConfigurationLoader
  38. {
  39. protected ConfigSettings m_configSettings;
  40. protected OpenSimConfigSource m_config;
  41. protected NetworkServersInfo m_networkServersInfo;
  42. public ConfigurationLoader()
  43. {
  44. }
  45. public OpenSimConfigSource LoadConfigSettings(IConfigSource configSource, out ConfigSettings configSettings, out NetworkServersInfo networkInfo)
  46. {
  47. m_configSettings = configSettings = new ConfigSettings();
  48. m_networkServersInfo = networkInfo = new NetworkServersInfo();
  49. bool iniFileExists = false;
  50. IConfig startupConfig = configSource.Configs["Startup"];
  51. string iniFileName = startupConfig.GetString("inifile", "OpenSim.ini");
  52. Application.iniFilePath = Path.Combine(Util.configDir(), iniFileName);
  53. string masterFileName = startupConfig.GetString("inimaster", "");
  54. string masterfilePath = Path.Combine(Util.configDir(), masterFileName);
  55. m_config = new OpenSimConfigSource();
  56. m_config.Source = new IniConfigSource();
  57. m_config.Source.Merge(DefaultConfig());
  58. //check for .INI file (either default or name passed in command line)
  59. if (File.Exists(masterfilePath))
  60. {
  61. m_config.Source.Merge(new IniConfigSource(masterfilePath));
  62. }
  63. if (File.Exists(Application.iniFilePath))
  64. {
  65. iniFileExists = true;
  66. // From reading Nini's code, it seems that later merged keys replace earlier ones.
  67. m_config.Source.Merge(new IniConfigSource(Application.iniFilePath));
  68. }
  69. else
  70. {
  71. // check for a xml config file
  72. Application.iniFilePath = Path.Combine(Util.configDir(), "OpenSim.xml");
  73. if (File.Exists(Application.iniFilePath))
  74. {
  75. iniFileExists = true;
  76. m_config.Source = new XmlConfigSource();
  77. m_config.Source.Merge(new XmlConfigSource(Application.iniFilePath));
  78. }
  79. }
  80. m_config.Source.Merge(configSource);
  81. if (!iniFileExists)
  82. m_config.Save("OpenSim.ini");
  83. ReadConfigSettings();
  84. return m_config;
  85. }
  86. /// <summary>
  87. /// Setup a default config values in case they aren't present in the ini file
  88. /// </summary>
  89. /// <returns></returns>
  90. public static IConfigSource DefaultConfig()
  91. {
  92. IConfigSource defaultConfig = new IniConfigSource();
  93. {
  94. IConfig config = defaultConfig.Configs["Startup"];
  95. if (null == config)
  96. config = defaultConfig.AddConfig("Startup");
  97. config.Set("region_info_source", "filesystem");
  98. config.Set("gridmode", false);
  99. config.Set("physics", "basicphysics");
  100. config.Set("meshing", "ZeroMesher");
  101. config.Set("physical_prim", true);
  102. config.Set("see_into_this_sim_from_neighbor", true);
  103. config.Set("serverside_object_permissions", false);
  104. config.Set("storage_plugin", "OpenSim.Data.SQLite.dll");
  105. config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3");
  106. config.Set("storage_prim_inventories", true);
  107. config.Set("startup_console_commands_file", String.Empty);
  108. config.Set("shutdown_console_commands_file", String.Empty);
  109. config.Set("DefaultScriptEngine", "XEngine");
  110. config.Set("asset_database", "local");
  111. config.Set("clientstack_plugin", "OpenSim.Region.ClientStack.LindenUDP.dll");
  112. // life doesn't really work without this
  113. config.Set("EventQueue", true);
  114. }
  115. {
  116. IConfig config = defaultConfig.Configs["StandAlone"];
  117. if (null == config)
  118. config = defaultConfig.AddConfig("StandAlone");
  119. config.Set("accounts_authenticate", false);
  120. config.Set("welcome_message", "Welcome to OpenSimulator");
  121. config.Set("inventory_plugin", "OpenSim.Data.SQLite.dll");
  122. config.Set("inventory_source", "");
  123. config.Set("userDatabase_plugin", "OpenSim.Data.SQLite.dll");
  124. config.Set("user_source", "");
  125. config.Set("asset_plugin", "OpenSim.Data.SQLite.dll");
  126. config.Set("asset_source", "");
  127. config.Set("dump_assets_to_file", false);
  128. }
  129. {
  130. IConfig config = defaultConfig.Configs["Network"];
  131. if (null == config)
  132. config = defaultConfig.AddConfig("Network");
  133. config.Set("default_location_x", 1000);
  134. config.Set("default_location_y", 1000);
  135. config.Set("http_listener_port", NetworkServersInfo.DefaultHttpListenerPort);
  136. config.Set("remoting_listener_port", NetworkServersInfo.RemotingListenerPort);
  137. config.Set("grid_server_url", "http://127.0.0.1:" + GridConfig.DefaultHttpPort.ToString());
  138. config.Set("grid_send_key", "null");
  139. config.Set("grid_recv_key", "null");
  140. config.Set("user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString());
  141. config.Set("user_send_key", "null");
  142. config.Set("user_recv_key", "null");
  143. config.Set("asset_server_url", "http://127.0.0.1:" + AssetConfig.DefaultHttpPort.ToString());
  144. config.Set("inventory_server_url", "http://127.0.0.1:" + InventoryConfig.DefaultHttpPort.ToString());
  145. config.Set("secure_inventory_server", "true");
  146. }
  147. return defaultConfig;
  148. }
  149. protected virtual void ReadConfigSettings()
  150. {
  151. IConfig startupConfig = m_config.Source.Configs["Startup"];
  152. if (startupConfig != null)
  153. {
  154. m_configSettings.Standalone = !startupConfig.GetBoolean("gridmode", false);
  155. m_configSettings.PhysicsEngine = startupConfig.GetString("physics");
  156. m_configSettings.MeshEngineName = startupConfig.GetString("meshing");
  157. m_configSettings.PhysicalPrim = startupConfig.GetBoolean("physical_prim", true);
  158. m_configSettings.See_into_region_from_neighbor = startupConfig.GetBoolean("see_into_this_sim_from_neighbor", true);
  159. m_configSettings.StorageDll = startupConfig.GetString("storage_plugin");
  160. if (m_configSettings.StorageDll == "OpenSim.DataStore.MonoSqlite.dll")
  161. {
  162. m_configSettings.StorageDll = "OpenSim.Data.SQLite.dll";
  163. Console.WriteLine("WARNING: OpenSim.DataStore.MonoSqlite.dll is deprecated. Set storage_plugin to OpenSim.Data.SQLite.dll.");
  164. Thread.Sleep(3000);
  165. }
  166. m_configSettings.StorageConnectionString = startupConfig.GetString("storage_connection_string");
  167. m_configSettings.EstateConnectionString = startupConfig.GetString("estate_connection_string", m_configSettings.StorageConnectionString);
  168. m_configSettings.AssetStorage = startupConfig.GetString("asset_database");
  169. m_configSettings.ClientstackDll = startupConfig.GetString("clientstack_plugin");
  170. }
  171. IConfig standaloneConfig = m_config.Source.Configs["StandAlone"];
  172. if (standaloneConfig != null)
  173. {
  174. m_configSettings.StandaloneAuthenticate = standaloneConfig.GetBoolean("accounts_authenticate", true);
  175. m_configSettings.StandaloneWelcomeMessage = standaloneConfig.GetString("welcome_message");
  176. m_configSettings.StandaloneInventoryPlugin = standaloneConfig.GetString("inventory_plugin");
  177. m_configSettings.StandaloneInventorySource = standaloneConfig.GetString("inventory_source");
  178. m_configSettings.StandaloneUserPlugin = standaloneConfig.GetString("userDatabase_plugin");
  179. m_configSettings.StandaloneUserSource = standaloneConfig.GetString("user_source");
  180. m_configSettings.StandaloneAssetPlugin = standaloneConfig.GetString("asset_plugin");
  181. m_configSettings.StandaloneAssetSource = standaloneConfig.GetString("asset_source");
  182. m_configSettings.DumpAssetsToFile = standaloneConfig.GetBoolean("dump_assets_to_file", false);
  183. }
  184. m_networkServersInfo.loadFromConfiguration(m_config.Source);
  185. }
  186. }
  187. }