OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
InstantMessageServiceConnector.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 using System;
28 using System.Collections;
29 using System.Collections.Generic;
30 using System.Net;
31 using System.Reflection;
32 
33 using OpenMetaverse;
34 using Nwc.XmlRpc;
35 using log4net;
36 
37 using OpenSim.Framework;
38 
39 namespace OpenSim.Services.Connectors.InstantMessage
40 {
42  {
43  private static readonly ILog m_log =
44  LogManager.GetLogger(
45  MethodBase.GetCurrentMethod().DeclaringType);
46 
53  public static bool SendInstantMessage(string url, GridInstantMessage im)
54  {
55  Hashtable xmlrpcdata = ConvertGridInstantMessageToXMLRPC(im);
56  xmlrpcdata["region_handle"] = 0;
57 
58  ArrayList SendParams = new ArrayList();
59  SendParams.Add(xmlrpcdata);
60  XmlRpcRequest GridReq = new XmlRpcRequest("grid_instant_message", SendParams);
61  try
62  {
63 
64  XmlRpcResponse GridResp = GridReq.Send(url, 10000);
65 
66  Hashtable responseData = (Hashtable)GridResp.Value;
67 
68  if (responseData.ContainsKey("success"))
69  {
70  if ((string)responseData["success"] == "TRUE")
71  {
72  //m_log.DebugFormat("[XXX] Success");
73  return true;
74  }
75  else
76  {
77  //m_log.DebugFormat("[XXX] Fail");
78  return false;
79  }
80  }
81  else
82  {
83  m_log.DebugFormat("[GRID INSTANT MESSAGE]: No response from {0}", url);
84  return false;
85  }
86  }
87  catch (WebException e)
88  {
89  m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Error sending message to {0} the host didn't respond " + e.ToString(), url);
90  }
91 
92  return false;
93  }
94 
101  {
102  Hashtable gim = new Hashtable();
103  gim["from_agent_id"] = msg.fromAgentID.ToString();
104  // Kept for compatibility
105  gim["from_agent_session"] = UUID.Zero.ToString();
106  gim["to_agent_id"] = msg.toAgentID.ToString();
107  gim["im_session_id"] = msg.imSessionID.ToString();
108  gim["timestamp"] = msg.timestamp.ToString();
109  gim["from_agent_name"] = msg.fromAgentName;
110  gim["message"] = msg.message;
111  byte[] dialogdata = new byte[1]; dialogdata[0] = msg.dialog;
112  gim["dialog"] = Convert.ToBase64String(dialogdata, Base64FormattingOptions.None);
113 
114  if (msg.fromGroup)
115  gim["from_group"] = "TRUE";
116  else
117  gim["from_group"] = "FALSE";
118  byte[] offlinedata = new byte[1]; offlinedata[0] = msg.offline;
119  gim["offline"] = Convert.ToBase64String(offlinedata, Base64FormattingOptions.None);
120  gim["parent_estate_id"] = msg.ParentEstateID.ToString();
121  gim["position_x"] = msg.Position.X.ToString();
122  gim["position_y"] = msg.Position.Y.ToString();
123  gim["position_z"] = msg.Position.Z.ToString();
124  gim["region_id"] = msg.RegionID.ToString();
125  gim["binary_bucket"] = Convert.ToBase64String(msg.binaryBucket, Base64FormattingOptions.None);
126  gim["region_id"] = new UUID(msg.RegionID).ToString();
127 
128  return gim;
129  }
130 
131  }
132 }
static bool SendInstantMessage(string url, GridInstantMessage im)
This actually does the XMLRPC Request
static Hashtable ConvertGridInstantMessageToXMLRPC(GridInstantMessage msg)
Takes a GridInstantMessage and converts it into a Hashtable for XMLRPC
Interactive OpenSim region server
Definition: OpenSim.cs:55