From 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 19 May 2019 21:24:15 +1000 Subject: Dump OpenSim 0.9.0.1 into it's own branch. --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 169 +++++++++++++++------ 1 file changed, 122 insertions(+), 47 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 08e7dd2..772485c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -167,7 +167,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends m_Enabled = true; m_log.DebugFormat("[FRIENDS MODULE]: {0} enabled.", Name); } - } + } } protected virtual void InitModule(IConfigSource config) @@ -247,14 +247,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { FriendInfo[] friends = GetFriendsFromCache(principalID); FriendInfo finfo = GetFriend(friends, friendID); - if (finfo != null) + if (finfo != null && finfo.TheirFlags != -1) { return finfo.TheirFlags; } - return 0; } + private void OnMakeRootAgent(ScenePresence sp) + { + if(sp.gotCrossUpdate) + return; + + RecacheFriends(sp.ControllingClient); + + lock (m_NeedsToNotifyStatus) + { + if (m_NeedsToNotifyStatus.Remove(sp.UUID)) + { + // Inform the friends that this user is online. This can only be done once the client is a Root Agent. + StatusChange(sp.UUID, true); + } + } + } + private void OnNewClient(IClientAPI client) { client.OnInstantMessage += OnInstantMessage; @@ -262,6 +278,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnTerminateFriendship += RemoveFriendship; client.OnGrantUserRights += GrantRights; + client.OnFindAgent += FindFriend; // We need to cache information for child agents as well as root agents so that friend edit/move/delete // permissions will work across borders where both regions are on different simulators. @@ -326,20 +343,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - private void OnMakeRootAgent(ScenePresence sp) - { - RecacheFriends(sp.ControllingClient); - - lock (m_NeedsToNotifyStatus) - { - if (m_NeedsToNotifyStatus.Remove(sp.UUID)) - { - // Inform the friends that this user is online. This can only be done once the client is a Root Agent. - StatusChange(sp.UUID, true); - } - } - } - private void OnClientLogin(IClientAPI client) { UUID agentID = client.AgentId; @@ -358,8 +361,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends m_NeedsListOfOnlineFriends.Add(agentID); } + public void IsNowRoot(ScenePresence sp) + { + OnMakeRootAgent(sp); + } + public virtual bool SendFriendsOnlineIfNeeded(IClientAPI client) { + if (client == null) + return false; + UUID agentID = client.AgentId; // Check if the online friends list is needed @@ -500,18 +511,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (((fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1)) friendList.Add(fi); } - - Util.FireAndForget( - delegate - { -// m_log.DebugFormat( -// "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}", -// friendList.Count, agentID, online); - - // Notify about this user status - StatusNotify(friendList, agentID, online); - }, null, "FriendsModule.StatusChange" - ); + if(friendList.Count > 0) + { + Util.FireAndForget( + delegate + { +// m_log.DebugFormat( +// "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}", +// friendList.Count, agentID, online); + + // Notify about this user status + StatusNotify(friendList, agentID, online); + }, null, "FriendsModule.StatusChange" + ); + } } } @@ -540,6 +553,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // We do this regrouping so that we can efficiently send a single request rather than one for each // friend in what may be a very large friends list. PresenceInfo[] friendSessions = PresenceService.GetAgents(remoteFriendStringIds.ToArray()); + if(friendSessions == null) + return; foreach (PresenceInfo friendSession in friendSessions) { @@ -561,7 +576,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends protected virtual void OnInstantMessage(IClientAPI client, GridInstantMessage im) { if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered) - { + { // we got a friendship offer UUID principalID = new UUID(im.fromAgentID); UUID friendID = new UUID(im.toAgentID); @@ -596,7 +611,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends im.imSessionID = im.fromAgentID; im.fromAgentName = GetFriendshipRequesterName(agentID); - // Try the local sim + // Try the local sim if (LocalFriendshipOffered(friendID, im)) return true; @@ -639,7 +654,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends ccm.CreateCallingCard(client.AgentId, friendID, UUID.Zero); } - // Update the local cache. + // Update the local cache. RecacheFriends(client); // @@ -695,7 +710,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } } - + public void RemoveFriendship(IClientAPI client, UUID exfriendID) { if (!DeleteFriendship(client.AgentId, exfriendID)) @@ -723,7 +738,65 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); m_FriendsSimConnector.FriendshipTerminated(region, client.AgentId, exfriendID); } - } + } + } + + public void FindFriend(IClientAPI remoteClient,UUID HunterID ,UUID PreyID) + { + UUID requester = remoteClient.AgentId; + if(requester != HunterID) // only allow client agent to be the hunter (?) + return; + + FriendInfo[] friends = GetFriendsFromCache(requester); + if (friends.Length == 0) + return; + + FriendInfo friend = GetFriend(friends, PreyID); + if (friend == null) + return; + + if(friend.TheirFlags == -1 || (friend.TheirFlags & (int)FriendRights.CanSeeOnMap) == 0) + return; + + Scene hunterScene = (Scene)remoteClient.Scene; + + if(hunterScene == null) + return; + + // check local + ScenePresence sp; + double px; + double py; + if(hunterScene.TryGetScenePresence(PreyID, out sp)) + { + if(sp == null) + return; + px = hunterScene.RegionInfo.WorldLocX + sp.AbsolutePosition.X; + py = hunterScene.RegionInfo.WorldLocY + sp.AbsolutePosition.Y; + + remoteClient.SendFindAgent(HunterID, PreyID, px, py); + return; + } + + PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { PreyID.ToString() }); + + if (friendSessions == null || friendSessions.Length == 0) + return; + + PresenceInfo friendSession = friendSessions[0]; + if (friendSession == null) + return; + + GridRegion region = GridService.GetRegionByUUID(hunterScene.RegionInfo.ScopeID, friendSession.RegionID); + + if(region == null) + return; + + // we don't have presence location so point to a standard region center for now + px = region.RegionLocX + 128.0; + py = region.RegionLocY + 128.0; + + remoteClient.SendFindAgent(HunterID, PreyID, px, py); } public void GrantRights(IClientAPI remoteClient, UUID friendID, int rights) @@ -745,7 +818,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (friend != null) // Found it { - // Store it on the DB + // Store it on service if (!StoreRights(requester, friendID, rights)) { remoteClient.SendAlertMessage("Unable to grant rights."); @@ -869,28 +942,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return false; } - public bool LocalGrantRights(UUID userID, UUID friendID, int userFlags, int rights) + public bool LocalGrantRights(UUID userID, UUID friendID, int oldRights, int newRights) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { - bool onlineBitChanged = ((rights ^ userFlags) & (int)FriendRights.CanSeeOnline) != 0; + int changedRights = newRights ^ oldRights; + bool onlineBitChanged = (changedRights & (int)FriendRights.CanSeeOnline) != 0; if (onlineBitChanged) { - if ((rights & (int)FriendRights.CanSeeOnline) == 1) + if ((newRights & (int)FriendRights.CanSeeOnline) == 1) friendClient.SendAgentOnline(new UUID[] { userID }); else friendClient.SendAgentOffline(new UUID[] { userID }); } - else - { - bool canEditObjectsChanged = ((rights ^ userFlags) & (int)FriendRights.CanModifyObjects) != 0; - if (canEditObjectsChanged) - friendClient.SendChangeUserRights(userID, friendID, rights); - } + + if(changedRights != 0) + friendClient.SendChangeUserRights(userID, friendID, newRights); // Update local cache - UpdateLocalCache(userID, friendID, rights); + UpdateLocalCache(userID, friendID, newRights); return true; } @@ -946,8 +1017,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends lock (m_Friends) { FriendInfo[] friends = GetFriendsFromCache(friendID); - FriendInfo finfo = GetFriend(friends, userID); - finfo.TheirFlags = rights; + if(friends != EMPTY_FRIENDS) + { + FriendInfo finfo = GetFriend(friends, userID); + if(finfo!= null) + finfo.TheirFlags = rights; + } } } -- cgit v1.1