opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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.Net;
31 using System.Net.Sockets;
32 using System.Reflection;
33  
34 using OpenSim.Framework;
35 using OpenMetaverse;
36  
37 using log4net;
38  
39 namespace OpenSim.Services.Interfaces
40 {
41 public interface IGridService
42 {
43 /// <summary>
44 /// Register a region with the grid service.
45 /// </summary>
46 /// <param name="regionInfos"> </param>
47 /// <returns></returns>
48 /// <exception cref="System.Exception">Thrown if region registration failed</exception>
49 string RegisterRegion(UUID scopeID, GridRegion regionInfos);
50  
51 /// <summary>
52 /// Deregister a region with the grid service.
53 /// </summary>
54 /// <param name="regionID"></param>
55 /// <returns></returns>
56 /// <exception cref="System.Exception">Thrown if region deregistration failed</exception>
57 bool DeregisterRegion(UUID regionID);
58  
59 /// <summary>
60 /// Get information about the regions neighbouring the given co-ordinates (in meters).
61 /// </summary>
62 /// <param name="x"></param>
63 /// <param name="y"></param>
64 /// <returns></returns>
65 List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID);
66  
67 GridRegion GetRegionByUUID(UUID scopeID, UUID regionID);
68  
69 /// <summary>
70 /// Get the region at the given position (in meters)
71 /// </summary>
72 /// <param name="scopeID"></param>
73 /// <param name="x"></param>
74 /// <param name="y"></param>
75 /// <returns></returns>
76 GridRegion GetRegionByPosition(UUID scopeID, int x, int y);
77  
78 /// <summary>
79 /// Get information about a region which exactly matches the name given.
80 /// </summary>
81 /// <param name="scopeID"></param>
82 /// <param name="regionName"></param>
83 /// <returns>Returns the region information if the name matched. Null otherwise.</returns>
84 GridRegion GetRegionByName(UUID scopeID, string regionName);
85  
86 /// <summary>
87 /// Get information about regions starting with the provided name.
88 /// </summary>
89 /// <param name="name">
90 /// The name to match against.
91 /// </param>
92 /// <param name="maxNumber">
93 /// The maximum number of results to return.
94 /// </param>
95 /// <returns>
96 /// A list of <see cref="RegionInfo"/>s of regions with matching name. If the
97 /// grid-server couldn't be contacted or returned an error, return null.
98 /// </returns>
99 List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber);
100  
101 List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax);
102  
103 List<GridRegion> GetDefaultRegions(UUID scopeID);
104 List<GridRegion> GetDefaultHypergridRegions(UUID scopeID);
105 List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y);
106 List<GridRegion> GetHyperlinks(UUID scopeID);
107  
108 /// <summary>
109 /// Get internal OpenSimulator region flags.
110 /// </summary>
111 /// <remarks>
112 /// See OpenSimulator.Framework.RegionFlags. These are not returned in the GridRegion structure -
113 /// they currently need to be requested separately. Possibly this should change to avoid multiple service calls
114 /// in some situations.
115 /// </remarks>
116 /// <returns>
117 /// The region flags.
118 /// </returns>
119 /// <param name='scopeID'></param>
120 /// <param name='regionID'></param>
121 int GetRegionFlags(UUID scopeID, UUID regionID);
122 }
123  
124 public class GridRegion
125 {
126 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
127 private static readonly string LogHeader = "[GRID REGION]";
128  
129 /// <summary>
130 /// The port by which http communication occurs with the region
131 /// </summary>
132 public uint HttpPort
133 {
134 get { return m_httpPort; }
135 set { m_httpPort = value; }
136 }
137 protected uint m_httpPort;
138  
139 /// <summary>
140 /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
141 /// </summary>
142 public string ServerURI
143 {
144 get {
145 if ( m_serverURI != string.Empty ) {
146 return m_serverURI;
147 } else {
148 if (m_httpPort == 0)
149 return "http://" + m_externalHostName + "/";
150 else
151 return "http://" + m_externalHostName + ":" + m_httpPort + "/";
152 }
153 }
154 set {
155 if ( value.EndsWith("/") ) {
156 m_serverURI = value;
157 } else {
158 m_serverURI = value + '/';
159 }
160 }
161 }
162 protected string m_serverURI;
163  
164 public string RegionName
165 {
166 get { return m_regionName; }
167 set { m_regionName = value; }
168 }
169 protected string m_regionName = String.Empty;
170  
171 protected string m_externalHostName;
172  
173 protected IPEndPoint m_internalEndPoint;
174  
175 /// <summary>
176 /// The co-ordinate of this region.
177 /// </summary>
178 public int RegionCoordX { get { return (int)Util.WorldToRegionLoc((uint)RegionLocX); } }
179  
180 /// <summary>
181 /// The co-ordinate of this region
182 /// </summary>
183 public int RegionCoordY { get { return (int)Util.WorldToRegionLoc((uint)RegionLocY); } }
184  
185 /// <summary>
186 /// The location of this region in meters.
187 /// DANGER DANGER! Note that this name means something different in RegionInfo.
188 /// </summary>
189 public int RegionLocX
190 {
191 get { return m_regionLocX; }
192 set { m_regionLocX = value; }
193 }
194 protected int m_regionLocX;
195  
196 public int RegionSizeX { get; set; }
197 public int RegionSizeY { get; set; }
198  
199 /// <summary>
200 /// The location of this region in meters.
201 /// DANGER DANGER! Note that this name means something different in RegionInfo.
202 /// </summary>
203 public int RegionLocY
204 {
205 get { return m_regionLocY; }
206 set { m_regionLocY = value; }
207 }
208 protected int m_regionLocY;
209  
210 protected UUID m_estateOwner;
211  
212 public UUID EstateOwner
213 {
214 get { return m_estateOwner; }
215 set { m_estateOwner = value; }
216 }
217  
218 public UUID RegionID = UUID.Zero;
219 public UUID ScopeID = UUID.Zero;
220  
221 public UUID TerrainImage = UUID.Zero;
222 public UUID ParcelImage = UUID.Zero;
223 public byte Access;
224 public int Maturity;
225 public string RegionSecret = string.Empty;
226 public string Token = string.Empty;
227  
228 public GridRegion()
229 {
230 RegionSizeX = (int)Constants.RegionSize;
231 RegionSizeY = (int)Constants.RegionSize;
232 m_serverURI = string.Empty;
233 }
234  
235 /*
236 public GridRegion(int regionLocX, int regionLocY, IPEndPoint internalEndPoint, string externalUri)
237 {
238 m_regionLocX = regionLocX;
239 m_regionLocY = regionLocY;
240 RegionSizeX = (int)Constants.RegionSize;
241 RegionSizeY = (int)Constants.RegionSize;
242  
243 m_internalEndPoint = internalEndPoint;
244 m_externalHostName = externalUri;
245 }
246  
247 public GridRegion(int regionLocX, int regionLocY, string externalUri, uint port)
248 {
249 m_regionLocX = regionLocX;
250 m_regionLocY = regionLocY;
251 RegionSizeX = (int)Constants.RegionSize;
252 RegionSizeY = (int)Constants.RegionSize;
253  
254 m_externalHostName = externalUri;
255  
256 m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)port);
257 }
258 */
259  
260 public GridRegion(uint xcell, uint ycell)
261 {
262 m_regionLocX = (int)Util.RegionToWorldLoc(xcell);
263 m_regionLocY = (int)Util.RegionToWorldLoc(ycell);
264 RegionSizeX = (int)Constants.RegionSize;
265 RegionSizeY = (int)Constants.RegionSize;
266 }
267  
268 public GridRegion(RegionInfo ConvertFrom)
269 {
270 m_regionName = ConvertFrom.RegionName;
271 m_regionLocX = (int)(ConvertFrom.WorldLocX);
272 m_regionLocY = (int)(ConvertFrom.WorldLocY);
273 RegionSizeX = (int)ConvertFrom.RegionSizeX;
274 RegionSizeY = (int)ConvertFrom.RegionSizeY;
275 m_internalEndPoint = ConvertFrom.InternalEndPoint;
276 m_externalHostName = ConvertFrom.ExternalHostName;
277 m_httpPort = ConvertFrom.HttpPort;
278 RegionID = ConvertFrom.RegionID;
279 ServerURI = ConvertFrom.ServerURI;
280 TerrainImage = ConvertFrom.RegionSettings.TerrainImageID;
281 ParcelImage = ConvertFrom.RegionSettings.ParcelImageID;
282 Access = ConvertFrom.AccessLevel;
283 Maturity = ConvertFrom.RegionSettings.Maturity;
284 RegionSecret = ConvertFrom.regionSecret;
285 EstateOwner = ConvertFrom.EstateSettings.EstateOwner;
286 }
287  
288 public GridRegion(GridRegion ConvertFrom)
289 {
290 m_regionName = ConvertFrom.RegionName;
291 m_regionLocX = ConvertFrom.RegionLocX;
292 m_regionLocY = ConvertFrom.RegionLocY;
293 RegionSizeX = ConvertFrom.RegionSizeX;
294 RegionSizeY = ConvertFrom.RegionSizeY;
295 m_internalEndPoint = ConvertFrom.InternalEndPoint;
296 m_externalHostName = ConvertFrom.ExternalHostName;
297 m_httpPort = ConvertFrom.HttpPort;
298 RegionID = ConvertFrom.RegionID;
299 ServerURI = ConvertFrom.ServerURI;
300 TerrainImage = ConvertFrom.TerrainImage;
301 ParcelImage = ConvertFrom.ParcelImage;
302 Access = ConvertFrom.Access;
303 Maturity = ConvertFrom.Maturity;
304 RegionSecret = ConvertFrom.RegionSecret;
305 EstateOwner = ConvertFrom.EstateOwner;
306 }
307  
308 # region Definition of equality
309  
310 /// <summary>
311 /// Define equality as two regions having the same, non-zero UUID.
312 /// </summary>
313 public bool Equals(GridRegion region)
314 {
315 if ((object)region == null)
316 return false;
317 // Return true if the non-zero UUIDs are equal:
318 return (RegionID != UUID.Zero) && RegionID.Equals(region.RegionID);
319 }
320  
321 public override bool Equals(Object obj)
322 {
323 if (obj == null)
324 return false;
325 return Equals(obj as GridRegion);
326 }
327  
328 public override int GetHashCode()
329 {
330 return RegionID.GetHashCode() ^ TerrainImage.GetHashCode() ^ ParcelImage.GetHashCode();
331 }
332  
333 #endregion
334  
335 /// <value>
336 /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
337 ///
338 /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
339 /// </value>
340 public IPEndPoint ExternalEndPoint
341 {
342 get
343 {
344 // Old one defaults to IPv6
345 //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
346  
347 IPAddress ia = null;
348 // If it is already an IP, don't resolve it - just return directly
349 if (IPAddress.TryParse(m_externalHostName, out ia))
350 return new IPEndPoint(ia, m_internalEndPoint.Port);
351  
352 // Reset for next check
353 ia = null;
354 try
355 {
356 foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
357 {
358 if (ia == null)
359 ia = Adr;
360  
361 if (Adr.AddressFamily == AddressFamily.InterNetwork)
362 {
363 ia = Adr;
364 break;
365 }
366 }
367 }
368 catch (SocketException e)
369 {
370 throw new Exception(
371 "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
372 e + "' attached to this exception", e);
373 }
374  
375 return new IPEndPoint(ia, m_internalEndPoint.Port);
376 }
377 }
378  
379 public string ExternalHostName
380 {
381 get { return m_externalHostName; }
382 set { m_externalHostName = value; }
383 }
384  
385 public IPEndPoint InternalEndPoint
386 {
387 get { return m_internalEndPoint; }
388 set { m_internalEndPoint = value; }
389 }
390  
391 public ulong RegionHandle
392 {
393 get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); }
394 }
395  
396 public Dictionary<string, object> ToKeyValuePairs()
397 {
398 Dictionary<string, object> kvp = new Dictionary<string, object>();
399 kvp["uuid"] = RegionID.ToString();
400 kvp["locX"] = RegionLocX.ToString();
401 kvp["locY"] = RegionLocY.ToString();
402 kvp["sizeX"] = RegionSizeX.ToString();
403 kvp["sizeY"] = RegionSizeY.ToString();
404 kvp["regionName"] = RegionName;
405 kvp["serverIP"] = ExternalHostName; //ExternalEndPoint.Address.ToString();
406 kvp["serverHttpPort"] = HttpPort.ToString();
407 kvp["serverURI"] = ServerURI;
408 kvp["serverPort"] = InternalEndPoint.Port.ToString();
409 kvp["regionMapTexture"] = TerrainImage.ToString();
410 kvp["parcelMapTexture"] = ParcelImage.ToString();
411 kvp["access"] = Access.ToString();
412 kvp["regionSecret"] = RegionSecret;
413 kvp["owner_uuid"] = EstateOwner.ToString();
414 kvp["Token"] = Token.ToString();
415 // Maturity doesn't seem to exist in the DB
416 return kvp;
417 }
418  
419 public GridRegion(Dictionary<string, object> kvp)
420 {
421 if (kvp.ContainsKey("uuid"))
422 RegionID = new UUID((string)kvp["uuid"]);
423  
424 if (kvp.ContainsKey("locX"))
425 RegionLocX = Convert.ToInt32((string)kvp["locX"]);
426  
427 if (kvp.ContainsKey("locY"))
428 RegionLocY = Convert.ToInt32((string)kvp["locY"]);
429  
430 if (kvp.ContainsKey("sizeX"))
431 RegionSizeX = Convert.ToInt32((string)kvp["sizeX"]);
432 else
433 RegionSizeX = (int)Constants.RegionSize;
434  
435 if (kvp.ContainsKey("sizeY"))
436 RegionSizeY = Convert.ToInt32((string)kvp["sizeY"]);
437 else
438 RegionSizeX = (int)Constants.RegionSize;
439  
440 if (kvp.ContainsKey("regionName"))
441 RegionName = (string)kvp["regionName"];
442  
443 if (kvp.ContainsKey("serverIP"))
444 {
445 //int port = 0;
446 //Int32.TryParse((string)kvp["serverPort"], out port);
447 //IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["serverIP"]), port);
448 ExternalHostName = (string)kvp["serverIP"];
449 }
450 else
451 ExternalHostName = "127.0.0.1";
452  
453 if (kvp.ContainsKey("serverPort"))
454 {
455 Int32 port = 0;
456 Int32.TryParse((string)kvp["serverPort"], out port);
457 InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
458 }
459  
460 if (kvp.ContainsKey("serverHttpPort"))
461 {
462 UInt32 port = 0;
463 UInt32.TryParse((string)kvp["serverHttpPort"], out port);
464 HttpPort = port;
465 }
466  
467 if (kvp.ContainsKey("serverURI"))
468 ServerURI = (string)kvp["serverURI"];
469  
470 if (kvp.ContainsKey("regionMapTexture"))
471 UUID.TryParse((string)kvp["regionMapTexture"], out TerrainImage);
472  
473 if (kvp.ContainsKey("parcelMapTexture"))
474 UUID.TryParse((string)kvp["parcelMapTexture"], out ParcelImage);
475  
476 if (kvp.ContainsKey("access"))
477 Access = Byte.Parse((string)kvp["access"]);
478  
479 if (kvp.ContainsKey("regionSecret"))
480 RegionSecret =(string)kvp["regionSecret"];
481  
482 if (kvp.ContainsKey("owner_uuid"))
483 EstateOwner = new UUID(kvp["owner_uuid"].ToString());
484  
485 if (kvp.ContainsKey("Token"))
486 Token = kvp["Token"].ToString();
487  
488 // m_log.DebugFormat("{0} New GridRegion. id={1}, loc=<{2},{3}>, size=<{4},{5}>",
489 // LogHeader, RegionID, RegionLocX, RegionLocY, RegionSizeX, RegionSizeY);
490 }
491 }
492 }