protected override void StoreFriendships(UUID agentID, UUID friendID) { Boolean agentIsLocal = true; Boolean friendIsLocal = true; if (UserManagementModule != null) { agentIsLocal = UserManagementModule.IsLocalGridUser(agentID); friendIsLocal = UserManagementModule.IsLocalGridUser(friendID); } // Are they both local users? if (agentIsLocal && friendIsLocal) { // local grid users m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local"); base.StoreFriendships(agentID, friendID); return; } // ok, at least one of them is foreigner, let's get their data IClientAPI agentClient = LocateClientObject(agentID); IClientAPI friendClient = LocateClientObject(friendID); AgentCircuitData agentClientCircuit = null; AgentCircuitData friendClientCircuit = null; string agentUUI = string.Empty; string friendUUI = string.Empty; string agentFriendService = string.Empty; string friendFriendService = string.Empty; if (agentClient != null) { agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); RecacheFriends(agentClient); } if (friendClient != null) { friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); RecacheFriends(friendClient); } m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", agentUUI, friendUUI, agentFriendService, friendFriendService); // Generate a random 8-character hex number that will sign this friendship string secret = UUID.Random().ToString().Substring(0, 8); string theFriendUUID = friendUUI + ";" + secret; string agentUUID = agentUUI + ";" + secret; if (agentIsLocal) // agent is local, 'friend' is foreigner { // This may happen when the agent returned home, in which case the friend is not there // We need to look for its information in the friends list itself FriendInfo[] finfos = null; bool confirming = false; if (friendUUI == string.Empty) { finfos = GetFriendsFromCache(agentID); foreach (FriendInfo finfo in finfos) { if (finfo.TheirFlags == -1) { if (finfo.Friend.StartsWith(friendID.ToString())) { friendUUI = finfo.Friend; theFriendUUID = friendUUI; UUID utmp = UUID.Zero; string url = String.Empty; string first = String.Empty; string last = String.Empty; // If it's confirming the friendship, we already have the full UUI with the secret if (Util.ParseUniversalUserIdentifier(theFriendUUID, out utmp, out url, out first, out last, out secret)) { agentUUID = agentUUI + ";" + secret; m_uMan.AddUser(utmp, first, last, url); } confirming = true; break; } } } if (!confirming) { friendUUI = m_uMan.GetUserUUI(friendID); theFriendUUID = friendUUI + ";" + secret; } friendFriendService = m_uMan.GetUserServerURL(friendID, "FriendsServerURI"); // m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", // agentUUI, friendUUI, agentFriendService, friendFriendService); } // Delete any previous friendship relations DeletePreviousRelations(agentID, friendID); // store in the local friends service a reference to the foreign friend FriendsService.StoreFriend(agentID.ToString(), theFriendUUID, 1); // and also the converse FriendsService.StoreFriend(theFriendUUID, agentID.ToString(), 1); //if (!confirming) //{ // store in the foreign friends service a reference to the local agent HGFriendsServicesConnector friendsConn = null; if (friendClientCircuit != null) // the friend is here, validate session { friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); } else // the friend is not here, he initiated the request in his home world { friendsConn = new HGFriendsServicesConnector(friendFriendService); } friendsConn.NewFriendship(friendID, agentUUID); //} } else if (friendIsLocal) // 'friend' is local, agent is foreigner { // Delete any previous friendship relations DeletePreviousRelations(agentID, friendID); // store in the local friends service a reference to the foreign agent FriendsService.StoreFriend(friendID.ToString(), agentUUI + ";" + secret, 1); // and also the converse FriendsService.StoreFriend(agentUUI + ";" + secret, friendID.ToString(), 1); if (agentClientCircuit != null) { // store in the foreign friends service a reference to the local agent HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID); friendsConn.NewFriendship(agentID, friendUUI + ";" + secret); } } else // They're both foreigners! { HGFriendsServicesConnector friendsConn; if (agentClientCircuit != null) { friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID); friendsConn.NewFriendship(agentID, friendUUI + ";" + secret); } if (friendClientCircuit != null) { friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); friendsConn.NewFriendship(friendID, agentUUI + ";" + secret); } } // my brain hurts now }
protected override bool DeleteFriendship(UUID agentID, UUID exfriendID) { Boolean agentIsLocal = true; Boolean friendIsLocal = true; if (UserManagementModule != null) { agentIsLocal = UserManagementModule.IsLocalGridUser(agentID); friendIsLocal = UserManagementModule.IsLocalGridUser(exfriendID); } // Are they both local users? if (agentIsLocal && friendIsLocal) { // local grid users return(base.DeleteFriendship(agentID, exfriendID)); } // ok, at least one of them is foreigner, let's get their data string agentUUI = string.Empty; string friendUUI = string.Empty; if (agentIsLocal) // agent is local, 'friend' is foreigner { // We need to look for its information in the friends list itself FriendInfo[] finfos = GetFriendsFromCache(agentID); FriendInfo finfo = GetFriend(finfos, exfriendID); if (finfo != null) { friendUUI = finfo.Friend; // delete in the local friends service the reference to the foreign friend FriendsService.Delete(agentID, friendUUI); // and also the converse FriendsService.Delete(friendUUI, agentID.ToString()); // notify the exfriend's service Util.FireAndForget( delegate { Delete(exfriendID, agentID, friendUUI); }, null, "HGFriendsModule.DeleteFriendshipForeignFriend"); m_log.DebugFormat("[HGFRIENDS MODULE]: {0} terminated {1}", agentID, friendUUI); return(true); } } else if (friendIsLocal) // agent is foreigner, 'friend' is local { agentUUI = GetUUI(exfriendID, agentID); if (agentUUI != string.Empty) { // delete in the local friends service the reference to the foreign agent FriendsService.Delete(exfriendID, agentUUI); // and also the converse FriendsService.Delete(agentUUI, exfriendID.ToString()); // notify the agent's service? Util.FireAndForget( delegate { Delete(agentID, exfriendID, agentUUI); }, null, "HGFriendsModule.DeleteFriendshipLocalFriend"); m_log.DebugFormat("[HGFRIENDS MODULE]: {0} terminated {1}", agentUUI, exfriendID); return(true); } } //else They're both foreigners! Can't handle this return(false); }
/// <summary> /// Gets the user account data. /// </summary> /// <returns> /// The user profile data. /// </returns> /// <param name='userID'> /// If set to <c>true</c> user I. /// </param> /// <param name='userInfo'> /// If set to <c>true</c> user info. /// </param> bool GetUserAccountData(UUID userID, out Dictionary <string, object> userInfo) { Dictionary <string, object> info = new Dictionary <string, object>(); if (UserManagementModule.IsLocalGridUser(userID)) { // Is local IUserAccountService uas = Scene.UserAccountService; UserAccount account = uas.GetUserAccount(Scene.RegionInfo.ScopeID, userID); info["user_flags"] = account.UserFlags; info["user_created"] = account.Created; if (!String.IsNullOrEmpty(account.UserTitle)) { info["user_title"] = account.UserTitle; } else { info["user_title"] = ""; } userInfo = info; return(false); } else { // Is Foreign string home_url = UserManagementModule.GetUserServerURL(userID, "HomeURI"); if (String.IsNullOrEmpty(home_url)) { info["user_flags"] = 0; info["user_created"] = 0; info["user_title"] = "Unavailable"; userInfo = info; return(true); } UserAgentServiceConnector uConn = new UserAgentServiceConnector(home_url); Dictionary <string, object> account; try { account = uConn.GetUserInfo(userID); } catch (Exception e) { m_log.Debug("[PROFILES]: GetUserInfo call failed ", e); account = new Dictionary <string, object>(); } if (account.Count > 0) { if (account.ContainsKey("user_flags")) { info["user_flags"] = account["user_flags"]; } else { info["user_flags"] = ""; } if (account.ContainsKey("user_created")) { info["user_created"] = account["user_created"]; } else { info["user_created"] = ""; } info["user_title"] = "HG Visitor"; } else { info["user_flags"] = 0; info["user_created"] = 0; info["user_title"] = "HG Visitor"; } userInfo = info; return(true); } }
protected override void StoreFriendships(UUID agentID, UUID friendID) { Boolean agentIsLocal = true; Boolean friendIsLocal = true; if (UserManagementModule != null) { agentIsLocal = UserManagementModule.IsLocalGridUser(agentID); friendIsLocal = UserManagementModule.IsLocalGridUser(friendID); } // Are they both local users? if (agentIsLocal && friendIsLocal) { // local grid users m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local"); base.StoreFriendships(agentID, friendID); return; } // ok, at least one of them is foreigner, let's get their data IClientAPI agentClient = LocateClientObject(agentID); IClientAPI friendClient = LocateClientObject(friendID); AgentCircuitData agentClientCircuit = null; AgentCircuitData friendClientCircuit = null; string agentUUI = string.Empty; string friendUUI = string.Empty; string agentFriendService = string.Empty; string friendFriendService = string.Empty; if (agentIsLocal) { agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); } if (friendIsLocal) { friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); } m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", agentUUI, friendUUI, agentFriendService, friendFriendService); // Generate a random 8-character hex number that will sign this friendship string secret = UUID.Random().ToString().Substring(0, 8); if (agentIsLocal) // agent is local, 'friend' is foreigner { // This may happen when the agent returned home, in which case the friend is not there // We need to look for its information in the friends list itself bool confirming = false; if (friendUUI == string.Empty) { FriendInfo[] finfos = GetFriends(agentID); foreach (FriendInfo finfo in finfos) { if (finfo.TheirFlags == -1) { if (finfo.Friend.StartsWith(friendID.ToString())) { friendUUI = finfo.Friend; confirming = true; } } } } // If it's confirming the friendship, we already have the full friendUUI with the secret string theFriendUUID = confirming ? friendUUI : friendUUI + ";" + secret; // store in the local friends service a reference to the foreign friend FriendsService.StoreFriend(agentID.ToString(), theFriendUUID, 1); // and also the converse FriendsService.StoreFriend(theFriendUUID, agentID.ToString(), 1); if (!confirming && friendClientCircuit != null) { // store in the foreign friends service a reference to the local agent HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); friendsConn.NewFriendship(friendID, agentUUI + ";" + secret); } } else if (friendIsLocal) // 'friend' is local, agent is foreigner { // store in the local friends service a reference to the foreign agent FriendsService.StoreFriend(friendID.ToString(), agentUUI + ";" + secret, 1); // and also the converse FriendsService.StoreFriend(agentUUI + ";" + secret, friendID.ToString(), 1); if (agentClientCircuit != null) { // store in the foreign friends service a reference to the local agent HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID); friendsConn.NewFriendship(agentID, friendUUI + ";" + secret); } } else // They're both foreigners! { HGFriendsServicesConnector friendsConn; if (agentClientCircuit != null) { friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID); friendsConn.NewFriendship(agentID, friendUUI + ";" + secret); } if (friendClientCircuit != null) { friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); friendsConn.NewFriendship(friendID, agentUUI + ";" + secret); } } // my brain hurts now }
public void SendInstantMessage(GridInstantMessage im, MessageResultNotification result) { UUID toAgentID = new UUID(im.toAgentID); try { // Try root avatar only first m_Scenes.ForEach(delegate(Scene scene) { // m_log.DebugFormat( // "[HG INSTANT MESSAGE]: Looking for root agent {0} in {1}", // toAgentID.ToString(), scene.RegionInfo.RegionName); ScenePresence sp = scene.GetScenePresence(toAgentID); if (sp != null && !sp.IsChildAgent) { // Local message // m_log.DebugFormat("[HG INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", user.Name, toAgentID); sp.ControllingClient.SendInstantMessage(im); // Message sent result(true); throw new ThreadedClasses.ReturnValueException <bool>(true); } }); // try child avatar second m_Scenes.ForEach(delegate(Scene scene) { // m_log.DebugFormat( // "[HG INSTANT MESSAGE]: Looking for child of {0} in {1}", // toAgentID, scene.RegionInfo.RegionName); ScenePresence sp = scene.GetScenePresence(toAgentID); if (sp != null) { // Local message // m_log.DebugFormat("[HG INSTANT MESSAGE]: Delivering IM to child agent {0} {1}", user.Name, toAgentID); sp.ControllingClient.SendInstantMessage(im); // Message sent result(true); throw new ThreadedClasses.ReturnValueException <bool>(true); } }); } catch (ThreadedClasses.ReturnValueException <bool> ) { return; } // m_log.DebugFormat("[HG INSTANT MESSAGE]: Delivering IM to {0} via XMLRPC", im.toAgentID); // Is the user a local user? string url = string.Empty; bool foreigner = false; byte dialog = im.dialog; if (dialog == (byte)InstantMessageDialog.MessageFromObject && !m_EnableObjectIM) { return; } if (UserManagementModule != null && !UserManagementModule.IsLocalGridUser(toAgentID)) // foreign user { url = UserManagementModule.GetUserServerURL(toAgentID, "IMServerURI"); foreigner = true; } Util.FireAndForget(delegate { bool success = false; if (foreigner && url == string.Empty) // we don't know about this user { string recipientUUI = TryGetRecipientUUI(new UUID(im.fromAgentID), toAgentID); m_log.DebugFormat("[HG MESSAGE TRANSFER]: Got UUI {0}", recipientUUI); if (recipientUUI != string.Empty) { UUID id; string u = string.Empty, first = string.Empty, last = string.Empty, secret = string.Empty; if (Util.ParseUniversalUserIdentifier(recipientUUI, out id, out u, out first, out last, out secret)) { ServicePointManagerTimeoutSupport.ResetHosts(); success = m_IMService.OutgoingInstantMessage(im, u, true); if (success) { UserManagementModule.AddUser(toAgentID, u + ";" + first + " " + last); } } } } else { ServicePointManagerTimeoutSupport.ResetHosts(); success = m_IMService.OutgoingInstantMessage(im, url, foreigner); } if (!success && !foreigner) { HandleUndeliveredMessage(im, result); } else { result(success); } }); return; }