From 180be7de07014aa33bc6066f12a0819b731c1c9d Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Tue, 10 Feb 2009 13:10:57 +0000 Subject: this is step 2 of 2 of the OpenSim.Region.Environment refactor. NOTHING has been deleted or moved off to forge at this point. what has happened is that OpenSim.Region.Environment.Modules has been split in two: - OpenSim.Region.CoreModules: all those modules that are either directly or indirectly referenced from other OpenSim packages, or that provide functionality that the OpenSim developer community considers core functionality: CoreModules/Agent/AssetTransaction CoreModules/Agent/Capabilities CoreModules/Agent/TextureDownload CoreModules/Agent/TextureSender CoreModules/Agent/TextureSender/Tests CoreModules/Agent/Xfer CoreModules/Avatar/AvatarFactory CoreModules/Avatar/Chat/ChatModule CoreModules/Avatar/Combat CoreModules/Avatar/Currency/SampleMoney CoreModules/Avatar/Dialog CoreModules/Avatar/Friends CoreModules/Avatar/Gestures CoreModules/Avatar/Groups CoreModules/Avatar/InstantMessage CoreModules/Avatar/Inventory CoreModules/Avatar/Inventory/Archiver CoreModules/Avatar/Inventory/Transfer CoreModules/Avatar/Lure CoreModules/Avatar/ObjectCaps CoreModules/Avatar/Profiles CoreModules/Communications/Local CoreModules/Communications/REST CoreModules/Framework/EventQueue CoreModules/Framework/InterfaceCommander CoreModules/Hypergrid CoreModules/InterGrid CoreModules/Scripting/DynamicTexture CoreModules/Scripting/EMailModules CoreModules/Scripting/HttpRequest CoreModules/Scripting/LoadImageURL CoreModules/Scripting/VectorRender CoreModules/Scripting/WorldComm CoreModules/Scripting/XMLRPC CoreModules/World/Archiver CoreModules/World/Archiver/Tests CoreModules/World/Estate CoreModules/World/Land CoreModules/World/Permissions CoreModules/World/Serialiser CoreModules/World/Sound CoreModules/World/Sun CoreModules/World/Terrain CoreModules/World/Terrain/DefaultEffects CoreModules/World/Terrain/DefaultEffects/bin CoreModules/World/Terrain/DefaultEffects/bin/Debug CoreModules/World/Terrain/Effects CoreModules/World/Terrain/FileLoaders CoreModules/World/Terrain/FloodBrushes CoreModules/World/Terrain/PaintBrushes CoreModules/World/Terrain/Tests CoreModules/World/Vegetation CoreModules/World/Wind CoreModules/World/WorldMap - OpenSim.Region.OptionalModules: all those modules that are not core modules: OptionalModules/Avatar/Chat/IRC-stuff OptionalModules/Avatar/Concierge OptionalModules/Avatar/Voice/AsterixVoice OptionalModules/Avatar/Voice/SIPVoice OptionalModules/ContentManagementSystem OptionalModules/Grid/Interregion OptionalModules/Python OptionalModules/SvnSerialiser OptionalModules/World/NPC OptionalModules/World/TreePopulator --- .../Avatar/InstantMessage/InstantMessageModule.cs | 170 ------ .../Avatar/InstantMessage/MessageTransferModule.cs | 655 --------------------- .../Avatar/InstantMessage/PresenceModule.cs | 426 -------------- 3 files changed, 1251 deletions(-) delete mode 100644 OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs delete mode 100644 OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs delete mode 100644 OpenSim/Region/Environment/Modules/Avatar/InstantMessage/PresenceModule.cs (limited to 'OpenSim/Region/Environment/Modules/Avatar/InstantMessage') diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs deleted file mode 100644 index 3a1b282..0000000 --- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Net; -using System.Threading; -using OpenMetaverse; -using log4net; -using Nini.Config; -using Nwc.XmlRpc; -using OpenSim.Framework; -using OpenSim.Framework.Client; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage -{ - public class InstantMessageModule : IRegionModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - /// - /// Is this module enabled? - /// - private bool m_enabled = false; - - private readonly List m_scenes = new List(); - - #region IRegionModule Members - - private IMessageTransferModule m_TransferModule = null; - - public void Initialise(Scene scene, IConfigSource config) - { - if (config.Configs["Messaging"] != null) - { - if (config.Configs["Messaging"].GetString( - "InstantMessageModule", "InstantMessageModule") != - "InstantMessageModule") - return; - } - - m_enabled = true; - - lock (m_scenes) - { - if (!m_scenes.Contains(scene)) - { - m_scenes.Add(scene); - scene.EventManager.OnClientConnect += OnClientConnect; - scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; - } - } - } - - void OnClientConnect(IClientCore client) - { - IClientIM clientIM; - if (client.TryGet(out clientIM)) - { - clientIM.OnInstantMessage += OnInstantMessage; - } - } - - public void PostInitialise() - { - if (!m_enabled) - return; - - m_TransferModule = - m_scenes[0].RequestModuleInterface(); - - if (m_TransferModule == null) - m_log.Error("[INSTANT MESSAGE]: No message transfer module, "+ - "IM will not work!"); - } - - public void Close() - { - } - - public string Name - { - get { return "InstantMessageModule"; } - } - - public bool IsSharedModule - { - get { return true; } - } - - #endregion - - public void OnInstantMessage(IClientAPI client, GridInstantMessage im) - { - byte dialog = im.dialog; - - if ( dialog != (byte)InstantMessageDialog.MessageFromAgent - && dialog != (byte)InstantMessageDialog.StartTyping - && dialog != (byte)InstantMessageDialog.StopTyping) - { - return; - } - - if (m_TransferModule != null) - { - m_TransferModule.SendInstantMessage(im, - delegate(bool success) - { - if (dialog == (uint)InstantMessageDialog.StartTyping || - dialog == (uint)InstantMessageDialog.StopTyping) - { - return; - } - - if ((client != null) && !success) - { - client.SendInstantMessage(new UUID(im.toAgentID), - "Unable to send instant message. "+ - "User is not logged in.", - new UUID(im.fromAgentID), "System", - (byte)InstantMessageDialog.BusyAutoResponse, - (uint)Util.UnixTimeSinceEpoch()); - } - } - ); - } - } - - /// - /// - /// - /// - private void OnGridInstantMessage(GridInstantMessage msg) - { - // Just call the Text IM handler above - // This event won't be raised unless we have that agent, - // so we can depend on the above not trying to send - // via grid again - // - OnInstantMessage(null, msg); - } - } -} diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs deleted file mode 100644 index 347c305..0000000 --- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs +++ /dev/null @@ -1,655 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Net; -using System.Threading; -using OpenMetaverse; -using log4net; -using Nini.Config; -using Nwc.XmlRpc; -using OpenSim.Framework; -using OpenSim.Framework.Client; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage -{ - public class MessageTransferModule : IRegionModule, IMessageTransferModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - // private bool m_Enabled = false; - private bool m_Gridmode = false; - private List m_Scenes = new List(); - private Dictionary m_UserRegionMap = new Dictionary(); - - public void Initialise(Scene scene, IConfigSource config) - { - IConfig cnf = config.Configs["Messaging"]; - if (cnf != null && cnf.GetString( - "MessageTransferModule", "MessageTransferModule") != - "MessageTransferModule") - return; - - cnf = config.Configs["Startup"]; - if (cnf != null) - m_Gridmode = cnf.GetBoolean("gridmode", false); - - // m_Enabled = true; - - lock (m_Scenes) - { - if (m_Scenes.Count == 0) - { - scene.CommsManager.HttpServer.AddXmlRPCHandler( - "grid_instant_message", processXMLRPCGridInstantMessage); - } - - scene.RegisterModuleInterface(this); - m_Scenes.Add(scene); - } - } - - public void PostInitialise() - { - } - - public void Close() - { - } - - public string Name - { - get { return "MessageTransferModule"; } - } - - public bool IsSharedModule - { - get { return true; } - } - - public void SendInstantMessage(GridInstantMessage im, MessageResultNotification result) - { - UUID toAgentID = new UUID(im.toAgentID); - - m_log.DebugFormat("[INSTANT MESSAGE]: Attempting delivery of IM from {0} to {1}", im.fromAgentName, toAgentID.ToString()); - - // Try root avatar only first - foreach (Scene scene in m_Scenes) - { - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) - { - m_log.DebugFormat("[INSTANT MESSAGE]: Looking for {0} in {1}", toAgentID.ToString(), scene.RegionInfo.RegionName); - // Local message - ScenePresence user = (ScenePresence) scene.Entities[toAgentID]; - if (!user.IsChildAgent) - { - m_log.DebugFormat("[INSTANT MESSAGE]: Delivering to client"); - user.ControllingClient.SendInstantMessage( - new UUID(im.fromAgentID), - im.message, - new UUID(im.toAgentID), - im.fromAgentName, - im.dialog, - im.timestamp, - new UUID(im.imSessionID), - im.fromGroup, - im.binaryBucket); - // Message sent - result(true); - return; - } - } - } - - // try child avatar second - foreach (Scene scene in m_Scenes) - { -// m_log.DebugFormat( -// "[INSTANT MESSAGE]: Looking for child of {0} in {1}", toAgentID, scene.RegionInfo.RegionName); - - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) - { - // Local message - ScenePresence user = (ScenePresence) scene.Entities[toAgentID]; - - m_log.DebugFormat("[INSTANT MESSAGE]: Delivering to client"); - user.ControllingClient.SendInstantMessage( - new UUID(im.fromAgentID), - im.message, - new UUID(im.toAgentID), - im.fromAgentName, - im.dialog, - im.timestamp, - new UUID(im.imSessionID), - im.fromGroup, - im.binaryBucket); - // Message sent - result(true); - return; - } - } - - if (m_Gridmode) - { - //m_log.DebugFormat("[INSTANT MESSAGE]: Delivering via grid"); - // Still here, try send via Grid - SendGridInstantMessageViaXMLRPC(im, result); - return; - } - - //m_log.DebugFormat("[INSTANT MESSAGE]: Undeliverable"); - result(false); - return; - } - - /// - /// Process a XMLRPC Grid Instant Message - /// - /// XMLRPC parameters - /// - /// Nothing much - protected virtual XmlRpcResponse processXMLRPCGridInstantMessage(XmlRpcRequest request) - { - bool successful = false; - - // TODO: For now, as IMs seem to be a bit unreliable on OSGrid, catch all exception that - // happen here and aren't caught and log them. - try - { - // various rational defaults - UUID fromAgentID = UUID.Zero; - UUID toAgentID = UUID.Zero; - UUID imSessionID = UUID.Zero; - uint timestamp = 0; - string fromAgentName = ""; - string message = ""; - byte dialog = (byte)0; - bool fromGroup = false; - byte offline = (byte)0; - uint ParentEstateID=0; - Vector3 Position = Vector3.Zero; - UUID RegionID = UUID.Zero ; - byte[] binaryBucket = new byte[0]; - - float pos_x = 0; - float pos_y = 0; - float pos_z = 0; - //m_log.Info("Processing IM"); - - - Hashtable requestData = (Hashtable)request.Params[0]; - // Check if it's got all the data - if (requestData.ContainsKey("from_agent_id") - && requestData.ContainsKey("to_agent_id") && requestData.ContainsKey("im_session_id") - && requestData.ContainsKey("timestamp") && requestData.ContainsKey("from_agent_name") - && requestData.ContainsKey("message") && requestData.ContainsKey("dialog") - && requestData.ContainsKey("from_group") - && requestData.ContainsKey("offline") && requestData.ContainsKey("parent_estate_id") - && requestData.ContainsKey("position_x") && requestData.ContainsKey("position_y") - && requestData.ContainsKey("position_z") && requestData.ContainsKey("region_id") - && requestData.ContainsKey("binary_bucket")) - { - // Do the easy way of validating the UUIDs - UUID.TryParse((string)requestData["from_agent_id"], out fromAgentID); - UUID.TryParse((string)requestData["to_agent_id"], out toAgentID); - UUID.TryParse((string)requestData["im_session_id"], out imSessionID); - UUID.TryParse((string)requestData["region_id"], out RegionID); - - try - { - timestamp = (uint)Convert.ToInt32((string)requestData["timestamp"]); - } - catch (ArgumentException) - { - } - catch (FormatException) - { - } - catch (OverflowException) - { - } - - fromAgentName = (string)requestData["from_agent_name"]; - message = (string)requestData["message"]; - - // Bytes don't transfer well over XMLRPC, so, we Base64 Encode them. - string requestData1 = (string)requestData["dialog"]; - if (string.IsNullOrEmpty(requestData1)) - { - dialog = 0; - } - else - { - byte[] dialogdata = Convert.FromBase64String(requestData1); - dialog = dialogdata[0]; - } - - if ((string)requestData["from_group"] == "TRUE") - fromGroup = true; - - string requestData2 = (string)requestData["offline"]; - if (String.IsNullOrEmpty(requestData2)) - { - offline = 0; - } - else - { - byte[] offlinedata = Convert.FromBase64String(requestData2); - offline = offlinedata[0]; - } - - try - { - ParentEstateID = (uint)Convert.ToInt32((string)requestData["parent_estate_id"]); - } - catch (ArgumentException) - { - } - catch (FormatException) - { - } - catch (OverflowException) - { - } - - try - { - pos_x = (uint)Convert.ToInt32((string)requestData["position_x"]); - } - catch (ArgumentException) - { - } - catch (FormatException) - { - } - catch (OverflowException) - { - } - try - { - pos_y = (uint)Convert.ToInt32((string)requestData["position_y"]); - } - catch (ArgumentException) - { - } - catch (FormatException) - { - } - catch (OverflowException) - { - } - try - { - pos_z = (uint)Convert.ToInt32((string)requestData["position_z"]); - } - catch (ArgumentException) - { - } - catch (FormatException) - { - } - catch (OverflowException) - { - } - - Position = new Vector3(pos_x, pos_y, pos_z); - - string requestData3 = (string)requestData["binary_bucket"]; - if (string.IsNullOrEmpty(requestData3)) - { - binaryBucket = new byte[0]; - } - else - { - binaryBucket = Convert.FromBase64String(requestData3); - } - - // Create a New GridInstantMessageObject the the data - GridInstantMessage gim = new GridInstantMessage(); - gim.fromAgentID = fromAgentID.Guid; - gim.fromAgentName = fromAgentName; - gim.fromGroup = fromGroup; - gim.imSessionID = imSessionID.Guid; - gim.RegionID = RegionID.Guid; - gim.timestamp = timestamp; - gim.toAgentID = toAgentID.Guid; - gim.message = message; - gim.dialog = dialog; - gim.offline = offline; - gim.ParentEstateID = ParentEstateID; - gim.Position = Position; - gim.binaryBucket = binaryBucket; - - - // Trigger the Instant message in the scene. - foreach (Scene scene in m_Scenes) - { - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) - { - ScenePresence user = - (ScenePresence)scene.Entities[toAgentID]; - - if (!user.IsChildAgent) - { - scene.EventManager.TriggerIncomingInstantMessage(gim); - successful = true; - } - } - } - if (!successful) - { - // If the message can't be delivered to an agent, it - // is likely to be a group IM. On a group IM, the - // imSessionID = toAgentID = group id. Raise the - // unhandled IM event to give the groups module - // a chance to pick it up. We raise that in a random - // scene, since the groups module is shared. - // - m_Scenes[0].EventManager.TriggerUnhandledInstantMessage(gim); - } - } - } - catch (Exception e) - { - m_log.Error("[INSTANT MESSAGE]: Caught unexpected exception:", e); - 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; - } - - /// - /// delegate for sending a grid instant message asynchronously - /// - public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle); - - private void GridInstantMessageCompleted(IAsyncResult iar) - { - GridInstantMessageDelegate icon = - (GridInstantMessageDelegate)iar.AsyncState; - icon.EndInvoke(iar); - } - - - protected virtual void SendGridInstantMessageViaXMLRPC(GridInstantMessage im, MessageResultNotification result) - { - GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync; - - d.BeginInvoke(im, result, 0, GridInstantMessageCompleted, d); - } - - /// - /// Recursive SendGridInstantMessage over XMLRPC method. - /// This is called from within a dedicated thread. - /// The first time this is called, prevRegionHandle will be 0 Subsequent times this is called from - /// itself, prevRegionHandle will be the last region handle that we tried to send. - /// If the handles are the same, we look up the user's location using the grid. - /// If the handles are still the same, we end. The send failed. - /// - /// - /// Pass in 0 the first time this method is called. It will be called recursively with the last - /// regionhandle tried - /// - protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle) - { - UUID toAgentID = new UUID(im.toAgentID); - - UserAgentData upd = null; - - bool lookupAgent = false; - - lock (m_UserRegionMap) - { - if (m_UserRegionMap.ContainsKey(toAgentID)) - { - upd = new UserAgentData(); - upd.AgentOnline = true; - upd.Handle = m_UserRegionMap[toAgentID]; - - // We need to compare the current regionhandle with the previous region handle - // or the recursive loop will never end because it will never try to lookup the agent again - if (prevRegionHandle == upd.Handle) - { - lookupAgent = true; - } - } - else - { - lookupAgent = true; - } - } - - - // Are we needing to look-up an agent? - if (lookupAgent) - { - // Non-cached user agent lookup. - upd = m_Scenes[0].CommsManager.UserService.GetAgentByUUID(toAgentID); - - if (upd != null) - { - // check if we've tried this before.. - // This is one way to end the recursive loop - // - if (upd.Handle == prevRegionHandle) - { - m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message"); - result(false); - return; - } - } - else - { - m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message"); - result(false); - return; - } - } - - if (upd != null) - { - if (upd.AgentOnline) - { - RegionInfo reginfo = m_Scenes[0].SceneGridService.RequestNeighbouringRegionInfo(upd.Handle); - if (reginfo != null) - { - Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im); - // Not actually used anymore, left in for compatibility - // Remove at next interface change - // - msgdata["region_handle"] = 0; - bool imresult = doIMSending(reginfo, msgdata); - if (imresult) - { - // IM delivery successful, so store the Agent's location in our local cache. - lock (m_UserRegionMap) - { - if (m_UserRegionMap.ContainsKey(toAgentID)) - { - m_UserRegionMap[toAgentID] = upd.Handle; - } - else - { - m_UserRegionMap.Add(toAgentID, upd.Handle); - } - } - result(true); - } - else - { - // try again, but lookup user this time. - // Warning, this must call the Async version - // of this method or we'll be making thousands of threads - // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync - // The version that spawns the thread is SendGridInstantMessageViaXMLRPC - - // This is recursive!!!!! - SendGridInstantMessageViaXMLRPCAsync(im, result, - upd.Handle); - } - - } - else - { - m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.Handle); - result(false); - } - } - else - { - result(false); - } - } - else - { - m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find user {0}", toAgentID); - result(false); - } - - } - - /// - /// 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. - private bool doIMSending(RegionInfo reginfo, Hashtable xmlrpcdata) - { - - ArrayList SendParams = new ArrayList(); - SendParams.Add(xmlrpcdata); - XmlRpcRequest GridReq = new XmlRpcRequest("grid_instant_message", SendParams); - try - { - - XmlRpcResponse GridResp = GridReq.Send("http://" + reginfo.ExternalHostName + ":" + reginfo.HttpPort, 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 message to http://{0}:{1} the host didn't respond ({2})", - reginfo.ExternalHostName, reginfo.HttpPort, e.Message); - } - - return false; - } - - /// - /// Get ulong region handle for region by it's Region UUID. - /// We use region handles over grid comms because there's all sorts of free and cool caching. - /// - /// UUID of region to get the region handle for - /// -// private ulong getLocalRegionHandleFromUUID(UUID regionID) -// { -// ulong returnhandle = 0; -// -// lock (m_Scenes) -// { -// foreach (Scene sn in m_Scenes) -// { -// if (sn.RegionInfo.RegionID == regionID) -// { -// returnhandle = sn.RegionInfo.RegionHandle; -// break; -// } -// } -// } -// return returnhandle; -// } - - /// - /// Takes a GridInstantMessage and converts it into a Hashtable for XMLRPC - /// - /// The GridInstantMessage object - /// Hashtable containing the XMLRPC request - private Hashtable ConvertGridInstantMessageToXMLRPC(GridInstantMessage msg) - { - Hashtable gim = new Hashtable(); - gim["from_agent_id"] = msg.fromAgentID.ToString(); - // Kept for compatibility - gim["from_agent_session"] = UUID.Zero.ToString(); - gim["to_agent_id"] = msg.toAgentID.ToString(); - gim["im_session_id"] = msg.imSessionID.ToString(); - gim["timestamp"] = msg.timestamp.ToString(); - gim["from_agent_name"] = msg.fromAgentName; - gim["message"] = msg.message; - byte[] dialogdata = new byte[1];dialogdata[0] = msg.dialog; - gim["dialog"] = Convert.ToBase64String(dialogdata,Base64FormattingOptions.None); - - if (msg.fromGroup) - gim["from_group"] = "TRUE"; - else - gim["from_group"] = "FALSE"; - byte[] offlinedata = new byte[1]; offlinedata[0] = msg.offline; - gim["offline"] = Convert.ToBase64String(offlinedata, Base64FormattingOptions.None); - gim["parent_estate_id"] = msg.ParentEstateID.ToString(); - gim["position_x"] = msg.Position.X.ToString(); - gim["position_y"] = msg.Position.Y.ToString(); - gim["position_z"] = msg.Position.Z.ToString(); - gim["region_id"] = msg.RegionID.ToString(); - gim["binary_bucket"] = Convert.ToBase64String(msg.binaryBucket,Base64FormattingOptions.None); - return gim; - } - - } -} diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/PresenceModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/PresenceModule.cs deleted file mode 100644 index c84d3d5..0000000 --- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/PresenceModule.cs +++ /dev/null @@ -1,426 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Net; -using System.Threading; -using OpenMetaverse; -using log4net; -using Nini.Config; -using Nwc.XmlRpc; -using OpenSim.Framework; -using OpenSim.Framework.Client; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage -{ - public class PresenceModule : IRegionModule, IPresenceModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private bool m_Enabled = false; - private bool m_Gridmode = false; - - // some default scene for doing things that aren't connected to a specific scene. Avoids locking. - private Scene m_initialScene; - - private List m_Scenes = new List(); - - // we currently are only interested in root-agents. If the root isn't here, we don't know the region the - // user is in, so we have to ask the messaging server anyway. - private Dictionary m_RootAgents = - new Dictionary(); - - public event PresenceChange OnPresenceChange; - public event BulkPresenceData OnBulkPresenceData; - - public void Initialise(Scene scene, IConfigSource config) - { - lock (m_Scenes) - { - // This is a shared module; Initialise will be called for every region on this server. - // Only check config once for the first region. - if (m_Scenes.Count == 0) - { - IConfig cnf = config.Configs["Messaging"]; - if (cnf != null && cnf.GetString( - "PresenceModule", "PresenceModule") != - "PresenceModule") - return; - - cnf = config.Configs["Startup"]; - if (cnf != null) - m_Gridmode = cnf.GetBoolean("gridmode", false); - - m_Enabled = true; - - m_initialScene = scene; - } - - if (m_Gridmode) - NotifyMessageServerOfStartup(scene); - - m_Scenes.Add(scene); - } - - scene.RegisterModuleInterface(this); - - scene.EventManager.OnNewClient += OnNewClient; - scene.EventManager.OnSetRootAgentScene += OnSetRootAgentScene; - scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; - } - - public void PostInitialise() - { - } - - public void Close() - { - if (!m_Gridmode || !m_Enabled) - return; - - if (OnPresenceChange != null) - { - lock (m_RootAgents) - { - // on shutdown, users are kicked, too - foreach (KeyValuePair pair in m_RootAgents) - { - OnPresenceChange(new PresenceInfo(pair.Key, UUID.Zero)); - } - } - } - - lock (m_Scenes) - { - foreach (Scene scene in m_Scenes) - NotifyMessageServerOfShutdown(scene); - } - } - - public string Name - { - get { return "PresenceModule"; } - } - - public bool IsSharedModule - { - get { return true; } - } - - public void RequestBulkPresenceData(UUID[] users) - { - if (OnBulkPresenceData != null) - { - PresenceInfo[] result = new PresenceInfo[users.Length]; - if (m_Gridmode) - { - // first check the local information - List uuids = new List(); // the uuids to check remotely - List indices = new List(); // just for performance. - lock (m_RootAgents) - { - for (int i = 0; i < uuids.Count; ++i) - { - Scene scene; - if (m_RootAgents.TryGetValue(users[i], out scene)) - { - result[i] = new PresenceInfo(users[i], scene.RegionInfo.RegionID); - } - else - { - uuids.Add(users[i]); - indices.Add(i); - } - } - } - - // now we have filtered out all the local root agents. The rest we have to request info about - Dictionary infos = m_initialScene.GetFriendRegionInfos(uuids); - for (int i = 0; i < uuids.Count; ++i) - { - FriendRegionInfo info; - if (infos.TryGetValue(uuids[i], out info) && info.isOnline) - { - UUID regionID = info.regionID; - if (regionID == UUID.Zero) - { - // TODO this is the old messaging-server protocol; only the regionHandle is available. - // Fetch region-info to get the id - RegionInfo regionInfo = m_initialScene.RequestNeighbouringRegionInfo(info.regionHandle); - regionID = regionInfo.RegionID; - } - result[indices[i]] = new PresenceInfo(uuids[i], regionID); - } - else result[indices[i]] = new PresenceInfo(uuids[i], UUID.Zero); - } - } - else - { - // in standalone mode, we have all the info locally available. - lock (m_RootAgents) - { - for (int i = 0; i < users.Length; ++i) - { - Scene scene; - if (m_RootAgents.TryGetValue(users[i], out scene)) - { - result[i] = new PresenceInfo(users[i], scene.RegionInfo.RegionID); - } - else - { - result[i] = new PresenceInfo(users[i], UUID.Zero); - } - } - } - } - - // tell everyone - OnBulkPresenceData(result); - } - } - - // new client doesn't mean necessarily that user logged in, it just means it entered one of the - // the regions on this server - public void OnNewClient(IClientAPI client) - { - client.OnConnectionClosed += OnConnectionClosed; - client.OnLogout += OnLogout; - - // KLUDGE: See handler for details. - client.OnEconomyDataRequest += OnEconomyDataRequest; - } - - // connection closed just means *one* client connection has been closed. It doesn't mean that the - // user has logged off; it might have just TPed away. - public void OnConnectionClosed(IClientAPI client) - { - // TODO: Have to think what we have to do here... - // Should we just remove the root from the list (if scene matches)? - if (!(client.Scene is Scene)) - return; - Scene scene = (Scene)client.Scene; - - lock (m_RootAgents) - { - Scene rootScene; - if (!(m_RootAgents.TryGetValue(client.AgentId, out rootScene)) || scene != rootScene) - return; - - m_RootAgents.Remove(client.AgentId); - } - - // Should it have logged off, we'll do the logout part in OnLogout, even if no root is stored - // anymore. It logged off, after all... - } - - // Triggered when the user logs off. - public void OnLogout(IClientAPI client) - { - if (!(client.Scene is Scene)) - return; - Scene scene = (Scene)client.Scene; - - // On logout, we really remove the client from rootAgents, even if the scene doesn't match - lock (m_RootAgents) - { - if (m_RootAgents.ContainsKey(client.AgentId)) m_RootAgents.Remove(client.AgentId); - } - - // now inform the messaging server and anyone who is interested - NotifyMessageServerOfAgentLeaving(client.AgentId, scene.RegionInfo.RegionID, scene.RegionInfo.RegionHandle); - if (OnPresenceChange != null) OnPresenceChange(new PresenceInfo(client.AgentId, UUID.Zero)); - } - - public void OnSetRootAgentScene(UUID agentID, Scene scene) - { - // OnSetRootAgentScene can be called from several threads at once (with different agentID). - // Concurrent access to m_RootAgents is prone to failure on multi-core/-processor systems without - // correct locking). - lock (m_RootAgents) - { - Scene rootScene; - if (m_RootAgents.TryGetValue(agentID, out rootScene) && scene == rootScene) - { - return; - } - m_RootAgents[agentID] = scene; - } - // inform messaging server that agent changed the region - NotifyMessageServerOfAgentLocation(agentID, scene.RegionInfo.RegionID, scene.RegionInfo.RegionHandle); - } - - private void OnEconomyDataRequest(UUID agentID) - { - // KLUDGE: This is the only way I found to get a message (only) after login was completed and the - // client is connected enough to receive UDP packets. - // This packet seems to be sent only once, just after connection was established to the first - // region after login. - // We use it here to trigger a presence update; the old update-on-login was never be heard by - // the freshly logged in viewer, as it wasn't connected to the region at that time. - // TODO: Feel free to replace this by a better solution if you find one. - - // get the agent. This should work every time, as we just got a packet from it - ScenePresence agent = null; - lock (m_Scenes) - { - foreach (Scene scene in m_Scenes) - { - agent = scene.GetScenePresence(agentID); - if (agent != null) break; - } - } - - // just to be paranoid... - if (agent == null) - { - m_log.ErrorFormat("[PRESENCE]: Got a packet from agent {0} who can't be found anymore!?", agentID); - return; - } - - // we are a bit premature here, but the next packet will switch this child agent to root. - if (OnPresenceChange != null) OnPresenceChange(new PresenceInfo(agentID, agent.Scene.RegionInfo.RegionID)); - } - - public void OnMakeChildAgent(ScenePresence agent) - { - // OnMakeChildAgent can be called from several threads at once (with different agent). - // Concurrent access to m_RootAgents is prone to failure on multi-core/-processor systems without - // correct locking). - lock (m_RootAgents) - { - Scene rootScene; - if (m_RootAgents.TryGetValue(agent.UUID, out rootScene) && agent.Scene == rootScene) - { - m_RootAgents.Remove(agent.UUID); - } - } - // don't notify the messaging-server; either this agent just had been downgraded and another one will be upgraded - // to root momentarily (which will notify the messaging-server), or possibly it will be closed in a moment, - // which will update the messaging-server, too. - } - - private void NotifyMessageServerOfStartup(Scene scene) - { - Hashtable xmlrpcdata = new Hashtable(); - xmlrpcdata["RegionUUID"] = scene.RegionInfo.RegionID.ToString(); - ArrayList SendParams = new ArrayList(); - SendParams.Add(xmlrpcdata); - try - { - XmlRpcRequest UpRequest = new XmlRpcRequest("region_startup", SendParams); - XmlRpcResponse resp = UpRequest.Send(scene.CommsManager.NetworkServersInfo.MessagingURL, 5000); - - Hashtable responseData = (Hashtable)resp.Value; - if (responseData == null || (!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE") - { - m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region startup for region {0}", scene.RegionInfo.RegionName); - } - } - catch (System.Net.WebException) - { - m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region startup for region {0}", scene.RegionInfo.RegionName); - } - } - - private void NotifyMessageServerOfShutdown(Scene scene) - { - Hashtable xmlrpcdata = new Hashtable(); - xmlrpcdata["RegionUUID"] = scene.RegionInfo.RegionID.ToString(); - ArrayList SendParams = new ArrayList(); - SendParams.Add(xmlrpcdata); - try - { - XmlRpcRequest DownRequest = new XmlRpcRequest("region_shutdown", SendParams); - XmlRpcResponse resp = DownRequest.Send(scene.CommsManager.NetworkServersInfo.MessagingURL, 5000); - - Hashtable responseData = (Hashtable)resp.Value; - if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE") - { - m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region shutdown for region {0}", scene.RegionInfo.RegionName); - } - } - catch (System.Net.WebException) - { - m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region shutdown for region {0}", scene.RegionInfo.RegionName); - } - } - - private void NotifyMessageServerOfAgentLocation(UUID agentID, UUID region, ulong regionHandle) - { - Hashtable xmlrpcdata = new Hashtable(); - xmlrpcdata["AgentID"] = agentID.ToString(); - xmlrpcdata["RegionUUID"] = region.ToString(); - xmlrpcdata["RegionHandle"] = regionHandle.ToString(); - ArrayList SendParams = new ArrayList(); - SendParams.Add(xmlrpcdata); - try - { - XmlRpcRequest LocationRequest = new XmlRpcRequest("agent_location", SendParams); - XmlRpcResponse resp = LocationRequest.Send(m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL, 5000); - - Hashtable responseData = (Hashtable)resp.Value; - if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE") - { - m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent location for {0}", agentID.ToString()); - } - } - catch (System.Net.WebException) - { - m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent location for {0}", agentID.ToString()); - } - } - - private void NotifyMessageServerOfAgentLeaving(UUID agentID, UUID region, ulong regionHandle) - { - Hashtable xmlrpcdata = new Hashtable(); - xmlrpcdata["AgentID"] = agentID.ToString(); - xmlrpcdata["RegionUUID"] = region.ToString(); - xmlrpcdata["RegionHandle"] = regionHandle.ToString(); - ArrayList SendParams = new ArrayList(); - SendParams.Add(xmlrpcdata); - try - { - XmlRpcRequest LeavingRequest = new XmlRpcRequest("agent_leaving", SendParams); - XmlRpcResponse resp = LeavingRequest.Send(m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL, 5000); - - Hashtable responseData = (Hashtable)resp.Value; - if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE") - { - m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent leaving for {0}", agentID.ToString()); - } - } - catch (System.Net.WebException) - { - m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent leaving for {0}", agentID.ToString()); - } - } - } -} -- cgit v1.1