diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid')
6 files changed, 428 insertions, 44 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..148331b 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)) |
@@ -539,8 +554,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
539 | x = (int)(ux / Constants.RegionSize); | 554 | x = (int)(ux / Constants.RegionSize); |
540 | y = (int)(uy / Constants.RegionSize); | 555 | y = (int)(uy / Constants.RegionSize); |
541 | 556 | ||
542 | if ((Math.Abs((int)(m_scene.RegionInfo.RegionLocX / Constants.RegionSize) - x) >= 4096) || | 557 | if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - x) >= 4096) || |
543 | (Math.Abs((int)(m_scene.RegionInfo.RegionLocY / Constants.RegionSize) - y) >= 4096)) | 558 | (Math.Abs((int)m_scene.RegionInfo.RegionLocY - y) >= 4096)) |
544 | { | 559 | { |
545 | return false; | 560 | return false; |
546 | } | 561 | } |
@@ -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..3ca4882 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,25 @@ 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); |
133 | 145 | ||
134 | scene.RegisterModuleInterface<IGridService>(this); | 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)); | ||
152 | } | ||
135 | } | 153 | } |
136 | 154 | ||
137 | public void RemoveRegion(Scene scene) | 155 | public void RemoveRegion(Scene scene) |
138 | { | 156 | { |
157 | if (m_MainInstance == this) | ||
158 | { | ||
159 | m_LocalCache[scene.RegionInfo.RegionID].Clear(); | ||
160 | m_LocalCache.Remove(scene.RegionInfo.RegionID); | ||
161 | } | ||
139 | } | 162 | } |
140 | 163 | ||
141 | public void RegionLoaded(Scene scene) | 164 | public void RegionLoaded(Scene scene) |
@@ -158,7 +181,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
158 | 181 | ||
159 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | 182 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) |
160 | { | 183 | { |
161 | return m_GridService.GetNeighbours(scopeID, regionID); | 184 | if (m_LocalCache.ContainsKey(regionID)) |
185 | { | ||
186 | List<GridRegion> neighbours = m_LocalCache[regionID].GetNeighbours(); | ||
187 | if (neighbours.Count == 0) | ||
188 | // try the DB | ||
189 | neighbours = m_GridService.GetNeighbours(scopeID, regionID); | ||
190 | return neighbours; | ||
191 | } | ||
192 | else | ||
193 | { | ||
194 | m_log.WarnFormat("[LOCAL GRID CONNECTOR]: GetNeighbours: Requested region {0} is not on this sim", regionID); | ||
195 | return new List<GridRegion>(); | ||
196 | } | ||
197 | |||
198 | // Don't go to the DB | ||
199 | //return m_GridService.GetNeighbours(scopeID, regionID); | ||
162 | } | 200 | } |
163 | 201 | ||
164 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | 202 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) |
@@ -187,5 +225,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
187 | } | 225 | } |
188 | 226 | ||
189 | #endregion | 227 | #endregion |
228 | |||
229 | public void NeighboursCommand(string module, string[] cmdparams) | ||
230 | { | ||
231 | foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache) | ||
232 | { | ||
233 | m_log.InfoFormat("*** Neighbours of {0} {1} ***", kvp.Key, kvp.Value.RegionName); | ||
234 | List<GridRegion> regions = kvp.Value.GetNeighbours(); | ||
235 | foreach (GridRegion r in regions) | ||
236 | m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); | ||
237 | } | ||
238 | } | ||
190 | } | 239 | } |
191 | } | 240 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs new file mode 100644 index 0000000..2b336bb --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs | |||
@@ -0,0 +1,79 @@ | |||
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.Reflection; | ||
31 | |||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
35 | |||
36 | using log4net; | ||
37 | |||
38 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | ||
39 | { | ||
40 | public class RegionCache | ||
41 | { | ||
42 | private static readonly ILog m_log = | ||
43 | LogManager.GetLogger( | ||
44 | MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | private Scene m_scene; | ||
47 | private Dictionary<ulong, GridRegion> m_neighbours = new Dictionary<ulong, GridRegion>(); | ||
48 | |||
49 | public string RegionName | ||
50 | { | ||
51 | get { return m_scene.RegionInfo.RegionName; } | ||
52 | } | ||
53 | |||
54 | public RegionCache(Scene s) | ||
55 | { | ||
56 | m_scene = s; | ||
57 | m_scene.EventManager.OnRegionUp += OnRegionUp; | ||
58 | } | ||
59 | |||
60 | private void OnRegionUp(GridRegion otherRegion) | ||
61 | { | ||
62 | m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}", | ||
63 | m_scene.RegionInfo.RegionName, otherRegion.RegionName, otherRegion.RegionLocX, otherRegion.RegionLocY); | ||
64 | |||
65 | m_neighbours[otherRegion.RegionHandle] = otherRegion; | ||
66 | } | ||
67 | |||
68 | public void Clear() | ||
69 | { | ||
70 | m_scene.EventManager.OnRegionUp -= OnRegionUp; | ||
71 | m_neighbours.Clear(); | ||
72 | } | ||
73 | |||
74 | public List<GridRegion> GetNeighbours() | ||
75 | { | ||
76 | return new List<GridRegion>(m_neighbours.Values); | ||
77 | } | ||
78 | } | ||
79 | } | ||
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 | { |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs index be32d6b..2ca90f8 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs | |||
@@ -78,6 +78,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests | |||
78 | r1.ExternalHostName = "127.0.0.1"; | 78 | r1.ExternalHostName = "127.0.0.1"; |
79 | r1.HttpPort = 9001; | 79 | r1.HttpPort = 9001; |
80 | r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); | 80 | r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); |
81 | Scene s = new Scene(new RegionInfo()); | ||
82 | s.RegionInfo.RegionID = r1.RegionID; | ||
83 | m_LocalConnector.AddRegion(s); | ||
84 | |||
81 | 85 | ||
82 | GridRegion r2 = new GridRegion(); | 86 | GridRegion r2 = new GridRegion(); |
83 | r2.RegionName = "Test Region 2"; | 87 | r2.RegionName = "Test Region 2"; |
@@ -87,6 +91,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests | |||
87 | r2.ExternalHostName = "127.0.0.1"; | 91 | r2.ExternalHostName = "127.0.0.1"; |
88 | r2.HttpPort = 9002; | 92 | r2.HttpPort = 9002; |
89 | r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); | 93 | r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); |
94 | s = new Scene(new RegionInfo()); | ||
95 | s.RegionInfo.RegionID = r1.RegionID; | ||
96 | m_LocalConnector.AddRegion(s); | ||
90 | 97 | ||
91 | GridRegion r3 = new GridRegion(); | 98 | GridRegion r3 = new GridRegion(); |
92 | r3.RegionName = "Test Region 3"; | 99 | r3.RegionName = "Test Region 3"; |
@@ -96,6 +103,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests | |||
96 | r3.ExternalHostName = "127.0.0.1"; | 103 | r3.ExternalHostName = "127.0.0.1"; |
97 | r3.HttpPort = 9003; | 104 | r3.HttpPort = 9003; |
98 | r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); | 105 | r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); |
106 | s = new Scene(new RegionInfo()); | ||
107 | s.RegionInfo.RegionID = r1.RegionID; | ||
108 | m_LocalConnector.AddRegion(s); | ||
99 | 109 | ||
100 | m_LocalConnector.RegisterRegion(UUID.Zero, r1); | 110 | m_LocalConnector.RegisterRegion(UUID.Zero, r1); |
101 | GridRegion result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test"); | 111 | GridRegion result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test"); |