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. --- .../Avatar/Friends/CallingCardModule.cs | 5 +- .../CoreModules/Avatar/Friends/FriendsModule.cs | 169 +++++++++++++++------ .../Avatar/Friends/FriendsRequestHandler.cs | 17 ++- .../CoreModules/Avatar/Friends/HGFriendsModule.cs | 58 ++++++- .../CoreModules/Avatar/Friends/HGStatusNotifier.cs | 2 +- .../Avatar/Friends/Tests/FriendModuleTests.cs | 2 +- 6 files changed, 185 insertions(+), 68 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar/Friends') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/CallingCardModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/CallingCardModule.cs index eb23e83..4a55a7e 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/CallingCardModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/CallingCardModule.cs @@ -118,7 +118,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // If we're in god mode, we reverse the meaning. Offer // calling card becomes "Take a calling card" for that // person, no matter if they agree or not. - if (sp.GodLevel >= 200) + if (sp.IsViewerUIGod) { CreateCallingCard(client.AgentId, destID, UUID.Zero, true); return; @@ -239,8 +239,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends InventoryFolderBase trashFolder = invService.GetFolderForType(client.AgentId, FolderType.Trash); - InventoryItemBase item = new InventoryItemBase(transactionID, client.AgentId); - item = invService.GetItem(item); + InventoryItemBase item = invService.GetItem(client.AgentId, transactionID); if (item != null && trashFolder != null) { 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; + } } } diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs index 13512a2..091b197 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs @@ -65,9 +65,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends protected override byte[] ProcessRequest( string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { - StreamReader sr = new StreamReader(requestData); - string body = sr.ReadToEnd(); - sr.Close(); + string body; + using(StreamReader sr = new StreamReader(requestData)) + body = sr.ReadToEnd(); + body = body.Trim(); //m_log.DebugFormat("[XXX]: query String: {0}", body); @@ -127,7 +128,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends UserAccount account = m_FriendsModule.UserAccountService.GetUserAccount(UUID.Zero, fromID); string name = (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; - GridInstantMessage im = new GridInstantMessage(m_FriendsModule.Scene, fromID, name, toID, + GridInstantMessage im = new GridInstantMessage(m_FriendsModule.Scene, fromID, name, toID, (byte)InstantMessageDialog.FriendshipOffered, message, false, Vector3.Zero); // !! HACK @@ -211,7 +212,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { UUID fromID = UUID.Zero; UUID toID = UUID.Zero; - int rights = 0, userFlags = 0; + int oldRights = 0, newRights = 0; if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) return FailureResult(); @@ -222,13 +223,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (!UUID.TryParse(request["ToID"].ToString(), out toID)) return FailureResult(); - if (!Int32.TryParse(request["UserFlags"].ToString(), out userFlags)) + if (!Int32.TryParse(request["UserFlags"].ToString(), out oldRights)) return FailureResult(); - if (!Int32.TryParse(request["Rights"].ToString(), out rights)) + if (!Int32.TryParse(request["Rights"].ToString(), out newRights)) return FailureResult(); - if (m_FriendsModule.LocalGrantRights(UUID.Zero, UUID.Zero, userFlags, rights)) + if (m_FriendsModule.LocalGrantRights(fromID, toID, oldRights, newRights)) return SuccessResult(); return FailureResult(); diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs index 27b7376..fae1e05 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs @@ -141,7 +141,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (avatar == null) return; - if (avatar.UserLevel < m_levelHGFriends) + if (avatar.GodController.UserLevel < m_levelHGFriends) { client.SendAgentAlertMessage("Unable to send friendship invitation to foreigner. Insufficient permissions.", false); return; @@ -214,7 +214,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends FriendInfo[] friends = GetFriendsFromCache(client.AgentId); foreach (FriendInfo f in friends) { - client.SendChangeUserRights(new UUID(f.Friend), client.AgentId, f.TheirFlags); + int rights = f.TheirFlags; + if(rights != -1 ) + client.SendChangeUserRights(new UUID(f.Friend), client.AgentId, rights); } } } @@ -337,7 +339,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (UUID.TryParse(friendID, out id)) return base.FriendshipMessage(friendID); - return "Please confirm this friendship you made while you were away."; + return "Please confirm this friendship you made while you where on another HG grid"; } protected override FriendInfo GetFriend(FriendInfo[] friends, UUID friendID) @@ -456,6 +458,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { // local grid users m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local"); + DeletePreviousHGRelations(agentID, friendID); base.StoreFriendships(agentID, friendID); return; } @@ -538,8 +541,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // 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); @@ -624,6 +627,45 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } + private void DeletePreviousHGRelations(UUID a1, UUID a2) + { + // Delete any previous friendship relations + FriendInfo[] finfos = null; + finfos = GetFriendsFromCache(a1); + if (finfos != null) + { + foreach (FriendInfo f in finfos) + { + if (f.TheirFlags == -1) + { + if (f.Friend.StartsWith(a2.ToString())) + { + FriendsService.Delete(a1, f.Friend); + // and also the converse + FriendsService.Delete(f.Friend, a1.ToString()); + } + } + } + } + + finfos = GetFriendsFromCache(a1); + if (finfos != null) + { + foreach (FriendInfo f in finfos) + { + if (f.TheirFlags == -1) + { + if (f.Friend.StartsWith(a1.ToString())) + { + FriendsService.Delete(a2, f.Friend); + // and also the converse + FriendsService.Delete(f.Friend, a2.ToString()); + } + } + } + } + } + protected override bool DeleteFriendship(UUID agentID, UUID exfriendID) { Boolean agentIsLocal = true; @@ -743,7 +785,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends m_log.DebugFormat("[HGFRIENDS MODULE]: Forwading friendship from {0} to {1} @ {2}", agentID, friendID, friendsURL); GridRegion region = new GridRegion(); region.ServerURI = friendsURL; - + string name = im.fromAgentName; if (m_uMan.IsLocalGridUser(agentID)) { @@ -775,7 +817,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } m_HGFriendsConnector.FriendshipOffered(region, agentID, friendID, im.message, name); - + return true; } } @@ -804,4 +846,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return false; } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGStatusNotifier.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGStatusNotifier.cs index 1fa4dd6..3fae271 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGStatusNotifier.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGStatusNotifier.cs @@ -32,7 +32,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { if (kvp.Key != "local") { - // For the others, call the user agent service + // For the others, call the user agent service List ids = new List(); foreach (FriendInfo f in kvp.Value) ids.Add(f.Friend); diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs index e6fd54e..3d9bd35 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs @@ -67,7 +67,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests // so that different services and simulator can share the data in standalone mode. This is pretty horrible // effectively the statics are global variables. NullFriendsData.Clear(); - + IConfigSource config = new IniConfigSource(); config.AddConfig("Modules"); // Not strictly necessary since FriendsModule assumes it is the default (!) -- cgit v1.1