diff options
Diffstat (limited to 'OpenSim/Framework/General/RegionInfo.cs')
-rw-r--r-- | OpenSim/Framework/General/RegionInfo.cs | 347 |
1 files changed, 347 insertions, 0 deletions
diff --git a/OpenSim/Framework/General/RegionInfo.cs b/OpenSim/Framework/General/RegionInfo.cs new file mode 100644 index 0000000..32f0c76 --- /dev/null +++ b/OpenSim/Framework/General/RegionInfo.cs | |||
@@ -0,0 +1,347 @@ | |||
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 OpenSim 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.Globalization; | ||
30 | using System.Net; | ||
31 | using System.Net.Sockets; | ||
32 | using Nini.Config; | ||
33 | using libsecondlife; | ||
34 | using OpenSim.Framework.Console; | ||
35 | using OpenSim.Framework.Interfaces; | ||
36 | using OpenSim.Framework; | ||
37 | |||
38 | namespace OpenSim.Framework | ||
39 | { | ||
40 | public class SimpleRegionInfo | ||
41 | { | ||
42 | public SimpleRegionInfo() | ||
43 | { | ||
44 | } | ||
45 | |||
46 | public SimpleRegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri) | ||
47 | { | ||
48 | |||
49 | m_regionLocX = regionLocX; | ||
50 | m_regionLocY = regionLocY; | ||
51 | |||
52 | m_internalEndPoint = internalEndPoint; | ||
53 | m_externalHostName = externalUri; | ||
54 | } | ||
55 | |||
56 | public SimpleRegionInfo(uint regionLocX, uint regionLocY, string externalUri, int port) | ||
57 | { | ||
58 | |||
59 | m_regionLocX = regionLocX; | ||
60 | m_regionLocY = regionLocY; | ||
61 | |||
62 | m_externalHostName = externalUri; | ||
63 | |||
64 | m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port); | ||
65 | } | ||
66 | |||
67 | public LLUUID RegionID = new LLUUID(); | ||
68 | |||
69 | private uint m_remotingPort; | ||
70 | public uint RemotingPort | ||
71 | { | ||
72 | get | ||
73 | { | ||
74 | return m_remotingPort; | ||
75 | } | ||
76 | set | ||
77 | { | ||
78 | m_remotingPort = value; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | public string RemotingAddress; | ||
83 | |||
84 | |||
85 | public IPEndPoint ExternalEndPoint | ||
86 | { | ||
87 | get | ||
88 | { | ||
89 | // Old one defaults to IPv6 | ||
90 | //return new IPEndPoint( Dns.GetHostAddresses( m_externalHostName )[0], m_internalEndPoint.Port ); | ||
91 | |||
92 | IPAddress ia = null; | ||
93 | // If it is already an IP, don't resolve it - just return directly | ||
94 | if (IPAddress.TryParse(m_externalHostName, out ia)) | ||
95 | return new IPEndPoint(ia, m_internalEndPoint.Port); | ||
96 | |||
97 | // Reset for next check | ||
98 | ia = null; | ||
99 | |||
100 | |||
101 | // New method favors IPv4 | ||
102 | foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName)) | ||
103 | { | ||
104 | if (ia == null) | ||
105 | ia = Adr; | ||
106 | |||
107 | if (Adr.AddressFamily == AddressFamily.InterNetwork) | ||
108 | { | ||
109 | ia = Adr; | ||
110 | break; | ||
111 | } | ||
112 | |||
113 | } | ||
114 | |||
115 | return new IPEndPoint(ia, m_internalEndPoint.Port); | ||
116 | } | ||
117 | |||
118 | set | ||
119 | { | ||
120 | m_externalHostName = value.ToString(); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | protected string m_externalHostName; | ||
125 | public string ExternalHostName | ||
126 | { | ||
127 | get | ||
128 | { | ||
129 | return m_externalHostName; | ||
130 | } | ||
131 | set | ||
132 | { | ||
133 | m_externalHostName = value; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | protected IPEndPoint m_internalEndPoint; | ||
138 | public IPEndPoint InternalEndPoint | ||
139 | { | ||
140 | get | ||
141 | { | ||
142 | return m_internalEndPoint; | ||
143 | } | ||
144 | set | ||
145 | { | ||
146 | m_internalEndPoint = value; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | protected uint? m_regionLocX; | ||
151 | public uint RegionLocX | ||
152 | { | ||
153 | get | ||
154 | { | ||
155 | return m_regionLocX.Value; | ||
156 | } | ||
157 | set | ||
158 | { | ||
159 | m_regionLocX = value; | ||
160 | } | ||
161 | } | ||
162 | |||
163 | protected uint? m_regionLocY; | ||
164 | public uint RegionLocY | ||
165 | { | ||
166 | get | ||
167 | { | ||
168 | return m_regionLocY.Value; | ||
169 | } | ||
170 | set | ||
171 | { | ||
172 | m_regionLocY = value; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | public ulong RegionHandle | ||
177 | { | ||
178 | get | ||
179 | { | ||
180 | return Util.UIntsToLong((RegionLocX * 256), (RegionLocY * 256)); | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | public class RegionInfo : SimpleRegionInfo | ||
186 | { | ||
187 | public string RegionName = ""; | ||
188 | |||
189 | public string DataStore = ""; | ||
190 | public bool isSandbox = false; | ||
191 | |||
192 | public LLUUID MasterAvatarAssignedUUID = new LLUUID(); | ||
193 | public string MasterAvatarFirstName = ""; | ||
194 | public string MasterAvatarLastName = ""; | ||
195 | public string MasterAvatarSandboxPassword = ""; | ||
196 | |||
197 | // Apparently, we're applying the same estatesettings regardless of whether it's local or remote. | ||
198 | private static EstateSettings m_estateSettings; | ||
199 | public EstateSettings EstateSettings | ||
200 | { | ||
201 | get | ||
202 | { | ||
203 | if( m_estateSettings == null ) | ||
204 | { | ||
205 | m_estateSettings = new EstateSettings(); | ||
206 | } | ||
207 | |||
208 | return m_estateSettings; | ||
209 | } | ||
210 | |||
211 | } | ||
212 | |||
213 | public ConfigurationMember configMember; | ||
214 | public RegionInfo(string description, string filename) | ||
215 | { | ||
216 | configMember = new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration); | ||
217 | configMember.performConfigurationRetrieve(); | ||
218 | } | ||
219 | |||
220 | public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri) : | ||
221 | base(regionLocX, regionLocY, internalEndPoint, externalUri) | ||
222 | { | ||
223 | |||
224 | |||
225 | } | ||
226 | |||
227 | public RegionInfo() | ||
228 | { | ||
229 | |||
230 | } | ||
231 | |||
232 | //not in use, should swap to nini though. | ||
233 | public void LoadFromNiniSource(IConfigSource source) | ||
234 | { | ||
235 | this.LoadFromNiniSource(source, "RegionInfo"); | ||
236 | } | ||
237 | |||
238 | //not in use, should swap to nini though. | ||
239 | public void LoadFromNiniSource(IConfigSource source, string sectionName) | ||
240 | { | ||
241 | string errorMessage = ""; | ||
242 | this.RegionID = new LLUUID(source.Configs[sectionName].GetString("Region_ID", LLUUID.Random().ToStringHyphenated())); | ||
243 | this.RegionName = source.Configs[sectionName].GetString("sim_name", "OpenSim Test"); | ||
244 | this.m_regionLocX = Convert.ToUInt32(source.Configs[sectionName].GetString("sim_location_x", "1000")); | ||
245 | this.m_regionLocY = Convert.ToUInt32(source.Configs[sectionName].GetString("sim_location_y", "1000")); | ||
246 | this.DataStore = source.Configs[sectionName].GetString("datastore", "OpenSim.db"); | ||
247 | |||
248 | string ipAddress = source.Configs[sectionName].GetString("internal_ip_address", "0.0.0.0"); | ||
249 | IPAddress ipAddressResult; | ||
250 | if (IPAddress.TryParse(ipAddress, out ipAddressResult)) | ||
251 | { | ||
252 | this.m_internalEndPoint = new IPEndPoint(ipAddressResult, 0); | ||
253 | } | ||
254 | else | ||
255 | { | ||
256 | errorMessage = "needs an IP Address (IPAddress)"; | ||
257 | } | ||
258 | this.m_internalEndPoint.Port = source.Configs[sectionName].GetInt("internal_ip_port", NetworkServersInfo.DefaultHttpListenerPort); | ||
259 | |||
260 | string externalHost = source.Configs[sectionName].GetString("external_host_name", "127.0.0.1"); | ||
261 | if (externalHost != "SYSTEMIP") | ||
262 | { | ||
263 | this.m_externalHostName = externalHost; | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | this.m_externalHostName = Util.GetLocalHost().ToString(); | ||
268 | } | ||
269 | |||
270 | this.MasterAvatarFirstName = source.Configs[sectionName].GetString("master_avatar_first", "Test"); | ||
271 | this.MasterAvatarLastName = source.Configs[sectionName].GetString("master_avatar_last", "User"); | ||
272 | this.MasterAvatarSandboxPassword = source.Configs[sectionName].GetString("master_avatar_pass", "test"); | ||
273 | |||
274 | if (errorMessage != "") | ||
275 | { | ||
276 | // a error | ||
277 | } | ||
278 | } | ||
279 | |||
280 | public void loadConfigurationOptions() | ||
281 | { | ||
282 | configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_LLUUID, "UUID of Region (Default is recommended, random UUID)", LLUUID.Random().ToString(), true); | ||
283 | configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Region Name", "OpenSim Test", false); | ||
284 | configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, "Grid Location (X Axis)", "1000", false); | ||
285 | configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, "Grid Location (Y Axis)", "1000", false); | ||
286 | configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false); | ||
287 | configMember.addConfigurationOption("internal_ip_address", ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS, "Internal IP Address for incoming UDP client connections", "0.0.0.0", false); | ||
288 | configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32, "Internal IP Port for incoming UDP client connections", NetworkServersInfo.DefaultHttpListenerPort.ToString(), false); | ||
289 | configMember.addConfigurationOption("external_host_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "External Host Name", "127.0.0.1", false); | ||
290 | configMember.addConfigurationOption("master_avatar_first", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "First Name of Master Avatar", "Test", false); | ||
291 | configMember.addConfigurationOption("master_avatar_last", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Last Name of Master Avatar", "User", false); | ||
292 | configMember.addConfigurationOption("master_avatar_pass", ConfigurationOption.ConfigurationTypes.TYPE_STRING, "(Sandbox Mode Only)Password for Master Avatar account", "test", false); | ||
293 | } | ||
294 | |||
295 | public bool handleIncomingConfiguration(string configuration_key, object configuration_result) | ||
296 | { | ||
297 | switch (configuration_key) | ||
298 | { | ||
299 | case "sim_UUID": | ||
300 | this.RegionID = (LLUUID)configuration_result; | ||
301 | break; | ||
302 | case "sim_name": | ||
303 | this.RegionName = (string)configuration_result; | ||
304 | break; | ||
305 | case "sim_location_x": | ||
306 | this.m_regionLocX = (uint)configuration_result; | ||
307 | break; | ||
308 | case "sim_location_y": | ||
309 | this.m_regionLocY = (uint)configuration_result; | ||
310 | break; | ||
311 | case "datastore": | ||
312 | this.DataStore = (string)configuration_result; | ||
313 | break; | ||
314 | case "internal_ip_address": | ||
315 | IPAddress address = (IPAddress)configuration_result; | ||
316 | this.m_internalEndPoint = new IPEndPoint(address, 0); | ||
317 | break; | ||
318 | case "internal_ip_port": | ||
319 | this.m_internalEndPoint.Port = (int)configuration_result; | ||
320 | break; | ||
321 | case "external_host_name": | ||
322 | if ((string)configuration_result != "SYSTEMIP") | ||
323 | { | ||
324 | this.m_externalHostName = (string)configuration_result; | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | this.m_externalHostName = Util.GetLocalHost().ToString(); | ||
329 | } | ||
330 | break; | ||
331 | case "master_avatar_first": | ||
332 | this.MasterAvatarFirstName = (string)configuration_result; | ||
333 | break; | ||
334 | case "master_avatar_last": | ||
335 | this.MasterAvatarLastName = (string)configuration_result; | ||
336 | break; | ||
337 | case "master_avatar_pass": | ||
338 | string tempMD5Passwd = (string)configuration_result; | ||
339 | this.MasterAvatarSandboxPassword = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + ""); | ||
340 | break; | ||
341 | } | ||
342 | |||
343 | return true; | ||
344 | } | ||
345 | |||
346 | } | ||
347 | } | ||