aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Null/NullFriendsData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/Null/NullFriendsData.cs')
-rw-r--r--OpenSim/Data/Null/NullFriendsData.cs74
1 files changed, 56 insertions, 18 deletions
diff --git a/OpenSim/Data/Null/NullFriendsData.cs b/OpenSim/Data/Null/NullFriendsData.cs
index 0a4b242..473999f 100644
--- a/OpenSim/Data/Null/NullFriendsData.cs
+++ b/OpenSim/Data/Null/NullFriendsData.cs
@@ -28,6 +28,9 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection;
32using System.Threading;
33using log4net;
31using OpenMetaverse; 34using OpenMetaverse;
32using OpenSim.Framework; 35using OpenSim.Framework;
33using OpenSim.Data; 36using OpenSim.Data;
@@ -36,12 +39,26 @@ namespace OpenSim.Data.Null
36{ 39{
37 public class NullFriendsData : IFriendsData 40 public class NullFriendsData : IFriendsData
38 { 41 {
42// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
39 private static List<FriendsData> m_Data = new List<FriendsData>(); 44 private static List<FriendsData> m_Data = new List<FriendsData>();
40 45
41 public NullFriendsData(string connectionString, string realm) 46 public NullFriendsData(string connectionString, string realm)
42 { 47 {
43 } 48 }
44 49
50 /// <summary>
51 /// Clear all friends data
52 /// </summary>
53 /// <remarks>
54 /// This is required by unit tests to clear the static data between test runs.
55 /// </remarks>
56 public static void Clear()
57 {
58 lock (m_Data)
59 m_Data.Clear();
60 }
61
45 public FriendsData[] GetFriends(UUID principalID) 62 public FriendsData[] GetFriends(UUID principalID)
46 { 63 {
47 return GetFriends(principalID.ToString()); 64 return GetFriends(principalID.ToString());
@@ -56,20 +73,30 @@ namespace OpenSim.Data.Null
56 /// <returns></returns> 73 /// <returns></returns>
57 public FriendsData[] GetFriends(string userID) 74 public FriendsData[] GetFriends(string userID)
58 { 75 {
59 List<FriendsData> lst = m_Data.FindAll(fdata => 76 lock (m_Data)
60 { 77 {
61 return fdata.PrincipalID == userID.ToString(); 78 List<FriendsData> lst = m_Data.FindAll(fdata =>
62 });
63
64 if (lst != null)
65 {
66 lst.ForEach(f =>
67 { 79 {
68 FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID); 80 return fdata.PrincipalID == userID.ToString();
69 if (f2 != null) { f.Data["TheirFlags"] = f2.Data["Flags"]; }
70 }); 81 });
71 82
72 return lst.ToArray(); 83 if (lst != null)
84 {
85 lst.ForEach(f =>
86 {
87 FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID);
88 if (f2 != null)
89 f.Data["TheirFlags"] = f2.Data["Flags"];
90
91 // m_log.DebugFormat(
92 // "[NULL FRIENDS DATA]: Got {0} {1} {2} for {3}",
93 // f.Friend, f.Data["Flags"], f2 != null ? f.Data["TheirFlags"] : "not found!", f.PrincipalID);
94 });
95
96 // m_log.DebugFormat("[NULL FRIENDS DATA]: Got {0} friends for {1}", lst.Count, userID);
97
98 return lst.ToArray();
99 }
73 } 100 }
74 101
75 return new FriendsData[0]; 102 return new FriendsData[0];
@@ -80,7 +107,11 @@ namespace OpenSim.Data.Null
80 if (data == null) 107 if (data == null)
81 return false; 108 return false;
82 109
83 m_Data.Add(data); 110// m_log.DebugFormat(
111// "[NULL FRIENDS DATA]: Storing {0} {1} {2}", data.PrincipalID, data.Friend, data.Data["Flags"]);
112
113 lock (m_Data)
114 m_Data.Add(data);
84 115
85 return true; 116 return true;
86 } 117 }
@@ -92,14 +123,21 @@ namespace OpenSim.Data.Null
92 123
93 public bool Delete(string userID, string friendID) 124 public bool Delete(string userID, string friendID)
94 { 125 {
95 List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); }); 126 lock (m_Data)
96 if (lst != null)
97 { 127 {
98 FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; }); 128 List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); });
99 if (friendID != null) 129 if (lst != null)
100 { 130 {
101 m_Data.Remove(friend); 131 FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; });
102 return true; 132 if (friendID != null)
133 {
134 // m_log.DebugFormat(
135 // "[NULL FRIENDS DATA]: Deleting friend {0} {1} for {2}",
136 // friend.Friend, friend.Data["Flags"], friend.PrincipalID);
137
138 m_Data.Remove(friend);
139 return true;
140 }
103 } 141 }
104 } 142 }
105 143