From fb716dbd6823f629138776cbcd98cb72f87ab5fc Mon Sep 17 00:00:00 2001 From: "Huaiyu (Kitty) Liu" Date: Sat, 4 Jun 2011 23:17:56 -0700 Subject: [PATCH] Added code to save and refire collision_start event if the colliders are not found in local scene yet. --- .../InstantMessage/MessageTransferModule.cs | 42 +++++----- .../SymmetricSync/GridDialogModule.cs | 4 +- .../SymmetricSync/RegionSyncModule.cs | 84 ++++++++++++++++--- 3 files changed, 96 insertions(+), 34 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index b88bdbb2b7..4cb45592f2 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs @@ -48,7 +48,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage private bool m_Enabled = false; protected List m_Scenes = new List(); - protected Dictionary m_UserRegionMap = new Dictionary(); + protected Dictionary m_UserRegionMap = new Dictionary(); protected Dictionary m_RegionInfoMap = new Dictionary(); public event UndeliveredMessage OnUndeliveredMessage; @@ -536,19 +536,19 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } if (upd != null) - { - GridRegion reginfo = null; - // Try to pull reginfo from our cache - lock (m_RegionInfoMap) - { - if (!m_RegionInfoMap.TryGetValue(upd.RegionID, out reginfo)) - reginfo = null; - } - - // If it wasn't there, then look it up from grid. - if (reginfo == null) - { - reginfo = m_Scenes[0].GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, upd.RegionID); + { + GridRegion reginfo = null; + // Try to pull reginfo from our cache + lock (m_RegionInfoMap) + { + if (!m_RegionInfoMap.TryGetValue(upd.RegionID, out reginfo)) + reginfo = null; + } + + // If it wasn't there, then look it up from grid. + if (reginfo == null) + { + reginfo = m_Scenes[0].GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, upd.RegionID); } // If we found the reginfo, send the IM to the region @@ -573,13 +573,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage { m_UserRegionMap.Add(toAgentID, upd.RegionID); } - } - lock (m_RegionInfoMap) - { - // Since we never look it up again, we don't need to update it - // but if it's not in the map yet, add it now. - if (!m_RegionInfoMap.ContainsKey(upd.RegionID)) - m_RegionInfoMap.Add(upd.RegionID, reginfo); + } + lock (m_RegionInfoMap) + { + // Since we never look it up again, we don't need to update it + // but if it's not in the map yet, add it now. + if (!m_RegionInfoMap.ContainsKey(upd.RegionID)) + m_RegionInfoMap.Add(upd.RegionID, reginfo); } result(true); } diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/GridDialogModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/GridDialogModule.cs index 149831bf6c..88ce5b25b7 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/GridDialogModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/GridDialogModule.cs @@ -200,7 +200,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule bool imresult = doDialogSending(reginfo, msgdata); if (!imresult) { - SendGridDialogViaXMLRPCAsync(avatarID, objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels, prevRegionID); + //SendGridDialogViaXMLRPCAsync(avatarID, objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels, prevRegionID); + m_log.WarnFormat("Couldn't deliver dialog to {0}" + avatarID); + return; } } } diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs index 4e279dae47..09a1195860 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs @@ -199,6 +199,13 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule get { return m_isSyncRelay; } } + public class SyncMessageRecord + { + public SymmetricSyncMessage SyncMessage; + public long ReceivedTime; + } + private List m_savedSyncMessage = new List(); + //The following Sendxxx calls,send out a message immediately, w/o putting it in the SyncConnector's outgoing queue. //May need some optimization there on the priorities. @@ -2154,7 +2161,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule HandleRemoteEvent_PhysicsCollision(init_actorID, evSeqNum, data); break; case SymmetricSyncMessage.MsgType.ScriptCollidingStart: - HandleRemoteEvent_ScriptCollidingStart(init_actorID, evSeqNum, data); + HandleRemoteEvent_ScriptCollidingStart(init_actorID, evSeqNum, data, DateTime.Now.Ticks); break; } @@ -2403,16 +2410,19 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_scene.EventManager.TriggerOnAttachLocally(localID, itemID, avatarID); } - private void HandleRemoteEvent_ScriptCollidingStart(string actorID, ulong evSeqNum, OSDMap data) + private void HandleRemoteEvent_ScriptCollidingStart(string actorID, ulong evSeqNum, OSDMap data, long recvTime) { if (!data.ContainsKey("primUUID") || !data.ContainsKey("collisionUUIDs")) { m_log.ErrorFormat("RemoteEvent_ScriptCollidingStart: either primUUID or collisionUUIDs is missing in incoming OSDMap"); + return; } ColliderArgs StartCollidingMessage = new ColliderArgs(); List colliding = new List(); - SceneObjectPart part=null; + SceneObjectPart part = null; + OSDArray collidersNotFound = new OSDArray(); + try { UUID primUUID = data["primUUID"].AsUUID(); @@ -2430,7 +2440,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_log.WarnFormat("{0}: HandleRemoteEvent_PhysicsCollision: no collisionLocalIDs", LogHeader); return; } - if(part.ParentGroup.IsDeleted == true) + if (part.ParentGroup.IsDeleted == true) return; m_log.DebugFormat("HandleRemoteEvent_ScriptCollidingStart received for {0}", part.Name); @@ -2473,8 +2483,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } else { - m_log.WarnFormat("HandleRemoteEvent_ScriptCollidingStart for SOP {0},{1} with another SOP/SP {2}, but the latter is not found in local Scene", + m_log.WarnFormat("HandleRemoteEvent_ScriptCollidingStart for SOP {0},{1} with SOP/SP {2}, but the latter is not found in local Scene. Saved for later processing", part.Name, part.UUID, collidingUUID); + collidersNotFound.Add(OSD.FromUUID(collidingUUID)); } } @@ -2485,6 +2496,27 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_log.ErrorFormat("HandleRemoteEvent_ScriptCollidingStart Error: {0}", e.Message); } + if (collidersNotFound.Count > 0) + { + + OSDMap newdata = new OSDMap(); + newdata["primUUID"] = OSD.FromUUID(part.UUID); + newdata["collisionUUIDs"] = collidersNotFound; + + newdata["actorID"] = OSD.FromString(actorID); + newdata["seqNum"] = OSD.FromULong(evSeqNum); + SymmetricSyncMessage rsm = new SymmetricSyncMessage(SymmetricSyncMessage.MsgType.ScriptCollidingStart, OSDParser.SerializeJsonString(newdata)); + + SyncMessageRecord syncMsgToSave = new SyncMessageRecord(); + syncMsgToSave.ReceivedTime = recvTime; + syncMsgToSave.SyncMessage = rsm; + lock (m_savedSyncMessage) + { + m_savedSyncMessage.Add(syncMsgToSave); + } + } + + if (colliding.Count > 0) { StartCollidingMessage.Colliders = colliding; @@ -2502,6 +2534,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule if (!data.ContainsKey("primUUID") || !data.ContainsKey("collisionUUIDs")) { m_log.ErrorFormat("RemoteEvent_PhysicsCollision: either primUUID or collisionUUIDs is missing in incoming OSDMap"); + return; } try @@ -2524,13 +2557,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // Build up the collision list. The contact point is ignored so we generate some default. CollisionEventUpdate e = new CollisionEventUpdate(); - /* - foreach (uint collisionID in collisionLocalIDs) - { - // e.addCollider(collisionID, new ContactPoint()); - e.addCollider(collisionID, new ContactPoint(Vector3.Zero, Vector3.UnitX, 0.03f)); - } - * */ + for (int i = 0; i < collisionUUIDs.Count; i++) { OSD arg = collisionUUIDs[i]; @@ -2955,6 +2982,39 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule /// public void SyncOutPrimUpdates() { + //we are riding on this periodic events to check if there are un-handled sync event messages + if (m_savedSyncMessage.Count > 0) + { + System.Threading.ThreadPool.QueueUserWorkItem(delegate + { + List savedSyncMessage; + lock (m_savedSyncMessage) + { + savedSyncMessage = new List(m_savedSyncMessage); + m_savedSyncMessage.Clear(); + } + foreach (SyncMessageRecord syncMsgSaved in savedSyncMessage) + { + SymmetricSyncMessage msg = syncMsgSaved.SyncMessage; + switch (msg.Type) + { + case SymmetricSyncMessage.MsgType.ScriptCollidingStart: + { + OSDMap data = DeserializeMessage(msg); + string init_actorID = data["actorID"].AsString(); + ulong evSeqNum = data["seqNum"].AsULong(); + bool savedForLater = false; + HandleRemoteEvent_ScriptCollidingStart(init_actorID, evSeqNum, data, syncMsgSaved.ReceivedTime); + break; + } + default: + break; + } + + } + }); + } + if (!IsSyncingWithOtherSyncNodes()) { //no SyncConnector connected. clear update queues and return.