clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.IO; |
||
31 | using System.Reflection; |
||
32 | using System.Threading; |
||
33 | using System.Xml; |
||
34 | using log4net; |
||
35 | using Nini.Config; |
||
36 | |||
37 | namespace OpenSim.Tools.Configger |
||
38 | { |
||
39 | /// <summary> |
||
40 | /// Loads the Configuration files into nIni |
||
41 | /// </summary> |
||
42 | public class ConfigurationLoader |
||
43 | { |
||
44 | /// <summary> |
||
45 | /// A source of Configuration data |
||
46 | /// </summary> |
||
47 | protected IConfigSource m_config; |
||
48 | |||
49 | /// <summary> |
||
50 | /// Console logger |
||
51 | /// </summary> |
||
52 | private static readonly ILog m_log = |
||
53 | LogManager.GetLogger( |
||
54 | MethodBase.GetCurrentMethod().DeclaringType); |
||
55 | |||
56 | public ConfigurationLoader() |
||
57 | { |
||
58 | } |
||
59 | |||
60 | /// <summary> |
||
61 | /// Loads the region configuration |
||
62 | /// </summary> |
||
63 | /// <param name="argvSource">Parameters passed into the process when started</param> |
||
64 | /// <param name="configSettings"></param> |
||
65 | /// <param name="networkInfo"></param> |
||
66 | /// <returns>A configuration that gets passed to modules</returns> |
||
67 | public IConfigSource LoadConfigSettings() |
||
68 | { |
||
69 | bool iniFileExists = false; |
||
70 | |||
71 | List<string> sources = new List<string>(); |
||
72 | |||
73 | string iniFileName = "OpenSim.ini"; |
||
74 | string iniFilePath = Path.Combine(".", iniFileName); |
||
75 | |||
76 | if (IsUri(iniFileName)) |
||
77 | { |
||
78 | if (!sources.Contains(iniFileName)) |
||
79 | sources.Add(iniFileName); |
||
80 | } |
||
81 | else |
||
82 | { |
||
83 | if (File.Exists(iniFilePath)) |
||
84 | { |
||
85 | if (!sources.Contains(iniFilePath)) |
||
86 | sources.Add(iniFilePath); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | m_config = new IniConfigSource(); |
||
91 | m_config.Merge(DefaultConfig()); |
||
92 | |||
93 | m_log.Info("[CONFIG] Reading configuration settings"); |
||
94 | |||
95 | if (sources.Count == 0) |
||
96 | { |
||
97 | m_log.FatalFormat("[CONFIG] Could not load any configuration"); |
||
98 | m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); |
||
99 | Environment.Exit(1); |
||
100 | } |
||
101 | |||
102 | for (int i = 0 ; i < sources.Count ; i++) |
||
103 | { |
||
104 | if (ReadConfig(sources[i])) |
||
105 | iniFileExists = true; |
||
106 | AddIncludes(sources); |
||
107 | } |
||
108 | |||
109 | if (!iniFileExists) |
||
110 | { |
||
111 | m_log.FatalFormat("[CONFIG] Could not load any configuration"); |
||
112 | m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!"); |
||
113 | Environment.Exit(1); |
||
114 | } |
||
115 | |||
116 | return m_config; |
||
117 | } |
||
118 | |||
119 | /// <summary> |
||
120 | /// Adds the included files as ini configuration files |
||
121 | /// </summary> |
||
122 | /// <param name="sources">List of URL strings or filename strings</param> |
||
123 | private void AddIncludes(List<string> sources) |
||
124 | { |
||
125 | //loop over config sources |
||
126 | foreach (IConfig config in m_config.Configs) |
||
127 | { |
||
128 | // Look for Include-* in the key name |
||
129 | string[] keys = config.GetKeys(); |
||
130 | foreach (string k in keys) |
||
131 | { |
||
132 | if (k.StartsWith("Include-")) |
||
133 | { |
||
134 | // read the config file to be included. |
||
135 | string file = config.GetString(k); |
||
136 | if (IsUri(file)) |
||
137 | { |
||
138 | if (!sources.Contains(file)) |
||
139 | sources.Add(file); |
||
140 | } |
||
141 | else |
||
142 | { |
||
143 | string basepath = Path.GetFullPath("."); |
||
144 | // Resolve relative paths with wildcards |
||
145 | string chunkWithoutWildcards = file; |
||
146 | string chunkWithWildcards = string.Empty; |
||
147 | int wildcardIndex = file.IndexOfAny(new char[] { '*', '?' }); |
||
148 | if (wildcardIndex != -1) |
||
149 | { |
||
150 | chunkWithoutWildcards = file.Substring(0, wildcardIndex); |
||
151 | chunkWithWildcards = file.Substring(wildcardIndex); |
||
152 | } |
||
153 | string path = Path.Combine(basepath, chunkWithoutWildcards); |
||
154 | path = Path.GetFullPath(path) + chunkWithWildcards; |
||
155 | string[] paths = Util.Glob(path); |
||
156 | foreach (string p in paths) |
||
157 | { |
||
158 | if (!sources.Contains(p)) |
||
159 | sources.Add(p); |
||
160 | } |
||
161 | } |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | } |
||
166 | /// <summary> |
||
167 | /// Check if we can convert the string to a URI |
||
168 | /// </summary> |
||
169 | /// <param name="file">String uri to the remote resource</param> |
||
170 | /// <returns>true if we can convert the string to a Uri object</returns> |
||
171 | bool IsUri(string file) |
||
172 | { |
||
173 | Uri configUri; |
||
174 | |||
175 | return Uri.TryCreate(file, UriKind.Absolute, |
||
176 | out configUri) && configUri.Scheme == Uri.UriSchemeHttp; |
||
177 | } |
||
178 | |||
179 | /// <summary> |
||
180 | /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http |
||
181 | /// </summary> |
||
182 | /// <param name="iniPath">Full path to the ini</param> |
||
183 | /// <returns></returns> |
||
184 | private bool ReadConfig(string iniPath) |
||
185 | { |
||
186 | bool success = false; |
||
187 | |||
188 | if (!IsUri(iniPath)) |
||
189 | { |
||
190 | m_log.InfoFormat("[CONFIG] Reading configuration file {0}", |
||
191 | Path.GetFullPath(iniPath)); |
||
192 | |||
193 | m_config.Merge(new IniConfigSource(iniPath)); |
||
194 | success = true; |
||
195 | } |
||
196 | else |
||
197 | { |
||
198 | m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", |
||
199 | iniPath); |
||
200 | |||
201 | // The ini file path is a http URI |
||
202 | // Try to read it |
||
203 | // |
||
204 | try |
||
205 | { |
||
206 | XmlReader r = XmlReader.Create(iniPath); |
||
207 | XmlConfigSource cs = new XmlConfigSource(r); |
||
208 | m_config.Merge(cs); |
||
209 | |||
210 | success = true; |
||
211 | } |
||
212 | catch (Exception e) |
||
213 | { |
||
214 | m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath); |
||
215 | Environment.Exit(1); |
||
216 | } |
||
217 | } |
||
218 | return success; |
||
219 | } |
||
220 | |||
221 | /// <summary> |
||
222 | /// Setup a default config values in case they aren't present in the ini file |
||
223 | /// </summary> |
||
224 | /// <returns>A Configuration source containing the default configuration</returns> |
||
225 | private static IConfigSource DefaultConfig() |
||
226 | { |
||
227 | IConfigSource defaultConfig = new IniConfigSource(); |
||
228 | |||
229 | { |
||
230 | IConfig config = defaultConfig.Configs["Startup"]; |
||
231 | |||
232 | if (null == config) |
||
233 | config = defaultConfig.AddConfig("Startup"); |
||
234 | |||
235 | config.Set("region_info_source", "filesystem"); |
||
236 | config.Set("allow_regionless", false); |
||
237 | |||
238 | config.Set("gridmode", false); |
||
239 | config.Set("physics", "OpenDynamicsEngine"); |
||
240 | config.Set("meshing", "Meshmerizer"); |
||
241 | config.Set("physical_prim", true); |
||
242 | config.Set("serverside_object_permissions", true); |
||
243 | config.Set("storage_plugin", "OpenSim.Data.SQLite.dll"); |
||
244 | config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3"); |
||
245 | config.Set("storage_prim_inventories", true); |
||
246 | config.Set("startup_console_commands_file", String.Empty); |
||
247 | config.Set("shutdown_console_commands_file", String.Empty); |
||
248 | config.Set("DefaultScriptEngine", "XEngine"); |
||
249 | config.Set("clientstack_plugin", "OpenSim.Region.ClientStack.LindenUDP.dll"); |
||
250 | // life doesn't really work without this |
||
251 | config.Set("EventQueue", true); |
||
252 | } |
||
253 | |||
254 | return defaultConfig; |
||
255 | } |
||
256 | |||
257 | } |
||
258 | } |