OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
UserAgentServerConnector.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 
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Net;
32 using System.Reflection;
33 
34 using Nini.Config;
35 using OpenSim.Framework;
36 using OpenSim.Server.Base;
37 using OpenSim.Services.Interfaces;
38 using OpenSim.Framework.Servers.HttpServer;
39 using OpenSim.Server.Handlers.Base;
41 
42 using log4net;
43 using Nwc.XmlRpc;
44 using OpenMetaverse;
45 
46 namespace OpenSim.Server.Handlers.Hypergrid
47 {
49  {
50 // private static readonly ILog m_log =
51 // LogManager.GetLogger(
52 // MethodBase.GetCurrentMethod().DeclaringType);
53 
54  private IUserAgentService m_HomeUsersService;
55  public IUserAgentService HomeUsersService
56  {
57  get { return m_HomeUsersService; }
58  }
59 
60  private string[] m_AuthorizedCallers;
61 
62  private bool m_VerifyCallers = false;
63 
64  public UserAgentServerConnector(IConfigSource config, IHttpServer server) :
65  this(config, server, (IFriendsSimConnector)null)
66  {
67  }
68 
69  public UserAgentServerConnector(IConfigSource config, IHttpServer server, string configName) :
70  this(config, server)
71  {
72  }
73 
74  public UserAgentServerConnector(IConfigSource config, IHttpServer server, IFriendsSimConnector friendsConnector) :
75  base(config, server, String.Empty)
76  {
77  IConfig gridConfig = config.Configs["UserAgentService"];
78  if (gridConfig != null)
79  {
80  string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty);
81 
82  Object[] args = new Object[] { config, friendsConnector };
83  m_HomeUsersService = ServerUtils.LoadPlugin<IUserAgentService>(serviceDll, args);
84  }
85  if (m_HomeUsersService == null)
86  throw new Exception("UserAgent server connector cannot proceed because of missing service");
87 
88  string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1");
89  bool proxy = gridConfig.GetBoolean("HasProxy", false);
90 
91  m_VerifyCallers = gridConfig.GetBoolean("VerifyCallers", false);
92  string csv = gridConfig.GetString("AuthorizedCallers", "127.0.0.1");
93  csv = csv.Replace(" ", "");
94  m_AuthorizedCallers = csv.Split(',');
95 
96  server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false);
97  server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false);
98  server.AddXmlRPCHandler("verify_agent", VerifyAgent, false);
99  server.AddXmlRPCHandler("verify_client", VerifyClient, false);
100  server.AddXmlRPCHandler("logout_agent", LogoutAgent, false);
101 
102 #pragma warning disable 0612
103  server.AddXmlRPCHandler("status_notification", StatusNotification, false);
104  server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false);
105 #pragma warning restore 0612
106  server.AddXmlRPCHandler("get_user_info", GetUserInfo, false);
107  server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false);
108 
109  server.AddXmlRPCHandler("locate_user", LocateUser, false);
110  server.AddXmlRPCHandler("get_uui", GetUUI, false);
111  server.AddXmlRPCHandler("get_uuid", GetUUID, false);
112 
113  server.AddStreamHandler(new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy));
114  }
115 
116  public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient)
117  {
118  Hashtable requestData = (Hashtable)request.Params[0];
119  //string host = (string)requestData["host"];
120  //string portstr = (string)requestData["port"];
121  string userID_str = (string)requestData["userID"];
122  UUID userID = UUID.Zero;
123  UUID.TryParse(userID_str, out userID);
124 
125  Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY;
126  GridRegion regInfo = m_HomeUsersService.GetHomeRegion(userID, out position, out lookAt);
127 
128  Hashtable hash = new Hashtable();
129  if (regInfo == null)
130  hash["result"] = "false";
131  else
132  {
133  hash["result"] = "true";
134  hash["uuid"] = regInfo.RegionID.ToString();
135  hash["x"] = regInfo.RegionLocX.ToString();
136  hash["y"] = regInfo.RegionLocY.ToString();
137  hash["size_x"] = regInfo.RegionSizeX.ToString();
138  hash["size_y"] = regInfo.RegionSizeY.ToString();
139  hash["region_name"] = regInfo.RegionName;
140  hash["hostname"] = regInfo.ExternalHostName;
141  hash["http_port"] = regInfo.HttpPort.ToString();
142  hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
143  hash["position"] = position.ToString();
144  hash["lookAt"] = lookAt.ToString();
145  }
146  XmlRpcResponse response = new XmlRpcResponse();
147  response.Value = hash;
148  return response;
149 
150  }
151 
152  public XmlRpcResponse AgentIsComingHome(XmlRpcRequest request, IPEndPoint remoteClient)
153  {
154  Hashtable requestData = (Hashtable)request.Params[0];
155  //string host = (string)requestData["host"];
156  //string portstr = (string)requestData["port"];
157  string sessionID_str = (string)requestData["sessionID"];
158  UUID sessionID = UUID.Zero;
159  UUID.TryParse(sessionID_str, out sessionID);
160  string gridName = (string)requestData["externalName"];
161 
162  bool success = m_HomeUsersService.IsAgentComingHome(sessionID, gridName);
163 
164  Hashtable hash = new Hashtable();
165  hash["result"] = success.ToString();
166  XmlRpcResponse response = new XmlRpcResponse();
167  response.Value = hash;
168  return response;
169 
170  }
171 
172  public XmlRpcResponse VerifyAgent(XmlRpcRequest request, IPEndPoint remoteClient)
173  {
174  Hashtable requestData = (Hashtable)request.Params[0];
175  //string host = (string)requestData["host"];
176  //string portstr = (string)requestData["port"];
177  string sessionID_str = (string)requestData["sessionID"];
178  UUID sessionID = UUID.Zero;
179  UUID.TryParse(sessionID_str, out sessionID);
180  string token = (string)requestData["token"];
181 
182  bool success = m_HomeUsersService.VerifyAgent(sessionID, token);
183 
184  Hashtable hash = new Hashtable();
185  hash["result"] = success.ToString();
186  XmlRpcResponse response = new XmlRpcResponse();
187  response.Value = hash;
188  return response;
189 
190  }
191 
192  public XmlRpcResponse VerifyClient(XmlRpcRequest request, IPEndPoint remoteClient)
193  {
194  Hashtable requestData = (Hashtable)request.Params[0];
195  //string host = (string)requestData["host"];
196  //string portstr = (string)requestData["port"];
197  string sessionID_str = (string)requestData["sessionID"];
198  UUID sessionID = UUID.Zero;
199  UUID.TryParse(sessionID_str, out sessionID);
200  string token = (string)requestData["token"];
201 
202  bool success = m_HomeUsersService.VerifyClient(sessionID, token);
203 
204  Hashtable hash = new Hashtable();
205  hash["result"] = success.ToString();
206  XmlRpcResponse response = new XmlRpcResponse();
207  response.Value = hash;
208  return response;
209 
210  }
211 
212  public XmlRpcResponse LogoutAgent(XmlRpcRequest request, IPEndPoint remoteClient)
213  {
214  Hashtable requestData = (Hashtable)request.Params[0];
215  //string host = (string)requestData["host"];
216  //string portstr = (string)requestData["port"];
217  string sessionID_str = (string)requestData["sessionID"];
218  UUID sessionID = UUID.Zero;
219  UUID.TryParse(sessionID_str, out sessionID);
220  string userID_str = (string)requestData["userID"];
221  UUID userID = UUID.Zero;
222  UUID.TryParse(userID_str, out userID);
223 
224  m_HomeUsersService.LogoutAgent(userID, sessionID);
225 
226  Hashtable hash = new Hashtable();
227  hash["result"] = "true";
228  XmlRpcResponse response = new XmlRpcResponse();
229  response.Value = hash;
230  return response;
231 
232  }
233 
234  [Obsolete]
235  public XmlRpcResponse StatusNotification(XmlRpcRequest request, IPEndPoint remoteClient)
236  {
237  Hashtable hash = new Hashtable();
238  hash["result"] = "false";
239 
240  Hashtable requestData = (Hashtable)request.Params[0];
241  //string host = (string)requestData["host"];
242  //string portstr = (string)requestData["port"];
243  if (requestData.ContainsKey("userID") && requestData.ContainsKey("online"))
244  {
245  string userID_str = (string)requestData["userID"];
246  UUID userID = UUID.Zero;
247  UUID.TryParse(userID_str, out userID);
248  List<string> ids = new List<string>();
249  foreach (object key in requestData.Keys)
250  {
251  if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null)
252  ids.Add(requestData[key].ToString());
253  }
254  bool online = false;
255  bool.TryParse(requestData["online"].ToString(), out online);
256 
257  // let's spawn a thread for this, because it may take a long time...
258  List<UUID> friendsOnline = m_HomeUsersService.StatusNotification(ids, userID, online);
259  if (friendsOnline.Count > 0)
260  {
261  int i = 0;
262  foreach (UUID id in friendsOnline)
263  {
264  hash["friend_" + i.ToString()] = id.ToString();
265  i++;
266  }
267  }
268  else
269  hash["result"] = "No Friends Online";
270 
271  }
272 
273  XmlRpcResponse response = new XmlRpcResponse();
274  response.Value = hash;
275  return response;
276 
277  }
278 
279  [Obsolete]
280  public XmlRpcResponse GetOnlineFriends(XmlRpcRequest request, IPEndPoint remoteClient)
281  {
282  Hashtable hash = new Hashtable();
283 
284  Hashtable requestData = (Hashtable)request.Params[0];
285  //string host = (string)requestData["host"];
286  //string portstr = (string)requestData["port"];
287  if (requestData.ContainsKey("userID"))
288  {
289  string userID_str = (string)requestData["userID"];
290  UUID userID = UUID.Zero;
291  UUID.TryParse(userID_str, out userID);
292  List<string> ids = new List<string>();
293  foreach (object key in requestData.Keys)
294  {
295  if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null)
296  ids.Add(requestData[key].ToString());
297  }
298 
299  //List<UUID> online = m_HomeUsersService.GetOnlineFriends(userID, ids);
300  //if (online.Count > 0)
301  //{
302  // int i = 0;
303  // foreach (UUID id in online)
304  // {
305  // hash["friend_" + i.ToString()] = id.ToString();
306  // i++;
307  // }
308  //}
309  //else
310  // hash["result"] = "No Friends Online";
311  }
312 
313  XmlRpcResponse response = new XmlRpcResponse();
314  response.Value = hash;
315  return response;
316 
317  }
318 
319  public XmlRpcResponse GetUserInfo(XmlRpcRequest request, IPEndPoint remoteClient)
320  {
321  Hashtable hash = new Hashtable();
322  Hashtable requestData = (Hashtable)request.Params[0];
323 
324  // This needs checking!
325  if (requestData.ContainsKey("userID"))
326  {
327  string userID_str = (string)requestData["userID"];
328  UUID userID = UUID.Zero;
329  UUID.TryParse(userID_str, out userID);
330 
331  //int userFlags = m_HomeUsersService.GetUserFlags(userID);
332  Dictionary<string,object> userInfo = m_HomeUsersService.GetUserInfo(userID);
333  if (userInfo.Count > 0)
334  {
335  foreach (KeyValuePair<string, object> kvp in userInfo)
336  {
337  hash[kvp.Key] = kvp.Value;
338  }
339  }
340  else
341  {
342  hash["result"] = "failure";
343  }
344  }
345 
346  XmlRpcResponse response = new XmlRpcResponse();
347  response.Value = hash;
348  return response;
349  }
350 
351  public XmlRpcResponse GetServerURLs(XmlRpcRequest request, IPEndPoint remoteClient)
352  {
353  Hashtable hash = new Hashtable();
354 
355  Hashtable requestData = (Hashtable)request.Params[0];
356  //string host = (string)requestData["host"];
357  //string portstr = (string)requestData["port"];
358  if (requestData.ContainsKey("userID"))
359  {
360  string userID_str = (string)requestData["userID"];
361  UUID userID = UUID.Zero;
362  UUID.TryParse(userID_str, out userID);
363 
364  Dictionary<string, object> serverURLs = m_HomeUsersService.GetServerURLs(userID);
365  if (serverURLs.Count > 0)
366  {
367  foreach (KeyValuePair<string, object> kvp in serverURLs)
368  hash["SRV_" + kvp.Key] = kvp.Value.ToString();
369  }
370  else
371  hash["result"] = "No Service URLs";
372  }
373 
374  XmlRpcResponse response = new XmlRpcResponse();
375  response.Value = hash;
376  return response;
377 
378  }
379 
387  public XmlRpcResponse LocateUser(XmlRpcRequest request, IPEndPoint remoteClient)
388  {
389  Hashtable hash = new Hashtable();
390 
391  bool authorized = true;
392  if (m_VerifyCallers)
393  {
394  authorized = false;
395  foreach (string s in m_AuthorizedCallers)
396  if (s == remoteClient.Address.ToString())
397  {
398  authorized = true;
399  break;
400  }
401  }
402 
403  if (authorized)
404  {
405  Hashtable requestData = (Hashtable)request.Params[0];
406  //string host = (string)requestData["host"];
407  //string portstr = (string)requestData["port"];
408  if (requestData.ContainsKey("userID"))
409  {
410  string userID_str = (string)requestData["userID"];
411  UUID userID = UUID.Zero;
412  UUID.TryParse(userID_str, out userID);
413 
414  string url = m_HomeUsersService.LocateUser(userID);
415  if (url != string.Empty)
416  hash["URL"] = url;
417  else
418  hash["result"] = "Unable to locate user";
419  }
420  }
421 
422  XmlRpcResponse response = new XmlRpcResponse();
423  response.Value = hash;
424  return response;
425 
426  }
427 
434  public XmlRpcResponse GetUUI(XmlRpcRequest request, IPEndPoint remoteClient)
435  {
436  Hashtable hash = new Hashtable();
437 
438  Hashtable requestData = (Hashtable)request.Params[0];
439  //string host = (string)requestData["host"];
440  //string portstr = (string)requestData["port"];
441  if (requestData.ContainsKey("userID") && requestData.ContainsKey("targetUserID"))
442  {
443  string userID_str = (string)requestData["userID"];
444  UUID userID = UUID.Zero;
445  UUID.TryParse(userID_str, out userID);
446 
447  string tuserID_str = (string)requestData["targetUserID"];
448  UUID targetUserID = UUID.Zero;
449  UUID.TryParse(tuserID_str, out targetUserID);
450  string uui = m_HomeUsersService.GetUUI(userID, targetUserID);
451  if (uui != string.Empty)
452  hash["UUI"] = uui;
453  else
454  hash["result"] = "User unknown";
455  }
456 
457  XmlRpcResponse response = new XmlRpcResponse();
458  response.Value = hash;
459  return response;
460  }
461 
468  public XmlRpcResponse GetUUID(XmlRpcRequest request, IPEndPoint remoteClient)
469  {
470  Hashtable hash = new Hashtable();
471 
472  Hashtable requestData = (Hashtable)request.Params[0];
473  //string host = (string)requestData["host"];
474  //string portstr = (string)requestData["port"];
475  if (requestData.ContainsKey("first") && requestData.ContainsKey("last"))
476  {
477  string first = (string)requestData["first"];
478  string last = (string)requestData["last"];
479  UUID uuid = m_HomeUsersService.GetUUID(first, last);
480  hash["UUID"] = uuid.ToString();
481  }
482 
483  XmlRpcResponse response = new XmlRpcResponse();
484  response.Value = hash;
485  return response;
486  }
487  }
488 }
XmlRpcResponse GetUUID(XmlRpcRequest request, IPEndPoint remoteClient)
Gets the UUID of a user given First name, Last name.
UserAgentServerConnector(IConfigSource config, IHttpServer server, IFriendsSimConnector friendsConnector)
XmlRpcResponse GetOnlineFriends(XmlRpcRequest request, IPEndPoint remoteClient)
XmlRpcResponse VerifyClient(XmlRpcRequest request, IPEndPoint remoteClient)
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
Definition: IHttpServer.cs:36
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
Definition: ICM_Api.cs:31
UserAgentServerConnector(IConfigSource config, IHttpServer server, string configName)
XmlRpcResponse GetUUI(XmlRpcRequest request, IPEndPoint remoteClient)
Returns the UUI of a user given a UUID.
XmlRpcResponse StatusNotification(XmlRpcRequest request, IPEndPoint remoteClient)
XmlRpcResponse VerifyAgent(XmlRpcRequest request, IPEndPoint remoteClient)
OpenSim.Services.Interfaces.GridRegion GridRegion
UserAgentServerConnector(IConfigSource config, IHttpServer server)
XmlRpcResponse GetUserInfo(XmlRpcRequest request, IPEndPoint remoteClient)
XmlRpcResponse LocateUser(XmlRpcRequest request, IPEndPoint remoteClient)
Locates the user. This is a sensitive operation, only authorized IP addresses can perform it...
XmlRpcResponse LogoutAgent(XmlRpcRequest request, IPEndPoint remoteClient)
XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient)
XmlRpcResponse AgentIsComingHome(XmlRpcRequest request, IPEndPoint remoteClient)
XmlRpcResponse GetServerURLs(XmlRpcRequest request, IPEndPoint remoteClient)