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