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