aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs')
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs243
1 files changed, 243 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs
new file mode 100644
index 0000000..80eb5d2
--- /dev/null
+++ b/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs
@@ -0,0 +1,243 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33
34using Nini.Config;
35using OpenSim.Framework;
36using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces;
38using OpenSim.Framework.Servers.HttpServer;
39using OpenSim.Server.Handlers.Base;
40using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41
42using log4net;
43using Nwc.XmlRpc;
44using OpenMetaverse;
45
46namespace OpenSim.Server.Handlers.Hypergrid
47{
48 public class InstantMessageServerConnector : ServiceConnector
49 {
50 private static readonly ILog m_log =
51 LogManager.GetLogger(
52 MethodBase.GetCurrentMethod().DeclaringType);
53
54 private IInstantMessage m_IMService;
55
56 public InstantMessageServerConnector(IConfigSource config, IHttpServer server) :
57 this(config, server, null)
58 {
59 }
60
61 public InstantMessageServerConnector(IConfigSource config, IHttpServer server, IInstantMessageSimConnector simConnector) :
62 base(config, server, String.Empty)
63 {
64 IConfig gridConfig = config.Configs["HGInstantMessageService"];
65 if (gridConfig != null)
66 {
67 string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty);
68
69 Object[] args = new Object[] { config, simConnector };
70 m_IMService = ServerUtils.LoadPlugin<IInstantMessage>(serviceDll, args);
71 }
72 if (m_IMService == null)
73 throw new Exception("InstantMessage server connector cannot proceed because of missing service");
74
75 server.AddXmlRPCHandler("grid_instant_message", ProcessInstantMessage, false);
76
77 }
78
79 public IInstantMessage GetService()
80 {
81 return m_IMService;
82 }
83
84 protected virtual XmlRpcResponse ProcessInstantMessage(XmlRpcRequest request, IPEndPoint remoteClient)
85 {
86 bool successful = false;
87
88 try
89 {
90 // various rational defaults
91 UUID fromAgentID = UUID.Zero;
92 UUID toAgentID = UUID.Zero;
93 UUID imSessionID = UUID.Zero;
94 uint timestamp = 0;
95 string fromAgentName = "";
96 string message = "";
97 byte dialog = (byte)0;
98 bool fromGroup = false;
99 byte offline = (byte)0;
100 uint ParentEstateID = 0;
101 Vector3 Position = Vector3.Zero;
102 UUID RegionID = UUID.Zero;
103 byte[] binaryBucket = new byte[0];
104
105 float pos_x = 0;
106 float pos_y = 0;
107 float pos_z = 0;
108 //m_log.Info("Processing IM");
109
110
111 Hashtable requestData = (Hashtable)request.Params[0];
112 // Check if it's got all the data
113 if (requestData.ContainsKey("from_agent_id")
114 && requestData.ContainsKey("to_agent_id") && requestData.ContainsKey("im_session_id")
115 && requestData.ContainsKey("timestamp") && requestData.ContainsKey("from_agent_name")
116 && requestData.ContainsKey("message") && requestData.ContainsKey("dialog")
117 && requestData.ContainsKey("from_group")
118 && requestData.ContainsKey("offline") && requestData.ContainsKey("parent_estate_id")
119 && requestData.ContainsKey("position_x") && requestData.ContainsKey("position_y")
120 && requestData.ContainsKey("position_z") && requestData.ContainsKey("region_id")
121 && requestData.ContainsKey("binary_bucket"))
122 {
123 // Do the easy way of validating the UUIDs
124 UUID.TryParse((string)requestData["from_agent_id"], out fromAgentID);
125 UUID.TryParse((string)requestData["to_agent_id"], out toAgentID);
126 UUID.TryParse((string)requestData["im_session_id"], out imSessionID);
127 UUID.TryParse((string)requestData["region_id"], out RegionID);
128 try
129 {
130 timestamp = (uint)Convert.ToInt32((string)requestData["timestamp"]);
131 }
132 catch (ArgumentException)
133 {
134 }
135 catch (FormatException)
136 {
137 }
138 catch (OverflowException)
139 {
140 }
141
142 fromAgentName = (string)requestData["from_agent_name"];
143 message = (string)requestData["message"];
144 if (message == null)
145 message = string.Empty;
146
147 // Bytes don't transfer well over XMLRPC, so, we Base64 Encode them.
148 string requestData1 = (string)requestData["dialog"];
149 if (string.IsNullOrEmpty(requestData1))
150 {
151 dialog = 0;
152 }
153 else
154 {
155 byte[] dialogdata = Convert.FromBase64String(requestData1);
156 dialog = dialogdata[0];
157 }
158
159 if ((string)requestData["from_group"] == "TRUE")
160 fromGroup = true;
161
162 string requestData2 = (string)requestData["offline"];
163 if (String.IsNullOrEmpty(requestData2))
164 {
165 offline = 0;
166 }
167 else
168 {
169 byte[] offlinedata = Convert.FromBase64String(requestData2);
170 offline = offlinedata[0];
171 }
172
173 try
174 {
175 ParentEstateID = (uint)Convert.ToInt32((string)requestData["parent_estate_id"]);
176 }
177 catch (ArgumentException)
178 {
179 }
180 catch (FormatException)
181 {
182 }
183 catch (OverflowException)
184 {
185 }
186
187 float.TryParse((string)requestData["position_x"], out pos_x);
188 float.TryParse((string)requestData["position_y"], out pos_y);
189 float.TryParse((string)requestData["position_z"], out pos_z);
190
191 Position = new Vector3(pos_x, pos_y, pos_z);
192
193 string requestData3 = (string)requestData["binary_bucket"];
194 if (string.IsNullOrEmpty(requestData3))
195 {
196 binaryBucket = new byte[0];
197 }
198 else
199 {
200 binaryBucket = Convert.FromBase64String(requestData3);
201 }
202
203 // Create a New GridInstantMessageObject the the data
204 GridInstantMessage gim = new GridInstantMessage();
205 gim.fromAgentID = fromAgentID.Guid;
206 gim.fromAgentName = fromAgentName;
207 gim.fromGroup = fromGroup;
208 gim.imSessionID = imSessionID.Guid;
209 gim.RegionID = RegionID.Guid;
210 gim.timestamp = timestamp;
211 gim.toAgentID = toAgentID.Guid;
212 gim.message = message;
213 gim.dialog = dialog;
214 gim.offline = offline;
215 gim.ParentEstateID = ParentEstateID;
216 gim.Position = Position;
217 gim.binaryBucket = binaryBucket;
218
219 successful = m_IMService.IncomingInstantMessage(gim);
220
221 }
222 }
223 catch (Exception e)
224 {
225 m_log.Error("[INSTANT MESSAGE]: Caught unexpected exception:", e);
226 successful = false;
227 }
228
229 //Send response back to region calling if it was successful
230 // calling region uses this to know when to look up a user's location again.
231 XmlRpcResponse resp = new XmlRpcResponse();
232 Hashtable respdata = new Hashtable();
233 if (successful)
234 respdata["success"] = "TRUE";
235 else
236 respdata["success"] = "FALSE";
237 resp.Value = respdata;
238
239 return resp;
240 }
241
242 }
243}