From 5c2168cae758ae19367f4c2f5a02713e74fc0912 Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Wed, 25 May 2011 12:32:21 -0700
Subject: HG: Instant Message working. Tested on HG standalones only. Needs a
lot more testing.
---
.../Hypergrid/UserAgentServiceConnector.cs | 58 +++++++++
.../InstantMessageServiceConnector.cs | 129 +++++++++++++++++++++
2 files changed, 187 insertions(+)
create mode 100644 OpenSim/Services/Connectors/InstantMessage/InstantMessageServiceConnector.cs
(limited to 'OpenSim/Services/Connectors')
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
index 265bacf..50036b3 100644
--- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
@@ -560,6 +560,64 @@ namespace OpenSim.Services.Connectors.Hypergrid
return serverURLs;
}
+ public string LocateUser(UUID userID)
+ {
+ Hashtable hash = new Hashtable();
+ hash["userID"] = userID.ToString();
+
+ IList paramList = new ArrayList();
+ paramList.Add(hash);
+
+ XmlRpcRequest request = new XmlRpcRequest("locate_user", paramList);
+ string reason = string.Empty;
+
+ // Send and get reply
+ string url = string.Empty;
+ XmlRpcResponse response = null;
+ try
+ {
+ response = request.Send(m_ServerURL, 10000);
+ }
+ catch (Exception e)
+ {
+ m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0}", m_ServerURL);
+ reason = "Exception: " + e.Message;
+ return url;
+ }
+
+ if (response.IsFault)
+ {
+ m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} returned an error: {1}", m_ServerURL, response.FaultString);
+ reason = "XMLRPC Fault";
+ return url;
+ }
+
+ hash = (Hashtable)response.Value;
+ //foreach (Object o in hash)
+ // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
+ try
+ {
+ if (hash == null)
+ {
+ m_log.ErrorFormat("[USER AGENT CONNECTOR]: LocateUser Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
+ reason = "Internal error 1";
+ return url;
+ }
+
+ // Here's the actual response
+ if (hash.ContainsKey("URL"))
+ url = hash["URL"].ToString();
+
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response.");
+ reason = "Exception: " + e.Message;
+ }
+
+ return url;
+ }
+
private bool GetBoolResponse(XmlRpcRequest request, out string reason)
{
//m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURL);
diff --git a/OpenSim/Services/Connectors/InstantMessage/InstantMessageServiceConnector.cs b/OpenSim/Services/Connectors/InstantMessage/InstantMessageServiceConnector.cs
new file mode 100644
index 0000000..65ee7c7
--- /dev/null
+++ b/OpenSim/Services/Connectors/InstantMessage/InstantMessageServiceConnector.cs
@@ -0,0 +1,129 @@
+/*
+ * 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 OpenSimulator 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.Net;
+using System.Reflection;
+
+using OpenMetaverse;
+using Nwc.XmlRpc;
+using log4net;
+
+using OpenSim.Framework;
+
+namespace OpenSim.Services.Connectors.InstantMessage
+{
+ public class InstantMessageServiceConnector
+ {
+ private static readonly ILog m_log =
+ LogManager.GetLogger(
+ MethodBase.GetCurrentMethod().DeclaringType);
+
+ ///
+ /// This actually does the XMLRPC Request
+ ///
+ /// URL we pull the data out of to send the request to
+ /// The Instant Message
+ /// Bool if the message was successfully delivered at the other side.
+ public static bool SendInstantMessage(string url, GridInstantMessage im)
+ {
+ Hashtable xmlrpcdata = ConvertGridInstantMessageToXMLRPC(im);
+ xmlrpcdata["region_handle"] = 0;
+
+ ArrayList SendParams = new ArrayList();
+ SendParams.Add(xmlrpcdata);
+ XmlRpcRequest GridReq = new XmlRpcRequest("grid_instant_message", SendParams);
+ try
+ {
+
+ XmlRpcResponse GridResp = GridReq.Send(url, 3000);
+
+ Hashtable responseData = (Hashtable)GridResp.Value;
+
+ if (responseData.ContainsKey("success"))
+ {
+ if ((string)responseData["success"] == "TRUE")
+ {
+ m_log.DebugFormat("[XXX] Success");
+ return true;
+ }
+ else
+ {
+ m_log.DebugFormat("[XXX] Fail");
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+ catch (WebException e)
+ {
+ m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Error sending message to {0} the host didn't respond " + e.ToString(), url);
+ }
+
+ return false;
+ }
+
+ ///
+ /// Takes a GridInstantMessage and converts it into a Hashtable for XMLRPC
+ ///
+ /// The GridInstantMessage object
+ /// Hashtable containing the XMLRPC request
+ protected static 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;
+ }
+
+ }
+}
--
cgit v1.1