diff options
author | Diva Canto | 2011-05-25 12:32:21 -0700 |
---|---|---|
committer | Diva Canto | 2011-05-25 12:32:21 -0700 |
commit | 5c2168cae758ae19367f4c2f5a02713e74fc0912 (patch) | |
tree | 7d189c03a177ca716c91cf903cc7fd2e91fed1dc /OpenSim/Services/Connectors/InstantMessage | |
parent | Added necessary code to drop inventory on hg friends using the profile window... (diff) | |
download | opensim-SC_OLD-5c2168cae758ae19367f4c2f5a02713e74fc0912.zip opensim-SC_OLD-5c2168cae758ae19367f4c2f5a02713e74fc0912.tar.gz opensim-SC_OLD-5c2168cae758ae19367f4c2f5a02713e74fc0912.tar.bz2 opensim-SC_OLD-5c2168cae758ae19367f4c2f5a02713e74fc0912.tar.xz |
HG: Instant Message working. Tested on HG standalones only. Needs a lot more testing.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/Connectors/InstantMessage/InstantMessageServiceConnector.cs | 129 |
1 files changed, 129 insertions, 0 deletions
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 @@ | |||
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 | { | ||
41 | public class InstantMessageServiceConnector | ||
42 | { | ||
43 | private static readonly ILog m_log = | ||
44 | LogManager.GetLogger( | ||
45 | MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | /// <summary> | ||
48 | /// This actually does the XMLRPC Request | ||
49 | /// </summary> | ||
50 | /// <param name="url">URL we pull the data out of to send the request to</param> | ||
51 | /// <param name="im">The Instant Message </param> | ||
52 | /// <returns>Bool if the message was successfully delivered at the other side.</returns> | ||
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, 3000); | ||
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 | return false; | ||
84 | } | ||
85 | } | ||
86 | catch (WebException e) | ||
87 | { | ||
88 | m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Error sending message to {0} the host didn't respond " + e.ToString(), url); | ||
89 | } | ||
90 | |||
91 | return false; | ||
92 | } | ||
93 | |||
94 | /// <summary> | ||
95 | /// Takes a GridInstantMessage and converts it into a Hashtable for XMLRPC | ||
96 | /// </summary> | ||
97 | /// <param name="msg">The GridInstantMessage object</param> | ||
98 | /// <returns>Hashtable containing the XMLRPC request</returns> | ||
99 | protected static Hashtable ConvertGridInstantMessageToXMLRPC(GridInstantMessage msg) | ||
100 | { | ||
101 | Hashtable gim = new Hashtable(); | ||
102 | gim["from_agent_id"] = msg.fromAgentID.ToString(); | ||
103 | // Kept for compatibility | ||
104 | gim["from_agent_session"] = UUID.Zero.ToString(); | ||
105 | gim["to_agent_id"] = msg.toAgentID.ToString(); | ||
106 | gim["im_session_id"] = msg.imSessionID.ToString(); | ||
107 | gim["timestamp"] = msg.timestamp.ToString(); | ||
108 | gim["from_agent_name"] = msg.fromAgentName; | ||
109 | gim["message"] = msg.message; | ||
110 | byte[] dialogdata = new byte[1]; dialogdata[0] = msg.dialog; | ||
111 | gim["dialog"] = Convert.ToBase64String(dialogdata, Base64FormattingOptions.None); | ||
112 | |||
113 | if (msg.fromGroup) | ||
114 | gim["from_group"] = "TRUE"; | ||
115 | else | ||
116 | gim["from_group"] = "FALSE"; | ||
117 | byte[] offlinedata = new byte[1]; offlinedata[0] = msg.offline; | ||
118 | gim["offline"] = Convert.ToBase64String(offlinedata, Base64FormattingOptions.None); | ||
119 | gim["parent_estate_id"] = msg.ParentEstateID.ToString(); | ||
120 | gim["position_x"] = msg.Position.X.ToString(); | ||
121 | gim["position_y"] = msg.Position.Y.ToString(); | ||
122 | gim["position_z"] = msg.Position.Z.ToString(); | ||
123 | gim["region_id"] = msg.RegionID.ToString(); | ||
124 | gim["binary_bucket"] = Convert.ToBase64String(msg.binaryBucket, Base64FormattingOptions.None); | ||
125 | return gim; | ||
126 | } | ||
127 | |||
128 | } | ||
129 | } | ||