From 67eaa574a3e8832a54290677eee83c29dbe653ae Mon Sep 17 00:00:00 2001 From: "Huaiyu (Kitty) Liu" Date: Fri, 27 May 2011 09:56:41 -0700 Subject: [PATCH] started to add functions to support llDialog in DSG mode. --- .../CoreModules/Avatar/Dialog/DialogModule.cs | 167 +++++++++++++++++- .../RegionSyncModule/RegionSyncAvatar.cs | 15 +- .../Framework/Interfaces/IDialogModule.cs | 4 + 3 files changed, 181 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs index 8a977c9b44..886515868e 100644 --- a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs @@ -37,9 +37,16 @@ using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; +//DSG +using Nwc.XmlRpc; +using System.Net; +using System.Collections; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; + namespace OpenSim.Region.CoreModules.Avatar.Dialog { - public class DialogModule : IRegionModule, IDialogModule + public class DialogModule : IRegionModule, IDialogModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -61,7 +68,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Dialog HandleAlertConsoleCommand); } - public void PostInitialise() {} + //public void PostInitialise() {} public void Close() {} public string Name { get { return "Dialog Module"; } } public bool IsSharedModule { get { return false; } } @@ -214,5 +221,161 @@ namespace OpenSim.Region.CoreModules.Avatar.Dialog return result; } + + #region GridCommunication + private IPresenceService m_PresenceService; + protected IPresenceService PresenceService + { + get + { + if (m_PresenceService == null) + m_PresenceService = m_scene.RequestModuleInterface(); + return m_PresenceService; + } + } + //DSG added to support llDialog with distributed script engine and client manager, + //following the same communication pattern as grid_instant_message + + public virtual void SendGridDialogViaXMLRPCAsync(UUID avatarID, string objectName, UUID objectID, string ownerFirstName, + string ownerLastName, string message, UUID textureID, int ch, string[] buttonlabels, UUID prevRegionID) + { + UUID toAgentID; + PresenceInfo upd = null; + // Non-cached user agent lookup. + PresenceInfo[] presences = PresenceService.GetAgents(new string[] { avatarID.ToString() }); + + if (presences != null && presences.Length > 0) + { + foreach (PresenceInfo p in presences) + { + if (p.RegionID != UUID.Zero) + { + upd = p; + break; + } + } + + if (upd != null) + { + // check if we've tried this before.. + // This is one way to end the recursive loop + // + if (upd.RegionID == prevRegionID) + { + //Dialog content undelivered + m_log.WarnFormat("Couldn't deliver dialog to {0}" + avatarID); + return; + } + } + else + { + //Dialog content undelivered + m_log.WarnFormat("Couldn't deliver dialog to {0}" + toAgentID); + return; + } + } + + if (upd != null) + { + GridRegion reginfo = m_scene.GridService.GetRegionByUUID(m_scene.RegionInfo.ScopeID, + upd.RegionID); + if (reginfo != null) + { + Hashtable msgdata = ConvertGridDialogToXMLRPC(avatarID, objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels); + //= ConvertGridInstantMessageToXMLRPC(im); + // Not actually used anymore, left in for compatibility + // Remove at next interface change + // + msgdata["region_handle"] = 0; + + bool imresult = doDialogSending(reginfo, msgdata); + if (imresult) + { + SendGridDialogViaXMLRPCAsync(avatarID, objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels, prevRegionID); + } + } + } + } + + private Hashtable ConvertGridDialogToXMLRPC(UUID avatarID, string objectName, UUID objectID, string ownerFirstName, string ownerLastName, + string message, UUID textureID, int ch, string[] buttonlabels) + { + Hashtable msgdata = new Hashtable(); + return msgdata; + } + + /// + /// This actually does the XMLRPC Request + /// + /// RegionInfo we pull the data out of to send the request to + /// The Instant Message data Hashtable + /// Bool if the message was successfully delivered at the other side. + protected virtual bool doDialogSending(GridRegion reginfo, Hashtable xmlrpcdata) + { + + ArrayList SendParams = new ArrayList(); + SendParams.Add(xmlrpcdata); + XmlRpcRequest GridReq = new XmlRpcRequest("grid_dialog", SendParams); + try + { + + XmlRpcResponse GridResp = GridReq.Send(reginfo.ServerURI, 3000); + + Hashtable responseData = (Hashtable)GridResp.Value; + + if (responseData.ContainsKey("success")) + { + if ((string)responseData["success"] == "TRUE") + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } + } + catch (WebException e) + { + m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Error sending grid_dialog to {0} the host didn't respond " + e.ToString(), reginfo.ServerURI.ToString()); + } + + return false; + } + + public virtual void PostInitialise() + { + MainServer.Instance.AddXmlRPCHandler( + "grid_dialog", processXMLRPCGridDialog); + } + + /// + /// Process a XMLRPC Grid Instant Message + /// + /// XMLRPC parameters + /// + /// Nothing much + protected virtual XmlRpcResponse processXMLRPCGridDialog(XmlRpcRequest request, IPEndPoint remoteClient) + { + bool successful = false; + + //Send response back to region calling if it was successful + // calling region uses this to know when to look up a user's location again. + XmlRpcResponse resp = new XmlRpcResponse(); + Hashtable respdata = new Hashtable(); + if (successful) + respdata["success"] = "TRUE"; + else + respdata["success"] = "FALSE"; + resp.Value = respdata; + + return resp; + } + +#endregion //GridCommunication } } \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncAvatar.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncAvatar.cs index 1786ef359f..0b3e071548 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncAvatar.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncAvatar.cs @@ -514,11 +514,11 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule public void SendInstantMessage(GridInstantMessage im) { - IMessageTransferModule m_msgTransferModule = m_scene.RequestModuleInterface(); + IMessageTransferModule msgTransferModule = m_scene.RequestModuleInterface(); - if (m_msgTransferModule != null) + if (msgTransferModule != null) { - m_msgTransferModule.SendGridInstantMessageViaXMLRPC(im, delegate(bool success) { }); + msgTransferModule.SendGridInstantMessageViaXMLRPC(im, delegate(bool success) { }); } } @@ -617,6 +617,15 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule public virtual void SendDialog(string objectname, UUID objectID, string ownerFirstName, string ownerLastName, string msg, UUID textureID, int ch, string[] buttonlabels) { + IDialogModule dialogModule = m_scene.RequestModuleInterface(); + + if (dialogModule != null) + { + //Seems that the two places calling DialogModule.SendDialogToUser, which calls current function, is + //pass (new UUID("00000000-0000-2222-3333-100000001000")) as the ownerID, so we copy that. + dialogModule.SendGridDialogViaXMLRPCAsync(this.AgentId, objectname, objectID, ownerFirstName, ownerLastName, + msg, textureID, ch, buttonlabels, UUID.Zero); + } } public virtual void ReprioritizeUpdates() diff --git a/OpenSim/Region/Framework/Interfaces/IDialogModule.cs b/OpenSim/Region/Framework/Interfaces/IDialogModule.cs index be9764a7ea..492bbe87cb 100644 --- a/OpenSim/Region/Framework/Interfaces/IDialogModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IDialogModule.cs @@ -123,5 +123,9 @@ namespace OpenSim.Region.Framework.Interfaces /// Send a textbox entry for the client to respond to /// void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid); + + //DSG added + void SendGridDialogViaXMLRPCAsync(UUID avatarID, string objectName, UUID objectID, string ownerFirstName, string ownerLastName, + string message, UUID textureID, int ch, string[] buttonlabels, UUID prevRegionID); } }