aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/IXGroupData.cs59
-rw-r--r--OpenSim/Data/Null/NullXGroupData.cs34
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs1
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs55
-rw-r--r--OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs152
5 files changed, 253 insertions, 48 deletions
diff --git a/OpenSim/Data/IXGroupData.cs b/OpenSim/Data/IXGroupData.cs
index 2965e8c..e5821ef 100644
--- a/OpenSim/Data/IXGroupData.cs
+++ b/OpenSim/Data/IXGroupData.cs
@@ -48,9 +48,57 @@ namespace OpenSim.Data
48 public ulong everyonePowers; 48 public ulong everyonePowers;
49 public ulong ownersPowers; 49 public ulong ownersPowers;
50 50
51 public Dictionary<UUID, XGroupMember> members = new Dictionary<UUID, XGroupMember>();
52 public Dictionary<UUID, XGroupNotice> notices = new Dictionary<UUID, XGroupNotice>();
53
51 public XGroup Clone() 54 public XGroup Clone()
52 { 55 {
53 return (XGroup)MemberwiseClone(); 56 XGroup clone = (XGroup)MemberwiseClone();
57 clone.members = new Dictionary<UUID, XGroupMember>();
58 clone.notices = new Dictionary<UUID, XGroupNotice>();
59
60 foreach (KeyValuePair<UUID, XGroupMember> kvp in members)
61 clone.members[kvp.Key] = kvp.Value.Clone();
62
63 foreach (KeyValuePair<UUID, XGroupNotice> kvp in notices)
64 clone.notices[kvp.Key] = kvp.Value.Clone();
65
66 return clone;
67 }
68 }
69
70 public class XGroupMember
71 {
72 public UUID agentID;
73 public UUID groupID;
74 public UUID roleID;
75 public bool acceptNotices = true;
76 public bool listInProfile = true;
77
78 public XGroupMember Clone()
79 {
80 return (XGroupMember)MemberwiseClone();
81 }
82 }
83
84 public class XGroupNotice
85 {
86 public UUID groupID;
87 public UUID noticeID;
88 public uint timestamp;
89 public string fromName;
90 public string subject;
91 public string message;
92 public byte[] binaryBucket;
93 public bool hasAttachment;
94 public int assetType;
95
96 public XGroupNotice Clone()
97 {
98 XGroupNotice clone = (XGroupNotice)MemberwiseClone();
99 clone.binaryBucket = (byte[])binaryBucket.Clone();
100
101 return clone;
54 } 102 }
55 } 103 }
56 104
@@ -58,14 +106,13 @@ namespace OpenSim.Data
58 /// Early stub interface for groups data, not final. 106 /// Early stub interface for groups data, not final.
59 /// </summary> 107 /// </summary>
60 /// <remarks> 108 /// <remarks>
61 /// Currently in-use only for regression test purposes. Needs to be filled out over time. 109 /// Currently in-use only for regression test purposes.
62 /// </remarks> 110 /// </remarks>
63 public interface IXGroupData 111 public interface IXGroupData
64 { 112 {
65 bool StoreGroup(XGroup group); 113 bool StoreGroup(XGroup group);
66 XGroup[] GetGroups(string field, string val); 114 XGroup GetGroup(UUID groupID);
67 XGroup[] GetGroups(string[] fields, string[] vals); 115 Dictionary<UUID, XGroup> GetGroups();
68 bool DeleteGroups(string field, string val); 116 bool DeleteGroup(UUID groupID);
69 bool DeleteGroups(string[] fields, string[] vals);
70 } 117 }
71} \ No newline at end of file 118} \ No newline at end of file
diff --git a/OpenSim/Data/Null/NullXGroupData.cs b/OpenSim/Data/Null/NullXGroupData.cs
index 7a86b9f..3fa9451 100644
--- a/OpenSim/Data/Null/NullXGroupData.cs
+++ b/OpenSim/Data/Null/NullXGroupData.cs
@@ -38,7 +38,7 @@ using OpenSim.Data;
38 38
39namespace OpenSim.Data.Null 39namespace OpenSim.Data.Null
40{ 40{
41 public class NullXGroupData : NullGenericDataHandler, IXGroupData 41 public class NullXGroupData : IXGroupData
42 { 42 {
43// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 44
@@ -56,35 +56,31 @@ namespace OpenSim.Data.Null
56 return true; 56 return true;
57 } 57 }
58 58
59 public XGroup[] GetGroups(string field, string val) 59 public XGroup GetGroup(UUID groupID)
60 { 60 {
61 return GetGroups(new string[] { field }, new string[] { val }); 61 XGroup group = null;
62 }
63 62
64 public XGroup[] GetGroups(string[] fields, string[] vals)
65 {
66 lock (m_groups) 63 lock (m_groups)
67 { 64 m_groups.TryGetValue(groupID, out group);
68 List<XGroup> origGroups = Get<XGroup>(fields, vals, m_groups.Values.ToList());
69 65
70 return origGroups.Select(g => g.Clone()).ToArray(); 66 return group;
71 }
72 } 67 }
73 68
74 public bool DeleteGroups(string field, string val) 69 public Dictionary<UUID, XGroup> GetGroups()
75 { 70 {
76 return DeleteGroups(new string[] { field }, new string[] { val }); 71 Dictionary<UUID, XGroup> groupsClone = new Dictionary<UUID, XGroup>();
72
73 lock (m_groups)
74 foreach (XGroup group in m_groups.Values)
75 groupsClone[group.groupID] = group.Clone();
76
77 return groupsClone;
77 } 78 }
78 79
79 public bool DeleteGroups(string[] fields, string[] vals) 80 public bool DeleteGroup(UUID groupID)
80 { 81 {
81 lock (m_groups) 82 lock (m_groups)
82 { 83 return m_groups.Remove(groupID);
83 XGroup[] groupsToDelete = GetGroups(fields, vals);
84 Array.ForEach(groupsToDelete, g => m_groups.Remove(g.groupID));
85 }
86
87 return true;
88 } 84 }
89 } 85 }
90} \ No newline at end of file 86} \ No newline at end of file
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
index d09d3ad..62020ee 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
@@ -497,6 +497,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
497 OnNewGroupNotice(GroupID, NoticeID); 497 OnNewGroupNotice(GroupID, NoticeID);
498 } 498 }
499 499
500 /*** We would insert call code here ***/
500 // Send notice out to everyone that wants notices 501 // Send notice out to everyone that wants notices
501 foreach (GroupMembersData member in m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), GroupID)) 502 foreach (GroupMembersData member in m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), GroupID))
502 { 503 {
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs
index 26d2597..08a93b8 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic;
30using System.Net; 31using System.Net;
31using System.Reflection; 32using System.Reflection;
32using Nini.Config; 33using Nini.Config;
@@ -118,5 +119,59 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups.Tests
118 119
119 // TODO: More checking of more actual event data. 120 // TODO: More checking of more actual event data.
120 } 121 }
122
123 [Test]
124 public void TestSendGroupNotice()
125 {
126 TestHelpers.InMethod();
127// TestHelpers.EnableLogging();
128
129 TestScene scene = new SceneHelpers().SetupScene();
130 IConfigSource configSource = new IniConfigSource();
131 IConfig config = configSource.AddConfig("Groups");
132 config.Set("Enabled", true);
133 config.Set("Module", "GroupsModule");
134 config.Set("DebugEnabled", true);
135
136 GroupsModule gm = new GroupsModule();
137
138 SceneHelpers.SetupSceneModules(scene, configSource, gm, new MockGroupsServicesConnector());
139
140 UUID userId = TestHelpers.ParseTail(0x1);
141 string subjectText = "newman";
142 string messageText = "Hello";
143 string combinedSubjectMessage = string.Format("{0}|{1}", subjectText, messageText);
144
145 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
146 TestClient tc = (TestClient)sp.ControllingClient;
147
148 UUID groupID = gm.CreateGroup(tc, "group1", null, true, UUID.Zero, 0, true, true, true);
149 gm.JoinGroupRequest(tc, groupID);
150
151 // Create a second user who doesn't want to receive notices
152 ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x2));
153 TestClient tc2 = (TestClient)sp2.ControllingClient;
154 gm.JoinGroupRequest(tc2, groupID);
155 gm.SetGroupAcceptNotices(tc2, groupID, false, true);
156
157 List<GridInstantMessage> spReceivedMessages = new List<GridInstantMessage>();
158 tc.OnReceivedInstantMessage += im => spReceivedMessages.Add(im);
159
160 List<GridInstantMessage> sp2ReceivedMessages = new List<GridInstantMessage>();
161 tc2.OnReceivedInstantMessage += im => sp2ReceivedMessages.Add(im);
162
163 GridInstantMessage noticeIm = new GridInstantMessage();
164 noticeIm.fromAgentID = userId.Guid;
165 noticeIm.toAgentID = groupID.Guid;
166 noticeIm.message = combinedSubjectMessage;
167 noticeIm.dialog = (byte)InstantMessageDialog.GroupNotice;
168
169 tc.HandleImprovedInstantMessage(noticeIm);
170
171 Assert.That(spReceivedMessages.Count, Is.EqualTo(1));
172 Assert.That(spReceivedMessages[0].message, Is.EqualTo(combinedSubjectMessage));
173
174 Assert.That(sp2ReceivedMessages.Count, Is.EqualTo(0));
175 }
121 } 176 }
122} \ No newline at end of file 177} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs b/OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs
index 3035cea..b3f8c36 100644
--- a/OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs
+++ b/OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs
@@ -138,33 +138,28 @@ namespace OpenSim.Tests.Common.Mock
138 { 138 {
139 } 139 }
140 140
141 private XGroup GetXGroup(UUID groupID, string name)
142 {
143 XGroup group = m_data.GetGroup(groupID);
144
145
146 if (group == null)
147 m_log.DebugFormat("[MOCK GROUPS SERVICES CONNECTOR]: No group found with ID {0}", groupID);
148
149 return group;
150 }
151
141 public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID groupID, string groupName) 152 public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID groupID, string groupName)
142 { 153 {
143 m_log.DebugFormat( 154 m_log.DebugFormat(
144 "[MOCK GROUPS SERVICES CONNECTOR]: Processing GetGroupRecord() for groupID {0}, name {1}", 155 "[MOCK GROUPS SERVICES CONNECTOR]: Processing GetGroupRecord() for groupID {0}, name {1}",
145 groupID, groupName); 156 groupID, groupName);
146 157
147 XGroup[] groups; 158 XGroup xg = GetXGroup(groupID, groupName);
148 string field, val;
149
150 if (groupID != UUID.Zero)
151 {
152 field = "groupID";
153 val = groupID.ToString();
154 }
155 else
156 {
157 field = "name";
158 val = groupName;
159 }
160
161 groups = m_data.GetGroups(field, val);
162 159
163 if (groups.Length == 0) 160 if (xg == null)
164 return null; 161 return null;
165 162
166 XGroup xg = groups[0];
167
168 GroupRecord gr = new GroupRecord() 163 GroupRecord gr = new GroupRecord()
169 { 164 {
170 GroupID = xg.groupID, 165 GroupID = xg.groupID,
@@ -196,8 +191,25 @@ namespace OpenSim.Tests.Common.Mock
196 { 191 {
197 } 192 }
198 193
199 public void SetAgentGroupInfo(UUID requestingAgentID, UUID AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile) 194 public void SetAgentGroupInfo(UUID requestingAgentID, UUID agentID, UUID groupID, bool acceptNotices, bool listInProfile)
200 { 195 {
196 m_log.DebugFormat(
197 "[MOCK GROUPS SERVICES CONNECTOR]: SetAgentGroupInfo, requestingAgentID {0}, agentID {1}, groupID {2}, acceptNotices {3}, listInProfile {4}",
198 requestingAgentID, agentID, groupID, acceptNotices, listInProfile);
199
200 XGroup group = GetXGroup(groupID, null);
201
202 if (group == null)
203 return;
204
205 XGroupMember xgm = null;
206 if (!group.members.TryGetValue(agentID, out xgm))
207 return;
208
209 xgm.acceptNotices = acceptNotices;
210 xgm.listInProfile = listInProfile;
211
212 m_data.StoreGroup(group);
201 } 213 }
202 214
203 public void AddAgentToGroupInvite(UUID requestingAgentID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID) 215 public void AddAgentToGroupInvite(UUID requestingAgentID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID)
@@ -213,8 +225,27 @@ namespace OpenSim.Tests.Common.Mock
213 { 225 {
214 } 226 }
215 227
216 public void AddAgentToGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID) 228 public void AddAgentToGroup(UUID requestingAgentID, UUID agentID, UUID groupID, UUID roleID)
217 { 229 {
230 m_log.DebugFormat(
231 "[MOCK GROUPS SERVICES CONNECTOR]: AddAgentToGroup, requestingAgentID {0}, agentID {1}, groupID {2}, roleID {3}",
232 requestingAgentID, agentID, groupID, roleID);
233
234 XGroup group = GetXGroup(groupID, null);
235
236 if (group == null)
237 return;
238
239 XGroupMember groupMember = new XGroupMember()
240 {
241 agentID = agentID,
242 groupID = groupID,
243 roleID = roleID
244 };
245
246 group.members[agentID] = groupMember;
247
248 m_data.StoreGroup(group);
218 } 249 }
219 250
220 public void RemoveAgentFromGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID) 251 public void RemoveAgentFromGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
@@ -259,9 +290,31 @@ namespace OpenSim.Tests.Common.Mock
259 return null; 290 return null;
260 } 291 }
261 292
262 public List<GroupMembersData> GetGroupMembers(UUID requestingAgentID, UUID GroupID) 293 public List<GroupMembersData> GetGroupMembers(UUID requestingAgentID, UUID groupID)
263 { 294 {
264 return null; 295 m_log.DebugFormat(
296 "[MOCK GROUPS SERVICES CONNECTOR]: GetGroupMembers, requestingAgentID {0}, groupID {1}",
297 requestingAgentID, groupID);
298
299 List<GroupMembersData> groupMembers = new List<GroupMembersData>();
300
301 XGroup group = GetXGroup(groupID, null);
302
303 if (group == null)
304 return groupMembers;
305
306 foreach (XGroupMember xgm in group.members.Values)
307 {
308 GroupMembersData gmd = new GroupMembersData();
309 gmd.AgentID = xgm.agentID;
310 gmd.IsOwner = group.founderID == gmd.AgentID;
311 gmd.AcceptNotices = xgm.acceptNotices;
312 gmd.ListInProfile = xgm.listInProfile;
313
314 groupMembers.Add(gmd);
315 }
316
317 return groupMembers;
265 } 318 }
266 319
267 public List<GroupRoleMembersData> GetGroupRoleMembers(UUID requestingAgentID, UUID GroupID) 320 public List<GroupRoleMembersData> GetGroupRoleMembers(UUID requestingAgentID, UUID GroupID)
@@ -269,18 +322,71 @@ namespace OpenSim.Tests.Common.Mock
269 return null; 322 return null;
270 } 323 }
271 324
272 public List<GroupNoticeData> GetGroupNotices(UUID requestingAgentID, UUID GroupID) 325 public List<GroupNoticeData> GetGroupNotices(UUID requestingAgentID, UUID groupID)
273 { 326 {
274 return null; 327 return null;
275 } 328 }
276 329
277 public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID) 330 public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID)
278 { 331 {
332 m_log.DebugFormat(
333 "[MOCK GROUPS SERVICES CONNECTOR]: GetGroupNotices, requestingAgentID {0}, noticeID {1}",
334 requestingAgentID, noticeID);
335
336 // Yes, not an efficient way to do it.
337 Dictionary<UUID, XGroup> groups = m_data.GetGroups();
338
339 foreach (XGroup group in groups.Values)
340 {
341 if (group.notices.ContainsKey(noticeID))
342 {
343 XGroupNotice n = group.notices[noticeID];
344
345 GroupNoticeInfo gni = new GroupNoticeInfo();
346 gni.GroupID = n.groupID;
347 gni.Message = n.message;
348 gni.BinaryBucket = n.binaryBucket;
349 gni.noticeData.NoticeID = n.noticeID;
350 gni.noticeData.Timestamp = n.timestamp;
351 gni.noticeData.FromName = n.fromName;
352 gni.noticeData.Subject = n.subject;
353 gni.noticeData.HasAttachment = n.hasAttachment;
354 gni.noticeData.AssetType = (byte)n.assetType;
355
356 return gni;
357 }
358 }
359
279 return null; 360 return null;
280 } 361 }
281 362
282 public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket) 363 public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket)
283 { 364 {
365 m_log.DebugFormat(
366 "[MOCK GROUPS SERVICES CONNECTOR]: AddGroupNotice, requestingAgentID {0}, groupID {1}, noticeID {2}, fromName {3}, subject {4}, message {5}, binaryBucket.Length {6}",
367 requestingAgentID, groupID, noticeID, fromName, subject, message, binaryBucket.Length);
368
369 XGroup group = GetXGroup(groupID, null);
370
371 if (group == null)
372 return;
373
374 XGroupNotice groupNotice = new XGroupNotice()
375 {
376 groupID = groupID,
377 noticeID = noticeID,
378 fromName = fromName,
379 subject = subject,
380 message = message,
381 timestamp = (uint)Util.UnixTimeSinceEpoch(),
382 hasAttachment = false,
383 assetType = 0,
384 binaryBucket = binaryBucket
385 };
386
387 group.notices[noticeID] = groupNotice;
388
389 m_data.StoreGroup(group);
284 } 390 }
285 391
286 public void ResetAgentGroupChatSessions(UUID agentID) 392 public void ResetAgentGroupChatSessions(UUID agentID)