From c6a5ff26fff6a1d0c3ab916a526cf0dd4e4142bc Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 1 Mar 2010 21:32:55 -0800 Subject: [PATCH] Friends rights under control. --- .../Avatar/Friends/FriendsModule.cs | 93 +++++-------------- .../Avatar/Friends/FriendsRequestHandler.cs | 10 +- .../Connectors/Friends/FriendsSimConnector.cs | 4 +- .../Services/Interfaces/IFriendsService.cs | 6 +- 4 files changed, 41 insertions(+), 72 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 61116a7065..555fb00e46 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -569,52 +569,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); // Let's find the friend in this user's friend list UserFriendData fd = m_Friends[remoteClient.AgentId]; - FriendInfo friend = new FriendInfo(); + FriendInfo friend = null; foreach (FriendInfo fi in fd.Friends) if (fi.Friend == target.ToString()) friend = fi; - if (!friend.PrincipalID.Equals(UUID.Zero)) // Found it + if (friend != null) // Found it { + // Store it on the DB FriendsService.StoreFriend(requester, target.ToString(), rights); - bool onlineBitChanged = ((rights ^ friend.MyFlags) & (int)FriendRights.CanSeeOnline) == 0; - if (!onlineBitChanged) - { - remoteClient.SendChangeUserRights(requester, target, rights); - } + // Store it in the local cache + int myFlags = friend.MyFlags; + friend.MyFlags = rights; + + // Always send this back to the original client + remoteClient.SendChangeUserRights(requester, target, rights); + + // + // Notify the friend + // // Try local - if (LocalGrantRights(requester, target, friend.MyFlags, rights)) + if (LocalGrantRights(requester, target, myFlags, rights)) return; - - //int delta = rights ^ friend.MyFlags; - //if ((delta & ~1) != 0) - //{ - // //remoteClient.SendChangeUserRights(remoteClient.AgentId, target, rights & ~1); - // // - // // Notify the friend - // // - - // if (friendClient != null) - // { - // friendClient.SendChangeUserRights(target, remoteClient.AgentId, rights & ~1); - // } - //} - //if ((delta & 1) != 0) - //{ - // if (friendClient != null) - // { - // if ((rights & 1) != 0) - // friendClient.SendAgentOnline(new UUID[] { new UUID(remoteClient.AgentId) }); - // else - // friendClient.SendAgentOffline(new UUID[] { new UUID(remoteClient.AgentId) }); - // } - //} - //if (friendClient != null) // Local, we're done - // return; - PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { target.ToString() }); PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); if (friendSession != null) @@ -622,7 +601,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); // TODO: You might want to send the delta to save the lookup // on the other end!! - m_FriendsSimConnector.GrantRights(region, requester, target); + m_FriendsSimConnector.GrantRights(region, requester, target, myFlags, rights); } } } @@ -693,53 +672,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return false; } - public bool LocalGrantRights(UUID userID, UUID friendID, int myFlags, int rights) + public bool LocalGrantRights(UUID userID, UUID friendID, int userFlags, int rights) { - m_log.DebugFormat("XXX Trying to locate {0}", friendID); IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { - bool onlineBitChanged = ((rights ^ myFlags) & (int)FriendRights.CanSeeOnline) == 0; - if (!onlineBitChanged) - friendClient.SendChangeUserRights(userID, friendID, rights); - else + bool onlineBitChanged = ((rights ^ userFlags) & (int)FriendRights.CanSeeOnline) != 0; + if (onlineBitChanged) { if ((rights & (int)FriendRights.CanSeeOnline) == 1) friendClient.SendAgentOnline(new UUID[] { new UUID(userID) }); else friendClient.SendAgentOffline(new UUID[] { new UUID(userID) }); } + else + { + bool canEditObjectsChanged = ((rights ^ userFlags) & (int)FriendRights.CanModifyObjects) != 0; + if (canEditObjectsChanged) + friendClient.SendChangeUserRights(userID, friendID, rights); + } + return true; } return false; - //int delta = rights ^ friend.MyFlags; - //if ((delta & ~1) != 0) - //{ - // //remoteClient.SendChangeUserRights(remoteClient.AgentId, target, rights & ~1); - // // - // // Notify the friend - // // - - // if (friendClient != null) - // { - // friendClient.SendChangeUserRights(target, remoteClient.AgentId, rights & ~1); - // } - //} - //if ((delta & 1) != 0) - //{ - // if (friendClient != null) - // { - // if ((rights & 1) != 0) - // friendClient.SendAgentOnline(new UUID[] { new UUID(remoteClient.AgentId) }); - // else - // friendClient.SendAgentOffline(new UUID[] { new UUID(remoteClient.AgentId) }); - // } - //} - //if (friendClient != null) // Local, we're done - // return; - } public bool LocalStatusNotification(UUID userID, UUID friendID, bool online) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs index 140660b779..0883c5ba83 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs @@ -196,6 +196,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { UUID fromID = UUID.Zero; UUID toID = UUID.Zero; + int rights = 0, userFlags = 0; if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) return FailureResult(); @@ -206,8 +207,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (!UUID.TryParse(request["ToID"].ToString(), out toID)) return FailureResult(); - // !!! - if (m_FriendsModule.LocalGrantRights(UUID.Zero, UUID.Zero, 0, 0)) + if (!Int32.TryParse(request["UserFlags"].ToString(), out userFlags)) + return FailureResult(); + + if (!Int32.TryParse(request["Rights"].ToString(), out rights)) + return FailureResult(); + + if (m_FriendsModule.LocalGrantRights(UUID.Zero, UUID.Zero, userFlags, rights)) return SuccessResult(); return FailureResult(); diff --git a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs index 490c8cfed3..a29ac2887c 100644 --- a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs +++ b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs @@ -99,7 +99,7 @@ namespace OpenSim.Services.Connectors.Friends return Call(region, sendData); } - public bool GrantRights(GridRegion region, UUID userID, UUID friendID) + public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights) { Dictionary sendData = new Dictionary(); //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); @@ -108,6 +108,8 @@ namespace OpenSim.Services.Connectors.Friends sendData["FromID"] = userID.ToString(); sendData["ToID"] = friendID.ToString(); + sendData["UserFlags"] = userFlags.ToString(); + sendData["Rights"] = rights.ToString(); return Call(region, sendData); } diff --git a/OpenSim/Services/Interfaces/IFriendsService.cs b/OpenSim/Services/Interfaces/IFriendsService.cs index fc20224bc3..2692c48f39 100644 --- a/OpenSim/Services/Interfaces/IFriendsService.cs +++ b/OpenSim/Services/Interfaces/IFriendsService.cs @@ -32,13 +32,17 @@ using System.Collections.Generic; namespace OpenSim.Services.Interfaces { - public struct FriendInfo + public class FriendInfo { public UUID PrincipalID; public string Friend; public int MyFlags; public int TheirFlags; + public FriendInfo() + { + } + public FriendInfo(Dictionary kvp) { PrincipalID = UUID.Zero;