*DANGER* rearange EnableChildAgents() so that hopefully it does it job

better, like not telling clients to log on regions where they are already
child
avinationmerge
UbitUmarov 2014-08-17 05:59:14 +01:00
parent 99a87f18c0
commit 8d11b96cd9
1 changed files with 90 additions and 108 deletions

View File

@ -1841,7 +1841,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
#region Enable Child Agent #region Enable Child Agent
/// <summary> /// <summary>
/// This informs a single neighbouring region about agent "avatar". /// This informs a single neighbouring region about agent "avatar", and avatar about it
/// Calls an asynchronous method to do so.. so it doesn't lag the sim. /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
/// </summary> /// </summary>
/// <param name="sp"></param> /// <param name="sp"></param>
@ -1857,8 +1857,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
agent.startpos = new Vector3(128, 128, 70); agent.startpos = new Vector3(128, 128, 70);
agent.child = true; agent.child = true;
//agent.Appearance = sp.Appearance;
//agent.Appearance = new AvatarAppearance(sp.Appearance, true, false);
agent.Appearance = new AvatarAppearance(); agent.Appearance = new AvatarAppearance();
agent.Appearance.AvatarHeight = sp.Appearance.AvatarHeight; agent.Appearance.AvatarHeight = sp.Appearance.AvatarHeight;
@ -1912,6 +1910,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
/// <summary> /// <summary>
/// This informs all neighbouring regions about agent "avatar". /// This informs all neighbouring regions about agent "avatar".
/// and as important informs the avatar about then
/// </summary> /// </summary>
/// <param name="sp"></param> /// <param name="sp"></param>
public void EnableChildAgents(ScenePresence sp) public void EnableChildAgents(ScenePresence sp)
@ -1928,58 +1927,43 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
m_log.Debug("[ENTITY TRANSFER MODULE]: m_regionInfo was null in EnableChildAgents, is this a NPC?"); m_log.Debug("[ENTITY TRANSFER MODULE]: m_regionInfo was null in EnableChildAgents, is this a NPC?");
} }
/// We need to find the difference between the new regions where there are no child agents LinkedList<ulong> previousRegionNeighbourHandles;
/// and the regions where there are already child agents. We only send notification to the former.
List<ulong> neighbourHandles = NeighbourHandles(neighbours); // on this region
neighbourHandles.Add(sp.Scene.RegionInfo.RegionHandle); // add this region too
List<ulong> previousRegionNeighbourHandles;
if (sp.Scene.CapsModule != null)
{
previousRegionNeighbourHandles =
new List<ulong>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID).Keys);
}
else
{
previousRegionNeighbourHandles = new List<ulong>();
}
List<ulong> newRegions = NewNeighbours(neighbourHandles, previousRegionNeighbourHandles);
List<ulong> oldRegions = OldNeighbours(neighbourHandles, previousRegionNeighbourHandles);
// Dump("Current Neighbors", neighbourHandles);
// Dump("Previous Neighbours", previousRegionNeighbourHandles);
// Dump("New Neighbours", newRegions);
// Dump("Old Neighbours", oldRegions);
/// Update the scene presence's known regions here on this region
sp.DropOldNeighbours(oldRegions);
/// Collect as many seeds as possible
Dictionary<ulong, string> seeds; Dictionary<ulong, string> seeds;
if (sp.Scene.CapsModule != null)
seeds = new Dictionary<ulong, string>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID));
else
seeds = new Dictionary<ulong, string>();
//m_log.Debug(" !!! No. of seeds: " + seeds.Count); if (sp.Scene.CapsModule != null)
{
seeds = new Dictionary<ulong, string>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID));
previousRegionNeighbourHandles = new LinkedList<ulong>(seeds.Keys);
}
else
{
seeds = new Dictionary<ulong, string>();
previousRegionNeighbourHandles = new LinkedList<ulong>();
}
if (!seeds.ContainsKey(sp.Scene.RegionInfo.RegionHandle)) if (!seeds.ContainsKey(sp.Scene.RegionInfo.RegionHandle))
seeds.Add(sp.Scene.RegionInfo.RegionHandle, sp.ControllingClient.RequestClientInfo().CapsPath); seeds.Add(sp.Scene.RegionInfo.RegionHandle, sp.ControllingClient.RequestClientInfo().CapsPath);
/// Create the necessary child agents AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
List<ulong> newneighbours = new List<ulong>();
List<AgentCircuitData> cagents = new List<AgentCircuitData>(); List<AgentCircuitData> cagents = new List<AgentCircuitData>();
ulong currentRegionHandler = sp.Scene.RegionInfo.RegionHandle;
foreach (GridRegion neighbour in neighbours) foreach (GridRegion neighbour in neighbours)
{ {
if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle) ulong handler = neighbour.RegionHandle;
{
AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); if (handler == currentRegionHandler)
continue;
AgentCircuitData agent = sp.ControllingClient.RequestClientInfo(); AgentCircuitData agent = sp.ControllingClient.RequestClientInfo();
agent.BaseFolder = UUID.Zero; agent.BaseFolder = UUID.Zero;
agent.InventoryFolder = UUID.Zero; agent.InventoryFolder = UUID.Zero;
agent.startpos = sp.AbsolutePosition + CalculateOffset(sp, neighbour); agent.startpos = sp.AbsolutePosition + CalculateOffset(sp, neighbour);
agent.child = true; agent.child = true;
// agent.Appearance = sp.Appearance;
// agent.Appearance = new AvatarAppearance(sp.Appearance, true, false);
agent.Appearance = new AvatarAppearance(); agent.Appearance = new AvatarAppearance();
agent.Appearance.AvatarHeight = sp.Appearance.AvatarHeight; agent.Appearance.AvatarHeight = sp.Appearance.AvatarHeight;
@ -1993,19 +1977,27 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
agent.Id0 = currentAgentCircuit.Id0; agent.Id0 = currentAgentCircuit.Id0;
} }
if (newRegions.Contains(neighbour.RegionHandle)) if (previousRegionNeighbourHandles.Contains(handler))
{ {
agent.CapsPath = CapsUtil.GetRandomCapsObjectPath(); previousRegionNeighbourHandles.Remove(handler);
sp.AddNeighbourRegion(neighbour.RegionHandle, agent.CapsPath); agent.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, handler);
seeds.Add(neighbour.RegionHandle, agent.CapsPath);
} }
else else
{ {
agent.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, neighbour.RegionHandle); newneighbours.Add(handler);
agent.CapsPath = CapsUtil.GetRandomCapsObjectPath();
sp.AddNeighbourRegion(handler, agent.CapsPath);
seeds.Add(handler, agent.CapsPath);
} }
cagents.Add(agent); cagents.Add(agent);
} }
//sp.DropOldNeighbours(previousRegionNeighbourHandles);
foreach (ulong handle in previousRegionNeighbourHandles)
{
sp.RemoveNeighbourRegion(handle);
Scene.CapsModule.DropChildSeed(sp.UUID, handle);
} }
/// Update all child agent with everyone's seeds /// Update all child agent with everyone's seeds
@ -2018,32 +2010,23 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
{ {
sp.Scene.CapsModule.SetChildrenSeed(sp.UUID, seeds); sp.Scene.CapsModule.SetChildrenSeed(sp.UUID, seeds);
} }
sp.KnownRegions = seeds; sp.KnownRegions = seeds;
//avatar.Scene.DumpChildrenSeeds(avatar.UUID); //avatar.Scene.DumpChildrenSeeds(avatar.UUID);
//avatar.DumpKnownRegions(); //avatar.DumpKnownRegions();
Util.FireAndForget(delegate Util.FireAndForget(delegate
{ {
/// 5000 is BAD test Thread.Sleep(200); // the original delay that was at InformClientOfNeighbourAsync start
Thread.Sleep(5000); // the original delay that was at InformClientOfNeighbourAsync start
int count = 0; int count = 0;
bool newAgent = false; bool newagent;
foreach (GridRegion neighbour in neighbours) foreach (GridRegion neighbour in neighbours)
{
//m_log.WarnFormat("--> Going to send child agent to {0}", neighbour.RegionName);
// Don't do it if there's already an agent in that region
if (newRegions.Contains(neighbour.RegionHandle))
newAgent = true;
else
newAgent = false;
// continue;
if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle)
{ {
try try
{ {
InformClientOfNeighbourAsync(sp, cagents[count], neighbour, neighbour.ExternalEndPoint, newAgent); newagent = newneighbours.Contains(neighbour.RegionHandle);
InformClientOfNeighbourAsync(sp, cagents[count], neighbour, neighbour.ExternalEndPoint, newagent);
} }
catch (ArgumentOutOfRangeException) catch (ArgumentOutOfRangeException)
@ -2071,7 +2054,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
// XXX: Well, decided to swallow the exception instead for now. Let us see how that goes. // XXX: Well, decided to swallow the exception instead for now. Let us see how that goes.
// throw e; // throw e;
} }
}
count++; count++;
} }
}); });