clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
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;
30 using System.Collections.Generic;
31 using System.Net;
32 using System.Net.Sockets;
33 using System.Reflection;
34  
35 using OpenSim.Framework;
36 using OpenMetaverse;
37  
38 using log4net;
39  
40 namespace 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 class GridRegion
128 {
129 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
130  
131 #pragma warning disable 414
132 private static readonly string LogHeader = "[GRID REGION]";
133 #pragma warning restore 414
134  
135 /// <summary>
136 /// The port by which http communication occurs with the region
137 /// </summary>
138 public uint HttpPort
139 {
140 get { return m_httpPort; }
141 set { m_httpPort = value; }
142 }
143 protected uint m_httpPort;
144  
145 /// <summary>
146 /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
147 /// </summary>
148 public string ServerURI
149 {
150 get {
151 if (!String.IsNullOrEmpty(m_serverURI)) {
152 return m_serverURI;
153 } else {
154 if (m_httpPort == 0)
155 return "http://" + m_externalHostName + "/";
156 else
157 return "http://" + m_externalHostName + ":" + m_httpPort + "/";
158 }
159 }
160 set {
161 if (value.EndsWith("/")) {
162 m_serverURI = value;
163 } else {
164 m_serverURI = value + '/';
165 }
166 }
167 }
168 protected string m_serverURI;
169  
170 /// <summary>
171 /// Provides direct access to the 'm_serverURI' field, without returning a generated URL if m_serverURI is missing.
172 /// </summary>
173 public string RawServerURI
174 {
175 get { return m_serverURI; }
176 set { m_serverURI = value; }
177 }
178  
179  
180 public string RegionName
181 {
182 get { return m_regionName; }
183 set { m_regionName = value; }
184 }
185 protected string m_regionName = String.Empty;
186  
187 protected string m_externalHostName;
188  
189 protected IPEndPoint m_internalEndPoint;
190  
191 /// <summary>
192 /// The co-ordinate of this region in region units.
193 /// </summary>
194 public int RegionCoordX { get { return (int)Util.WorldToRegionLoc((uint)RegionLocX); } }
195  
196 /// <summary>
197 /// The co-ordinate of this region in region units
198 /// </summary>
199 public int RegionCoordY { get { return (int)Util.WorldToRegionLoc((uint)RegionLocY); } }
200  
201 /// <summary>
202 /// The location of this region in meters.
203 /// DANGER DANGER! Note that this name means something different in RegionInfo.
204 /// </summary>
205 public int RegionLocX
206 {
207 get { return m_regionLocX; }
208 set { m_regionLocX = value; }
209 }
210 protected int m_regionLocX;
211  
212 public int RegionSizeX { get; set; }
213 public int RegionSizeY { get; set; }
214  
215 /// <summary>
216 /// The location of this region in meters.
217 /// DANGER DANGER! Note that this name means something different in RegionInfo.
218 /// </summary>
219 public int RegionLocY
220 {
221 get { return m_regionLocY; }
222 set { m_regionLocY = value; }
223 }
224 protected int m_regionLocY;
225  
226 protected UUID m_estateOwner;
227  
228 public UUID EstateOwner
229 {
230 get { return m_estateOwner; }
231 set { m_estateOwner = value; }
232 }
233  
234 public UUID RegionID = UUID.Zero;
235 public UUID ScopeID = UUID.Zero;
236  
237 public UUID TerrainImage = UUID.Zero;
238 public UUID ParcelImage = UUID.Zero;
239 public byte Access;
240 public int Maturity;
241 public string RegionSecret = string.Empty;
242 public string Token = string.Empty;
243  
244 public GridRegion()
245 {
246 RegionSizeX = (int)Constants.RegionSize;
247 RegionSizeY = (int)Constants.RegionSize;
248 m_serverURI = string.Empty;
249 }
250  
251 /*
252 public GridRegion(int regionLocX, int regionLocY, IPEndPoint internalEndPoint, string externalUri)
253 {
254 m_regionLocX = regionLocX;
255 m_regionLocY = regionLocY;
256 RegionSizeX = (int)Constants.RegionSize;
257 RegionSizeY = (int)Constants.RegionSize;
258  
259 m_internalEndPoint = internalEndPoint;
260 m_externalHostName = externalUri;
261 }
262  
263 public GridRegion(int regionLocX, int regionLocY, string externalUri, uint port)
264 {
265 m_regionLocX = regionLocX;
266 m_regionLocY = regionLocY;
267 RegionSizeX = (int)Constants.RegionSize;
268 RegionSizeY = (int)Constants.RegionSize;
269  
270 m_externalHostName = externalUri;
271  
272 m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)port);
273 }
274 */
275  
276 public GridRegion(uint xcell, uint ycell)
277 {
278 m_regionLocX = (int)Util.RegionToWorldLoc(xcell);
279 m_regionLocY = (int)Util.RegionToWorldLoc(ycell);
280 RegionSizeX = (int)Constants.RegionSize;
281 RegionSizeY = (int)Constants.RegionSize;
282 }
283  
284 public GridRegion(RegionInfo ConvertFrom)
285 {
286 m_regionName = ConvertFrom.RegionName;
287 m_regionLocX = (int)(ConvertFrom.WorldLocX);
288 m_regionLocY = (int)(ConvertFrom.WorldLocY);
289 RegionSizeX = (int)ConvertFrom.RegionSizeX;
290 RegionSizeY = (int)ConvertFrom.RegionSizeY;
291 m_internalEndPoint = ConvertFrom.InternalEndPoint;
292 m_externalHostName = ConvertFrom.ExternalHostName;
293 m_httpPort = ConvertFrom.HttpPort;
294 RegionID = ConvertFrom.RegionID;
295 ServerURI = ConvertFrom.ServerURI;
296 TerrainImage = ConvertFrom.RegionSettings.TerrainImageID;
297 ParcelImage = ConvertFrom.RegionSettings.ParcelImageID;
298 Access = ConvertFrom.AccessLevel;
299 Maturity = ConvertFrom.RegionSettings.Maturity;
300 RegionSecret = ConvertFrom.regionSecret;
301 EstateOwner = ConvertFrom.EstateSettings.EstateOwner;
302 }
303  
304 public GridRegion(GridRegion ConvertFrom)
305 {
306 m_regionName = ConvertFrom.RegionName;
307 m_regionLocX = ConvertFrom.RegionLocX;
308 m_regionLocY = ConvertFrom.RegionLocY;
309 RegionSizeX = ConvertFrom.RegionSizeX;
310 RegionSizeY = ConvertFrom.RegionSizeY;
311 m_internalEndPoint = ConvertFrom.InternalEndPoint;
312 m_externalHostName = ConvertFrom.ExternalHostName;
313 m_httpPort = ConvertFrom.HttpPort;
314 RegionID = ConvertFrom.RegionID;
315 ServerURI = ConvertFrom.ServerURI;
316 TerrainImage = ConvertFrom.TerrainImage;
317 ParcelImage = ConvertFrom.ParcelImage;
318 Access = ConvertFrom.Access;
319 Maturity = ConvertFrom.Maturity;
320 RegionSecret = ConvertFrom.RegionSecret;
321 EstateOwner = ConvertFrom.EstateOwner;
322 }
323  
324 # region Definition of equality
325  
326 /// <summary>
327 /// Define equality as two regions having the same, non-zero UUID.
328 /// </summary>
329 public bool Equals(GridRegion region)
330 {
331 if ((object)region == null)
332 return false;
333 // Return true if the non-zero UUIDs are equal:
334 return (RegionID != UUID.Zero) && RegionID.Equals(region.RegionID);
335 }
336  
337 public override bool Equals(Object obj)
338 {
339 if (obj == null)
340 return false;
341 return Equals(obj as GridRegion);
342 }
343  
344 public override int GetHashCode()
345 {
346 return RegionID.GetHashCode() ^ TerrainImage.GetHashCode() ^ ParcelImage.GetHashCode();
347 }
348  
349 #endregion
350  
351 /// <value>
352 /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
353 ///
354 /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
355 /// </value>
356 public IPEndPoint ExternalEndPoint
357 {
358 get
359 {
360 // Old one defaults to IPv6
361 //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
362  
363 IPAddress ia = null;
364 // If it is already an IP, don't resolve it - just return directly
365 if (IPAddress.TryParse(m_externalHostName, out ia))
366 return new IPEndPoint(ia, m_internalEndPoint.Port);
367  
368 // Reset for next check
369 ia = null;
370 try
371 {
372 foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
373 {
374 if (ia == null)
375 ia = Adr;
376  
377 if (Adr.AddressFamily == AddressFamily.InterNetwork)
378 {
379 ia = Adr;
380 break;
381 }
382 }
383 }
384 catch (SocketException e)
385 {
386 throw new Exception(
387 "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
388 e + "' attached to this exception", e);
389 }
390  
391 return new IPEndPoint(ia, m_internalEndPoint.Port);
392 }
393 }
394  
395 public string ExternalHostName
396 {
397 get { return m_externalHostName; }
398 set { m_externalHostName = value; }
399 }
400  
401 public IPEndPoint InternalEndPoint
402 {
403 get { return m_internalEndPoint; }
404 set { m_internalEndPoint = value; }
405 }
406  
407 public ulong RegionHandle
408 {
409 get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); }
410 }
411  
412 public Dictionary<string, object> ToKeyValuePairs()
413 {
414 Dictionary<string, object> kvp = new Dictionary<string, object>();
415 kvp["uuid"] = RegionID.ToString();
416 kvp["locX"] = RegionLocX.ToString();
417 kvp["locY"] = RegionLocY.ToString();
418 kvp["sizeX"] = RegionSizeX.ToString();
419 kvp["sizeY"] = RegionSizeY.ToString();
420 kvp["regionName"] = RegionName;
421 kvp["serverIP"] = ExternalHostName; //ExternalEndPoint.Address.ToString();
422 kvp["serverHttpPort"] = HttpPort.ToString();
423 kvp["serverURI"] = ServerURI;
424 kvp["serverPort"] = InternalEndPoint.Port.ToString();
425 kvp["regionMapTexture"] = TerrainImage.ToString();
426 kvp["parcelMapTexture"] = ParcelImage.ToString();
427 kvp["access"] = Access.ToString();
428 kvp["regionSecret"] = RegionSecret;
429 kvp["owner_uuid"] = EstateOwner.ToString();
430 kvp["Token"] = Token.ToString();
431 // Maturity doesn't seem to exist in the DB
432 return kvp;
433 }
434  
435 public GridRegion(Dictionary<string, object> kvp)
436 {
437 if (kvp.ContainsKey("uuid"))
438 RegionID = new UUID((string)kvp["uuid"]);
439  
440 if (kvp.ContainsKey("locX"))
441 RegionLocX = Convert.ToInt32((string)kvp["locX"]);
442  
443 if (kvp.ContainsKey("locY"))
444 RegionLocY = Convert.ToInt32((string)kvp["locY"]);
445  
446 if (kvp.ContainsKey("sizeX"))
447 RegionSizeX = Convert.ToInt32((string)kvp["sizeX"]);
448 else
449 RegionSizeX = (int)Constants.RegionSize;
450  
451 if (kvp.ContainsKey("sizeY"))
452 RegionSizeY = Convert.ToInt32((string)kvp["sizeY"]);
453 else
454 RegionSizeX = (int)Constants.RegionSize;
455  
456 if (kvp.ContainsKey("regionName"))
457 RegionName = (string)kvp["regionName"];
458  
459 if (kvp.ContainsKey("serverIP"))
460 {
461 //int port = 0;
462 //Int32.TryParse((string)kvp["serverPort"], out port);
463 //IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["serverIP"]), port);
464 ExternalHostName = (string)kvp["serverIP"];
465 }
466 else
467 ExternalHostName = "127.0.0.1";
468  
469 if (kvp.ContainsKey("serverPort"))
470 {
471 Int32 port = 0;
472 Int32.TryParse((string)kvp["serverPort"], out port);
473 InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
474 }
475  
476 if (kvp.ContainsKey("serverHttpPort"))
477 {
478 UInt32 port = 0;
479 UInt32.TryParse((string)kvp["serverHttpPort"], out port);
480 HttpPort = port;
481 }
482  
483 if (kvp.ContainsKey("serverURI"))
484 ServerURI = (string)kvp["serverURI"];
485  
486 if (kvp.ContainsKey("regionMapTexture"))
487 UUID.TryParse((string)kvp["regionMapTexture"], out TerrainImage);
488  
489 if (kvp.ContainsKey("parcelMapTexture"))
490 UUID.TryParse((string)kvp["parcelMapTexture"], out ParcelImage);
491  
492 if (kvp.ContainsKey("access"))
493 Access = Byte.Parse((string)kvp["access"]);
494  
495 if (kvp.ContainsKey("regionSecret"))
496 RegionSecret =(string)kvp["regionSecret"];
497  
498 if (kvp.ContainsKey("owner_uuid"))
499 EstateOwner = new UUID(kvp["owner_uuid"].ToString());
500  
501 if (kvp.ContainsKey("Token"))
502 Token = kvp["Token"].ToString();
503  
504 // m_log.DebugFormat("{0} New GridRegion. id={1}, loc=<{2},{3}>, size=<{4},{5}>",
505 // LogHeader, RegionID, RegionLocX, RegionLocY, RegionSizeX, RegionSizeY);
506 }
507 }
508 }