From e6eb571c1d19972fe7eb4c3f7de113b1b91f5e02 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sun, 14 Dec 2008 02:17:12 +0000 Subject: Mantis#2725. Thank you kindly, Diva, for a patch that: Adds missing protocol pieces for EstablishAgentCommunication event which allows the client to activate CAPS and the EQ for child agents. --- OpenSim/Region/Environment/Scenes/ScenePresence.cs | 129 ++++++++++++++++----- 1 file changed, 101 insertions(+), 28 deletions(-) (limited to 'OpenSim/Region/Environment/Scenes/ScenePresence.cs') diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 3bd6be9..f139ba5 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -188,8 +188,9 @@ namespace OpenSim.Region.Environment.Scenes protected List m_attachments = new List(); - //neighbouring regions we have enabled a child agent in - private readonly List m_knownChildRegions = new List(); + // neighbouring regions we have enabled a child agent in + // holds the seed cap for the child agent in that region + private Dictionary m_knownChildRegions = new Dictionary(); /// /// Implemented Control Flags @@ -483,9 +484,38 @@ namespace OpenSim.Region.Environment.Scenes /// /// These are the region handles known by the avatar. /// - public List KnownChildRegions + public List KnownChildRegionHandles + { + get + { + if (m_knownChildRegions.Count == 0) + return new List(); + else + return new List(m_knownChildRegions.Keys); + } + } + + public Dictionary KnownRegions { get { return m_knownChildRegions; } + set + { + //Console.WriteLine(" !! Setting known regions in {0} to {1}", Scene.RegionInfo.RegionName, value.Count); + m_knownChildRegions = value; + } + } + + public void DumpKnownRegions() + { + Console.WriteLine("================ KnownRegions {0} ================", Scene.RegionInfo.RegionName); + foreach (KeyValuePair kvp in KnownRegions) + { + uint x, y; + Utils.LongToUInts(kvp.Key, out x, out y); + x = x / Constants.RegionSize; + y = y / Constants.RegionSize; + Console.WriteLine(" >> {0}, {1}: {2}", x, y, kvp.Value); + } } public AnimationSet Animations @@ -529,6 +559,8 @@ namespace OpenSim.Region.Environment.Scenes CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid); if (userInfo != null) userInfo.OnItemReceived += ItemReceived; + + m_log.Info("[AVATAR]: New ScenePresence in " + Scene.RegionInfo.RegionName); } public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, @@ -742,7 +774,9 @@ namespace OpenSim.Region.Environment.Scenes m_log.DebugFormat( "[SCENE]: Upgrading child to root agent for {0} in {1}", Name, m_scene.RegionInfo.RegionName); - + + m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); + IGroupsModule gm = m_scene.RequestModuleInterface(); if (gm != null) m_grouptitle = gm.GetGroupTitle(m_uuid); @@ -881,25 +915,43 @@ namespace OpenSim.Region.Environment.Scenes SendFullUpdateToAllClients(); } - public void AddNeighbourRegion(ulong regionHandle) + public void AddNeighbourRegion(ulong regionHandle, string cap) { - if (!m_knownChildRegions.Contains(regionHandle)) + lock (m_knownChildRegions) { - m_knownChildRegions.Add(regionHandle); + if (!m_knownChildRegions.ContainsKey(regionHandle)) + { + uint x, y; + Utils.LongToUInts(regionHandle, out x, out y); + m_knownChildRegions.Add(regionHandle, cap); + } } } public void RemoveNeighbourRegion(ulong regionHandle) { - if (m_knownChildRegions.Contains(regionHandle)) + lock (m_knownChildRegions) { - m_knownChildRegions.Remove(regionHandle); + if (m_knownChildRegions.ContainsKey(regionHandle)) + { + m_knownChildRegions.Remove(regionHandle); + //Console.WriteLine(" !!! removing known region {0} in {1}. Count = {2}", regionHandle, Scene.RegionInfo.RegionName, m_knownChildRegions.Count); + } + } + } + + public void DropOldNeighbours(List oldRegions) + { + foreach (ulong handle in oldRegions) + { + RemoveNeighbourRegion(handle); + Scene.DropChildSeed(UUID, handle); } } public List GetKnownRegionList() { - return m_knownChildRegions; + return new List(m_knownChildRegions.Keys); } #endregion @@ -1856,6 +1908,7 @@ namespace OpenSim.Region.Environment.Scenes #region Overridden Methods + int x = 0; public override void Update() { SendPrimUpdates(); @@ -1896,6 +1949,9 @@ namespace OpenSim.Region.Environment.Scenes CheckForBorderCrossing(); CheckForSignificantMovement(); // sends update to the modules. } + + //if ((x++ % 30) == 0) + // Console.WriteLine(" >> In {0} known regions: {0}, seeds:{1}", Scene.RegionInfo.RegionName, KnownRegions.Count, Scene.GetChildrenSeeds(UUID)); } #endregion @@ -2338,7 +2394,7 @@ namespace OpenSim.Region.Environment.Scenes // When the neighbour is informed of the border crossing, it will set up CAPS handlers for the avatar // This means we need to remove the current caps handler here and possibly compensate later, // in case both scenes are being hosted on the same region server. Messy - m_scene.RemoveCapsHandler(UUID); + //m_scene.RemoveCapsHandler(UUID); newpos = newpos + (vel); CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(UUID); @@ -2358,10 +2414,14 @@ namespace OpenSim.Region.Environment.Scenes { AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo(); + //Console.WriteLine("BEFORE CROSS"); + //Scene.DumpChildrenSeeds(UUID); + //DumpKnownRegions(); + // TODO Should construct this behind a method string capsPath = "http://" + neighbourRegion.ExternalHostName + ":" + neighbourRegion.HttpPort - + "/CAPS/" + circuitdata.CapsPath + "0000/"; + + "/CAPS/" + m_knownChildRegions[neighbourRegion.RegionHandle] /*circuitdata.CapsPath*/ + "0000/"; m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, m_uuid); @@ -2386,6 +2446,8 @@ namespace OpenSim.Region.Environment.Scenes CrossAttachmentsIntoNewRegion(neighbourHandle, true); // m_scene.SendKillObject(m_localId); + // Next, let's close the child agent connections that are too far away. + CloseChildAgents(neighbourx, neighboury); m_scene.NotifyMyCoarseLocationChange(); // the user may change their profile information in other region, @@ -2401,6 +2463,11 @@ namespace OpenSim.Region.Environment.Scenes m_scene.AddCapsHandler(UUID); } } + + //Console.WriteLine("AFTER CROSS"); + //Scene.DumpChildrenSeeds(UUID); + //DumpKnownRegions(); + } /// @@ -2413,31 +2480,36 @@ namespace OpenSim.Region.Environment.Scenes public void CloseChildAgents(uint newRegionX, uint newRegionY) { List byebyeRegions = new List(); + m_log.DebugFormat("[AVATAR]: Closing child agents. Checking {0} regions in {1}", m_knownChildRegions.Keys.Count, Scene.RegionInfo.RegionName); + //DumpKnownRegions(); - foreach (ulong handle in m_knownChildRegions) + lock (m_knownChildRegions) { - uint x, y; - Utils.LongToUInts(handle, out x, out y); - x = x / Constants.RegionSize; - y = y / Constants.RegionSize; - - if (Util.IsOutsideView(x, newRegionX, y, newRegionY)) + foreach (ulong handle in m_knownChildRegions.Keys) { - Console.WriteLine("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs(x-newRegionX)); - Console.WriteLine("---> y: " + y + "; newy:" + newRegionY); - byebyeRegions.Add(handle); + uint x, y; + Utils.LongToUInts(handle, out x, out y); + x = x / Constants.RegionSize; + y = y / Constants.RegionSize; + + //Console.WriteLine("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); + //Console.WriteLine("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); + if (Util.IsOutsideView(x, newRegionX, y, newRegionY)) + { + byebyeRegions.Add(handle); + } } } - foreach (ulong handle in byebyeRegions) - { - RemoveNeighbourRegion(handle); - } - if (byebyeRegions.Count > 0) { m_log.Info("[AVATAR]: Closing " + byebyeRegions.Count + " child agents"); m_scene.SceneGridService.SendCloseChildAgentConnections(m_controllingClient.AgentId, byebyeRegions); } + foreach (ulong handle in byebyeRegions) + { + RemoveNeighbourRegion(handle); + } + } @@ -2940,7 +3012,8 @@ namespace OpenSim.Region.Environment.Scenes m_DrawDistance = (float)info.GetValue("m_DrawDistance", typeof(float)); m_appearance = (AvatarAppearance)info.GetValue("m_appearance", typeof(AvatarAppearance)); - m_knownChildRegions = (List)info.GetValue("m_knownChildRegions", typeof(List)); + + m_knownChildRegions = (Dictionary)info.GetValue("m_knownChildRegions", typeof(Dictionary)); posLastSignificantMove = new Vector3( -- cgit v1.1