From d9fb48cdcffbdcece3a68727e1a986fec8fab5db Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 17 Apr 2022 22:26:41 +0100 Subject: [PATCH] ok add 2 much, so now the rest --- .../EntityTransfer/EntityTransferModule.cs | 68 ++++++-------- .../EntityTransfer/HGEntityTransferModule.cs | 89 +++++++++++++++++++ .../Interfaces/IEntityTransferModule.cs | 1 + OpenSim/Region/Framework/Scenes/Scene.cs | 15 ++++ .../Region/Framework/Scenes/ScenePresence.cs | 12 ++- 5 files changed, 144 insertions(+), 41 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index e565e01202..2455f07393 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -2737,45 +2737,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return successYN; } - /// - /// Cross the attachments for an avatar into the destination region. - /// - /// - /// This is only invoked for simulators released prior to April 2011. Versions of OpenSimulator since then - /// transfer attachments in one go as part of the ChildAgentDataUpdate data passed in the update agent call. - /// - /// - /// - /// - protected void CrossAttachmentsIntoNewRegion(GridRegion destination, ScenePresence sp, bool silent) - { - List attachments = sp.GetAttachments(); - -// m_log.DebugFormat( -// "[ENTITY TRANSFER MODULE]: Crossing {0} attachments into {1} for {2}", -// m_attachments.Count, destination.RegionName, sp.Name); - - foreach (SceneObjectGroup gobj in attachments) - { - // If the prim group is null then something must have happened to it! - if (gobj != null && !gobj.IsDeleted) - { - SceneObjectGroup clone = (SceneObjectGroup)gobj.CloneForNewScene(); - clone.RootPart.GroupPosition = gobj.RootPart.AttachedPos; - clone.IsAttachment = false; - - //gobj.RootPart.LastOwnerID = gobj.GetFromAssetID(); - m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: Sending attachment {0} to region {1}", - clone.UUID, destination.RegionName); - - CrossPrimGroupIntoNewRegion(destination, Vector3.Zero, clone, silent,true); - } - } - - sp.ClearAttachments(); - } - #endregion #region Misc @@ -2797,7 +2758,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if (i < sp.InTransitScriptStates.Count) { sog.SetState(sp.InTransitScriptStates[i++], sp.Scene); - sog.CreateScriptInstances(0, false, sp.Scene.DefaultScriptEngine, 0); + sog.CreateScriptInstances(0, false, sp.Scene.DefaultScriptEngine, -1); sog.ResumeScripts(); } else @@ -2866,6 +2827,33 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return true; } + public virtual bool HandleIncomingAttachments(ScenePresence sp, List attachments) + { + if (sp.IsDeleted) + return false; + + if (m_sceneRegionInfo.EstateSettings.IsBanned(sp.UUID)) + { + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: Denied Attachments for banned avatar {0}", sp.Name); + return false; + } + + foreach(SceneObjectGroup so in attachments) + { + if (!m_scene.AddSceneObject(so)) + { + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: Problem adding attachment {0} {1} into {2} ", + so.Name, so.UUID, m_sceneName); + continue; + } + } + + sp.GotAttachmentsData = true; + return true; + } + private int GetStateSource(SceneObjectGroup sog) { ScenePresence sp = m_scene.GetScenePresence(sog.OwnerID); diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 7fea690cfa..9fd5fe9cde 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs @@ -754,6 +754,95 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return true; } + public override bool HandleIncomingAttachments(ScenePresence sp, List attachments) + { + UUID OwnerID = sp.UUID; + if (m_sceneRegionInfo.EstateSettings.IsBanned(OwnerID)) + { + m_log.DebugFormat( + "[HG TRANSFER MODULE]: Attachments of banned avatar {0} into {1}", sp.Name, m_sceneName); + return false; + } + + if (OwnerID.IsZero() || m_scene.UserManagementModule.IsLocalGridUser(OwnerID)) + return base.HandleIncomingAttachments(sp, attachments); + + // foreign user + AgentCircuitData aCircuit = m_scene.AuthenticateHandler.GetAgentCircuitData(OwnerID); + if (aCircuit != null) + { + if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) == 0) + { + // first region in local grid did pull the necessary attachments from the source grid. + base.HandleIncomingAttachments(sp, attachments); + } + else + { + if (aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI")) + { + ScenePresence defsp = sp; + List deftatt = attachments; + List toadd = new List(deftatt.Count); + m_incomingSceneObjectEngine.QueueJob( + string.Format("HG UUID Gather attachments {0}", defsp.Name), () => + { + string url = aCircuit.ServiceURLs["AssetServerURI"].ToString(); + IDictionary ids = new Dictionary(); + HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, url, ids); + + foreach (SceneObjectGroup defso in deftatt) + { + uuidGatherer.AddForInspection(defso); + while (!uuidGatherer.Complete) + { + if (sp.IsDeleted) + { + deftatt = null; + defsp = null; + uuidGatherer = null; + toadd = null; + return; + } + uuidGatherer.GatherNext(); + } + toadd.Add(defso); + } + deftatt = null; + + foreach (UUID id in ids.Keys) + { + int tickStart = Util.EnvironmentTickCount(); + + uuidGatherer.FetchAsset(id); + + int ticksElapsed = Util.EnvironmentTickCountSubtract(tickStart); + + if (sp.IsDeleted || ticksElapsed > 30000) + { + m_log.WarnFormat( + "[HG ENTITY TRANSFER]: Aborting fetch attachments assets for HG user {0}", sp.Name); + + defsp = null; + uuidGatherer = null; + toadd = null; + return; + } + } + + base.HandleIncomingAttachments(sp, toadd); + + defsp = null; + uuidGatherer = null; + toadd = null; + }, + OwnerID.ToString()); + } + } + } + + return true; + } + #endregion #region IUserAgentVerificationModule diff --git a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs index c1c204b8de..b161cb3a34 100644 --- a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs @@ -107,6 +107,7 @@ namespace OpenSim.Region.Framework.Interfaces bool CrossAgentCreateFarChild(ScenePresence agent, GridRegion neighbourRegion, Vector3 pos, EntityTransferContext ctx); bool HandleIncomingSceneObject(SceneObjectGroup so, Vector3 newPosition); + bool HandleIncomingAttachments(ScenePresence sp, List attachments); } public interface IUserAgentVerificationModule diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 329144f4c5..461d146278 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -3013,6 +3013,21 @@ namespace OpenSim.Region.Framework.Scenes return true; } + public bool IncomingAttechments(ScenePresence sp, List attachments) + { + //m_log.DebugFormat(" >>> IncomingCreateObject(sog) <<< {0} deleted? {1} isAttach? {2}", ((SceneObjectGroup)sog).AbsolutePosition, + // ((SceneObjectGroup)sog).IsDeleted, ((SceneObjectGroup)sog).RootPart.IsAttachment); + + if (!EntityTransferModule.HandleIncomingAttachments(sp, attachments) || sp.IsDeleted) + return false; + + // Do this as late as possible so that listeners have full access to the incoming object + foreach(SceneObjectGroup newObject in attachments) + EventManager.TriggerOnIncomingSceneObject(newObject); + + return true; + } + /// /// Adds a Scene Object group to the Scene. /// Verifies that the creator of the object is not banned from the simulator. diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index c062594e09..bd32300527 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -81,7 +81,7 @@ namespace OpenSim.Region.Framework.Scenes // m_log.DebugFormat("[SCENE PRESENCE]: Destructor called on {0}", Name); // } - + public bool GotAttachmentsData = false; public int EnvironmentVersion = -1; private ViewerEnvironment m_environment = null; public ViewerEnvironment Environment @@ -3991,6 +3991,16 @@ namespace OpenSim.Region.Framework.Scenes if (++NeedInitialData < 6) // needs fix if update rate changes on heartbeat return; + /* + if(!GotAttachmentsData) + { + if(++NeedInitialData == 300) // 30s in current heartbeat + m_log.WarnFormat("[ScenePresence({0}] slow attachment assets transfer for {1}", Scene.Name, Name); + } + else if((m_teleportFlags & TeleportFlags.ViaHGLogin) != 0) + m_log.WarnFormat("[ScenePresence({0}] got hg attachment assets transfer for {1}, cntr = {2}", Scene.Name, Name, NeedInitialData); + */ + NeedInitialData = -1; bool selfappearance = (flags & 4) != 0;