aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers
diff options
context:
space:
mode:
authorDiva Canto2011-05-25 12:32:21 -0700
committerDiva Canto2011-05-25 12:32:21 -0700
commit5c2168cae758ae19367f4c2f5a02713e74fc0912 (patch)
tree7d189c03a177ca716c91cf903cc7fd2e91fed1dc /OpenSim/Server/Handlers
parentAdded necessary code to drop inventory on hg friends using the profile window... (diff)
downloadopensim-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 'OpenSim/Server/Handlers')
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs280
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs48
2 files changed, 328 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..138313a
--- /dev/null
+++ b/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs
@@ -0,0 +1,280 @@
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 MainServer.Instance.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
129 try
130 {
131 timestamp = (uint)Convert.ToInt32((string)requestData["timestamp"]);
132 }
133 catch (ArgumentException)
134 {
135 }
136 catch (FormatException)
137 {
138 }
139 catch (OverflowException)
140 {
141 }
142
143 fromAgentName = (string)requestData["from_agent_name"];
144 message = (string)requestData["message"];
145 if (message == null)
146 message = string.Empty;
147
148 // Bytes don't transfer well over XMLRPC, so, we Base64 Encode them.
149 string requestData1 = (string)requestData["dialog"];
150 if (string.IsNullOrEmpty(requestData1))
151 {
152 dialog = 0;
153 }
154 else
155 {
156 byte[] dialogdata = Convert.FromBase64String(requestData1);
157 dialog = dialogdata[0];
158 }
159
160 if ((string)requestData["from_group"] == "TRUE")
161 fromGroup = true;
162
163 string requestData2 = (string)requestData["offline"];
164 if (String.IsNullOrEmpty(requestData2))
165 {
166 offline = 0;
167 }
168 else
169 {
170 byte[] offlinedata = Convert.FromBase64String(requestData2);
171 offline = offlinedata[0];
172 }
173
174 try
175 {
176 ParentEstateID = (uint)Convert.ToInt32((string)requestData["parent_estate_id"]);
177 }
178 catch (ArgumentException)
179 {
180 }
181 catch (FormatException)
182 {
183 }
184 catch (OverflowException)
185 {
186 }
187
188 try
189 {
190 pos_x = (uint)Convert.ToInt32((string)requestData["position_x"]);
191 }
192 catch (ArgumentException)
193 {
194 }
195 catch (FormatException)
196 {
197 }
198 catch (OverflowException)
199 {
200 }
201 try
202 {
203 pos_y = (uint)Convert.ToInt32((string)requestData["position_y"]);
204 }
205 catch (ArgumentException)
206 {
207 }
208 catch (FormatException)
209 {
210 }
211 catch (OverflowException)
212 {
213 }
214 try
215 {
216 pos_z = (uint)Convert.ToInt32((string)requestData["position_z"]);
217 }
218 catch (ArgumentException)
219 {
220 }
221 catch (FormatException)
222 {
223 }
224 catch (OverflowException)
225 {
226 }
227
228 Position = new Vector3(pos_x, pos_y, pos_z);
229
230 string requestData3 = (string)requestData["binary_bucket"];
231 if (string.IsNullOrEmpty(requestData3))
232 {
233 binaryBucket = new byte[0];
234 }
235 else
236 {
237 binaryBucket = Convert.FromBase64String(requestData3);
238 }
239
240 // Create a New GridInstantMessageObject the the data
241 GridInstantMessage gim = new GridInstantMessage();
242 gim.fromAgentID = fromAgentID.Guid;
243 gim.fromAgentName = fromAgentName;
244 gim.fromGroup = fromGroup;
245 gim.imSessionID = imSessionID.Guid;
246 gim.RegionID = UUID.Zero.Guid; // RegionID.Guid;
247 gim.timestamp = timestamp;
248 gim.toAgentID = toAgentID.Guid;
249 gim.message = message;
250 gim.dialog = dialog;
251 gim.offline = offline;
252 gim.ParentEstateID = ParentEstateID;
253 gim.Position = Position;
254 gim.binaryBucket = binaryBucket;
255
256 successful = m_IMService.IncomingInstantMessage(gim);
257
258 }
259 }
260 catch (Exception e)
261 {
262 m_log.Error("[INSTANT MESSAGE]: Caught unexpected exception:", e);
263 successful = false;
264 }
265
266 //Send response back to region calling if it was successful
267 // calling region uses this to know when to look up a user's location again.
268 XmlRpcResponse resp = new XmlRpcResponse();
269 Hashtable respdata = new Hashtable();
270 if (successful)
271 respdata["success"] = "TRUE";
272 else
273 respdata["success"] = "FALSE";
274 resp.Value = respdata;
275
276 return resp;
277 }
278
279 }
280}
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
index e51fe0b..942d960 100644
--- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
@@ -52,6 +52,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
52// MethodBase.GetCurrentMethod().DeclaringType); 52// MethodBase.GetCurrentMethod().DeclaringType);
53 53
54 private IUserAgentService m_HomeUsersService; 54 private IUserAgentService m_HomeUsersService;
55 private string[] m_AuthorizedCallers;
55 56
56 public UserAgentServerConnector(IConfigSource config, IHttpServer server) : 57 public UserAgentServerConnector(IConfigSource config, IHttpServer server) :
57 this(config, server, null) 58 this(config, server, null)
@@ -75,6 +76,10 @@ namespace OpenSim.Server.Handlers.Hypergrid
75 string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1"); 76 string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1");
76 bool proxy = gridConfig.GetBoolean("HasProxy", false); 77 bool proxy = gridConfig.GetBoolean("HasProxy", false);
77 78
79 string csv = gridConfig.GetString("AuthorizedCallers", "127.0.0.1");
80 csv = csv.Replace(" ", "");
81 m_AuthorizedCallers = csv.Split(',');
82
78 server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); 83 server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false);
79 server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); 84 server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false);
80 server.AddXmlRPCHandler("verify_agent", VerifyAgent, false); 85 server.AddXmlRPCHandler("verify_agent", VerifyAgent, false);
@@ -85,6 +90,8 @@ namespace OpenSim.Server.Handlers.Hypergrid
85 server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false); 90 server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false);
86 server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false); 91 server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false);
87 92
93 server.AddXmlRPCHandler("locate_user", LocateUser, false);
94
88 server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler); 95 server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler);
89 } 96 }
90 97
@@ -306,5 +313,46 @@ namespace OpenSim.Server.Handlers.Hypergrid
306 313
307 } 314 }
308 315
316 /// <summary>
317 /// Locates the user.
318 /// This is a sensitive operation, only authorized IP addresses can perform it.
319 /// </summary>
320 /// <param name="request"></param>
321 /// <param name="remoteClient"></param>
322 /// <returns></returns>
323 public XmlRpcResponse LocateUser(XmlRpcRequest request, IPEndPoint remoteClient)
324 {
325 Hashtable hash = new Hashtable();
326
327 bool authorized = false;
328 foreach (string s in m_AuthorizedCallers)
329 if (s == remoteClient.Address.ToString())
330 {
331 authorized = true;
332 break;
333 }
334
335 if (authorized)
336 {
337 Hashtable requestData = (Hashtable)request.Params[0];
338 //string host = (string)requestData["host"];
339 //string portstr = (string)requestData["port"];
340 if (requestData.ContainsKey("userID"))
341 {
342 string userID_str = (string)requestData["userID"];
343 UUID userID = UUID.Zero;
344 UUID.TryParse(userID_str, out userID);
345
346 string url = m_HomeUsersService.LocateUser(userID);
347 if (url != string.Empty)
348 hash["URL"] = url;
349 }
350 }
351
352 XmlRpcResponse response = new XmlRpcResponse();
353 response.Value = hash;
354 return response;
355
356 }
309 } 357 }
310} 358}