aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/General/Types/RegionInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/General/Types/RegionInfo.cs342
1 files changed, 342 insertions, 0 deletions
diff --git a/OpenSim/Framework/General/Types/RegionInfo.cs b/OpenSim/Framework/General/Types/RegionInfo.cs
new file mode 100644
index 0000000..cfc0925
--- /dev/null
+++ b/OpenSim/Framework/General/Types/RegionInfo.cs
@@ -0,0 +1,342 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Globalization;
30using System.Net;
31using System.Net.Sockets;
32using libsecondlife;
33using OpenSim.Framework.Console;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Utilities;
36
37namespace OpenSim.Framework.Types
38{
39 public class RegionInfo
40 {
41 public LLUUID SimUUID = new LLUUID();
42 public string RegionName = "";
43
44 private IPEndPoint m_internalEndPoint;
45 public IPEndPoint InternalEndPoint
46 {
47 get
48 {
49 return m_internalEndPoint;
50 }
51 }
52
53 public IPEndPoint ExternalEndPoint
54 {
55 get
56 {
57 // Old one defaults to IPv6
58 //return new IPEndPoint( Dns.GetHostAddresses( m_externalHostName )[0], m_internalEndPoint.Port );
59
60 // New method favors IPv4
61 IPAddress ia = null;
62 foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
63 {
64 if (ia == null)
65 ia = Adr;
66
67 if (Adr.AddressFamily == AddressFamily.InterNetwork)
68 {
69 ia = Adr;
70 break;
71 }
72
73 }
74
75 return new IPEndPoint(ia, m_internalEndPoint.Port);
76 }
77 }
78
79 private string m_externalHostName;
80 public string ExternalHostName
81 {
82 get
83 {
84 return m_externalHostName;
85 }
86 }
87
88 private uint? m_regionLocX;
89 public uint RegionLocX
90 {
91 get
92 {
93 return m_regionLocX.Value;
94 }
95 }
96
97 private uint? m_regionLocY;
98 public uint RegionLocY
99 {
100 get
101 {
102 return m_regionLocY.Value;
103 }
104 }
105
106 private ulong? m_regionHandle;
107 public ulong RegionHandle
108 {
109 get
110 {
111 if (!m_regionHandle.HasValue)
112 {
113 m_regionHandle = Util.UIntsToLong((RegionLocX * 256), (RegionLocY * 256));
114 }
115
116 return m_regionHandle.Value;
117 }
118 }
119
120 // Only used for remote regions , ie ones not in the current instance
121 private uint m_remotingPort;
122 public uint RemotingPort
123 {
124 get
125 {
126 return m_remotingPort;
127 }
128 set
129 {
130 m_remotingPort = value;
131 }
132 }
133 public string RemotingAddress;
134
135 public string DataStore = "";
136 public bool isSandbox = false;
137
138 public LLUUID MasterAvatarAssignedUUID = new LLUUID();
139 public string MasterAvatarFirstName = "";
140 public string MasterAvatarLastName = "";
141 public string MasterAvatarSandboxPassword = "";
142
143 public EstateSettings estateSettings;
144
145 public RegionInfo()
146 {
147 estateSettings = new EstateSettings();
148 }
149
150 public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
151 : this()
152 {
153 m_regionLocX = regionLocX;
154 m_regionLocY = regionLocY;
155
156 m_internalEndPoint = internalEndPoint;
157 m_externalHostName = externalUri;
158 }
159
160 public void InitConfig(bool sandboxMode, IGenericConfig configData)
161 {
162 this.isSandbox = sandboxMode;
163 try
164 {
165 string attri = "";
166
167 // Sim UUID
168 string simId = configData.GetAttribute("SimUUID");
169 if (String.IsNullOrEmpty( simId ))
170 {
171 this.SimUUID = LLUUID.Random();
172 }
173 else
174 {
175 this.SimUUID = new LLUUID(simId);
176 }
177 configData.SetAttribute("SimUUID", this.SimUUID.ToString());
178
179 this.RegionName = GetString(configData, "SimName", "OpenSim test", "Region Name");
180
181 //m_regionLocX = (uint) GetInt(configData, "SimLocationX", 1000, "Grid Location X");
182
183 attri = "";
184 attri = configData.GetAttribute("SimLocationX");
185 if (attri == "")
186 {
187 string location = MainLog.Instance.CmdPrompt("Grid Location X", "1000");
188 configData.SetAttribute("SimLocationX", location);
189 m_regionLocX = (uint)Convert.ToUInt32(location);
190 }
191 else
192 {
193 m_regionLocX = (uint)Convert.ToUInt32(attri);
194 }
195 // Sim/Grid location Y
196 attri = "";
197 attri = configData.GetAttribute("SimLocationY");
198 if (attri == "")
199 {
200 string location = MainLog.Instance.CmdPrompt("Grid Location Y", "1000");
201 configData.SetAttribute("SimLocationY", location);
202 m_regionLocY = (uint)Convert.ToUInt32(location);
203 }
204 else
205 {
206 m_regionLocY = (uint)Convert.ToUInt32(attri);
207 }
208
209 m_regionHandle = null;
210
211 this.DataStore = GetString(configData, "Datastore", "localworld.yap", "Filename for local storage");
212
213 IPAddress internalAddress = GetIPAddress(configData, "InternalIPAddress", "0.0.0.0", "Internal IP Address for UDP client connections");
214 int internalPort = GetIPPort(configData, "InternalIPPort", "9000", "Internal IP Port for UDP client connections");
215 m_internalEndPoint = new IPEndPoint(internalAddress, internalPort);
216
217 m_externalHostName = GetString(configData, "ExternalHostName", "127.0.0.1", "External Host Name");
218
219 estateSettings.terrainFile =
220 GetString(configData, "TerrainFile", "default.r32", "GENERAL SETTING: Default Terrain File");
221
222 attri = "";
223 attri = configData.GetAttribute("TerrainMultiplier");
224 if (attri == "")
225 {
226 string re = MainLog.Instance.CmdPrompt("GENERAL SETTING: Terrain Height Multiplier", "60.0");
227 this.estateSettings.terrainMultiplier = Convert.ToDouble(re, CultureInfo.InvariantCulture);
228 configData.SetAttribute("TerrainMultiplier", this.estateSettings.terrainMultiplier.ToString());
229 }
230 else
231 {
232 this.estateSettings.terrainMultiplier = Convert.ToDouble(attri);
233 }
234
235 attri = "";
236 attri = configData.GetAttribute("MasterAvatarFirstName");
237 if (attri == "")
238 {
239 this.MasterAvatarFirstName = MainLog.Instance.CmdPrompt("First name of Master Avatar (Land and Region Owner)", "Test");
240
241 configData.SetAttribute("MasterAvatarFirstName", this.MasterAvatarFirstName);
242 }
243 else
244 {
245 this.MasterAvatarFirstName = attri;
246 }
247
248 attri = "";
249 attri = configData.GetAttribute("MasterAvatarLastName");
250 if (attri == "")
251 {
252 this.MasterAvatarLastName = MainLog.Instance.CmdPrompt("Last name of Master Avatar (Land and Region Owner)", "User");
253
254 configData.SetAttribute("MasterAvatarLastName", this.MasterAvatarLastName);
255 }
256 else
257 {
258 this.MasterAvatarLastName = attri;
259 }
260
261 if (isSandbox) //Sandbox Mode Specific Settings
262 {
263 attri = "";
264 attri = configData.GetAttribute("MasterAvatarSandboxPassword");
265 if (attri == "")
266 {
267 this.MasterAvatarSandboxPassword = MainLog.Instance.CmdPrompt("Password of Master Avatar (Needed for sandbox mode account creation only)", "test");
268
269 //Should I store this?
270 configData.SetAttribute("MasterAvatarSandboxPassword", this.MasterAvatarSandboxPassword);
271 }
272 else
273 {
274 this.MasterAvatarSandboxPassword = attri;
275 }
276 }
277
278 configData.Commit();
279 }
280 catch (Exception e)
281 {
282 MainLog.Instance.Warn("Config.cs:InitConfig() - Exception occured");
283 MainLog.Instance.Warn(e.ToString());
284 }
285
286 MainLog.Instance.Verbose("Sim settings loaded:");
287 MainLog.Instance.Verbose("UUID: " + this.SimUUID.ToStringHyphenated());
288 MainLog.Instance.Verbose("Name: " + this.RegionName);
289 MainLog.Instance.Verbose("Region Location: [" + this.RegionLocX.ToString() + "," + this.RegionLocY + "]");
290 MainLog.Instance.Verbose("Region Handle: " + this.RegionHandle.ToString());
291 MainLog.Instance.Verbose("Listening on IP end point: " + m_internalEndPoint.ToString() );
292 MainLog.Instance.Verbose("Sandbox Mode? " + isSandbox.ToString());
293
294 }
295
296 private uint GetInt(IGenericConfig configData, string p, int p_3, string p_4)
297 {
298 throw new Exception("The method or operation is not implemented.");
299 }
300
301 private string GetString(IGenericConfig configData, string attrName, string defaultvalue, string prompt)
302 {
303 string s = configData.GetAttribute(attrName);
304
305 if (String.IsNullOrEmpty( s ))
306 {
307 s = MainLog.Instance.CmdPrompt(prompt, defaultvalue);
308 configData.SetAttribute(attrName, s );
309 }
310 return s;
311 }
312
313 private IPAddress GetIPAddress(IGenericConfig configData, string attrName, string defaultvalue, string prompt)
314 {
315 string addressStr = configData.GetAttribute(attrName);
316
317 IPAddress address;
318
319 if (!IPAddress.TryParse(addressStr, out address))
320 {
321 address = MainLog.Instance.CmdPromptIPAddress(prompt, defaultvalue);
322 configData.SetAttribute(attrName, address.ToString());
323 }
324 return address;
325 }
326
327 private int GetIPPort(IGenericConfig configData, string attrName, string defaultvalue, string prompt)
328 {
329 string portStr = configData.GetAttribute(attrName);
330
331 int port;
332
333 if (!int.TryParse(portStr, out port))
334 {
335 port = MainLog.Instance.CmdPromptIPPort(prompt, defaultvalue);
336 configData.SetAttribute(attrName, port.ToString());
337 }
338
339 return port;
340 }
341 }
342}