aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2009-09-24 17:35:03 +0100
committerJustin Clark-Casey (justincc)2009-09-24 17:35:03 +0100
commitad753d784cfefacd8fb745a1431bf98feac9bbd6 (patch)
tree795ec1ba25eada570c342746f07654849a7199f4 /OpenSim/Services
parentminor: make rest (not comm) modules less noisy if they are disabled (diff)
parentChanged name of the hyperlink XMLRPC method to linkk-region, so that it doesn... (diff)
downloadopensim-SC_OLD-ad753d784cfefacd8fb745a1431bf98feac9bbd6.zip
opensim-SC_OLD-ad753d784cfefacd8fb745a1431bf98feac9bbd6.tar.gz
opensim-SC_OLD-ad753d784cfefacd8fb745a1431bf98feac9bbd6.tar.bz2
opensim-SC_OLD-ad753d784cfefacd8fb745a1431bf98feac9bbd6.tar.xz
Merge branch 'master' of ssh://justincc@opensimulator.org/var/git/opensim
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/Connectors/Grid/GridServiceConnector.cs41
-rw-r--r--OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs152
-rw-r--r--OpenSim/Services/GridService/GridService.cs58
-rw-r--r--OpenSim/Services/GridService/GridServiceBase.cs2
-rw-r--r--OpenSim/Services/Interfaces/IGridService.cs249
5 files changed, 450 insertions, 52 deletions
diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
index ae7db7e..0a867db 100644
--- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
@@ -35,6 +35,7 @@ using OpenSim.Framework;
35using OpenSim.Framework.Communications; 35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer; 36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38using OpenSim.Server.Base; 39using OpenSim.Server.Base;
39using OpenMetaverse; 40using OpenMetaverse;
40 41
@@ -85,7 +86,7 @@ namespace OpenSim.Services.Connectors
85 86
86 #region IGridService 87 #region IGridService
87 88
88 public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) 89 public virtual bool RegisterRegion(UUID scopeID, GridRegion regionInfo)
89 { 90 {
90 Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs(); 91 Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs();
91 Dictionary<string, string> sendData = new Dictionary<string,string>(); 92 Dictionary<string, string> sendData = new Dictionary<string,string>();
@@ -108,7 +109,7 @@ namespace OpenSim.Services.Connectors
108 return false; 109 return false;
109 } 110 }
110 111
111 public bool DeregisterRegion(UUID regionID) 112 public virtual bool DeregisterRegion(UUID regionID)
112 { 113 {
113 Dictionary<string, string> sendData = new Dictionary<string, string>(); 114 Dictionary<string, string> sendData = new Dictionary<string, string>();
114 115
@@ -128,7 +129,7 @@ namespace OpenSim.Services.Connectors
128 return false; 129 return false;
129 } 130 }
130 131
131 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID) 132 public virtual List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
132 { 133 {
133 Dictionary<string, string> sendData = new Dictionary<string, string>(); 134 Dictionary<string, string> sendData = new Dictionary<string, string>();
134 135
@@ -143,7 +144,7 @@ namespace OpenSim.Services.Connectors
143 144
144 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 145 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
145 146
146 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 147 List<GridRegion> rinfos = new List<GridRegion>();
147 if (replyData != null) 148 if (replyData != null)
148 { 149 {
149 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; 150 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
@@ -151,7 +152,7 @@ namespace OpenSim.Services.Connectors
151 { 152 {
152 if (r is Dictionary<string, object>) 153 if (r is Dictionary<string, object>)
153 { 154 {
154 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); 155 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
155 rinfos.Add(rinfo); 156 rinfos.Add(rinfo);
156 } 157 }
157 else 158 else
@@ -166,7 +167,7 @@ namespace OpenSim.Services.Connectors
166 return rinfos; 167 return rinfos;
167 } 168 }
168 169
169 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) 170 public virtual GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
170 { 171 {
171 Dictionary<string, string> sendData = new Dictionary<string, string>(); 172 Dictionary<string, string> sendData = new Dictionary<string, string>();
172 173
@@ -181,11 +182,11 @@ namespace OpenSim.Services.Connectors
181 182
182 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 183 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
183 184
184 SimpleRegionInfo rinfo = null; 185 GridRegion rinfo = null;
185 if ((replyData != null) && (replyData["result"] != null)) 186 if ((replyData != null) && (replyData["result"] != null))
186 { 187 {
187 if (replyData["result"] is Dictionary<string, object>) 188 if (replyData["result"] is Dictionary<string, object>)
188 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); 189 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
189 else 190 else
190 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received invalid response", 191 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received invalid response",
191 scopeID, regionID); 192 scopeID, regionID);
@@ -197,7 +198,7 @@ namespace OpenSim.Services.Connectors
197 return rinfo; 198 return rinfo;
198 } 199 }
199 200
200 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) 201 public virtual GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
201 { 202 {
202 Dictionary<string, string> sendData = new Dictionary<string, string>(); 203 Dictionary<string, string> sendData = new Dictionary<string, string>();
203 204
@@ -213,11 +214,11 @@ namespace OpenSim.Services.Connectors
213 214
214 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 215 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
215 216
216 SimpleRegionInfo rinfo = null; 217 GridRegion rinfo = null;
217 if ((replyData != null) && (replyData["result"] != null)) 218 if ((replyData != null) && (replyData["result"] != null))
218 { 219 {
219 if (replyData["result"] is Dictionary<string, object>) 220 if (replyData["result"] is Dictionary<string, object>)
220 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); 221 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
221 else 222 else
222 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response", 223 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response",
223 scopeID, x, y); 224 scopeID, x, y);
@@ -229,7 +230,7 @@ namespace OpenSim.Services.Connectors
229 return rinfo; 230 return rinfo;
230 } 231 }
231 232
232 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) 233 public virtual GridRegion GetRegionByName(UUID scopeID, string regionName)
233 { 234 {
234 Dictionary<string, string> sendData = new Dictionary<string, string>(); 235 Dictionary<string, string> sendData = new Dictionary<string, string>();
235 236
@@ -244,11 +245,11 @@ namespace OpenSim.Services.Connectors
244 245
245 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 246 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
246 247
247 SimpleRegionInfo rinfo = null; 248 GridRegion rinfo = null;
248 if ((replyData != null) && (replyData["result"] != null)) 249 if ((replyData != null) && (replyData["result"] != null))
249 { 250 {
250 if (replyData["result"] is Dictionary<string, object>) 251 if (replyData["result"] is Dictionary<string, object>)
251 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); 252 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
252 else 253 else
253 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received invalid response", 254 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received invalid response",
254 scopeID, regionName); 255 scopeID, regionName);
@@ -260,7 +261,7 @@ namespace OpenSim.Services.Connectors
260 return rinfo; 261 return rinfo;
261 } 262 }
262 263
263 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber) 264 public virtual List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
264 { 265 {
265 Dictionary<string, string> sendData = new Dictionary<string, string>(); 266 Dictionary<string, string> sendData = new Dictionary<string, string>();
266 267
@@ -276,7 +277,7 @@ namespace OpenSim.Services.Connectors
276 277
277 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 278 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
278 279
279 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 280 List<GridRegion> rinfos = new List<GridRegion>();
280 if (replyData != null) 281 if (replyData != null)
281 { 282 {
282 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; 283 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
@@ -284,7 +285,7 @@ namespace OpenSim.Services.Connectors
284 { 285 {
285 if (r is Dictionary<string, object>) 286 if (r is Dictionary<string, object>)
286 { 287 {
287 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); 288 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
288 rinfos.Add(rinfo); 289 rinfos.Add(rinfo);
289 } 290 }
290 else 291 else
@@ -299,7 +300,7 @@ namespace OpenSim.Services.Connectors
299 return rinfos; 300 return rinfos;
300 } 301 }
301 302
302 public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) 303 public virtual List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
303 { 304 {
304 Dictionary<string, string> sendData = new Dictionary<string, string>(); 305 Dictionary<string, string> sendData = new Dictionary<string, string>();
305 306
@@ -317,7 +318,7 @@ namespace OpenSim.Services.Connectors
317 318
318 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 319 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
319 320
320 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 321 List<GridRegion> rinfos = new List<GridRegion>();
321 if (replyData != null) 322 if (replyData != null)
322 { 323 {
323 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; 324 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
@@ -325,7 +326,7 @@ namespace OpenSim.Services.Connectors
325 { 326 {
326 if (r is Dictionary<string, object>) 327 if (r is Dictionary<string, object>)
327 { 328 {
328 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); 329 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
329 rinfos.Add(rinfo); 330 rinfos.Add(rinfo);
330 } 331 }
331 else 332 else
diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs
new file mode 100644
index 0000000..b5e8743
--- /dev/null
+++ b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs
@@ -0,0 +1,152 @@
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.Text;
32using System.Drawing;
33using System.Net;
34using System.Reflection;
35using OpenSim.Services.Interfaces;
36using GridRegion = OpenSim.Services.Interfaces.GridRegion;
37
38using OpenSim.Framework;
39
40using OpenMetaverse;
41using OpenMetaverse.Imaging;
42using log4net;
43using Nwc.XmlRpc;
44
45namespace OpenSim.Services.Connectors.Grid
46{
47 public class HypergridServiceConnector
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IAssetService m_AssetService;
52
53 public HypergridServiceConnector(IAssetService assService)
54 {
55 m_AssetService = assService;
56 }
57
58 public UUID LinkRegion(GridRegion info, out ulong realHandle)
59 {
60 UUID uuid = UUID.Zero;
61 realHandle = 0;
62
63 Hashtable hash = new Hashtable();
64 hash["region_name"] = info.RegionName;
65
66 IList paramList = new ArrayList();
67 paramList.Add(hash);
68
69 XmlRpcRequest request = new XmlRpcRequest("linkk_region", paramList);
70 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
71 m_log.Debug("[HGrid]: Linking to " + uri);
72 XmlRpcResponse response = request.Send(uri, 10000);
73 if (response.IsFault)
74 {
75 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
76 }
77 else
78 {
79 hash = (Hashtable)response.Value;
80 //foreach (Object o in hash)
81 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
82 try
83 {
84 UUID.TryParse((string)hash["uuid"], out uuid);
85 info.RegionID = uuid;
86 if ((string)hash["handle"] != null)
87 {
88 realHandle = Convert.ToUInt64((string)hash["handle"]);
89 m_log.Debug(">> HERE, realHandle: " + realHandle);
90 }
91 //if (hash["region_image"] != null)
92 //{
93 // UUID img = UUID.Zero;
94 // UUID.TryParse((string)hash["region_image"], out img);
95 // info.RegionSettings.TerrainImageID = img;
96 //}
97 if (hash["region_name"] != null)
98 {
99 info.RegionName = (string)hash["region_name"];
100 //m_log.Debug(">> " + info.RegionName);
101 }
102 if (hash["internal_port"] != null)
103 {
104 int port = Convert.ToInt32((string)hash["internal_port"]);
105 info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
106 //m_log.Debug(">> " + info.InternalEndPoint.ToString());
107 }
108
109 }
110 catch (Exception e)
111 {
112 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
113 }
114 }
115 return uuid;
116 }
117
118 public void GetMapImage(GridRegion info)
119 {
120 try
121 {
122 string regionimage = "regionImage" + info.RegionID.ToString();
123 regionimage = regionimage.Replace("-", "");
124
125 WebClient c = new WebClient();
126 string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage;
127 //m_log.Debug("JPEG: " + uri);
128 c.DownloadFile(uri, info.RegionID.ToString() + ".jpg");
129 Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg");
130 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
131 byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
132 AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString());
133
134 // !!! for now
135 //info.RegionSettings.TerrainImageID = ass.FullID;
136
137 ass.Type = (int)AssetType.Texture;
138 ass.Temporary = true;
139 ass.Local = true;
140 ass.Data = imageData;
141
142 m_AssetService.Store(ass);
143
144 }
145 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
146 {
147 m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache");
148 }
149 }
150
151 }
152}
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 2229421..01ffa1d 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -35,6 +35,7 @@ using OpenSim.Framework;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Data; 36using OpenSim.Data;
37using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38using OpenMetaverse; 39using OpenMetaverse;
39 40
40namespace OpenSim.Services.GridService 41namespace OpenSim.Services.GridService
@@ -48,6 +49,7 @@ namespace OpenSim.Services.GridService
48 public GridService(IConfigSource config) 49 public GridService(IConfigSource config)
49 : base(config) 50 : base(config)
50 { 51 {
52 m_log.DebugFormat("[GRID SERVICE]: Starting...");
51 MainConsole.Instance.Commands.AddCommand("kfs", false, 53 MainConsole.Instance.Commands.AddCommand("kfs", false,
52 "show digest", 54 "show digest",
53 "show digest <ID>", 55 "show digest <ID>",
@@ -62,14 +64,16 @@ namespace OpenSim.Services.GridService
62 64
63 #region IGridService 65 #region IGridService
64 66
65 public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfos) 67 public bool RegisterRegion(UUID scopeID, GridRegion regionInfos)
66 { 68 {
67 if (m_Database.Get(regionInfos.RegionID, scopeID) != null) 69 if (m_Database.Get(regionInfos.RegionID, scopeID) != null)
68 { 70 {
69 m_log.WarnFormat("[GRID SERVICE]: Region {0} already registered in scope {1}.", regionInfos.RegionID, scopeID); 71 m_log.WarnFormat("[GRID SERVICE]: Region {0} already registered in scope {1}.", regionInfos.RegionID, scopeID);
70 return false; 72 return false;
71 } 73 }
72 if (m_Database.Get((int)regionInfos.RegionLocX, (int)regionInfos.RegionLocY, scopeID) != null) 74 // This needs better sanity testing. What if regionInfo is registering in
75 // overlapping coords?
76 if (m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID) != null)
73 { 77 {
74 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", 78 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
75 regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); 79 regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
@@ -88,22 +92,25 @@ namespace OpenSim.Services.GridService
88 return m_Database.Delete(regionID); 92 return m_Database.Delete(regionID);
89 } 93 }
90 94
91 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID) 95 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
92 { 96 {
93 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 97 List<GridRegion> rinfos = new List<GridRegion>();
94 RegionData region = m_Database.Get(regionID, scopeID); 98 RegionData region = m_Database.Get(regionID, scopeID);
95 if (region != null) 99 if (region != null)
96 { 100 {
97 // Not really? Maybe? 101 // Not really? Maybe?
98 List<RegionData> rdatas = m_Database.Get(region.posX - 1, region.posY - 1, region.posX + 1, region.posY + 1, scopeID); 102 List<RegionData> rdatas = m_Database.Get(region.posX - (int)Constants.RegionSize, region.posY - (int)Constants.RegionSize,
103 region.posX + (int)Constants.RegionSize, region.posY + (int)Constants.RegionSize, scopeID);
104
99 foreach (RegionData rdata in rdatas) 105 foreach (RegionData rdata in rdatas)
100 rinfos.Add(RegionData2RegionInfo(rdata)); 106 if (rdata.RegionID != regionID)
107 rinfos.Add(RegionData2RegionInfo(rdata));
101 108
102 } 109 }
103 return rinfos; 110 return rinfos;
104 } 111 }
105 112
106 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) 113 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
107 { 114 {
108 RegionData rdata = m_Database.Get(regionID, scopeID); 115 RegionData rdata = m_Database.Get(regionID, scopeID);
109 if (rdata != null) 116 if (rdata != null)
@@ -112,16 +119,18 @@ namespace OpenSim.Services.GridService
112 return null; 119 return null;
113 } 120 }
114 121
115 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) 122 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
116 { 123 {
117 RegionData rdata = m_Database.Get(x, y, scopeID); 124 int snapX = (int)(x / Constants.RegionSize) * (int)Constants.RegionSize;
125 int snapY = (int)(y / Constants.RegionSize) * (int)Constants.RegionSize;
126 RegionData rdata = m_Database.Get(snapX, snapY, scopeID);
118 if (rdata != null) 127 if (rdata != null)
119 return RegionData2RegionInfo(rdata); 128 return RegionData2RegionInfo(rdata);
120 129
121 return null; 130 return null;
122 } 131 }
123 132
124 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) 133 public GridRegion GetRegionByName(UUID scopeID, string regionName)
125 { 134 {
126 List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID); 135 List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID);
127 if ((rdatas != null) && (rdatas.Count > 0)) 136 if ((rdatas != null) && (rdatas.Count > 0))
@@ -130,12 +139,12 @@ namespace OpenSim.Services.GridService
130 return null; 139 return null;
131 } 140 }
132 141
133 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber) 142 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
134 { 143 {
135 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID); 144 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID);
136 145
137 int count = 0; 146 int count = 0;
138 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 147 List<GridRegion> rinfos = new List<GridRegion>();
139 148
140 if (rdatas != null) 149 if (rdatas != null)
141 { 150 {
@@ -149,10 +158,15 @@ namespace OpenSim.Services.GridService
149 return rinfos; 158 return rinfos;
150 } 159 }
151 160
152 public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) 161 public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
153 { 162 {
154 List<RegionData> rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID); 163 int xminSnap = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize;
155 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 164 int xmaxSnap = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize;
165 int yminSnap = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize;
166 int ymaxSnap = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize;
167
168 List<RegionData> rdatas = m_Database.Get(xminSnap, yminSnap, xmaxSnap, ymaxSnap, scopeID);
169 List<GridRegion> rinfos = new List<GridRegion>();
156 foreach (RegionData rdata in rdatas) 170 foreach (RegionData rdata in rdatas)
157 rinfos.Add(RegionData2RegionInfo(rdata)); 171 rinfos.Add(RegionData2RegionInfo(rdata));
158 172
@@ -163,25 +177,25 @@ namespace OpenSim.Services.GridService
163 177
164 #region Data structure conversions 178 #region Data structure conversions
165 179
166 protected RegionData RegionInfo2RegionData(SimpleRegionInfo rinfo) 180 protected RegionData RegionInfo2RegionData(GridRegion rinfo)
167 { 181 {
168 RegionData rdata = new RegionData(); 182 RegionData rdata = new RegionData();
169 rdata.posX = (int)rinfo.RegionLocX; 183 rdata.posX = (int)rinfo.RegionLocX;
170 rdata.posY = (int)rinfo.RegionLocY; 184 rdata.posY = (int)rinfo.RegionLocY;
171 rdata.RegionID = rinfo.RegionID; 185 rdata.RegionID = rinfo.RegionID;
172 rdata.Data = rinfo.ToKeyValuePairs(); 186 rdata.Data = rinfo.ToKeyValuePairs();
173 //rdata.RegionName = rinfo.RegionName; 187 rdata.RegionName = rinfo.RegionName;
174 188
175 return rdata; 189 return rdata;
176 } 190 }
177 191
178 protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata) 192 protected GridRegion RegionData2RegionInfo(RegionData rdata)
179 { 193 {
180 SimpleRegionInfo rinfo = new SimpleRegionInfo(rdata.Data); 194 GridRegion rinfo = new GridRegion(rdata.Data);
181 rinfo.RegionLocX = (uint)rdata.posX; 195 rinfo.RegionLocX = rdata.posX;
182 rinfo.RegionLocY = (uint)rdata.posY; 196 rinfo.RegionLocY = rdata.posY;
183 rinfo.RegionID = rdata.RegionID; 197 rinfo.RegionID = rdata.RegionID;
184 //rinfo.RegionName = rdata.RegionName; 198 rinfo.RegionName = rdata.RegionName;
185 199
186 return rinfo; 200 return rinfo;
187 } 201 }
diff --git a/OpenSim/Services/GridService/GridServiceBase.cs b/OpenSim/Services/GridService/GridServiceBase.cs
index 7522e64..444f79b 100644
--- a/OpenSim/Services/GridService/GridServiceBase.cs
+++ b/OpenSim/Services/GridService/GridServiceBase.cs
@@ -68,7 +68,7 @@ namespace OpenSim.Services.GridService
68 connString = gridConfig.GetString("ConnectionString", connString); 68 connString = gridConfig.GetString("ConnectionString", connString);
69 realm = gridConfig.GetString("Realm", realm); 69 realm = gridConfig.GetString("Realm", realm);
70 } 70 }
71 71
72 // 72 //
73 // We tried, but this doesn't exist. We can't proceed. 73 // We tried, but this doesn't exist. We can't proceed.
74 // 74 //
diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs
index 8f6c524..a188f7e 100644
--- a/OpenSim/Services/Interfaces/IGridService.cs
+++ b/OpenSim/Services/Interfaces/IGridService.cs
@@ -25,8 +25,11 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using OpenSim.Framework; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Net;
31using System.Net.Sockets;
32using OpenSim.Framework;
30using OpenMetaverse; 33using OpenMetaverse;
31 34
32namespace OpenSim.Services.Interfaces 35namespace OpenSim.Services.Interfaces
@@ -39,7 +42,7 @@ namespace OpenSim.Services.Interfaces
39 /// <param name="regionInfos"> </param> 42 /// <param name="regionInfos"> </param>
40 /// <returns></returns> 43 /// <returns></returns>
41 /// <exception cref="System.Exception">Thrown if region registration failed</exception> 44 /// <exception cref="System.Exception">Thrown if region registration failed</exception>
42 bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfos); 45 bool RegisterRegion(UUID scopeID, GridRegion regionInfos);
43 46
44 /// <summary> 47 /// <summary>
45 /// Deregister a region with the grid service. 48 /// Deregister a region with the grid service.
@@ -55,9 +58,9 @@ namespace OpenSim.Services.Interfaces
55 /// <param name="x"></param> 58 /// <param name="x"></param>
56 /// <param name="y"></param> 59 /// <param name="y"></param>
57 /// <returns></returns> 60 /// <returns></returns>
58 List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID); 61 List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID);
59 62
60 SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID); 63 GridRegion GetRegionByUUID(UUID scopeID, UUID regionID);
61 64
62 /// <summary> 65 /// <summary>
63 /// Get the region at the given position (in meters) 66 /// Get the region at the given position (in meters)
@@ -66,9 +69,9 @@ namespace OpenSim.Services.Interfaces
66 /// <param name="x"></param> 69 /// <param name="x"></param>
67 /// <param name="y"></param> 70 /// <param name="y"></param>
68 /// <returns></returns> 71 /// <returns></returns>
69 SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y); 72 GridRegion GetRegionByPosition(UUID scopeID, int x, int y);
70 73
71 SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName); 74 GridRegion GetRegionByName(UUID scopeID, string regionName);
72 75
73 /// <summary> 76 /// <summary>
74 /// Get information about regions starting with the provided name. 77 /// Get information about regions starting with the provided name.
@@ -83,9 +86,237 @@ namespace OpenSim.Services.Interfaces
83 /// A list of <see cref="RegionInfo"/>s of regions with matching name. If the 86 /// A list of <see cref="RegionInfo"/>s of regions with matching name. If the
84 /// grid-server couldn't be contacted or returned an error, return null. 87 /// grid-server couldn't be contacted or returned an error, return null.
85 /// </returns> 88 /// </returns>
86 List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber); 89 List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber);
87 90
88 List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax); 91 List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax);
89 92
90 } 93 }
94
95 public class GridRegion
96 {
97
98 /// <summary>
99 /// The port by which http communication occurs with the region
100 /// </summary>
101 public uint HttpPort
102 {
103 get { return m_httpPort; }
104 set { m_httpPort = value; }
105 }
106 protected uint m_httpPort;
107
108 /// <summary>
109 /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
110 /// </summary>
111 public string ServerURI
112 {
113 get { return m_serverURI; }
114 set { m_serverURI = value; }
115 }
116 protected string m_serverURI;
117
118 public string RegionName
119 {
120 get { return m_regionName; }
121 set { m_regionName = value; }
122 }
123 protected string m_regionName = String.Empty;
124
125 protected bool Allow_Alternate_Ports;
126 public bool m_allow_alternate_ports;
127
128 protected string m_externalHostName;
129
130 protected IPEndPoint m_internalEndPoint;
131
132 public int RegionLocX
133 {
134 get { return m_regionLocX; }
135 set { m_regionLocX = value; }
136 }
137 protected int m_regionLocX;
138
139 public int RegionLocY
140 {
141 get { return m_regionLocY; }
142 set { m_regionLocY = value; }
143 }
144 protected int m_regionLocY;
145
146 public UUID RegionID = UUID.Zero;
147 public UUID ScopeID = UUID.Zero;
148
149 public GridRegion()
150 {
151 }
152
153 public GridRegion(int regionLocX, int regionLocY, IPEndPoint internalEndPoint, string externalUri)
154 {
155 m_regionLocX = regionLocX;
156 m_regionLocY = regionLocY;
157
158 m_internalEndPoint = internalEndPoint;
159 m_externalHostName = externalUri;
160 }
161
162 public GridRegion(int regionLocX, int regionLocY, string externalUri, uint port)
163 {
164 m_regionLocX = regionLocX;
165 m_regionLocY = regionLocY;
166
167 m_externalHostName = externalUri;
168
169 m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)port);
170 }
171
172 public GridRegion(uint xcell, uint ycell)
173 {
174 m_regionLocX = (int)(xcell * Constants.RegionSize);
175 m_regionLocY = (int)(ycell * Constants.RegionSize);
176 }
177
178 public GridRegion(RegionInfo ConvertFrom)
179 {
180 m_regionName = ConvertFrom.RegionName;
181 m_regionLocX = (int)(ConvertFrom.RegionLocX * Constants.RegionSize);
182 m_regionLocY = (int)(ConvertFrom.RegionLocY * Constants.RegionSize);
183 m_internalEndPoint = ConvertFrom.InternalEndPoint;
184 m_externalHostName = ConvertFrom.ExternalHostName;
185 m_httpPort = ConvertFrom.HttpPort;
186 m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports;
187 RegionID = UUID.Zero;
188 ServerURI = ConvertFrom.ServerURI;
189 }
190
191
192 /// <value>
193 /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
194 ///
195 /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
196 /// </value>
197 public IPEndPoint ExternalEndPoint
198 {
199 get
200 {
201 // Old one defaults to IPv6
202 //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
203
204 IPAddress ia = null;
205 // If it is already an IP, don't resolve it - just return directly
206 if (IPAddress.TryParse(m_externalHostName, out ia))
207 return new IPEndPoint(ia, m_internalEndPoint.Port);
208
209 // Reset for next check
210 ia = null;
211 try
212 {
213 foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
214 {
215 if (ia == null)
216 ia = Adr;
217
218 if (Adr.AddressFamily == AddressFamily.InterNetwork)
219 {
220 ia = Adr;
221 break;
222 }
223 }
224 }
225 catch (SocketException e)
226 {
227 throw new Exception(
228 "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
229 e + "' attached to this exception", e);
230 }
231
232 return new IPEndPoint(ia, m_internalEndPoint.Port);
233 }
234
235 set { m_externalHostName = value.ToString(); }
236 }
237
238 public string ExternalHostName
239 {
240 get { return m_externalHostName; }
241 set { m_externalHostName = value; }
242 }
243
244 public IPEndPoint InternalEndPoint
245 {
246 get { return m_internalEndPoint; }
247 set { m_internalEndPoint = value; }
248 }
249
250 public ulong RegionHandle
251 {
252 get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); }
253 }
254
255 public int getInternalEndPointPort()
256 {
257 return m_internalEndPoint.Port;
258 }
259
260 public Dictionary<string, object> ToKeyValuePairs()
261 {
262 Dictionary<string, object> kvp = new Dictionary<string, object>();
263 kvp["uuid"] = RegionID.ToString();
264 kvp["locX"] = RegionLocX.ToString();
265 kvp["locY"] = RegionLocY.ToString();
266 kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
267 kvp["external_port"] = ExternalEndPoint.Port.ToString();
268 kvp["external_host_name"] = ExternalHostName;
269 kvp["http_port"] = HttpPort.ToString();
270 kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
271 kvp["internal_port"] = InternalEndPoint.Port.ToString();
272 kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
273 kvp["server_uri"] = ServerURI;
274
275 return kvp;
276 }
277
278 public GridRegion(Dictionary<string, object> kvp)
279 {
280 if ((kvp["external_ip_address"] != null) && (kvp["external_port"] != null))
281 {
282 int port = 0;
283 Int32.TryParse((string)kvp["external_port"], out port);
284 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["external_ip_address"]), port);
285 ExternalEndPoint = ep;
286 }
287 else
288 ExternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
289
290 if (kvp["external_host_name"] != null)
291 ExternalHostName = (string)kvp["external_host_name"];
292
293 if (kvp["http_port"] != null)
294 {
295 UInt32 port = 0;
296 UInt32.TryParse((string)kvp["http_port"], out port);
297 HttpPort = port;
298 }
299
300 if ((kvp["internal_ip_address"] != null) && (kvp["internal_port"] != null))
301 {
302 int port = 0;
303 Int32.TryParse((string)kvp["internal_port"], out port);
304 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["internal_ip_address"]), port);
305 InternalEndPoint = ep;
306 }
307 else
308 InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
309
310 if (kvp["alternate_ports"] != null)
311 {
312 bool alts = false;
313 Boolean.TryParse((string)kvp["alternate_ports"], out alts);
314 m_allow_alternate_ports = alts;
315 }
316
317 if (kvp["server_uri"] != null)
318 ServerURI = (string)kvp["server_uri"];
319 }
320 }
321
91} 322}