aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/GridService/HypergridLinker.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/GridService/HypergridLinker.cs')
-rw-r--r--OpenSim/Services/GridService/HypergridLinker.cs189
1 files changed, 103 insertions, 86 deletions
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs
index aebbf7c..dabfd3b 100644
--- a/OpenSim/Services/GridService/HypergridLinker.cs
+++ b/OpenSim/Services/GridService/HypergridLinker.cs
@@ -63,6 +63,7 @@ namespace OpenSim.Services.GridService
63 protected GatekeeperServiceConnector m_GatekeeperConnector; 63 protected GatekeeperServiceConnector m_GatekeeperConnector;
64 64
65 protected UUID m_ScopeID = UUID.Zero; 65 protected UUID m_ScopeID = UUID.Zero;
66// protected bool m_Check4096 = true;
66 protected string m_MapTileDirectory = string.Empty; 67 protected string m_MapTileDirectory = string.Empty;
67 protected string m_ThisGatekeeper = string.Empty; 68 protected string m_ThisGatekeeper = string.Empty;
68 protected Uri m_ThisGatekeeperURI = null; 69 protected Uri m_ThisGatekeeperURI = null;
@@ -119,8 +120,9 @@ namespace OpenSim.Services.GridService
119 if (scope != string.Empty) 120 if (scope != string.Empty)
120 UUID.TryParse(scope, out m_ScopeID); 121 UUID.TryParse(scope, out m_ScopeID);
121 122
122// TODO OpenSim is crazy, this is called from Robust and OpenSim, Robust needs the ../caches bit, OpenSim somehow adds a path already. I can't tell why. So strip the path. 123// m_Check4096 = gridConfig.GetBoolean("Check4096", true);
123 m_MapTileDirectory = "../caches/" + Path.GetFileName(gridConfig.GetString("MapTileDirectory", "maptiles")); 124
125 m_MapTileDirectory = gridConfig.GetString("MapTileDirectory", "maptiles");
124 126
125 m_ThisGatekeeper = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI", 127 m_ThisGatekeeper = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
126 new string[] { "Startup", "Hypergrid", "GridService" }, String.Empty); 128 new string[] { "Startup", "Hypergrid", "GridService" }, String.Empty);
@@ -135,18 +137,27 @@ namespace OpenSim.Services.GridService
135 m_log.WarnFormat("[HYPERGRID LINKER]: Malformed URL in [GridService], variable Gatekeeper = {0}", m_ThisGatekeeper); 137 m_log.WarnFormat("[HYPERGRID LINKER]: Malformed URL in [GridService], variable Gatekeeper = {0}", m_ThisGatekeeper);
136 } 138 }
137 139
140 m_ThisGatekeeper = m_ThisGatekeeperURI.AbsoluteUri;
141 if(m_ThisGatekeeperURI.Port == 80)
142 m_ThisGatekeeper = m_ThisGatekeeper.Trim(new char[] { '/', ' ' }) +":80/";
143 else if(m_ThisGatekeeperURI.Port == 443)
144 m_ThisGatekeeper = m_ThisGatekeeper.Trim(new char[] { '/', ' ' }) +":443/";
145
138 m_GatekeeperConnector = new GatekeeperServiceConnector(m_AssetService); 146 m_GatekeeperConnector = new GatekeeperServiceConnector(m_AssetService);
139 147
140 m_log.Debug("[HYPERGRID LINKER]: Loaded all services..."); 148 m_log.Debug("[HYPERGRID LINKER]: Loaded all services...");
141 149
142 try 150 if (!string.IsNullOrEmpty(m_MapTileDirectory))
143 {
144 Directory.CreateDirectory(m_MapTileDirectory);
145 }
146 catch (Exception e)
147 { 151 {
148 m_log.WarnFormat("[HYPERGRID LINKER]: Could not create map tile storage directory {0}: {1}", m_MapTileDirectory, e); 152 try
149 m_MapTileDirectory = string.Empty; 153 {
154 Directory.CreateDirectory(m_MapTileDirectory);
155 }
156 catch (Exception e)
157 {
158 m_log.WarnFormat("[HYPERGRID LINKER]: Could not create map tile storage directory {0}: {1}", m_MapTileDirectory, e);
159 m_MapTileDirectory = string.Empty;
160 }
150 } 161 }
151 162
152 if (MainConsole.Instance != null) 163 if (MainConsole.Instance != null)
@@ -186,85 +197,29 @@ namespace OpenSim.Services.GridService
186 return TryLinkRegionToCoords(scopeID, mapName, xloc, yloc, UUID.Zero, out reason); 197 return TryLinkRegionToCoords(scopeID, mapName, xloc, yloc, UUID.Zero, out reason);
187 } 198 }
188 199
200 public bool IsLocalGrid(string serverURI)
201 {
202 return serverURI == m_ThisGatekeeper;
203 }
204
189 public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, UUID ownerID, out string reason) 205 public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, UUID ownerID, out string reason)
190 { 206 {
191 reason = string.Empty; 207 reason = string.Empty;
192 GridRegion regInfo = null; 208 GridRegion regInfo = null;
193 209
194 mapName = mapName.Trim(); 210 string serverURI = string.Empty;
211 string regionName = string.Empty;
195 212
196 if (!mapName.StartsWith("http")) 213 if(!Util.buildHGRegionURI(mapName, out serverURI, out regionName))
197 { 214 {
198 // Formats: grid.example.com:8002:region name 215 reason = "Wrong URI format for link-region";
199 // grid.example.com:region name 216 return null;
200 // grid.example.com:8002
201 // grid.example.com
202
203 string host;
204 uint port = 80;
205 string regionName = "";
206
207 string[] parts = mapName.Split(new char[] { ':' });
208
209 if (parts.Length == 0)
210 {
211 reason = "Wrong format for link-region";
212 return null;
213 }
214
215 host = parts[0];
216
217 if (parts.Length >= 2)
218 {
219 // If it's a number then assume it's a port. Otherwise, it's a region name.
220 if (!UInt32.TryParse(parts[1], out port))
221 regionName = parts[1];
222 }
223
224 // always take the last one
225 if (parts.Length >= 3)
226 {
227 regionName = parts[2];
228 }
229
230
231 bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, ownerID, out regInfo, out reason);
232 if (success)
233 {
234 regInfo.RegionName = mapName;
235 return regInfo;
236 }
237 } 217 }
238 else
239 {
240 // Formats: http://grid.example.com region name
241 // http://grid.example.com "region name"
242 // http://grid.example.com
243
244 string serverURI;
245 string regionName = "";
246 218
247 string[] parts = mapName.Split(new char[] { ' ' }); 219 if (TryCreateLink(scopeID, xloc, yloc, regionName, 0, null, serverURI, ownerID, out regInfo, out reason))
248 220 {
249 if (parts.Length == 0) 221 regInfo.RegionName = serverURI + regionName;
250 { 222 return regInfo;
251 reason = "Wrong format for link-region";
252 return null;
253 }
254
255 serverURI = parts[0];
256
257 if (parts.Length >= 2)
258 {
259 regionName = mapName.Substring(serverURI.Length);
260 regionName = regionName.Trim(new char[] { '"', ' ' });
261 }
262
263 if (TryCreateLink(scopeID, xloc, yloc, regionName, 0, null, serverURI, ownerID, out regInfo, out reason))
264 {
265 regInfo.RegionName = mapName;
266 return regInfo;
267 }
268 } 223 }
269 224
270 return null; 225 return null;
@@ -285,7 +240,7 @@ namespace OpenSim.Services.GridService
285 240
286 private bool TryCreateLinkImpl(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason) 241 private bool TryCreateLinkImpl(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason)
287 { 242 {
288 m_log.InfoFormat("[HYPERGRID LINKER]: Link to {0} {1}, in <{2},{3}>", 243 m_log.InfoFormat("[HYPERGRID LINKER]: Link to {0} {1}, in <{2},{3}>",
289 ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI), 244 ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI),
290 remoteRegionName, Util.WorldToRegionLoc((uint)xloc), Util.WorldToRegionLoc((uint)yloc)); 245 remoteRegionName, Util.WorldToRegionLoc((uint)xloc), Util.WorldToRegionLoc((uint)yloc));
291 246
@@ -361,7 +316,9 @@ namespace OpenSim.Services.GridService
361 UUID regionID = UUID.Zero; 316 UUID regionID = UUID.Zero;
362 string externalName = string.Empty; 317 string externalName = string.Empty;
363 string imageURL = string.Empty; 318 string imageURL = string.Empty;
364 if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason)) 319 int sizeX = (int)Constants.RegionSize;
320 int sizeY = (int)Constants.RegionSize;
321 if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason, out sizeX, out sizeY))
365 return false; 322 return false;
366 323
367 if (regionID == UUID.Zero) 324 if (regionID == UUID.Zero)
@@ -374,13 +331,27 @@ namespace OpenSim.Services.GridService
374 region = m_GridService.GetRegionByUUID(scopeID, regionID); 331 region = m_GridService.GetRegionByUUID(scopeID, regionID);
375 if (region != null) 332 if (region != null)
376 { 333 {
377 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates <{0},{1}>", 334 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates <{0},{1}>", Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY));
378 Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY));
379 regInfo = region; 335 regInfo = region;
380 return true; 336 return true;
381 } 337 }
382 338
339 // We are now performing this check for each individual teleport in the EntityTransferModule instead. This
340 // allows us to give better feedback when teleports fail because of the distance reason (which can't be
341 // done here) and it also hypergrid teleports that are within range (possibly because the source grid
342 // itself has regions that are very far apart).
343// uint x, y;
344// if (m_Check4096 && !Check4096(handle, out x, out y))
345// {
346// //RemoveHyperlinkRegion(regInfo.RegionID);
347// reason = "Region is too far (" + x + ", " + y + ")";
348// m_log.Info("[HYPERGRID LINKER]: Unable to link, region is too far (" + x + ", " + y + ")");
349// //return false;
350// }
351
383 regInfo.RegionID = regionID; 352 regInfo.RegionID = regionID;
353 regInfo.RegionSizeX = sizeX;
354 regInfo.RegionSizeY = sizeY;
384 355
385 if (externalName == string.Empty) 356 if (externalName == string.Empty)
386 regInfo.RegionName = regInfo.ServerURI; 357 regInfo.RegionName = regInfo.ServerURI;
@@ -412,7 +383,7 @@ namespace OpenSim.Services.GridService
412 OpenSim.Framework.RegionFlags rflags = (OpenSim.Framework.RegionFlags)Convert.ToInt32(regions[0].Data["flags"]); 383 OpenSim.Framework.RegionFlags rflags = (OpenSim.Framework.RegionFlags)Convert.ToInt32(regions[0].Data["flags"]);
413 if ((rflags & OpenSim.Framework.RegionFlags.Hyperlink) != 0) 384 if ((rflags & OpenSim.Framework.RegionFlags.Hyperlink) != 0)
414 { 385 {
415 regInfo = new GridRegion(); 386 regInfo = new GridRegion();
416 regInfo.RegionID = regions[0].RegionID; 387 regInfo.RegionID = regions[0].RegionID;
417 regInfo.ScopeID = m_ScopeID; 388 regInfo.ScopeID = m_ScopeID;
418 } 389 }
@@ -430,6 +401,52 @@ namespace OpenSim.Services.GridService
430 } 401 }
431 } 402 }
432 403
404// Not currently used
405// /// <summary>
406// /// Cope with this viewer limitation.
407// /// </summary>
408// /// <param name="regInfo"></param>
409// /// <returns></returns>
410// public bool Check4096(ulong realHandle, out uint x, out uint y)
411// {
412// uint ux = 0, uy = 0;
413// Utils.LongToUInts(realHandle, out ux, out uy);
414// x = Util.WorldToRegionLoc(ux);
415// y = Util.WorldToRegionLoc(uy);
416//
417// const uint limit = Util.RegionToWorldLoc(4096 - 1);
418// uint xmin = ux - limit;
419// uint xmax = ux + limit;
420// uint ymin = uy - limit;
421// uint ymax = uy + limit;
422// // World map boundary checks
423// if (xmin < 0 || xmin > ux)
424// xmin = 0;
425// if (xmax > int.MaxValue || xmax < ux)
426// xmax = int.MaxValue;
427// if (ymin < 0 || ymin > uy)
428// ymin = 0;
429// if (ymax > int.MaxValue || ymax < uy)
430// ymax = int.MaxValue;
431//
432// // Check for any regions that are within the possible teleport range to the linked region
433// List<GridRegion> regions = m_GridService.GetRegionRange(m_ScopeID, (int)xmin, (int)xmax, (int)ymin, (int)ymax);
434// if (regions.Count == 0)
435// {
436// return false;
437// }
438// else
439// {
440// // Check for regions which are not linked regions
441// List<GridRegion> hyperlinks = m_GridService.GetHyperlinks(m_ScopeID);
442// IEnumerable<GridRegion> availableRegions = regions.Except(hyperlinks);
443// if (availableRegions.Count() == 0)
444// return false;
445// }
446//
447// return true;
448// }
449
433 private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) 450 private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
434 { 451 {
435 RegionData rdata = m_GridService.RegionInfo2RegionData(regionInfo); 452 RegionData rdata = m_GridService.RegionInfo2RegionData(regionInfo);
@@ -474,7 +491,7 @@ namespace OpenSim.Services.GridService
474 { 491 {
475 MainConsole.Instance.Output( 492 MainConsole.Instance.Output(
476 String.Format("{0}\n{2,-32} {1}\n", 493 String.Format("{0}\n{2,-32} {1}\n",
477 r.RegionName, r.RegionID, 494 r.RegionName, r.RegionID,
478 String.Format("{0},{1} ({2},{3})", r.posX, r.posY, 495 String.Format("{0},{1} ({2},{3})", r.posX, r.posY,
479 Util.WorldToRegionLoc((uint)r.posX), Util.WorldToRegionLoc((uint)r.posY) 496 Util.WorldToRegionLoc((uint)r.posX), Util.WorldToRegionLoc((uint)r.posY)
480 ) 497 )
@@ -556,7 +573,7 @@ namespace OpenSim.Services.GridService
556 if (cmdparams[2].StartsWith("http")) 573 if (cmdparams[2].StartsWith("http"))
557 { 574 {
558 RunLinkRegionCommand(cmdparams); 575 RunLinkRegionCommand(cmdparams);
559 } 576 }
560 else if (cmdparams[2].Contains(":")) 577 else if (cmdparams[2].Contains(":"))
561 { 578 {
562 // New format 579 // New format