clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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;
40 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41  
42 using log4net;
43 using Nwc.XmlRpc;
44 using OpenMetaverse;
45  
46 namespace OpenSim.Server.Handlers.Hypergrid
47 {
48 public class UserAgentServerConnector : ServiceConnector
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 server.AddXmlRPCHandler("status_notification", StatusNotification, false);
103 server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false);
104 server.AddXmlRPCHandler("get_user_info", GetUserInfo, false);
105 server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false);
106  
107 server.AddXmlRPCHandler("locate_user", LocateUser, false);
108 server.AddXmlRPCHandler("get_uui", GetUUI, false);
109 server.AddXmlRPCHandler("get_uuid", GetUUID, false);
110  
111 server.AddStreamHandler(new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy));
112 }
113  
114 public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient)
115 {
116 Hashtable requestData = (Hashtable)request.Params[0];
117 //string host = (string)requestData["host"];
118 //string portstr = (string)requestData["port"];
119 string userID_str = (string)requestData["userID"];
120 UUID userID = UUID.Zero;
121 UUID.TryParse(userID_str, out userID);
122  
123 Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY;
124 GridRegion regInfo = m_HomeUsersService.GetHomeRegion(userID, out position, out lookAt);
125  
126 Hashtable hash = new Hashtable();
127 if (regInfo == null)
128 hash["result"] = "false";
129 else
130 {
131 hash["result"] = "true";
132 hash["uuid"] = regInfo.RegionID.ToString();
133 hash["x"] = regInfo.RegionLocX.ToString();
134 hash["y"] = regInfo.RegionLocY.ToString();
135 hash["region_name"] = regInfo.RegionName;
136 hash["hostname"] = regInfo.ExternalHostName;
137 hash["http_port"] = regInfo.HttpPort.ToString();
138 hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
139 hash["position"] = position.ToString();
140 hash["lookAt"] = lookAt.ToString();
141 }
142 XmlRpcResponse response = new XmlRpcResponse();
143 response.Value = hash;
144 return response;
145  
146 }
147  
148 public XmlRpcResponse AgentIsComingHome(XmlRpcRequest request, IPEndPoint remoteClient)
149 {
150 Hashtable requestData = (Hashtable)request.Params[0];
151 //string host = (string)requestData["host"];
152 //string portstr = (string)requestData["port"];
153 string sessionID_str = (string)requestData["sessionID"];
154 UUID sessionID = UUID.Zero;
155 UUID.TryParse(sessionID_str, out sessionID);
156 string gridName = (string)requestData["externalName"];
157  
158 bool success = m_HomeUsersService.IsAgentComingHome(sessionID, gridName);
159  
160 Hashtable hash = new Hashtable();
161 hash["result"] = success.ToString();
162 XmlRpcResponse response = new XmlRpcResponse();
163 response.Value = hash;
164 return response;
165  
166 }
167  
168 public XmlRpcResponse VerifyAgent(XmlRpcRequest request, IPEndPoint remoteClient)
169 {
170 Hashtable requestData = (Hashtable)request.Params[0];
171 //string host = (string)requestData["host"];
172 //string portstr = (string)requestData["port"];
173 string sessionID_str = (string)requestData["sessionID"];
174 UUID sessionID = UUID.Zero;
175 UUID.TryParse(sessionID_str, out sessionID);
176 string token = (string)requestData["token"];
177  
178 bool success = m_HomeUsersService.VerifyAgent(sessionID, token);
179  
180 Hashtable hash = new Hashtable();
181 hash["result"] = success.ToString();
182 XmlRpcResponse response = new XmlRpcResponse();
183 response.Value = hash;
184 return response;
185  
186 }
187  
188 public XmlRpcResponse VerifyClient(XmlRpcRequest request, IPEndPoint remoteClient)
189 {
190 Hashtable requestData = (Hashtable)request.Params[0];
191 //string host = (string)requestData["host"];
192 //string portstr = (string)requestData["port"];
193 string sessionID_str = (string)requestData["sessionID"];
194 UUID sessionID = UUID.Zero;
195 UUID.TryParse(sessionID_str, out sessionID);
196 string token = (string)requestData["token"];
197  
198 bool success = m_HomeUsersService.VerifyClient(sessionID, token);
199  
200 Hashtable hash = new Hashtable();
201 hash["result"] = success.ToString();
202 XmlRpcResponse response = new XmlRpcResponse();
203 response.Value = hash;
204 return response;
205  
206 }
207  
208 public XmlRpcResponse LogoutAgent(XmlRpcRequest request, IPEndPoint remoteClient)
209 {
210 Hashtable requestData = (Hashtable)request.Params[0];
211 //string host = (string)requestData["host"];
212 //string portstr = (string)requestData["port"];
213 string sessionID_str = (string)requestData["sessionID"];
214 UUID sessionID = UUID.Zero;
215 UUID.TryParse(sessionID_str, out sessionID);
216 string userID_str = (string)requestData["userID"];
217 UUID userID = UUID.Zero;
218 UUID.TryParse(userID_str, out userID);
219  
220 m_HomeUsersService.LogoutAgent(userID, sessionID);
221  
222 Hashtable hash = new Hashtable();
223 hash["result"] = "true";
224 XmlRpcResponse response = new XmlRpcResponse();
225 response.Value = hash;
226 return response;
227  
228 }
229  
230 [Obsolete]
231 public XmlRpcResponse StatusNotification(XmlRpcRequest request, IPEndPoint remoteClient)
232 {
233 Hashtable hash = new Hashtable();
234 hash["result"] = "false";
235  
236 Hashtable requestData = (Hashtable)request.Params[0];
237 //string host = (string)requestData["host"];
238 //string portstr = (string)requestData["port"];
239 if (requestData.ContainsKey("userID") && requestData.ContainsKey("online"))
240 {
241 string userID_str = (string)requestData["userID"];
242 UUID userID = UUID.Zero;
243 UUID.TryParse(userID_str, out userID);
244 List<string> ids = new List<string>();
245 foreach (object key in requestData.Keys)
246 {
247 if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null)
248 ids.Add(requestData[key].ToString());
249 }
250 bool online = false;
251 bool.TryParse(requestData["online"].ToString(), out online);
252  
253 // let's spawn a thread for this, because it may take a long time...
254 List<UUID> friendsOnline = m_HomeUsersService.StatusNotification(ids, userID, online);
255 if (friendsOnline.Count > 0)
256 {
257 int i = 0;
258 foreach (UUID id in friendsOnline)
259 {
260 hash["friend_" + i.ToString()] = id.ToString();
261 i++;
262 }
263 }
264 else
265 hash["result"] = "No Friends Online";
266  
267 }
268  
269 XmlRpcResponse response = new XmlRpcResponse();
270 response.Value = hash;
271 return response;
272  
273 }
274  
275 [Obsolete]
276 public XmlRpcResponse GetOnlineFriends(XmlRpcRequest request, IPEndPoint remoteClient)
277 {
278 Hashtable hash = new Hashtable();
279  
280 Hashtable requestData = (Hashtable)request.Params[0];
281 //string host = (string)requestData["host"];
282 //string portstr = (string)requestData["port"];
283 if (requestData.ContainsKey("userID"))
284 {
285 string userID_str = (string)requestData["userID"];
286 UUID userID = UUID.Zero;
287 UUID.TryParse(userID_str, out userID);
288 List<string> ids = new List<string>();
289 foreach (object key in requestData.Keys)
290 {
291 if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null)
292 ids.Add(requestData[key].ToString());
293 }
294  
295 //List<UUID> online = m_HomeUsersService.GetOnlineFriends(userID, ids);
296 //if (online.Count > 0)
297 //{
298 // int i = 0;
299 // foreach (UUID id in online)
300 // {
301 // hash["friend_" + i.ToString()] = id.ToString();
302 // i++;
303 // }
304 //}
305 //else
306 // hash["result"] = "No Friends Online";
307 }
308  
309 XmlRpcResponse response = new XmlRpcResponse();
310 response.Value = hash;
311 return response;
312  
313 }
314  
315 public XmlRpcResponse GetUserInfo(XmlRpcRequest request, IPEndPoint remoteClient)
316 {
317 Hashtable hash = new Hashtable();
318 Hashtable requestData = (Hashtable)request.Params[0];
319  
320 // This needs checking!
321 if (requestData.ContainsKey("userID"))
322 {
323 string userID_str = (string)requestData["userID"];
324 UUID userID = UUID.Zero;
325 UUID.TryParse(userID_str, out userID);
326  
327 //int userFlags = m_HomeUsersService.GetUserFlags(userID);
328 Dictionary<string,object> userInfo = m_HomeUsersService.GetUserInfo(userID);
329 if (userInfo.Count > 0)
330 {
331 foreach (KeyValuePair<string, object> kvp in userInfo)
332 {
333 hash[kvp.Key] = kvp.Value;
334 }
335 }
336 else
337 {
338 hash["result"] = "failure";
339 }
340 }
341  
342 XmlRpcResponse response = new XmlRpcResponse();
343 response.Value = hash;
344 return response;
345 }
346  
347 public XmlRpcResponse GetServerURLs(XmlRpcRequest request, IPEndPoint remoteClient)
348 {
349 Hashtable hash = new Hashtable();
350  
351 Hashtable requestData = (Hashtable)request.Params[0];
352 //string host = (string)requestData["host"];
353 //string portstr = (string)requestData["port"];
354 if (requestData.ContainsKey("userID"))
355 {
356 string userID_str = (string)requestData["userID"];
357 UUID userID = UUID.Zero;
358 UUID.TryParse(userID_str, out userID);
359  
360 Dictionary<string, object> serverURLs = m_HomeUsersService.GetServerURLs(userID);
361 if (serverURLs.Count > 0)
362 {
363 foreach (KeyValuePair<string, object> kvp in serverURLs)
364 hash["SRV_" + kvp.Key] = kvp.Value.ToString();
365 }
366 else
367 hash["result"] = "No Service URLs";
368 }
369  
370 XmlRpcResponse response = new XmlRpcResponse();
371 response.Value = hash;
372 return response;
373  
374 }
375  
376 /// <summary>
377 /// Locates the user.
378 /// This is a sensitive operation, only authorized IP addresses can perform it.
379 /// </summary>
380 /// <param name="request"></param>
381 /// <param name="remoteClient"></param>
382 /// <returns></returns>
383 public XmlRpcResponse LocateUser(XmlRpcRequest request, IPEndPoint remoteClient)
384 {
385 Hashtable hash = new Hashtable();
386  
387 bool authorized = true;
388 if (m_VerifyCallers)
389 {
390 authorized = false;
391 foreach (string s in m_AuthorizedCallers)
392 if (s == remoteClient.Address.ToString())
393 {
394 authorized = true;
395 break;
396 }
397 }
398  
399 if (authorized)
400 {
401 Hashtable requestData = (Hashtable)request.Params[0];
402 //string host = (string)requestData["host"];
403 //string portstr = (string)requestData["port"];
404 if (requestData.ContainsKey("userID"))
405 {
406 string userID_str = (string)requestData["userID"];
407 UUID userID = UUID.Zero;
408 UUID.TryParse(userID_str, out userID);
409  
410 string url = m_HomeUsersService.LocateUser(userID);
411 if (url != string.Empty)
412 hash["URL"] = url;
413 else
414 hash["result"] = "Unable to locate user";
415 }
416 }
417  
418 XmlRpcResponse response = new XmlRpcResponse();
419 response.Value = hash;
420 return response;
421  
422 }
423  
424 /// <summary>
425 /// Returns the UUI of a user given a UUID.
426 /// </summary>
427 /// <param name="request"></param>
428 /// <param name="remoteClient"></param>
429 /// <returns></returns>
430 public XmlRpcResponse GetUUI(XmlRpcRequest request, IPEndPoint remoteClient)
431 {
432 Hashtable hash = new Hashtable();
433  
434 Hashtable requestData = (Hashtable)request.Params[0];
435 //string host = (string)requestData["host"];
436 //string portstr = (string)requestData["port"];
437 if (requestData.ContainsKey("userID") && requestData.ContainsKey("targetUserID"))
438 {
439 string userID_str = (string)requestData["userID"];
440 UUID userID = UUID.Zero;
441 UUID.TryParse(userID_str, out userID);
442  
443 string tuserID_str = (string)requestData["targetUserID"];
444 UUID targetUserID = UUID.Zero;
445 UUID.TryParse(tuserID_str, out targetUserID);
446 string uui = m_HomeUsersService.GetUUI(userID, targetUserID);
447 if (uui != string.Empty)
448 hash["UUI"] = uui;
449 else
450 hash["result"] = "User unknown";
451 }
452  
453 XmlRpcResponse response = new XmlRpcResponse();
454 response.Value = hash;
455 return response;
456 }
457  
458 /// <summary>
459 /// Gets the UUID of a user given First name, Last name.
460 /// </summary>
461 /// <param name="request"></param>
462 /// <param name="remoteClient"></param>
463 /// <returns></returns>
464 public XmlRpcResponse GetUUID(XmlRpcRequest request, IPEndPoint remoteClient)
465 {
466 Hashtable hash = new Hashtable();
467  
468 Hashtable requestData = (Hashtable)request.Params[0];
469 //string host = (string)requestData["host"];
470 //string portstr = (string)requestData["port"];
471 if (requestData.ContainsKey("first") && requestData.ContainsKey("last"))
472 {
473 string first = (string)requestData["first"];
474 string last = (string)requestData["last"];
475 UUID uuid = m_HomeUsersService.GetUUID(first, last);
476 hash["UUID"] = uuid.ToString();
477 }
478  
479 XmlRpcResponse response = new XmlRpcResponse();
480 response.Value = hash;
481 return response;
482 }
483 }
484 }