aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs356
1 files changed, 345 insertions, 11 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
index 7ddcfa6..4ce406c 100644
--- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
@@ -51,20 +51,31 @@ namespace OpenSim.Services.Connectors.Hypergrid
51 MethodBase.GetCurrentMethod().DeclaringType); 51 MethodBase.GetCurrentMethod().DeclaringType);
52 52
53 string m_ServerURL; 53 string m_ServerURL;
54 public UserAgentServiceConnector(string url) 54
55 public UserAgentServiceConnector(string url) : this(url, true)
56 {
57 }
58
59 public UserAgentServiceConnector(string url, bool dnsLookup)
55 { 60 {
56 m_ServerURL = url; 61 m_ServerURL = url;
57 // Doing this here, because XML-RPC or mono have some strong ideas about 62
58 // caching DNS translations. 63 if (dnsLookup)
59 try
60 {
61 Uri m_Uri = new Uri(m_ServerURL);
62 IPAddress ip = Util.GetHostFromDNS(m_Uri.Host);
63 m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString()); ;
64 }
65 catch (Exception e)
66 { 64 {
67 m_log.DebugFormat("[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", m_ServerURL, e.Message); 65 // Doing this here, because XML-RPC or mono have some strong ideas about
66 // caching DNS translations.
67 try
68 {
69 Uri m_Uri = new Uri(m_ServerURL);
70 IPAddress ip = Util.GetHostFromDNS(m_Uri.Host);
71 m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString());
72 if (!m_ServerURL.EndsWith("/"))
73 m_ServerURL += "/";
74 }
75 catch (Exception e)
76 {
77 m_log.DebugFormat("[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", m_ServerURL, e.Message);
78 }
68 } 79 }
69 m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0} ({1})", url, m_ServerURL); 80 m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0} ({1})", url, m_ServerURL);
70 } 81 }
@@ -400,6 +411,329 @@ namespace OpenSim.Services.Connectors.Hypergrid
400 GetBoolResponse(request, out reason); 411 GetBoolResponse(request, out reason);
401 } 412 }
402 413
414 public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online)
415 {
416 Hashtable hash = new Hashtable();
417 hash["userID"] = userID.ToString();
418 hash["online"] = online.ToString();
419 int i = 0;
420 foreach (string s in friends)
421 {
422 hash["friend_" + i.ToString()] = s;
423 i++;
424 }
425
426 IList paramList = new ArrayList();
427 paramList.Add(hash);
428
429 XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList);
430 string reason = string.Empty;
431
432 // Send and get reply
433 List<UUID> friendsOnline = new List<UUID>();
434 XmlRpcResponse response = null;
435 try
436 {
437 response = request.Send(m_ServerURL, 6000);
438 }
439 catch (Exception e)
440 {
441 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0}", m_ServerURL);
442 reason = "Exception: " + e.Message;
443 return friendsOnline;
444 }
445
446 if (response.IsFault)
447 {
448 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} returned an error: {1}", m_ServerURL, response.FaultString);
449 reason = "XMLRPC Fault";
450 return friendsOnline;
451 }
452
453 hash = (Hashtable)response.Value;
454 //foreach (Object o in hash)
455 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
456 try
457 {
458 if (hash == null)
459 {
460 m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
461 reason = "Internal error 1";
462 return friendsOnline;
463 }
464
465 // Here is the actual response
466 foreach (object key in hash.Keys)
467 {
468 if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
469 {
470 UUID uuid;
471 if (UUID.TryParse(hash[key].ToString(), out uuid))
472 friendsOnline.Add(uuid);
473 }
474 }
475
476 }
477 catch (Exception e)
478 {
479 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
480 reason = "Exception: " + e.Message;
481 }
482
483 return friendsOnline;
484 }
485
486 public List<UUID> GetOnlineFriends(UUID userID, List<string> friends)
487 {
488 Hashtable hash = new Hashtable();
489 hash["userID"] = userID.ToString();
490 int i = 0;
491 foreach (string s in friends)
492 {
493 hash["friend_" + i.ToString()] = s;
494 i++;
495 }
496
497 IList paramList = new ArrayList();
498 paramList.Add(hash);
499
500 XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList);
501 string reason = string.Empty;
502
503 // Send and get reply
504 List<UUID> online = new List<UUID>();
505 XmlRpcResponse response = null;
506 try
507 {
508 response = request.Send(m_ServerURL, 10000);
509 }
510 catch (Exception e)
511 {
512 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0}", m_ServerURL);
513 reason = "Exception: " + e.Message;
514 return online;
515 }
516
517 if (response.IsFault)
518 {
519 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} returned an error: {1}", m_ServerURL, response.FaultString);
520 reason = "XMLRPC Fault";
521 return online;
522 }
523
524 hash = (Hashtable)response.Value;
525 //foreach (Object o in hash)
526 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
527 try
528 {
529 if (hash == null)
530 {
531 m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
532 reason = "Internal error 1";
533 return online;
534 }
535
536 // Here is the actual response
537 foreach (object key in hash.Keys)
538 {
539 if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
540 {
541 UUID uuid;
542 if (UUID.TryParse(hash[key].ToString(), out uuid))
543 online.Add(uuid);
544 }
545 }
546
547 }
548 catch (Exception e)
549 {
550 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
551 reason = "Exception: " + e.Message;
552 }
553
554 return online;
555 }
556
557 public Dictionary<string, object> GetServerURLs(UUID userID)
558 {
559 Hashtable hash = new Hashtable();
560 hash["userID"] = userID.ToString();
561
562 IList paramList = new ArrayList();
563 paramList.Add(hash);
564
565 XmlRpcRequest request = new XmlRpcRequest("get_server_urls", paramList);
566 string reason = string.Empty;
567
568 // Send and get reply
569 Dictionary<string, object> serverURLs = new Dictionary<string,object>();
570 XmlRpcResponse response = null;
571 try
572 {
573 response = request.Send(m_ServerURL, 10000);
574 }
575 catch (Exception e)
576 {
577 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0}", m_ServerURL);
578 reason = "Exception: " + e.Message;
579 return serverURLs;
580 }
581
582 if (response.IsFault)
583 {
584 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} returned an error: {1}", m_ServerURL, response.FaultString);
585 reason = "XMLRPC Fault";
586 return serverURLs;
587 }
588
589 hash = (Hashtable)response.Value;
590 //foreach (Object o in hash)
591 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
592 try
593 {
594 if (hash == null)
595 {
596 m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetServerURLs Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
597 reason = "Internal error 1";
598 return serverURLs;
599 }
600
601 // Here is the actual response
602 foreach (object key in hash.Keys)
603 {
604 if (key is string && ((string)key).StartsWith("SRV_") && hash[key] != null)
605 {
606 string serverType = key.ToString().Substring(4); // remove "SRV_"
607 serverURLs.Add(serverType, hash[key].ToString());
608 }
609 }
610
611 }
612 catch (Exception e)
613 {
614 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
615 reason = "Exception: " + e.Message;
616 }
617
618 return serverURLs;
619 }
620
621 public string LocateUser(UUID userID)
622 {
623 Hashtable hash = new Hashtable();
624 hash["userID"] = userID.ToString();
625
626 IList paramList = new ArrayList();
627 paramList.Add(hash);
628
629 XmlRpcRequest request = new XmlRpcRequest("locate_user", paramList);
630 string reason = string.Empty;
631
632 // Send and get reply
633 string url = string.Empty;
634 XmlRpcResponse response = null;
635 try
636 {
637 response = request.Send(m_ServerURL, 10000);
638 }
639 catch (Exception e)
640 {
641 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0}", m_ServerURL);
642 reason = "Exception: " + e.Message;
643 return url;
644 }
645
646 if (response.IsFault)
647 {
648 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} returned an error: {1}", m_ServerURL, response.FaultString);
649 reason = "XMLRPC Fault";
650 return url;
651 }
652
653 hash = (Hashtable)response.Value;
654 //foreach (Object o in hash)
655 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
656 try
657 {
658 if (hash == null)
659 {
660 m_log.ErrorFormat("[USER AGENT CONNECTOR]: LocateUser Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
661 reason = "Internal error 1";
662 return url;
663 }
664
665 // Here's the actual response
666 if (hash.ContainsKey("URL"))
667 url = hash["URL"].ToString();
668
669 }
670 catch (Exception e)
671 {
672 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response.");
673 reason = "Exception: " + e.Message;
674 }
675
676 return url;
677 }
678
679 public string GetUUI(UUID userID, UUID targetUserID)
680 {
681 Hashtable hash = new Hashtable();
682 hash["userID"] = userID.ToString();
683 hash["targetUserID"] = targetUserID.ToString();
684
685 IList paramList = new ArrayList();
686 paramList.Add(hash);
687
688 XmlRpcRequest request = new XmlRpcRequest("get_uui", paramList);
689 string reason = string.Empty;
690
691 // Send and get reply
692 string uui = string.Empty;
693 XmlRpcResponse response = null;
694 try
695 {
696 response = request.Send(m_ServerURL, 10000);
697 }
698 catch (Exception e)
699 {
700 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0}", m_ServerURL);
701 reason = "Exception: " + e.Message;
702 return uui;
703 }
704
705 if (response.IsFault)
706 {
707 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} returned an error: {1}", m_ServerURL, response.FaultString);
708 reason = "XMLRPC Fault";
709 return uui;
710 }
711
712 hash = (Hashtable)response.Value;
713 //foreach (Object o in hash)
714 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
715 try
716 {
717 if (hash == null)
718 {
719 m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUI Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
720 reason = "Internal error 1";
721 return uui;
722 }
723
724 // Here's the actual response
725 if (hash.ContainsKey("UUI"))
726 uui = hash["UUI"].ToString();
727
728 }
729 catch (Exception e)
730 {
731 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response.");
732 reason = "Exception: " + e.Message;
733 }
734
735 return uui;
736 }
403 737
404 private bool GetBoolResponse(XmlRpcRequest request, out string reason) 738 private bool GetBoolResponse(XmlRpcRequest request, out string reason)
405 { 739 {