Moved all HG1 operations to HGGridConnector.cs and HypergridServerConnector.cs/HypergridServiceConnector.cs, away from Region.Communications and HGNetworkServersInfo.

Fixed small bugs with hyperlinked regions' map positions.
This commit is contained in:
Diva Canto
2009-09-26 21:00:51 -07:00
parent dcfd08b8dd
commit f4bf581b96
14 changed files with 538 additions and 101 deletions

View File

@@ -37,6 +37,7 @@ using OpenSim.Region.Framework.Interfaces;
using OpenSim.Server.Base;
using OpenSim.Server.Handlers.Base;
using OpenSim.Server.Handlers.Grid;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid
@@ -95,20 +96,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid
if (!m_Enabled)
return;
if (!m_Registered)
{
m_Registered = true;
m_log.Info("[HypergridService]: Starting...");
Object[] args = new Object[] { m_Config, MainServer.Instance };
m_HypergridHandler = new HypergridServiceInConnector(m_Config, MainServer.Instance);
//ServerUtils.LoadPlugin<HypergridServiceInConnector>("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args);
}
GridRegion rinfo = new GridRegion(scene.RegionInfo);
m_HypergridHandler.AddRegion(rinfo);
}
public void RemoveRegion(Scene scene)
@@ -122,6 +109,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid
public void RegionLoaded(Scene scene)
{
if (!m_Registered)
{
m_Registered = true;
m_log.Info("[HypergridService]: Starting...");
Object[] args = new Object[] { m_Config, MainServer.Instance };
m_HypergridHandler = new HypergridServiceInConnector(m_Config, MainServer.Instance, scene.RequestModuleInterface<IHyperlinkService>());
//ServerUtils.LoadPlugin<HypergridServiceInConnector>("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args);
}
GridRegion rinfo = new GridRegion(scene.RegionInfo);
m_HypergridHandler.AddRegion(rinfo);
}
#endregion

View File

@@ -31,6 +31,7 @@ using System.Net;
using System.Reflection;
using System.Xml;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@@ -52,10 +53,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private static string LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI;
private bool m_Enabled = false;
private bool m_Initialized = false;
private Scene m_aScene;
private Dictionary<ulong, Scene> m_LocalScenes = new Dictionary<ulong, Scene>();
private IGridService m_GridServiceConnector;
private HypergridServiceConnector m_HypergridServiceConnector;
@@ -141,6 +146,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
if (!m_Enabled)
return;
m_LocalScenes[scene.RegionInfo.RegionHandle] = scene;
scene.RegisterModuleInterface<IGridService>(this);
scene.RegisterModuleInterface<IHyperlinkService>(this);
@@ -148,6 +154,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
public void RemoveRegion(Scene scene)
{
m_LocalScenes.Remove(scene.RegionInfo.RegionHandle);
}
public void RegionLoaded(Scene scene)
@@ -157,7 +164,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
if (!m_Initialized)
{
m_aScene = scene;
LocalAssetServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL;
LocalInventoryServerURI = m_aScene.CommsManager.NetworkServersInfo.InventoryURL;
LocalUserServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL;
m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService);
HGCommands hgCommands = new HGCommands(this, scene);
MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region",
"link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
@@ -167,6 +180,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
"Unlink a hypergrid region", hgCommands.RunCommand);
MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [<x> <y>] <cr>",
"Set local coordinate to map HG regions to", hgCommands.RunCommand);
// Yikes!! Remove this as soon as user services get refactored
HGNetworkServersInfo.Init(LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI);
m_Initialized = true;
}
}
@@ -240,7 +257,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
// Try the foreign users home collection
foreach (GridRegion r in m_knownRegions.Values)
if (r.RegionID == regionID)
return m_knownRegions[regionID];
return r;
// Finally, try the normal route
return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID);
@@ -261,7 +278,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
foreach (GridRegion r in m_knownRegions.Values)
{
if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
{
return r;
}
}
// Finally, try the normal route
@@ -328,8 +347,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
{
m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo);
m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle);
m_HyperlinkRegions[regionInfo.RegionID] = regionInfo;
m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
}
private void RemoveHyperlinkRegion(UUID regionID)
@@ -340,8 +359,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle)
{
m_knownRegions.Add(userID, regionInfo);
m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle);
m_knownRegions[userID] = regionInfo;
m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
}
private void RemoveHyperlinkHomeRegion(UUID regionID)
@@ -412,7 +431,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
// From the map search and secondlife://blah
public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName)
{
int xloc = random.Next(0, Int16.MaxValue);
int xloc = random.Next(0, Int16.MaxValue) * (int) Constants.RegionSize;
return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0);
}
@@ -563,10 +582,206 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
foreach (GridRegion r in m_HyperlinkRegions.Values)
if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID)))
return m_HyperlinkHandles[r.RegionID];
foreach (GridRegion r in m_knownRegions.Values)
if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID)))
return m_HyperlinkHandles[r.RegionID];
return handle;
}
public bool SendUserInformation(GridRegion regInfo, AgentCircuitData agentData)
{
CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID);
if ((IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) ||
(!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo)))
{
m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere");
// Set the position of the region on the remote grid
ulong realHandle = FindRegionHandle(regInfo.RegionHandle);
uint x = 0, y = 0;
Utils.LongToUInts(regInfo.RegionHandle, out x, out y);
GridRegion clonedRegion = new GridRegion(regInfo);
clonedRegion.RegionLocX = (int)x;
clonedRegion.RegionLocY = (int)y;
// Get the user's home region information
GridRegion home = m_aScene.GridService.GetRegionByUUID(m_aScene.RegionInfo.ScopeID, uinfo.UserProfile.HomeRegionID);
// Get the user's service URLs
string serverURI = "";
if (uinfo.UserProfile is ForeignUserProfileData)
serverURI = Util.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
string userServer = (serverURI == "") || (serverURI == null) ? LocalUserServerURI : serverURI;
string assetServer = Util.ServerURI(uinfo.UserProfile.UserAssetURI);
if ((assetServer == null) || (assetServer == ""))
assetServer = LocalAssetServerURI;
string inventoryServer = Util.ServerURI(uinfo.UserProfile.UserInventoryURI);
if ((inventoryServer == null) || (inventoryServer == ""))
inventoryServer = LocalInventoryServerURI;
if (!m_HypergridServiceConnector.InformRegionOfUser(clonedRegion, agentData, home, userServer, assetServer, inventoryServer))
{
m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
return false;
}
}
//if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
//{
// m_log.Info("[HGrid]: User seems to be going to foreign region.");
// if (!InformRegionOfUser(regInfo, agentData))
// {
// m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
// return false;
// }
//}
//else
// m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
// May need to change agent's name
if (IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null))
{
agentData.firstname = agentData.firstname + "." + agentData.lastname;
agentData.lastname = "@" + LocalUserServerURI.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
}
return true;
}
public void AdjustUserInformation(AgentCircuitData agentData)
{
CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID);
if ((uinfo != null) && (uinfo.UserProfile != null) &&
(IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData)))
{
//m_log.Debug("---------------> Local User!");
string[] parts = agentData.firstname.Split(new char[] { '.' });
if (parts.Length == 2)
{
agentData.firstname = parts[0];
agentData.lastname = parts[1];
}
}
//else
// m_log.Debug("---------------> Foreign User!");
}
// Check if a local user exists with the same UUID as the incoming foreign user
public bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome)
{
comingHome = false;
if (!m_aScene.SceneGridService.RegionLoginsEnabled)
return false;
CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
if (uinfo != null)
{
// uh-oh we have a potential intruder
if (uinfo.SessionID != sessionID)
// can't have a foreigner with a local UUID
return false;
else
// oh, so it's you! welcome back
comingHome = true;
}
// OK, user can come in
return true;
}
public void AcceptUser(ForeignUserProfileData user, GridRegion home)
{
m_aScene.CommsManager.UserProfileCacheService.PreloadUserCache(user);
ulong realHandle = home.RegionHandle;
// Change the local coordinates
// X=0 on the map
home.RegionLocX = 0;
home.RegionLocY = random.Next(0, 10000) * (int)Constants.RegionSize;
AddHyperlinkHomeRegion(user.ID, home, realHandle);
DumpUserData(user);
DumpRegionData(home);
}
public bool IsLocalUser(UUID userID)
{
CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
return IsLocalUser(uinfo);
}
#endregion
#region IHyperlink Misc
protected bool IsComingHome(ForeignUserProfileData userData)
{
return (userData.UserServerURI == LocalUserServerURI);
}
// Is the user going back to the home region or the home grid?
protected bool IsGoingHome(CachedUserInfo uinfo, GridRegion rinfo)
{
if (uinfo.UserProfile == null)
return false;
if (!(uinfo.UserProfile is ForeignUserProfileData))
// it's a home user, can't be outside to return home
return false;
// OK, it's a foreign user with a ForeignUserProfileData
// and is going back to exactly the home region.
// We can't check if it's going back to a non-home region
// of the home grid. That will be dealt with in the
// receiving end
return (uinfo.UserProfile.HomeRegionID == rinfo.RegionID);
}
protected bool IsLocalUser(CachedUserInfo uinfo)
{
if (uinfo == null)
return false;
return !(uinfo.UserProfile is ForeignUserProfileData);
}
protected bool IsLocalRegion(ulong handle)
{
return m_LocalScenes.ContainsKey(handle);
}
private void DumpUserData(ForeignUserProfileData userData)
{
m_log.Info(" ------------ User Data Dump ----------");
m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName);
m_log.Info(" >> HomeID: " + userData.HomeRegionID);
m_log.Info(" >> UserServer: " + userData.UserServerURI);
m_log.Info(" >> InvServer: " + userData.UserInventoryURI);
m_log.Info(" >> AssetServer: " + userData.UserAssetURI);
m_log.Info(" ------------ -------------- ----------");
}
private void DumpRegionData(GridRegion rinfo)
{
m_log.Info(" ------------ Region Data Dump ----------");
m_log.Info(" >> handle: " + rinfo.RegionHandle);
m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY);
m_log.Info(" >> external host name: " + rinfo.ExternalHostName);
m_log.Info(" >> http port: " + rinfo.HttpPort);
m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address);
m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port);
m_log.Info(" ------------ -------------- ----------");
}
#endregion
}
}

View File

@@ -824,29 +824,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion
public override void SendUserInformation(GridRegion regInfo, AgentCircuitData aCircuit)
{
try
{
if (m_aScene.SceneGridService is HGSceneCommunicationService)
{
// big hack for now
RegionInfo r = new RegionInfo();
r.ExternalHostName = regInfo.ExternalHostName;
r.HttpPort = regInfo.HttpPort;
r.RegionID = regInfo.RegionID;
r.RegionLocX = (uint)regInfo.RegionLocX;
r.RegionLocY = (uint)regInfo.RegionLocY;
((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(r, aCircuit);
}
}
catch // Bad cast
{ }
if (m_hyperlinkService != null)
m_hyperlinkService.SendUserInformation(regInfo, aCircuit);
}
public override void AdjustUserInformation(AgentCircuitData aCircuit)
{
if (m_aScene.SceneGridService is HGSceneCommunicationService)
((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit);
if (m_hyperlinkService != null)
m_hyperlinkService.AdjustUserInformation(aCircuit);
}
}

View File

@@ -525,7 +525,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
return true;
}
string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
if ((uinfo.UserProfile.UserInventoryURI == null) || (uinfo.UserProfile.UserInventoryURI == ""))
// this happens in standalone profiles, apparently
return true;
string userInventoryServerURI = Util.ServerURI(uinfo.UserProfile.UserInventoryURI);
string uri = m_LocalGridInventoryURI.TrimEnd('/');
if ((userInventoryServerURI == uri) || (userInventoryServerURI == ""))
@@ -544,7 +549,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
if ((uinfo == null) || (uinfo.UserProfile == null))
return invURI;
string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
string userInventoryServerURI = Util.ServerURI(uinfo.UserProfile.UserInventoryURI);
if ((userInventoryServerURI != null) &&
(userInventoryServerURI != ""))

View File

@@ -137,8 +137,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
data.Name = info.RegionName;
data.RegionFlags = 0; // TODO not used?
data.WaterHeight = 0; // not used
data.X = (ushort)info.RegionLocX;
data.Y = (ushort)info.RegionLocY;
data.X = (ushort)(info.RegionLocX / Constants.RegionSize);
data.Y = (ushort)(info.RegionLocY / Constants.RegionSize);
blocks.Add(data);
}
}