diff options
author | Melanie | 2009-09-28 23:03:47 +0100 |
---|---|---|
committer | Melanie | 2009-09-28 23:03:47 +0100 |
commit | 07091493134341a316624d9a1f6a2ef1cfa2f2d8 (patch) | |
tree | 1d394e128be9766656a441058b2bdf141ba90269 /OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid | |
parent | Allow the notation config_name@port/dll_name:class_name as a handler spec (diff) | |
parent | Forgot a return statement. (diff) | |
download | opensim-SC_OLD-07091493134341a316624d9a1f6a2ef1cfa2f2d8.zip opensim-SC_OLD-07091493134341a316624d9a1f6a2ef1cfa2f2d8.tar.gz opensim-SC_OLD-07091493134341a316624d9a1f6a2ef1cfa2f2d8.tar.bz2 opensim-SC_OLD-07091493134341a316624d9a1f6a2ef1cfa2f2d8.tar.xz |
Merge branch 'grid-service-redux'
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid')
5 files changed, 386 insertions, 42 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs index 36915ef..0974372 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs | |||
@@ -86,7 +86,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
86 | 86 | ||
87 | private void RunHGCommand(string command, string[] cmdparams) | 87 | private void RunHGCommand(string command, string[] cmdparams) |
88 | { | 88 | { |
89 | if (command.Equals("linkk-mapping")) | 89 | if (command.Equals("link-mapping")) |
90 | { | 90 | { |
91 | if (cmdparams.Length == 2) | 91 | if (cmdparams.Length == 2) |
92 | { | 92 | { |
@@ -104,7 +104,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
104 | } | 104 | } |
105 | } | 105 | } |
106 | } | 106 | } |
107 | else if (command.Equals("linkk-region")) | 107 | else if (command.Equals("link-region")) |
108 | { | 108 | { |
109 | if (cmdparams.Length < 3) | 109 | if (cmdparams.Length < 3) |
110 | { | 110 | { |
@@ -187,7 +187,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
187 | } | 187 | } |
188 | return; | 188 | return; |
189 | } | 189 | } |
190 | else if (command.Equals("unlinkk-region")) | 190 | else if (command.Equals("unlink-region")) |
191 | { | 191 | { |
192 | if (cmdparams.Length < 1) | 192 | if (cmdparams.Length < 1) |
193 | { | 193 | { |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 0c2a835..1eb481e 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs | |||
@@ -31,6 +31,7 @@ using System.Net; | |||
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Xml; | 32 | using System.Xml; |
33 | 33 | ||
34 | using OpenSim.Framework.Communications.Cache; | ||
34 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
35 | using OpenSim.Region.Framework.Interfaces; | 36 | using OpenSim.Region.Framework.Interfaces; |
36 | using OpenSim.Region.Framework.Scenes; | 37 | using OpenSim.Region.Framework.Scenes; |
@@ -47,15 +48,19 @@ using Nini.Config; | |||
47 | 48 | ||
48 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | 49 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid |
49 | { | 50 | { |
50 | public class HGGridConnector : ISharedRegionModule, IGridService | 51 | public class HGGridConnector : ISharedRegionModule, IGridService, IHyperlinkService |
51 | { | 52 | { |
52 | private static readonly ILog m_log = | 53 | private static readonly ILog m_log = |
53 | LogManager.GetLogger( | 54 | LogManager.GetLogger( |
54 | MethodBase.GetCurrentMethod().DeclaringType); | 55 | MethodBase.GetCurrentMethod().DeclaringType); |
56 | private static string LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI; | ||
55 | 57 | ||
56 | private bool m_Enabled = false; | 58 | private bool m_Enabled = false; |
57 | private bool m_Initialized = false; | 59 | private bool m_Initialized = false; |
58 | 60 | ||
61 | private Scene m_aScene; | ||
62 | private Dictionary<ulong, Scene> m_LocalScenes = new Dictionary<ulong, Scene>(); | ||
63 | |||
59 | private IGridService m_GridServiceConnector; | 64 | private IGridService m_GridServiceConnector; |
60 | private HypergridServiceConnector m_HypergridServiceConnector; | 65 | private HypergridServiceConnector m_HypergridServiceConnector; |
61 | 66 | ||
@@ -130,6 +135,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
130 | 135 | ||
131 | public void PostInitialise() | 136 | public void PostInitialise() |
132 | { | 137 | { |
138 | if (m_Enabled) | ||
139 | ((ISharedRegionModule)m_GridServiceConnector).PostInitialise(); | ||
133 | } | 140 | } |
134 | 141 | ||
135 | public void Close() | 142 | public void Close() |
@@ -141,12 +148,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
141 | if (!m_Enabled) | 148 | if (!m_Enabled) |
142 | return; | 149 | return; |
143 | 150 | ||
151 | m_LocalScenes[scene.RegionInfo.RegionHandle] = scene; | ||
144 | scene.RegisterModuleInterface<IGridService>(this); | 152 | scene.RegisterModuleInterface<IGridService>(this); |
153 | scene.RegisterModuleInterface<IHyperlinkService>(this); | ||
154 | |||
155 | ((ISharedRegionModule)m_GridServiceConnector).AddRegion(scene); | ||
145 | 156 | ||
146 | } | 157 | } |
147 | 158 | ||
148 | public void RemoveRegion(Scene scene) | 159 | public void RemoveRegion(Scene scene) |
149 | { | 160 | { |
161 | if (m_Enabled) | ||
162 | { | ||
163 | m_LocalScenes.Remove(scene.RegionInfo.RegionHandle); | ||
164 | ((ISharedRegionModule)m_GridServiceConnector).RemoveRegion(scene); | ||
165 | } | ||
150 | } | 166 | } |
151 | 167 | ||
152 | public void RegionLoaded(Scene scene) | 168 | public void RegionLoaded(Scene scene) |
@@ -156,29 +172,28 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
156 | 172 | ||
157 | if (!m_Initialized) | 173 | if (!m_Initialized) |
158 | { | 174 | { |
175 | m_aScene = scene; | ||
176 | LocalAssetServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL; | ||
177 | LocalInventoryServerURI = m_aScene.CommsManager.NetworkServersInfo.InventoryURL; | ||
178 | LocalUserServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL; | ||
179 | |||
159 | m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); | 180 | m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); |
181 | |||
160 | HGCommands hgCommands = new HGCommands(this, scene); | 182 | HGCommands hgCommands = new HGCommands(this, scene); |
161 | MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-region", | 183 | MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region", |
162 | "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", | 184 | "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", |
163 | "Link a hypergrid region", hgCommands.RunCommand); | 185 | "Link a hypergrid region", hgCommands.RunCommand); |
164 | MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlinkk-region", | 186 | MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlink-region", |
165 | "unlink-region <local name> or <HostName>:<HttpPort> <cr>", | 187 | "unlink-region <local name> or <HostName>:<HttpPort> <cr>", |
166 | "Unlink a hypergrid region", hgCommands.RunCommand); | 188 | "Unlink a hypergrid region", hgCommands.RunCommand); |
167 | MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-mapping", "link-mapping [<x> <y>] <cr>", | 189 | MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [<x> <y>] <cr>", |
168 | "Set local coordinate to map HG regions to", hgCommands.RunCommand); | 190 | "Set local coordinate to map HG regions to", hgCommands.RunCommand); |
169 | m_Initialized = true; | ||
170 | } | ||
171 | 191 | ||
192 | // Yikes!! Remove this as soon as user services get refactored | ||
193 | HGNetworkServersInfo.Init(LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI); | ||
172 | 194 | ||
173 | //scene.AddCommand("HGGridServicesConnector", "linkk-region", | 195 | m_Initialized = true; |
174 | // "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", | 196 | } |
175 | // "Link a hypergrid region", hgCommands.RunCommand); | ||
176 | //scene.AddCommand("HGGridServicesConnector", "unlinkk-region", | ||
177 | // "unlink-region <local name> or <HostName>:<HttpPort> <cr>", | ||
178 | // "Unlink a hypergrid region", hgCommands.RunCommand); | ||
179 | //scene.AddCommand("HGGridServicesConnector", "linkk-mapping", "link-mapping [<x> <y>] <cr>", | ||
180 | // "Set local coordinate to map HG regions to", hgCommands.RunCommand); | ||
181 | |||
182 | } | 197 | } |
183 | 198 | ||
184 | #endregion | 199 | #endregion |
@@ -250,7 +265,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
250 | // Try the foreign users home collection | 265 | // Try the foreign users home collection |
251 | foreach (GridRegion r in m_knownRegions.Values) | 266 | foreach (GridRegion r in m_knownRegions.Values) |
252 | if (r.RegionID == regionID) | 267 | if (r.RegionID == regionID) |
253 | return m_knownRegions[regionID]; | 268 | return r; |
254 | 269 | ||
255 | // Finally, try the normal route | 270 | // Finally, try the normal route |
256 | return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); | 271 | return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); |
@@ -271,7 +286,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
271 | foreach (GridRegion r in m_knownRegions.Values) | 286 | foreach (GridRegion r in m_knownRegions.Values) |
272 | { | 287 | { |
273 | if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) | 288 | if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) |
289 | { | ||
274 | return r; | 290 | return r; |
291 | } | ||
275 | } | 292 | } |
276 | 293 | ||
277 | // Finally, try the normal route | 294 | // Finally, try the normal route |
@@ -338,8 +355,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
338 | 355 | ||
339 | private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) | 356 | private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) |
340 | { | 357 | { |
341 | m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); | 358 | m_HyperlinkRegions[regionInfo.RegionID] = regionInfo; |
342 | m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); | 359 | m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; |
343 | } | 360 | } |
344 | 361 | ||
345 | private void RemoveHyperlinkRegion(UUID regionID) | 362 | private void RemoveHyperlinkRegion(UUID regionID) |
@@ -350,8 +367,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
350 | 367 | ||
351 | private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle) | 368 | private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle) |
352 | { | 369 | { |
353 | m_knownRegions.Add(userID, regionInfo); | 370 | m_knownRegions[userID] = regionInfo; |
354 | m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); | 371 | m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; |
355 | } | 372 | } |
356 | 373 | ||
357 | private void RemoveHyperlinkHomeRegion(UUID regionID) | 374 | private void RemoveHyperlinkHomeRegion(UUID regionID) |
@@ -367,10 +384,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
367 | } | 384 | } |
368 | #endregion | 385 | #endregion |
369 | 386 | ||
370 | #region Hyperlinks | 387 | #region IHyperlinkService |
371 | 388 | ||
372 | private static Random random = new Random(); | 389 | private static Random random = new Random(); |
373 | 390 | ||
391 | |||
374 | public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc) | 392 | public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc) |
375 | { | 393 | { |
376 | string host = "127.0.0.1"; | 394 | string host = "127.0.0.1"; |
@@ -417,10 +435,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
417 | return null; | 435 | return null; |
418 | } | 436 | } |
419 | 437 | ||
438 | |||
420 | // From the map search and secondlife://blah | 439 | // From the map search and secondlife://blah |
421 | public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) | 440 | public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) |
422 | { | 441 | { |
423 | int xloc = random.Next(0, Int16.MaxValue); | 442 | int xloc = random.Next(0, Int16.MaxValue) * (int) Constants.RegionSize; |
424 | return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); | 443 | return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); |
425 | } | 444 | } |
426 | 445 | ||
@@ -447,15 +466,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
447 | } | 466 | } |
448 | 467 | ||
449 | // Finally, link it | 468 | // Finally, link it |
450 | try | 469 | if (!RegisterRegion(UUID.Zero, regInfo)) |
451 | { | 470 | { |
452 | RegisterRegion(UUID.Zero, regInfo); | 471 | m_log.Warn("[HGrid]: Unable to link region"); |
453 | } | 472 | return false; |
454 | catch (Exception e) | 473 | } |
455 | { | ||
456 | m_log.Warn("[HGrid]: Unable to link region: " + e.Message); | ||
457 | return false; | ||
458 | } | ||
459 | 474 | ||
460 | int x, y; | 475 | int x, y; |
461 | if (!Check4096(m_scene, regInfo, out x, out y)) | 476 | if (!Check4096(m_scene, regInfo, out x, out y)) |
@@ -554,7 +569,227 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
554 | return true; | 569 | return true; |
555 | } | 570 | } |
556 | 571 | ||
572 | public GridRegion TryLinkRegion(IClientAPI client, string regionDescriptor) | ||
573 | { | ||
574 | return TryLinkRegion((Scene)client.Scene, client, regionDescriptor); | ||
575 | } | ||
576 | |||
577 | public GridRegion GetHyperlinkRegion(ulong handle) | ||
578 | { | ||
579 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
580 | if (r.RegionHandle == handle) | ||
581 | return r; | ||
582 | foreach (GridRegion r in m_knownRegions.Values) | ||
583 | if (r.RegionHandle == handle) | ||
584 | return r; | ||
585 | return null; | ||
586 | } | ||
587 | |||
588 | public ulong FindRegionHandle(ulong handle) | ||
589 | { | ||
590 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
591 | if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) | ||
592 | return m_HyperlinkHandles[r.RegionID]; | ||
593 | |||
594 | foreach (GridRegion r in m_knownRegions.Values) | ||
595 | if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) | ||
596 | return m_HyperlinkHandles[r.RegionID]; | ||
597 | |||
598 | return handle; | ||
599 | } | ||
600 | |||
601 | public bool SendUserInformation(GridRegion regInfo, AgentCircuitData agentData) | ||
602 | { | ||
603 | CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID); | ||
604 | |||
605 | if ((IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) || | ||
606 | (!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo))) | ||
607 | { | ||
608 | m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere"); | ||
609 | |||
610 | // Set the position of the region on the remote grid | ||
611 | ulong realHandle = FindRegionHandle(regInfo.RegionHandle); | ||
612 | uint x = 0, y = 0; | ||
613 | Utils.LongToUInts(regInfo.RegionHandle, out x, out y); | ||
614 | GridRegion clonedRegion = new GridRegion(regInfo); | ||
615 | clonedRegion.RegionLocX = (int)x; | ||
616 | clonedRegion.RegionLocY = (int)y; | ||
617 | |||
618 | // Get the user's home region information | ||
619 | GridRegion home = m_aScene.GridService.GetRegionByUUID(m_aScene.RegionInfo.ScopeID, uinfo.UserProfile.HomeRegionID); | ||
620 | |||
621 | // Get the user's service URLs | ||
622 | string serverURI = ""; | ||
623 | if (uinfo.UserProfile is ForeignUserProfileData) | ||
624 | serverURI = Util.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI); | ||
625 | string userServer = (serverURI == "") || (serverURI == null) ? LocalUserServerURI : serverURI; | ||
626 | |||
627 | string assetServer = Util.ServerURI(uinfo.UserProfile.UserAssetURI); | ||
628 | if ((assetServer == null) || (assetServer == "")) | ||
629 | assetServer = LocalAssetServerURI; | ||
630 | |||
631 | string inventoryServer = Util.ServerURI(uinfo.UserProfile.UserInventoryURI); | ||
632 | if ((inventoryServer == null) || (inventoryServer == "")) | ||
633 | inventoryServer = LocalInventoryServerURI; | ||
634 | |||
635 | if (!m_HypergridServiceConnector.InformRegionOfUser(clonedRegion, agentData, home, userServer, assetServer, inventoryServer)) | ||
636 | { | ||
637 | m_log.Warn("[HGrid]: Could not inform remote region of transferring user."); | ||
638 | return false; | ||
639 | } | ||
640 | } | ||
641 | //if ((uinfo == null) || !IsGoingHome(uinfo, regInfo)) | ||
642 | //{ | ||
643 | // m_log.Info("[HGrid]: User seems to be going to foreign region."); | ||
644 | // if (!InformRegionOfUser(regInfo, agentData)) | ||
645 | // { | ||
646 | // m_log.Warn("[HGrid]: Could not inform remote region of transferring user."); | ||
647 | // return false; | ||
648 | // } | ||
649 | //} | ||
650 | //else | ||
651 | // m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName); | ||
652 | |||
653 | // May need to change agent's name | ||
654 | if (IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) | ||
655 | { | ||
656 | agentData.firstname = agentData.firstname + "." + agentData.lastname; | ||
657 | agentData.lastname = "@" + LocalUserServerURI.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI; | ||
658 | } | ||
659 | |||
660 | return true; | ||
661 | } | ||
662 | |||
663 | public void AdjustUserInformation(AgentCircuitData agentData) | ||
664 | { | ||
665 | CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID); | ||
666 | if ((uinfo != null) && (uinfo.UserProfile != null) && | ||
667 | (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData))) | ||
668 | { | ||
669 | //m_log.Debug("---------------> Local User!"); | ||
670 | string[] parts = agentData.firstname.Split(new char[] { '.' }); | ||
671 | if (parts.Length == 2) | ||
672 | { | ||
673 | agentData.firstname = parts[0]; | ||
674 | agentData.lastname = parts[1]; | ||
675 | } | ||
676 | } | ||
677 | //else | ||
678 | // m_log.Debug("---------------> Foreign User!"); | ||
679 | } | ||
680 | |||
681 | // Check if a local user exists with the same UUID as the incoming foreign user | ||
682 | public bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome) | ||
683 | { | ||
684 | comingHome = false; | ||
685 | if (!m_aScene.SceneGridService.RegionLoginsEnabled) | ||
686 | return false; | ||
687 | |||
688 | CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID); | ||
689 | if (uinfo != null) | ||
690 | { | ||
691 | // uh-oh we have a potential intruder | ||
692 | if (uinfo.SessionID != sessionID) | ||
693 | // can't have a foreigner with a local UUID | ||
694 | return false; | ||
695 | else | ||
696 | // oh, so it's you! welcome back | ||
697 | comingHome = true; | ||
698 | } | ||
699 | |||
700 | // OK, user can come in | ||
701 | return true; | ||
702 | } | ||
703 | |||
704 | public void AcceptUser(ForeignUserProfileData user, GridRegion home) | ||
705 | { | ||
706 | m_aScene.CommsManager.UserProfileCacheService.PreloadUserCache(user); | ||
707 | ulong realHandle = home.RegionHandle; | ||
708 | // Change the local coordinates | ||
709 | // X=0 on the map | ||
710 | home.RegionLocX = 0; | ||
711 | home.RegionLocY = random.Next(0, 10000) * (int)Constants.RegionSize; | ||
712 | |||
713 | AddHyperlinkHomeRegion(user.ID, home, realHandle); | ||
714 | |||
715 | DumpUserData(user); | ||
716 | DumpRegionData(home); | ||
717 | |||
718 | } | ||
719 | |||
720 | public bool IsLocalUser(UUID userID) | ||
721 | { | ||
722 | CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID); | ||
723 | return IsLocalUser(uinfo); | ||
724 | } | ||
725 | |||
557 | #endregion | 726 | #endregion |
558 | 727 | ||
728 | #region IHyperlink Misc | ||
729 | |||
730 | protected bool IsComingHome(ForeignUserProfileData userData) | ||
731 | { | ||
732 | return (userData.UserServerURI == LocalUserServerURI); | ||
733 | } | ||
734 | |||
735 | // Is the user going back to the home region or the home grid? | ||
736 | protected bool IsGoingHome(CachedUserInfo uinfo, GridRegion rinfo) | ||
737 | { | ||
738 | if (uinfo.UserProfile == null) | ||
739 | return false; | ||
740 | |||
741 | if (!(uinfo.UserProfile is ForeignUserProfileData)) | ||
742 | // it's a home user, can't be outside to return home | ||
743 | return false; | ||
744 | |||
745 | // OK, it's a foreign user with a ForeignUserProfileData | ||
746 | // and is going back to exactly the home region. | ||
747 | // We can't check if it's going back to a non-home region | ||
748 | // of the home grid. That will be dealt with in the | ||
749 | // receiving end | ||
750 | return (uinfo.UserProfile.HomeRegionID == rinfo.RegionID); | ||
751 | } | ||
752 | |||
753 | protected bool IsLocalUser(CachedUserInfo uinfo) | ||
754 | { | ||
755 | if (uinfo == null) | ||
756 | return false; | ||
757 | |||
758 | return !(uinfo.UserProfile is ForeignUserProfileData); | ||
759 | |||
760 | } | ||
761 | |||
762 | protected bool IsLocalRegion(ulong handle) | ||
763 | { | ||
764 | return m_LocalScenes.ContainsKey(handle); | ||
765 | } | ||
766 | |||
767 | private void DumpUserData(ForeignUserProfileData userData) | ||
768 | { | ||
769 | m_log.Info(" ------------ User Data Dump ----------"); | ||
770 | m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName); | ||
771 | m_log.Info(" >> HomeID: " + userData.HomeRegionID); | ||
772 | m_log.Info(" >> UserServer: " + userData.UserServerURI); | ||
773 | m_log.Info(" >> InvServer: " + userData.UserInventoryURI); | ||
774 | m_log.Info(" >> AssetServer: " + userData.UserAssetURI); | ||
775 | m_log.Info(" ------------ -------------- ----------"); | ||
776 | } | ||
777 | |||
778 | private void DumpRegionData(GridRegion rinfo) | ||
779 | { | ||
780 | m_log.Info(" ------------ Region Data Dump ----------"); | ||
781 | m_log.Info(" >> handle: " + rinfo.RegionHandle); | ||
782 | m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY); | ||
783 | m_log.Info(" >> external host name: " + rinfo.ExternalHostName); | ||
784 | m_log.Info(" >> http port: " + rinfo.HttpPort); | ||
785 | m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address); | ||
786 | m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port); | ||
787 | m_log.Info(" ------------ -------------- ----------"); | ||
788 | } | ||
789 | |||
790 | |||
791 | #endregion | ||
792 | |||
793 | |||
559 | } | 794 | } |
560 | } | 795 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 743d3b9..6c2928a 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | |||
@@ -31,6 +31,7 @@ using System; | |||
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Console; | ||
34 | using OpenSim.Server.Base; | 35 | using OpenSim.Server.Base; |
35 | using OpenSim.Region.Framework.Interfaces; | 36 | using OpenSim.Region.Framework.Interfaces; |
36 | using OpenSim.Region.Framework.Scenes; | 37 | using OpenSim.Region.Framework.Scenes; |
@@ -47,7 +48,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
47 | LogManager.GetLogger( | 48 | LogManager.GetLogger( |
48 | MethodBase.GetCurrentMethod().DeclaringType); | 49 | MethodBase.GetCurrentMethod().DeclaringType); |
49 | 50 | ||
51 | private static LocalGridServicesConnector m_MainInstance; | ||
52 | |||
50 | private IGridService m_GridService; | 53 | private IGridService m_GridService; |
54 | private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); | ||
51 | 55 | ||
52 | private bool m_Enabled = false; | 56 | private bool m_Enabled = false; |
53 | 57 | ||
@@ -58,6 +62,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
58 | public LocalGridServicesConnector(IConfigSource source) | 62 | public LocalGridServicesConnector(IConfigSource source) |
59 | { | 63 | { |
60 | m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated"); | 64 | m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated"); |
65 | m_MainInstance = this; | ||
61 | InitialiseService(source); | 66 | InitialiseService(source); |
62 | } | 67 | } |
63 | 68 | ||
@@ -82,6 +87,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
82 | if (name == Name) | 87 | if (name == Name) |
83 | { | 88 | { |
84 | InitialiseService(source); | 89 | InitialiseService(source); |
90 | m_MainInstance = this; | ||
85 | m_Enabled = true; | 91 | m_Enabled = true; |
86 | m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled"); | 92 | m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled"); |
87 | } | 93 | } |
@@ -120,6 +126,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
120 | 126 | ||
121 | public void PostInitialise() | 127 | public void PostInitialise() |
122 | { | 128 | { |
129 | if (m_MainInstance == this) | ||
130 | { | ||
131 | MainConsole.Instance.Commands.AddCommand("LocalGridConnector", false, "show neighbours", | ||
132 | "show neighbours", | ||
133 | "Shows the local regions' neighbours", NeighboursCommand); | ||
134 | } | ||
123 | } | 135 | } |
124 | 136 | ||
125 | public void Close() | 137 | public void Close() |
@@ -128,14 +140,26 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
128 | 140 | ||
129 | public void AddRegion(Scene scene) | 141 | public void AddRegion(Scene scene) |
130 | { | 142 | { |
131 | if (!m_Enabled) | 143 | if (m_Enabled) |
132 | return; | 144 | scene.RegisterModuleInterface<IGridService>(this); |
145 | |||
146 | if (m_MainInstance == this) | ||
147 | { | ||
148 | if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID)) | ||
149 | m_log.ErrorFormat("[LOCAL GRID CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!"); | ||
150 | else | ||
151 | m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene)); | ||
133 | 152 | ||
134 | scene.RegisterModuleInterface<IGridService>(this); | 153 | } |
135 | } | 154 | } |
136 | 155 | ||
137 | public void RemoveRegion(Scene scene) | 156 | public void RemoveRegion(Scene scene) |
138 | { | 157 | { |
158 | if (m_MainInstance == this) | ||
159 | { | ||
160 | m_LocalCache[scene.RegionInfo.RegionID].Clear(); | ||
161 | m_LocalCache.Remove(scene.RegionInfo.RegionID); | ||
162 | } | ||
139 | } | 163 | } |
140 | 164 | ||
141 | public void RegionLoaded(Scene scene) | 165 | public void RegionLoaded(Scene scene) |
@@ -158,7 +182,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
158 | 182 | ||
159 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | 183 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) |
160 | { | 184 | { |
161 | return m_GridService.GetNeighbours(scopeID, regionID); | 185 | if (m_LocalCache.ContainsKey(regionID)) |
186 | { | ||
187 | return m_LocalCache[regionID].GetNeighbours(); | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | m_log.WarnFormat("[LOCAL GRID CONNECTOR]: GetNeighbours: Requested region {0} is not on this sim", regionID); | ||
192 | return new List<GridRegion>(); | ||
193 | } | ||
194 | |||
195 | // Don't go to the DB | ||
196 | //return m_GridService.GetNeighbours(scopeID, regionID); | ||
162 | } | 197 | } |
163 | 198 | ||
164 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | 199 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) |
@@ -187,5 +222,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
187 | } | 222 | } |
188 | 223 | ||
189 | #endregion | 224 | #endregion |
225 | |||
226 | public void NeighboursCommand(string module, string[] cmdparams) | ||
227 | { | ||
228 | foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache) | ||
229 | { | ||
230 | m_log.InfoFormat("*** Neighbours of {0} {1} ***", kvp.Key, kvp.Value.RegionName); | ||
231 | List<GridRegion> regions = kvp.Value.GetNeighbours(); | ||
232 | foreach (GridRegion r in regions) | ||
233 | m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); | ||
234 | } | ||
235 | } | ||
190 | } | 236 | } |
191 | } | 237 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs new file mode 100644 index 0000000..ea205a2 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs | |||
@@ -0,0 +1,52 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | |||
5 | using OpenSim.Region.Framework.Scenes; | ||
6 | using OpenSim.Services.Interfaces; | ||
7 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
8 | |||
9 | using log4net; | ||
10 | |||
11 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | ||
12 | { | ||
13 | public class RegionCache | ||
14 | { | ||
15 | private static readonly ILog m_log = | ||
16 | LogManager.GetLogger( | ||
17 | MethodBase.GetCurrentMethod().DeclaringType); | ||
18 | |||
19 | private Scene m_scene; | ||
20 | private Dictionary<ulong, GridRegion> m_neighbours = new Dictionary<ulong, GridRegion>(); | ||
21 | |||
22 | public string RegionName | ||
23 | { | ||
24 | get { return m_scene.RegionInfo.RegionName; } | ||
25 | } | ||
26 | |||
27 | public RegionCache(Scene s) | ||
28 | { | ||
29 | m_scene = s; | ||
30 | m_scene.EventManager.OnRegionUp += OnRegionUp; | ||
31 | } | ||
32 | |||
33 | private void OnRegionUp(GridRegion otherRegion) | ||
34 | { | ||
35 | m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}", | ||
36 | m_scene.RegionInfo.RegionName, otherRegion.RegionName, otherRegion.RegionLocX, otherRegion.RegionLocY); | ||
37 | |||
38 | m_neighbours[otherRegion.RegionHandle] = otherRegion; | ||
39 | } | ||
40 | |||
41 | public void Clear() | ||
42 | { | ||
43 | m_scene.EventManager.OnRegionUp -= OnRegionUp; | ||
44 | m_neighbours.Clear(); | ||
45 | } | ||
46 | |||
47 | public List<GridRegion> GetNeighbours() | ||
48 | { | ||
49 | return new List<GridRegion>(m_neighbours.Values); | ||
50 | } | ||
51 | } | ||
52 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 91a808b..72c00fc 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs | |||
@@ -104,6 +104,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
104 | 104 | ||
105 | public void PostInitialise() | 105 | public void PostInitialise() |
106 | { | 106 | { |
107 | if (m_LocalGridService != null) | ||
108 | ((ISharedRegionModule)m_LocalGridService).PostInitialise(); | ||
107 | } | 109 | } |
108 | 110 | ||
109 | public void Close() | 111 | public void Close() |
@@ -112,14 +114,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
112 | 114 | ||
113 | public void AddRegion(Scene scene) | 115 | public void AddRegion(Scene scene) |
114 | { | 116 | { |
115 | if (!m_Enabled) | 117 | if (m_Enabled) |
116 | return; | 118 | scene.RegisterModuleInterface<IGridService>(this); |
117 | 119 | ||
118 | scene.RegisterModuleInterface<IGridService>(this); | 120 | if (m_LocalGridService != null) |
121 | ((ISharedRegionModule)m_LocalGridService).AddRegion(scene); | ||
119 | } | 122 | } |
120 | 123 | ||
121 | public void RemoveRegion(Scene scene) | 124 | public void RemoveRegion(Scene scene) |
122 | { | 125 | { |
126 | if (m_LocalGridService != null) | ||
127 | ((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene); | ||
123 | } | 128 | } |
124 | 129 | ||
125 | public void RegionLoaded(Scene scene) | 130 | public void RegionLoaded(Scene scene) |
@@ -146,7 +151,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
146 | return false; | 151 | return false; |
147 | } | 152 | } |
148 | 153 | ||
149 | // Let's not override GetNeighbours -- let's get them all from the grid server | 154 | // Let's override GetNeighbours completely -- never go to the grid server |
155 | // Neighbours are/should be cached locally | ||
156 | // For retrieval from the DB, caller should call GetRegionByPosition | ||
157 | public override List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | ||
158 | { | ||
159 | return m_LocalGridService.GetNeighbours(scopeID, regionID); | ||
160 | } | ||
150 | 161 | ||
151 | public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | 162 | public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) |
152 | { | 163 | { |