From 9ecf1c21aabd0a0a4d550316001cf238362a8959 Mon Sep 17 00:00:00 2001 From: "Huaiyu (Kitty) Liu" Date: Thu, 6 Jan 2011 17:02:46 -0800 Subject: [PATCH] Enabled chats (avatar to avatar, avatar to object) to work under the new EventManager (Dan's old way of propagating chats is disabled by not subscribing to OnChatFromClientRaw in RegionSyncClient and not subscribing to OnChatFromClientRaw/OnChatFromClientRaw in RegionSyncClientView. Also, fixed a few minor bugs: 1. GetRemoteSyncListenerInfo() in RegionSyncModule fixed. 2. ActorID sent out when an actor connects to ScenePersistence actor. --- .../RegionSyncModule/RegionSyncClient.cs | 3 +- .../RegionSyncModule/RegionSyncClientView.cs | 6 +- .../SceneToScriptEngineConnector.cs | 2 - .../SymmetricSync/RegionSyncModule.cs | 95 ++++++++++++++++++- .../SymmetricSync/SymmetricSyncMessage.cs | 1 + .../Scripting/WorldComm/WorldCommModule.cs | 3 + .../Region/Framework/Scenes/EventManager.cs | 42 +++++++- 7 files changed, 139 insertions(+), 13 deletions(-) diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncClient.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncClient.cs index 0a8d6893d6..91d3ca6bae 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncClient.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncClient.cs @@ -883,7 +883,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // Register for interesting client events which will be forwarded to auth sim // These are the raw packet data blocks from the client, intercepted and sent up to the sim client.OnAgentUpdateRaw += HandleAgentUpdateRaw; - client.OnChatFromClientRaw += HandleChatFromClientRaw; + //SYMMETRIC SYNC: do not subscribe to OnChatFromClientRaw, we may remove this event entirely later + //client.OnChatFromClientRaw += HandleChatFromClientRaw; client.OnAgentRequestSit += HandleAgentRequestSit; client.OnAgentSit += HandleAgentSit; client.OnGrabObject += HandleGrabObject; diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncClientView.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncClientView.cs index b629e6ae1e..3f39e6a630 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncClientView.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncClientView.cs @@ -179,8 +179,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // *** This is the main receive loop thread for each connected client private void ReceiveLoop() { - m_scene.EventManager.OnChatFromClient += new EventManager.ChatFromClientEvent(EventManager_OnChatFromClient); - m_scene.EventManager.OnChatFromWorld += new EventManager.ChatFromWorldEvent(EventManager_OnChatFromClient); + //SYMMETRIC SYNC: commenting out the code for handling chats + // m_scene.EventManager.OnChatFromClient += new EventManager.ChatFromClientEvent(EventManager_OnChatFromClient); + // m_scene.EventManager.OnChatFromWorld += new EventManager.ChatFromWorldEvent(EventManager_OnChatFromClient); + //end of SYMMETRIC SYNC // Reset stats and time diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToScriptEngineConnector.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToScriptEngineConnector.cs index 258ce57482..3167d901c4 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToScriptEngineConnector.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToScriptEngineConnector.cs @@ -188,8 +188,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // *** This is the main thread loop for each connected client private void ReceiveLoop() { - //m_scene.EventManager.OnChatFromClient += new EventManager.ChatFromClientEvent(EventManager_OnChatFromClient); - // Reset stats and time lastStatTime = DateTime.Now; msgsIn = msgsOut = bytesIn = bytesOut = 0; diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs index 5d797b4530..50cf0bbbd2 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs @@ -550,6 +550,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //For now, we use configuration to access the information. Might be replaced by some Grid Service later on. private RegionSyncListenerInfo GetLocalSyncListenerInfo() { + m_log.Debug("reading in " + m_scene.RegionInfo.RegionName + "_SyncListenerIPAddress" + " and " + m_scene.RegionInfo.RegionName + "_SyncListenerPort"); + string addr = m_sysConfig.GetString(m_scene.RegionInfo.RegionName+"_SyncListenerIPAddress", IPAddrUnknown); int port = m_sysConfig.GetInt(m_scene.RegionInfo.RegionName+"_SyncListenerPort", PortUnknown); @@ -573,8 +575,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { //For now, we assume there is only one remote listener to connect to. Later on, //we may need to modify the code to read in multiple listeners. - string addr = m_sysConfig.GetString("SyncListenerIPAddress", IPAddrUnknown); - int port = m_sysConfig.GetInt("SyncListenerPort", PortUnknown); + string addr = m_sysConfig.GetString(m_scene.RegionInfo.RegionName + "_SyncListenerIPAddress", IPAddrUnknown); + int port = m_sysConfig.GetInt(m_scene.RegionInfo.RegionName + "_SyncListenerPort", PortUnknown); if (!addr.Equals(IPAddrUnknown) && port != PortUnknown) { RegionSyncListenerInfo info = new RegionSyncListenerInfo(addr, port); @@ -594,7 +596,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule if (m_isSyncListenerLocal) { - if (m_localSyncListener.IsListening) + if (m_localSyncListener!=null && m_localSyncListener.IsListening) { m_log.Warn("[REGION SYNC MODULE]: RegionSyncListener is local, already started"); } @@ -618,7 +620,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { if (m_isSyncListenerLocal) { - if (m_localSyncListener.IsListening) + if (m_localSyncListener!=null && m_localSyncListener.IsListening) { m_localSyncListener.Shutdown(); } @@ -646,6 +648,12 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //For now, there is only one remote listener. private void StartSyncConnections() { + if (m_remoteSyncListeners == null) + { + m_log.Error(LogHeader + " SyncListener's address or port has not been configured."); + return; + } + foreach (RegionSyncListenerInfo remoteListener in m_remoteSyncListeners) { SyncConnector syncConnector = new SyncConnector(m_syncConnectorNum++, remoteListener, this); @@ -720,6 +728,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule SendSyncMessage(SymmetricSyncMessage.MsgType.RegionName, m_scene.RegionInfo.RegionName); m_log.WarnFormat("Sending region name: \"{0}\"", m_scene.RegionInfo.RegionName); + SendSyncMessage(SymmetricSyncMessage.MsgType.ActorID, m_actorID); + SendSyncMessage(SymmetricSyncMessage.MsgType.GetTerrain); SendSyncMessage(SymmetricSyncMessage.MsgType.GetObjects); //Send(new RegionSyncMessage(RegionSyncMessage.MsgType.GetAvatars)); @@ -842,6 +852,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //EVENTS PROCESSING case SymmetricSyncMessage.MsgType.UpdateScript: case SymmetricSyncMessage.MsgType.ScriptReset: + case SymmetricSyncMessage.MsgType.ChatFromClient: { HandleRemoteEvent(msg); return; @@ -993,6 +1004,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule case SymmetricSyncMessage.MsgType.ScriptReset: HandleRemoteEvent_OnScriptReset(init_actorID, evSeqNum, data); break; + case SymmetricSyncMessage.MsgType.ChatFromClient: + HandleRemoteEvent_OnChatFromClient(init_actorID, evSeqNum, data); + break; } //if this is a relay node, forwards the event @@ -1041,6 +1055,46 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_scene.EventManager.TriggerScriptResetLocally(part.LocalId, itemID); } + /// + /// Special actions for remote event ChatFromClient + /// + /// OSDMap data of event args + private void HandleRemoteEvent_OnChatFromClient(string actorID, ulong evSeqNum, OSDMap data) + { + m_log.Debug(LogHeader + ", " + m_actorID + ": received ChatFromClient from "+actorID+", seq "+evSeqNum); + + OSChatMessage args = new OSChatMessage(); + args.Channel = data["channel"].AsInteger(); + args.Message = data["msg"].AsString(); + args.Position = data["pos"].AsVector3(); + args.From = data["name"].AsString(); + UUID id = data["id"].AsUUID(); + args.Scene = m_scene; + //args.Type = ChatTypeEnum.Say; + args.Type = (ChatTypeEnum) data["type"].AsInteger(); + ScenePresence sp; + m_scene.TryGetScenePresence(id, out sp); + + + //m_scene.EventManager.TriggerOnChatFromClientLocally(sp, args); + + m_scene.EventManager.TriggerOnChatFromWorldLocally(sp, args); + /* + if (sp != null) + { + args.Sender = sp.ControllingClient; + args.SenderUUID = id; + m_scene.EventManager.TriggerOnChatBroadcastLocally(sp.ControllingClient, args); + } + else + { + args.Sender = null; + args.SenderUUID = id; + m_scene.EventManager.TriggerOnChatFromWorldLocally(null, args); + } + * */ + //m_scene.EventManager + } /// /// Send a sync message to remove the given objects in all connected actors, if this is a relay node. @@ -1087,6 +1141,14 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } OnLocalScriptReset((uint)evArgs[0], (UUID)evArgs[1]); return; + case EventManager.EventNames.ChatFromClient: + if (evArgs.Length < 2) + { + m_log.Error(LogHeader + " not enough event args for ChatFromClient"); + return; + } + OnLocalChatFromClient(evArgs[0], (OSChatMessage)evArgs[1]); + return; default: return; } @@ -1111,12 +1173,15 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule data["running"] = OSD.FromBoolean(isScriptRunning); data["assetID"] = OSD.FromUUID(newAssetID); + /* data["actorID"] = OSD.FromString(m_actorID); data["seqNum"] = OSD.FromULong(GetNextEventSeq()); SymmetricSyncMessage rsm = new SymmetricSyncMessage(SymmetricSyncMessage.MsgType.UpdateScript, OSDParser.SerializeJsonString(data)); //send to actors who are interested in the event SendSceneEventToRelevantSyncConnectors(m_actorID, rsm); + * */ + SendSceneEvent(SymmetricSyncMessage.MsgType.UpdateScript, data); } private void OnLocalScriptReset(uint localID, UUID itemID) @@ -1131,6 +1196,28 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule SendSceneEvent(SymmetricSyncMessage.MsgType.ScriptReset, data); } + + private void OnLocalChatFromClient(Object sender, OSChatMessage chat) + { + ScenePresence avatar = m_scene.GetScenePresence(chat.SenderUUID); + + if (avatar == null) + { + m_log.Warn(LogHeader + "avatar " + chat.SenderUUID + " not exist locally, NOT sending out ChatFromClient"); + return; + } + + OSDMap data = new OSDMap(); + data["channel"] = OSD.FromInteger(chat.Channel); + data["msg"] = OSD.FromString(chat.Message); + data["pos"] = OSD.FromVector3(chat.Position); + //data["name"] = OSD.FromString(chat.From); + data["name"] = OSD.FromString(avatar.Name); + data["id"] = OSD.FromUUID(chat.SenderUUID); + data["type"] = OSD.FromInteger((int)chat.Type); + SendSceneEvent(SymmetricSyncMessage.MsgType.ChatFromClient, data); + } + private void SendSceneEvent(SymmetricSyncMessage.MsgType msgType, OSDMap data) { data["actorID"] = OSD.FromString(m_actorID); diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs index 0b47f16234..f04a6b5616 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs @@ -36,6 +36,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //events UpdateScript, ScriptReset, + ChatFromClient, } #endregion diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs index d647e71693..dc7164925a 100644 --- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs @@ -125,6 +125,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm m_listenerManager = new ListenerManager(maxlisteners, maxhandles); m_scene.EventManager.OnChatFromClient += DeliverClientMessage; m_scene.EventManager.OnChatBroadcast += DeliverClientMessage; + //SYMMETRIC SYNC + m_scene.EventManager.OnChatFromWorld += DeliverClientMessage; + //end SYMMETRIC SYNC m_pendingQ = new Queue(); m_pending = Queue.Synchronized(m_pendingQ); } diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index f26db672cc..5fb40cc9e6 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -52,6 +52,7 @@ namespace OpenSim.Region.Framework.Scenes { UpdateScript, ScriptReset, + ChatFromClient, } public EventManager(Scene scene) @@ -59,7 +60,7 @@ namespace OpenSim.Region.Framework.Scenes m_scene = scene; } -#region UpdateScript + #region UpdateScript public override void TriggerUpdateScript(UUID clientId, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID) { //publish the event to other actors who are intersted in it @@ -84,8 +85,9 @@ namespace OpenSim.Region.Framework.Scenes #endregion //UpdateScript #region ScriptReset - public virtual void TriggerScriptReset(uint localID, UUID itemID) + public override void TriggerScriptReset(uint localID, UUID itemID) { + //publish the event to other actors who are intersted in it if (m_scene.RegionSyncModule != null) { Object[] eventArgs = new Object[2]; @@ -93,13 +95,43 @@ namespace OpenSim.Region.Framework.Scenes eventArgs[1] = (Object)itemID; m_scene.RegionSyncModule.PublishSceneEvent(EventNames.ScriptReset, eventArgs); } + //trigger event locally, as the legacy code does + TriggerScriptResetLocally(localID, itemID); } - public virtual void TriggerScriptResetLocally(uint localID, UUID itemID) + public void TriggerScriptResetLocally(uint localID, UUID itemID) { base.TriggerScriptReset(localID, itemID); } #endregion //UpdateScript + + #region ChatFromClient + public override void TriggerOnChatFromClient(Object sender, OSChatMessage chat) + { + if (m_scene.RegionSyncModule != null) + { + Object[] eventArgs = new Object[2]; + eventArgs[0] = sender; + eventArgs[1] = (Object)chat; + m_scene.RegionSyncModule.PublishSceneEvent(EventNames.ChatFromClient, eventArgs); + } + TriggerOnChatFromClientLocally(sender, chat); + } + public void TriggerOnChatFromClientLocally(Object sender, OSChatMessage chat) + { + base.TriggerOnChatFromClient(sender, chat); + } + #endregion //ChatFromClient + + public void TriggerOnChatBroadcastLocally(Object sender, OSChatMessage chat) + { + base.TriggerOnChatBroadcast(sender, chat); + } + + public void TriggerOnChatFromWorldLocally(Object sender, OSChatMessage chat) + { + base.TriggerOnChatFromWorld(sender, chat); + } } /// @@ -1659,7 +1691,9 @@ namespace OpenSim.Region.Framework.Scenes } } - public void TriggerOnChatFromClient(Object sender, OSChatMessage chat) + //SYMMETRIC SYNC: overiding this in the inherited class + //public void TriggerOnChatFromClient(Object sender, OSChatMessage chat) + public virtual void TriggerOnChatFromClient(Object sender, OSChatMessage chat) { ChatFromClientEvent handlerChatFromClient = OnChatFromClient; if (handlerChatFromClient != null)