From 59157d9d63c0e038ca0a619bfae1be3ed6f77677 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 30 Mar 2012 00:40:19 +0100 Subject: Add simple login test with online friends. Add IFriendsModule.GrantRights() for granting rights via a module call. Rename IFriendsModule.GetFriendPerms() -> GetRightsGrantedByFriend() to be more self-documenting and consistent with friends module terminology. Add some method doc. --- OpenSim/Data/Null/NullFriendsData.cs | 31 ++++++++++++++++++++++++++++++- OpenSim/Data/Null/NullPresenceData.cs | 1 - 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'OpenSim/Data/Null') diff --git a/OpenSim/Data/Null/NullFriendsData.cs b/OpenSim/Data/Null/NullFriendsData.cs index 0a4b242..0be32a4 100644 --- a/OpenSim/Data/Null/NullFriendsData.cs +++ b/OpenSim/Data/Null/NullFriendsData.cs @@ -28,6 +28,8 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Reflection; +using log4net; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Data; @@ -36,12 +38,25 @@ namespace OpenSim.Data.Null { public class NullFriendsData : IFriendsData { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static List m_Data = new List(); public NullFriendsData(string connectionString, string realm) { } + /// + /// Clear all friends data + /// + /// + /// This is required by unit tests to clear the static data between test runs. + /// + public static void Clear() + { + m_Data.Clear(); + } + public FriendsData[] GetFriends(UUID principalID) { return GetFriends(principalID.ToString()); @@ -66,9 +81,16 @@ namespace OpenSim.Data.Null lst.ForEach(f => { FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID); - if (f2 != null) { f.Data["TheirFlags"] = f2.Data["Flags"]; } + if (f2 != null) + f.Data["TheirFlags"] = f2.Data["Flags"]; + +// m_log.DebugFormat( +// "[NULL FRIENDS DATA]: Got {0} {1} {2} for {3}", +// f.Friend, f.Data["Flags"], f2 != null ? f.Data["TheirFlags"] : "not found!", f.PrincipalID); }); +// m_log.DebugFormat("[NULL FRIENDS DATA]: Got {0} friends for {1}", lst.Count, userID); + return lst.ToArray(); } @@ -80,6 +102,9 @@ namespace OpenSim.Data.Null if (data == null) return false; +// m_log.DebugFormat( +// "[NULL FRIENDS DATA]: Storing {0} {1} {2}", data.PrincipalID, data.Friend, data.Data["Flags"]); + m_Data.Add(data); return true; @@ -98,6 +123,10 @@ namespace OpenSim.Data.Null FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; }); if (friendID != null) { +// m_log.DebugFormat( +// "[NULL FRIENDS DATA]: Deleting friend {0} {1} for {2}", +// friend.Friend, friend.Data["Flags"], friend.PrincipalID); + m_Data.Remove(friend); return true; } diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs index 91f1cc5..c06c223 100644 --- a/OpenSim/Data/Null/NullPresenceData.cs +++ b/OpenSim/Data/Null/NullPresenceData.cs @@ -110,7 +110,6 @@ namespace OpenSim.Data.Null return false; } - public PresenceData[] Get(string field, string data) { if (Instance != this) -- cgit v1.1 From 1ef62ca75ef8c551303b4e86e737b5d958d07ce7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 30 Mar 2012 01:23:34 +0100 Subject: Lock NullFriendsData.m_Data for consistency and against concurrent read/write --- OpenSim/Data/Null/NullFriendsData.cs | 69 ++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 30 deletions(-) (limited to 'OpenSim/Data/Null') diff --git a/OpenSim/Data/Null/NullFriendsData.cs b/OpenSim/Data/Null/NullFriendsData.cs index 0be32a4..473999f 100644 --- a/OpenSim/Data/Null/NullFriendsData.cs +++ b/OpenSim/Data/Null/NullFriendsData.cs @@ -29,6 +29,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Reflection; +using System.Threading; using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -54,7 +55,8 @@ namespace OpenSim.Data.Null /// public static void Clear() { - m_Data.Clear(); + lock (m_Data) + m_Data.Clear(); } public FriendsData[] GetFriends(UUID principalID) @@ -71,27 +73,30 @@ namespace OpenSim.Data.Null /// public FriendsData[] GetFriends(string userID) { - List lst = m_Data.FindAll(fdata => + lock (m_Data) { - return fdata.PrincipalID == userID.ToString(); - }); - - if (lst != null) - { - lst.ForEach(f => + List lst = m_Data.FindAll(fdata => { - FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID); - if (f2 != null) - f.Data["TheirFlags"] = f2.Data["Flags"]; - -// m_log.DebugFormat( -// "[NULL FRIENDS DATA]: Got {0} {1} {2} for {3}", -// f.Friend, f.Data["Flags"], f2 != null ? f.Data["TheirFlags"] : "not found!", f.PrincipalID); + return fdata.PrincipalID == userID.ToString(); }); - -// m_log.DebugFormat("[NULL FRIENDS DATA]: Got {0} friends for {1}", lst.Count, userID); - - return lst.ToArray(); + + if (lst != null) + { + lst.ForEach(f => + { + FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID); + if (f2 != null) + f.Data["TheirFlags"] = f2.Data["Flags"]; + + // m_log.DebugFormat( + // "[NULL FRIENDS DATA]: Got {0} {1} {2} for {3}", + // f.Friend, f.Data["Flags"], f2 != null ? f.Data["TheirFlags"] : "not found!", f.PrincipalID); + }); + + // m_log.DebugFormat("[NULL FRIENDS DATA]: Got {0} friends for {1}", lst.Count, userID); + + return lst.ToArray(); + } } return new FriendsData[0]; @@ -105,7 +110,8 @@ namespace OpenSim.Data.Null // m_log.DebugFormat( // "[NULL FRIENDS DATA]: Storing {0} {1} {2}", data.PrincipalID, data.Friend, data.Data["Flags"]); - m_Data.Add(data); + lock (m_Data) + m_Data.Add(data); return true; } @@ -117,18 +123,21 @@ namespace OpenSim.Data.Null public bool Delete(string userID, string friendID) { - List lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); }); - if (lst != null) + lock (m_Data) { - FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; }); - if (friendID != null) + List lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); }); + if (lst != null) { -// m_log.DebugFormat( -// "[NULL FRIENDS DATA]: Deleting friend {0} {1} for {2}", -// friend.Friend, friend.Data["Flags"], friend.PrincipalID); - - m_Data.Remove(friend); - return true; + FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; }); + if (friendID != null) + { + // m_log.DebugFormat( + // "[NULL FRIENDS DATA]: Deleting friend {0} {1} for {2}", + // friend.Friend, friend.Data["Flags"], friend.PrincipalID); + + m_Data.Remove(friend); + return true; + } } } -- cgit v1.1