diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs | 219 |
1 files changed, 218 insertions, 1 deletions
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs index 0e8ce80..72a4aea 100644 --- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs | |||
@@ -52,15 +52,24 @@ 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; | ||
56 | |||
57 | private bool m_VerifyCallers = false; | ||
55 | 58 | ||
56 | public UserAgentServerConnector(IConfigSource config, IHttpServer server) : | 59 | public UserAgentServerConnector(IConfigSource config, IHttpServer server) : |
60 | this(config, server, null) | ||
61 | { | ||
62 | } | ||
63 | |||
64 | public UserAgentServerConnector(IConfigSource config, IHttpServer server, IFriendsSimConnector friendsConnector) : | ||
57 | base(config, server, String.Empty) | 65 | base(config, server, String.Empty) |
58 | { | 66 | { |
59 | IConfig gridConfig = config.Configs["UserAgentService"]; | 67 | IConfig gridConfig = config.Configs["UserAgentService"]; |
60 | if (gridConfig != null) | 68 | if (gridConfig != null) |
61 | { | 69 | { |
62 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); | 70 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); |
63 | Object[] args = new Object[] { config }; | 71 | |
72 | Object[] args = new Object[] { config, friendsConnector }; | ||
64 | m_HomeUsersService = ServerUtils.LoadPlugin<IUserAgentService>(serviceDll, args); | 73 | m_HomeUsersService = ServerUtils.LoadPlugin<IUserAgentService>(serviceDll, args); |
65 | } | 74 | } |
66 | if (m_HomeUsersService == null) | 75 | if (m_HomeUsersService == null) |
@@ -69,12 +78,24 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
69 | string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1"); | 78 | string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1"); |
70 | bool proxy = gridConfig.GetBoolean("HasProxy", false); | 79 | bool proxy = gridConfig.GetBoolean("HasProxy", false); |
71 | 80 | ||
81 | m_VerifyCallers = gridConfig.GetBoolean("VerifyCallers", false); | ||
82 | string csv = gridConfig.GetString("AuthorizedCallers", "127.0.0.1"); | ||
83 | csv = csv.Replace(" ", ""); | ||
84 | m_AuthorizedCallers = csv.Split(','); | ||
85 | |||
72 | server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); | 86 | server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); |
73 | server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); | 87 | server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); |
74 | server.AddXmlRPCHandler("verify_agent", VerifyAgent, false); | 88 | server.AddXmlRPCHandler("verify_agent", VerifyAgent, false); |
75 | server.AddXmlRPCHandler("verify_client", VerifyClient, false); | 89 | server.AddXmlRPCHandler("verify_client", VerifyClient, false); |
76 | server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); | 90 | server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); |
77 | 91 | ||
92 | server.AddXmlRPCHandler("status_notification", StatusNotification, false); | ||
93 | server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false); | ||
94 | server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false); | ||
95 | |||
96 | server.AddXmlRPCHandler("locate_user", LocateUser, false); | ||
97 | server.AddXmlRPCHandler("get_uui", GetUUI, false); | ||
98 | |||
78 | server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler); | 99 | server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler); |
79 | } | 100 | } |
80 | 101 | ||
@@ -194,5 +215,201 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
194 | 215 | ||
195 | } | 216 | } |
196 | 217 | ||
218 | public XmlRpcResponse StatusNotification(XmlRpcRequest request, IPEndPoint remoteClient) | ||
219 | { | ||
220 | Hashtable hash = new Hashtable(); | ||
221 | hash["result"] = "false"; | ||
222 | |||
223 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
224 | //string host = (string)requestData["host"]; | ||
225 | //string portstr = (string)requestData["port"]; | ||
226 | if (requestData.ContainsKey("userID") && requestData.ContainsKey("online")) | ||
227 | { | ||
228 | string userID_str = (string)requestData["userID"]; | ||
229 | UUID userID = UUID.Zero; | ||
230 | UUID.TryParse(userID_str, out userID); | ||
231 | List<string> ids = new List<string>(); | ||
232 | foreach (object key in requestData.Keys) | ||
233 | { | ||
234 | if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null) | ||
235 | ids.Add(requestData[key].ToString()); | ||
236 | } | ||
237 | bool online = false; | ||
238 | bool.TryParse(requestData["online"].ToString(), out online); | ||
239 | |||
240 | // let's spawn a thread for this, because it may take a long time... | ||
241 | List<UUID> friendsOnline = m_HomeUsersService.StatusNotification(ids, userID, online); | ||
242 | if (friendsOnline.Count > 0) | ||
243 | { | ||
244 | int i = 0; | ||
245 | foreach (UUID id in friendsOnline) | ||
246 | { | ||
247 | hash["friend_" + i.ToString()] = id.ToString(); | ||
248 | i++; | ||
249 | } | ||
250 | } | ||
251 | else | ||
252 | hash["result"] = "No Friends Online"; | ||
253 | |||
254 | } | ||
255 | |||
256 | XmlRpcResponse response = new XmlRpcResponse(); | ||
257 | response.Value = hash; | ||
258 | return response; | ||
259 | |||
260 | } | ||
261 | |||
262 | public XmlRpcResponse GetOnlineFriends(XmlRpcRequest request, IPEndPoint remoteClient) | ||
263 | { | ||
264 | Hashtable hash = new Hashtable(); | ||
265 | |||
266 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
267 | //string host = (string)requestData["host"]; | ||
268 | //string portstr = (string)requestData["port"]; | ||
269 | if (requestData.ContainsKey("userID")) | ||
270 | { | ||
271 | string userID_str = (string)requestData["userID"]; | ||
272 | UUID userID = UUID.Zero; | ||
273 | UUID.TryParse(userID_str, out userID); | ||
274 | List<string> ids = new List<string>(); | ||
275 | foreach (object key in requestData.Keys) | ||
276 | { | ||
277 | if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null) | ||
278 | ids.Add(requestData[key].ToString()); | ||
279 | } | ||
280 | |||
281 | //List<UUID> online = m_HomeUsersService.GetOnlineFriends(userID, ids); | ||
282 | //if (online.Count > 0) | ||
283 | //{ | ||
284 | // int i = 0; | ||
285 | // foreach (UUID id in online) | ||
286 | // { | ||
287 | // hash["friend_" + i.ToString()] = id.ToString(); | ||
288 | // i++; | ||
289 | // } | ||
290 | //} | ||
291 | //else | ||
292 | // hash["result"] = "No Friends Online"; | ||
293 | } | ||
294 | |||
295 | XmlRpcResponse response = new XmlRpcResponse(); | ||
296 | response.Value = hash; | ||
297 | return response; | ||
298 | |||
299 | } | ||
300 | |||
301 | public XmlRpcResponse GetServerURLs(XmlRpcRequest request, IPEndPoint remoteClient) | ||
302 | { | ||
303 | Hashtable hash = new Hashtable(); | ||
304 | |||
305 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
306 | //string host = (string)requestData["host"]; | ||
307 | //string portstr = (string)requestData["port"]; | ||
308 | if (requestData.ContainsKey("userID")) | ||
309 | { | ||
310 | string userID_str = (string)requestData["userID"]; | ||
311 | UUID userID = UUID.Zero; | ||
312 | UUID.TryParse(userID_str, out userID); | ||
313 | |||
314 | Dictionary<string, object> serverURLs = m_HomeUsersService.GetServerURLs(userID); | ||
315 | if (serverURLs.Count > 0) | ||
316 | { | ||
317 | foreach (KeyValuePair<string, object> kvp in serverURLs) | ||
318 | hash["SRV_" + kvp.Key] = kvp.Value.ToString(); | ||
319 | } | ||
320 | else | ||
321 | hash["result"] = "No Service URLs"; | ||
322 | } | ||
323 | |||
324 | XmlRpcResponse response = new XmlRpcResponse(); | ||
325 | response.Value = hash; | ||
326 | return response; | ||
327 | |||
328 | } | ||
329 | |||
330 | /// <summary> | ||
331 | /// Locates the user. | ||
332 | /// This is a sensitive operation, only authorized IP addresses can perform it. | ||
333 | /// </summary> | ||
334 | /// <param name="request"></param> | ||
335 | /// <param name="remoteClient"></param> | ||
336 | /// <returns></returns> | ||
337 | public XmlRpcResponse LocateUser(XmlRpcRequest request, IPEndPoint remoteClient) | ||
338 | { | ||
339 | Hashtable hash = new Hashtable(); | ||
340 | |||
341 | bool authorized = true; | ||
342 | if (m_VerifyCallers) | ||
343 | { | ||
344 | authorized = false; | ||
345 | foreach (string s in m_AuthorizedCallers) | ||
346 | if (s == remoteClient.Address.ToString()) | ||
347 | { | ||
348 | authorized = true; | ||
349 | break; | ||
350 | } | ||
351 | } | ||
352 | |||
353 | if (authorized) | ||
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 | string url = m_HomeUsersService.LocateUser(userID); | ||
365 | if (url != string.Empty) | ||
366 | hash["URL"] = url; | ||
367 | else | ||
368 | hash["result"] = "Unable to locate user"; | ||
369 | } | ||
370 | } | ||
371 | |||
372 | XmlRpcResponse response = new XmlRpcResponse(); | ||
373 | response.Value = hash; | ||
374 | return response; | ||
375 | |||
376 | } | ||
377 | |||
378 | /// <summary> | ||
379 | /// Locates the user. | ||
380 | /// This is a sensitive operation, only authorized IP addresses can perform it. | ||
381 | /// </summary> | ||
382 | /// <param name="request"></param> | ||
383 | /// <param name="remoteClient"></param> | ||
384 | /// <returns></returns> | ||
385 | public XmlRpcResponse GetUUI(XmlRpcRequest request, IPEndPoint remoteClient) | ||
386 | { | ||
387 | Hashtable hash = new Hashtable(); | ||
388 | |||
389 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
390 | //string host = (string)requestData["host"]; | ||
391 | //string portstr = (string)requestData["port"]; | ||
392 | if (requestData.ContainsKey("userID") && requestData.ContainsKey("targetUserID")) | ||
393 | { | ||
394 | string userID_str = (string)requestData["userID"]; | ||
395 | UUID userID = UUID.Zero; | ||
396 | UUID.TryParse(userID_str, out userID); | ||
397 | |||
398 | string tuserID_str = (string)requestData["targetUserID"]; | ||
399 | UUID targetUserID = UUID.Zero; | ||
400 | UUID.TryParse(tuserID_str, out targetUserID); | ||
401 | string uui = m_HomeUsersService.GetUUI(userID, targetUserID); | ||
402 | if (uui != string.Empty) | ||
403 | hash["UUI"] = uui; | ||
404 | else | ||
405 | hash["result"] = "User unknown"; | ||
406 | } | ||
407 | |||
408 | XmlRpcResponse response = new XmlRpcResponse(); | ||
409 | response.Value = hash; | ||
410 | return response; | ||
411 | |||
412 | } | ||
413 | |||
197 | } | 414 | } |
198 | } | 415 | } |