aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs1390
1 files changed, 1390 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs
new file mode 100644
index 0000000..9363205
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs
@@ -0,0 +1,1390 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Collections.Specialized;
32using System.Reflection;
33
34using Nwc.XmlRpc;
35
36using log4net;
37using Mono.Addins;
38using Nini.Config;
39
40using OpenMetaverse;
41using OpenMetaverse.StructuredData;
42
43using OpenSim.Framework;
44using OpenSim.Framework.Communications;
45using OpenSim.Region.Framework.Interfaces;
46using OpenSim.Services.Interfaces;
47
48/***************************************************************************
49 * Simian Data Map
50 * ===============
51 *
52 * OwnerID -> Type -> Key
53 * -----------------------
54 *
55 * UserID -> Group -> ActiveGroup
56 * + GroupID
57 *
58 * UserID -> GroupSessionDropped -> GroupID
59 * UserID -> GroupSessionInvited -> GroupID
60 *
61 * UserID -> GroupMember -> GroupID
62 * + SelectedRoleID [UUID]
63 * + AcceptNotices [bool]
64 * + ListInProfile [bool]
65 * + Contribution [int]
66 *
67 * UserID -> GroupRole[GroupID] -> RoleID
68 *
69 *
70 * GroupID -> Group -> GroupName
71 * + Charter
72 * + ShowInList
73 * + InsigniaID
74 * + MembershipFee
75 * + OpenEnrollment
76 * + AllowPublish
77 * + MaturePublish
78 * + FounderID
79 * + EveryonePowers
80 * + OwnerRoleID
81 * + OwnersPowers
82 *
83 * GroupID -> GroupRole -> RoleID
84 * + Name
85 * + Description
86 * + Title
87 * + Powers
88 *
89 * GroupID -> GroupMemberInvite -> InviteID
90 * + AgentID
91 * + RoleID
92 *
93 * GroupID -> GroupNotice -> NoticeID
94 * + TimeStamp [uint]
95 * + FromName [string]
96 * + Subject [string]
97 * + Message [string]
98 * + BinaryBucket [byte[]]
99 *
100 * */
101
102namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
103{
104 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
105 public class SimianGroupsServicesConnectorModule : ISharedRegionModule, IGroupsServicesConnector
106 {
107 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
108
109 public const GroupPowers m_DefaultEveryonePowers = GroupPowers.AllowSetHome |
110 GroupPowers.Accountable |
111 GroupPowers.JoinChat |
112 GroupPowers.AllowVoiceChat |
113 GroupPowers.ReceiveNotices |
114 GroupPowers.StartProposal |
115 GroupPowers.VoteOnProposal;
116
117 // Would this be cleaner as (GroupPowers)ulong.MaxValue;
118 public const GroupPowers m_DefaultOwnerPowers = GroupPowers.Accountable
119 | GroupPowers.AllowEditLand
120 | GroupPowers.AllowFly
121 | GroupPowers.AllowLandmark
122 | GroupPowers.AllowRez
123 | GroupPowers.AllowSetHome
124 | GroupPowers.AllowVoiceChat
125 | GroupPowers.AssignMember
126 | GroupPowers.AssignMemberLimited
127 | GroupPowers.ChangeActions
128 | GroupPowers.ChangeIdentity
129 | GroupPowers.ChangeMedia
130 | GroupPowers.ChangeOptions
131 | GroupPowers.CreateRole
132 | GroupPowers.DeedObject
133 | GroupPowers.DeleteRole
134 | GroupPowers.Eject
135 | GroupPowers.FindPlaces
136 | GroupPowers.Invite
137 | GroupPowers.JoinChat
138 | GroupPowers.LandChangeIdentity
139 | GroupPowers.LandDeed
140 | GroupPowers.LandDivideJoin
141 | GroupPowers.LandEdit
142 | GroupPowers.LandEjectAndFreeze
143 | GroupPowers.LandGardening
144 | GroupPowers.LandManageAllowed
145 | GroupPowers.LandManageBanned
146 | GroupPowers.LandManagePasses
147 | GroupPowers.LandOptions
148 | GroupPowers.LandRelease
149 | GroupPowers.LandSetSale
150 | GroupPowers.ModerateChat
151 | GroupPowers.ObjectManipulate
152 | GroupPowers.ObjectSetForSale
153 | GroupPowers.ReceiveNotices
154 | GroupPowers.RemoveMember
155 | GroupPowers.ReturnGroupOwned
156 | GroupPowers.ReturnGroupSet
157 | GroupPowers.ReturnNonGroup
158 | GroupPowers.RoleProperties
159 | GroupPowers.SendNotices
160 | GroupPowers.SetLandingPoint
161 | GroupPowers.StartProposal
162 | GroupPowers.VoteOnProposal;
163
164 private bool m_connectorEnabled = false;
165
166 private string m_groupsServerURI = string.Empty;
167
168 private bool m_debugEnabled = false;
169
170 private ExpiringCache<string, OSDMap> m_memoryCache;
171 private int m_cacheTimeout = 30;
172
173 // private IUserAccountService m_accountService = null;
174
175
176 #region IRegionModuleBase Members
177
178 public string Name
179 {
180 get { return "SimianGroupsServicesConnector"; }
181 }
182
183 // this module is not intended to be replaced, but there should only be 1 of them.
184 public Type ReplaceableInterface
185 {
186 get { return null; }
187 }
188
189 public void Initialise(IConfigSource config)
190 {
191 IConfig groupsConfig = config.Configs["Groups"];
192
193 if (groupsConfig == null)
194 {
195 // Do not run this module by default.
196 return;
197 }
198 else
199 {
200 // if groups aren't enabled, we're not needed.
201 // if we're not specified as the connector to use, then we're not wanted
202 if ((groupsConfig.GetBoolean("Enabled", false) == false)
203 || (groupsConfig.GetString("ServicesConnectorModule", "Default") != Name))
204 {
205 m_connectorEnabled = false;
206 return;
207 }
208
209 m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR]: Initializing {0}", this.Name);
210
211 m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty);
212 if ((m_groupsServerURI == null) ||
213 (m_groupsServerURI == string.Empty))
214 {
215 m_log.ErrorFormat("Please specify a valid Simian Server for GroupsServerURI in OpenSim.ini, [Groups]");
216 m_connectorEnabled = false;
217 return;
218 }
219
220
221 m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30);
222 if (m_cacheTimeout == 0)
223 {
224 m_log.WarnFormat("[SIMIAN-GROUPS-CONNECTOR] Groups Cache Disabled.");
225 }
226 else
227 {
228 m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Groups Cache Timeout set to {0}.", m_cacheTimeout);
229 }
230
231
232
233 m_memoryCache = new ExpiringCache<string,OSDMap>();
234
235
236 // If we got all the config options we need, lets start'er'up
237 m_connectorEnabled = true;
238
239 m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true);
240
241 }
242 }
243
244 public void Close()
245 {
246 m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR]: Closing {0}", this.Name);
247 }
248
249 public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene)
250 {
251 if (m_connectorEnabled)
252 {
253 scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
254 }
255 }
256
257 public void RemoveRegion(OpenSim.Region.Framework.Scenes.Scene scene)
258 {
259 if (scene.RequestModuleInterface<IGroupsServicesConnector>() == this)
260 {
261 scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
262 }
263 }
264
265 public void RegionLoaded(OpenSim.Region.Framework.Scenes.Scene scene)
266 {
267 // TODO: May want to consider listenning for Agent Connections so we can pre-cache group info
268 // scene.EventManager.OnNewClient += OnNewClient;
269 }
270
271 #endregion
272
273 #region ISharedRegionModule Members
274
275 public void PostInitialise()
276 {
277 // NoOp
278 }
279
280 #endregion
281
282
283
284
285 #region IGroupsServicesConnector Members
286
287 /// <summary>
288 /// Create a Group, including Everyone and Owners Role, place FounderID in both groups, select Owner as selected role, and newly created group as agent's active role.
289 /// </summary>
290 public UUID CreateGroup(UUID requestingAgentID, string name, string charter, bool showInList, UUID insigniaID,
291 int membershipFee, bool openEnrollment, bool allowPublish,
292 bool maturePublish, UUID founderID)
293 {
294 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
295
296 UUID GroupID = UUID.Random();
297 UUID OwnerRoleID = UUID.Random();
298
299 OSDMap GroupInfoMap = new OSDMap();
300 GroupInfoMap["Charter"] = OSD.FromString(charter);
301 GroupInfoMap["ShowInList"] = OSD.FromBoolean(showInList);
302 GroupInfoMap["InsigniaID"] = OSD.FromUUID(insigniaID);
303 GroupInfoMap["MembershipFee"] = OSD.FromInteger(0);
304 GroupInfoMap["OpenEnrollment"] = OSD.FromBoolean(openEnrollment);
305 GroupInfoMap["AllowPublish"] = OSD.FromBoolean(allowPublish);
306 GroupInfoMap["MaturePublish"] = OSD.FromBoolean(maturePublish);
307 GroupInfoMap["FounderID"] = OSD.FromUUID(founderID);
308 GroupInfoMap["EveryonePowers"] = OSD.FromULong((ulong)m_DefaultEveryonePowers);
309 GroupInfoMap["OwnerRoleID"] = OSD.FromUUID(OwnerRoleID);
310 GroupInfoMap["OwnersPowers"] = OSD.FromULong((ulong)m_DefaultOwnerPowers);
311
312 if(SimianAddGeneric(GroupID, "Group", name, GroupInfoMap))
313 {
314 AddGroupRole(requestingAgentID, GroupID, UUID.Zero, "Everyone", "Members of " + name, "Member of " + name, (ulong)m_DefaultEveryonePowers);
315 AddGroupRole(requestingAgentID, GroupID, OwnerRoleID, "Owners", "Owners of " + name, "Owner of " + name, (ulong)m_DefaultOwnerPowers);
316
317 AddAgentToGroup(requestingAgentID, requestingAgentID, GroupID, OwnerRoleID);
318
319 return GroupID;
320 }
321 else
322 {
323 return UUID.Zero;
324 }
325 }
326
327
328 public void UpdateGroup(UUID requestingAgentID, UUID groupID, string charter, bool showInList,
329 UUID insigniaID, int membershipFee, bool openEnrollment,
330 bool allowPublish, bool maturePublish)
331 {
332 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
333 // TODO: Check to make sure requestingAgentID has permission to update group
334
335 string GroupName;
336 OSDMap GroupInfoMap;
337 if( SimianGetFirstGenericEntry(groupID, "GroupInfo", out GroupName, out GroupInfoMap) )
338 {
339 GroupInfoMap["Charter"] = OSD.FromString(charter);
340 GroupInfoMap["ShowInList"] = OSD.FromBoolean(showInList);
341 GroupInfoMap["InsigniaID"] = OSD.FromUUID(insigniaID);
342 GroupInfoMap["MembershipFee"] = OSD.FromInteger(0);
343 GroupInfoMap["OpenEnrollment"] = OSD.FromBoolean(openEnrollment);
344 GroupInfoMap["AllowPublish"] = OSD.FromBoolean(allowPublish);
345 GroupInfoMap["MaturePublish"] = OSD.FromBoolean(maturePublish);
346
347 SimianAddGeneric(groupID, "Group", GroupName, GroupInfoMap);
348 }
349
350 }
351
352
353 public void AddGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID, string name, string description,
354 string title, ulong powers)
355 {
356 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
357
358 OSDMap GroupRoleInfo = new OSDMap();
359 GroupRoleInfo["Name"] = OSD.FromString(name);
360 GroupRoleInfo["Description"] = OSD.FromString(description);
361 GroupRoleInfo["Title"] = OSD.FromString(title);
362 GroupRoleInfo["Powers"] = OSD.FromULong((ulong)powers);
363
364 // TODO: Add security, make sure that requestingAgentID has permision to add roles
365 SimianAddGeneric(groupID, "GroupRole", roleID.ToString(), GroupRoleInfo);
366 }
367
368 public void RemoveGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID)
369 {
370 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
371
372 // TODO: Add security
373
374 // Can't delete the Everyone Role
375 if (roleID != UUID.Zero)
376 {
377 // Remove all GroupRole Members from Role
378 Dictionary<UUID, OSDMap> GroupRoleMembers;
379 string GroupRoleMemberType = "GroupRole" + groupID.ToString();
380 if (SimianGetGenericEntries(GroupRoleMemberType, roleID.ToString(), out GroupRoleMembers))
381 {
382 foreach(UUID UserID in GroupRoleMembers.Keys)
383 {
384 EnsureRoleNotSelectedByMember(groupID, roleID, UserID);
385
386 SimianRemoveGenericEntry(UserID, GroupRoleMemberType, roleID.ToString());
387 }
388 }
389
390 // Remove role
391 SimianRemoveGenericEntry(groupID, "GroupRole", roleID.ToString());
392 }
393 }
394
395
396 public void UpdateGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID, string name, string description,
397 string title, ulong powers)
398 {
399 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
400
401 // TODO: Security, check that requestingAgentID is allowed to update group roles
402
403 OSDMap GroupRoleInfo;
404 if (SimianGetGenericEntry(groupID, "GroupRole", roleID.ToString(), out GroupRoleInfo))
405 {
406 if (name != null)
407 {
408 GroupRoleInfo["Name"] = OSD.FromString(name);
409 }
410 if (description != null)
411 {
412 GroupRoleInfo["Description"] = OSD.FromString(description);
413 }
414 if (title != null)
415 {
416 GroupRoleInfo["Title"] = OSD.FromString(title);
417 }
418 GroupRoleInfo["Powers"] = OSD.FromULong((ulong)powers);
419
420 }
421
422
423 SimianAddGeneric(groupID, "GroupRole", roleID.ToString(), GroupRoleInfo);
424 }
425
426 public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID groupID, string groupName)
427 {
428 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
429
430 OSDMap GroupInfoMap = null;
431 if (groupID != UUID.Zero)
432 {
433 if (!SimianGetFirstGenericEntry(groupID, "Group", out groupName, out GroupInfoMap))
434 {
435 return null;
436 }
437 }
438 else if ((groupName != null) && (groupName != string.Empty))
439 {
440 if (!SimianGetFirstGenericEntry("Group", groupName, out groupID, out GroupInfoMap))
441 {
442 return null;
443 }
444 }
445
446 GroupRecord GroupInfo = new GroupRecord();
447
448 GroupInfo.GroupID = groupID;
449 GroupInfo.GroupName = groupName;
450 GroupInfo.Charter = GroupInfoMap["Charter"].AsString();
451 GroupInfo.ShowInList = GroupInfoMap["ShowInList"].AsBoolean();
452 GroupInfo.GroupPicture = GroupInfoMap["InsigniaID"].AsUUID();
453 GroupInfo.MembershipFee = GroupInfoMap["MembershipFee"].AsInteger();
454 GroupInfo.OpenEnrollment = GroupInfoMap["OpenEnrollment"].AsBoolean();
455 GroupInfo.AllowPublish = GroupInfoMap["AllowPublish"].AsBoolean();
456 GroupInfo.MaturePublish = GroupInfoMap["MaturePublish"].AsBoolean();
457 GroupInfo.FounderID = GroupInfoMap["FounderID"].AsUUID();
458 GroupInfo.OwnerRoleID = GroupInfoMap["OwnerRoleID"].AsUUID();
459
460 return GroupInfo;
461
462 }
463
464 public GroupProfileData GetMemberGroupProfile(UUID requestingAgentID, UUID groupID, UUID memberID)
465 {
466 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
467
468 OSDMap groupProfile;
469 string groupName;
470 if (!SimianGetFirstGenericEntry(groupID, "Group", out groupName, out groupProfile))
471 {
472 // GroupProfileData is not nullable
473 return new GroupProfileData();
474 }
475
476 GroupProfileData MemberGroupProfile = new GroupProfileData();
477 MemberGroupProfile.GroupID = groupID;
478 MemberGroupProfile.Name = groupName;
479
480 if (groupProfile["Charter"] != null)
481 {
482 MemberGroupProfile.Charter = groupProfile["Charter"].AsString();
483 }
484
485 MemberGroupProfile.ShowInList = groupProfile["ShowInList"].AsString() == "1";
486 MemberGroupProfile.InsigniaID = groupProfile["InsigniaID"].AsUUID();
487 MemberGroupProfile.MembershipFee = groupProfile["MembershipFee"].AsInteger();
488 MemberGroupProfile.OpenEnrollment = groupProfile["OpenEnrollment"].AsBoolean();
489 MemberGroupProfile.AllowPublish = groupProfile["AllowPublish"].AsBoolean();
490 MemberGroupProfile.MaturePublish = groupProfile["MaturePublish"].AsBoolean();
491 MemberGroupProfile.FounderID = groupProfile["FounderID"].AsUUID();;
492 MemberGroupProfile.OwnerRole = groupProfile["OwnerRoleID"].AsUUID();
493
494 Dictionary<UUID, OSDMap> Members;
495 if (SimianGetGenericEntries("GroupMember",groupID.ToString(), out Members))
496 {
497 MemberGroupProfile.GroupMembershipCount = Members.Count;
498 }
499
500 Dictionary<string, OSDMap> Roles;
501 if (SimianGetGenericEntries(groupID, "GroupRole", out Roles))
502 {
503 MemberGroupProfile.GroupRolesCount = Roles.Count;
504 }
505
506 // TODO: Get Group Money balance from somewhere
507 // group.Money = 0;
508
509 GroupMembershipData MemberInfo = GetAgentGroupMembership(requestingAgentID, memberID, groupID);
510
511 MemberGroupProfile.MemberTitle = MemberInfo.GroupTitle;
512 MemberGroupProfile.PowersMask = MemberInfo.GroupPowers;
513
514 return MemberGroupProfile;
515 }
516
517 public void SetAgentActiveGroup(UUID requestingAgentID, UUID agentID, UUID groupID)
518 {
519 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
520
521 OSDMap ActiveGroup = new OSDMap();
522 ActiveGroup.Add("GroupID", OSD.FromUUID(groupID));
523 SimianAddGeneric(agentID, "Group", "ActiveGroup", ActiveGroup);
524 }
525
526 public void SetAgentActiveGroupRole(UUID requestingAgentID, UUID agentID, UUID groupID, UUID roleID)
527 {
528 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
529
530 OSDMap GroupMemberInfo;
531 if (!SimianGetGenericEntry(agentID, "GroupMember", groupID.ToString(), out GroupMemberInfo))
532 {
533 GroupMemberInfo = new OSDMap();
534 }
535
536 GroupMemberInfo["SelectedRoleID"] = OSD.FromUUID(roleID);
537 SimianAddGeneric(agentID, "GroupMember", groupID.ToString(), GroupMemberInfo);
538 }
539
540 public void SetAgentGroupInfo(UUID requestingAgentID, UUID agentID, UUID groupID, bool acceptNotices, bool listInProfile)
541 {
542 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
543
544 OSDMap GroupMemberInfo;
545 if (!SimianGetGenericEntry(agentID, "GroupMember", groupID.ToString(), out GroupMemberInfo))
546 {
547 GroupMemberInfo = new OSDMap();
548 }
549
550 GroupMemberInfo["AcceptNotices"] = OSD.FromBoolean(acceptNotices);
551 GroupMemberInfo["ListInProfile"] = OSD.FromBoolean(listInProfile);
552 GroupMemberInfo["Contribution"] = OSD.FromInteger(0);
553 GroupMemberInfo["SelectedRole"] = OSD.FromUUID(UUID.Zero);
554 SimianAddGeneric(agentID, "GroupMember", groupID.ToString(), GroupMemberInfo);
555 }
556
557 public void AddAgentToGroupInvite(UUID requestingAgentID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID)
558 {
559 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
560
561 OSDMap Invite = new OSDMap();
562 Invite["AgentID"] = OSD.FromUUID(agentID);
563 Invite["RoleID"] = OSD.FromUUID(roleID);
564
565 SimianAddGeneric(groupID, "GroupMemberInvite", inviteID.ToString(), Invite);
566 }
567
568 public GroupInviteInfo GetAgentToGroupInvite(UUID requestingAgentID, UUID inviteID)
569 {
570 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
571
572 OSDMap GroupMemberInvite;
573 UUID GroupID;
574 if (!SimianGetFirstGenericEntry("GroupMemberInvite", inviteID.ToString(), out GroupID, out GroupMemberInvite))
575 {
576 return null;
577 }
578
579 GroupInviteInfo inviteInfo = new GroupInviteInfo();
580 inviteInfo.InviteID = inviteID;
581 inviteInfo.GroupID = GroupID;
582 inviteInfo.AgentID = GroupMemberInvite["AgentID"].AsUUID();
583 inviteInfo.RoleID = GroupMemberInvite["RoleID"].AsUUID();
584
585 return inviteInfo;
586 }
587
588 public void RemoveAgentToGroupInvite(UUID requestingAgentID, UUID inviteID)
589 {
590 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
591
592 GroupInviteInfo invite = GetAgentToGroupInvite(requestingAgentID, inviteID);
593 SimianRemoveGenericEntry(invite.GroupID, "GroupMemberInvite", inviteID.ToString());
594 }
595
596 public void AddAgentToGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
597 {
598 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
599
600 // Setup Agent/Group information
601 SetAgentGroupInfo(requestingAgentID, AgentID, GroupID, true, true);
602
603 // Add agent to Everyone Group
604 AddAgentToGroupRole(requestingAgentID, AgentID, GroupID, UUID.Zero);
605
606 // Add agent to Specified Role
607 AddAgentToGroupRole(requestingAgentID, AgentID, GroupID, RoleID);
608
609 // Set selected role in this group to specified role
610 SetAgentActiveGroupRole(requestingAgentID, AgentID, GroupID, RoleID);
611 }
612
613 public void RemoveAgentFromGroup(UUID requestingAgentID, UUID agentID, UUID groupID)
614 {
615 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
616
617 // If current active group is the group the agent is being removed from, change their group to UUID.Zero
618 GroupMembershipData memberActiveMembership = GetAgentActiveMembership(requestingAgentID, agentID);
619 if (memberActiveMembership.GroupID == groupID)
620 {
621 SetAgentActiveGroup(agentID, agentID, UUID.Zero);
622 }
623
624 // Remove Group Member information for this group
625 SimianRemoveGenericEntry(agentID, "GroupMember", groupID.ToString());
626
627 // By using a Simian Generics Type consisting of a prefix and a groupID,
628 // combined with RoleID as key allows us to get a list of roles a particular member
629 // of a group is assigned to.
630 string GroupRoleMemberType = "GroupRole" + groupID.ToString();
631
632 // Take Agent out of all other group roles
633 Dictionary<string, OSDMap> GroupRoles;
634 if (SimianGetGenericEntries(agentID, GroupRoleMemberType, out GroupRoles))
635 {
636 foreach (string roleID in GroupRoles.Keys)
637 {
638 SimianRemoveGenericEntry(agentID, GroupRoleMemberType, roleID);
639 }
640 }
641 }
642
643 public void AddAgentToGroupRole(UUID requestingAgentID, UUID agentID, UUID groupID, UUID roleID)
644 {
645 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
646
647 SimianAddGeneric(agentID, "GroupRole" + groupID.ToString(), roleID.ToString(), new OSDMap());
648 }
649
650 public void RemoveAgentFromGroupRole(UUID requestingAgentID, UUID agentID, UUID groupID, UUID roleID)
651 {
652 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
653
654 // Cannot remove members from the Everyone Role
655 if (roleID != UUID.Zero)
656 {
657 EnsureRoleNotSelectedByMember(groupID, roleID, agentID);
658
659 string GroupRoleMemberType = "GroupRole" + groupID.ToString();
660 SimianRemoveGenericEntry(agentID, GroupRoleMemberType, roleID.ToString());
661 }
662 }
663
664 public List<DirGroupsReplyData> FindGroups(UUID requestingAgentID, string search)
665 {
666 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
667
668 List<DirGroupsReplyData> findings = new List<DirGroupsReplyData>();
669
670 NameValueCollection requestArgs = new NameValueCollection
671 {
672 { "RequestMethod", "GetGenerics" },
673 { "Type", "Group" },
674 { "Key", search },
675 { "Fuzzy", "1" }
676 };
677
678
679 OSDMap response = CachedPostRequest(requestArgs);
680 if (response["Success"].AsBoolean() && response["Entries"] is OSDArray)
681 {
682 OSDArray entryArray = (OSDArray)response["Entries"];
683 foreach (OSDMap entryMap in entryArray)
684 {
685 DirGroupsReplyData data = new DirGroupsReplyData();
686 data.groupID = entryMap["OwnerID"].AsUUID();
687 data.groupName = entryMap["Key"].AsString();
688
689 // TODO: is there a better way to do this?
690 Dictionary<UUID, OSDMap> Members;
691 if (SimianGetGenericEntries("GroupMember", data.groupID.ToString(), out Members))
692 {
693 data.members = Members.Count;
694 }
695 else
696 {
697 data.members = 0;
698 }
699
700 // TODO: sort results?
701 // data.searchOrder = order;
702
703 findings.Add(data);
704 }
705 }
706
707
708 return findings;
709 }
710
711 public GroupMembershipData GetAgentGroupMembership(UUID requestingAgentID, UUID agentID, UUID groupID)
712 {
713 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
714
715 GroupMembershipData data = new GroupMembershipData();
716
717 ///////////////////////////////
718 // Agent Specific Information:
719 //
720 OSDMap UserActiveGroup;
721 if (SimianGetGenericEntry(agentID, "Group", "ActiveGroup", out UserActiveGroup))
722 {
723 data.Active = UserActiveGroup["GroupID"].AsUUID().Equals(groupID);
724 }
725
726 OSDMap UserGroupMemberInfo;
727 if( SimianGetGenericEntry(agentID, "GroupMember", groupID.ToString(), out UserGroupMemberInfo) )
728 {
729 data.AcceptNotices = UserGroupMemberInfo["AcceptNotices"].AsBoolean();
730 data.Contribution = UserGroupMemberInfo["Contribution"].AsInteger();
731 data.ListInProfile = UserGroupMemberInfo["ListInProfile"].AsBoolean();
732 data.ActiveRole = UserGroupMemberInfo["SelectedRoleID"].AsUUID();
733
734 ///////////////////////////////
735 // Role Specific Information:
736 //
737
738 OSDMap GroupRoleInfo;
739 if( SimianGetGenericEntry(groupID, "GroupRole", data.ActiveRole.ToString(), out GroupRoleInfo) )
740 {
741 data.GroupTitle = GroupRoleInfo["Title"].AsString();
742 data.GroupPowers = GroupRoleInfo["Powers"].AsULong();
743 }
744 }
745
746 ///////////////////////////////
747 // Group Specific Information:
748 //
749 OSDMap GroupInfo;
750 string GroupName;
751 if( SimianGetFirstGenericEntry(groupID, "Group", out GroupName, out GroupInfo) )
752 {
753 data.GroupID = groupID;
754 data.AllowPublish = GroupInfo["AllowPublish"].AsBoolean();
755 data.Charter = GroupInfo["Charter"].AsString();
756 data.FounderID = GroupInfo["FounderID"].AsUUID();
757 data.GroupName = GroupName;
758 data.GroupPicture = GroupInfo["InsigniaID"].AsUUID();
759 data.MaturePublish = GroupInfo["MaturePublish"].AsBoolean();
760 data.MembershipFee = GroupInfo["MembershipFee"].AsInteger();
761 data.OpenEnrollment = GroupInfo["OpenEnrollment"].AsBoolean();
762 data.ShowInList = GroupInfo["ShowInList"].AsBoolean();
763 }
764
765 return data;
766 }
767
768 public GroupMembershipData GetAgentActiveMembership(UUID requestingAgentID, UUID agentID)
769 {
770 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
771
772 UUID GroupID = UUID.Zero;
773 OSDMap UserActiveGroup;
774 if (SimianGetGenericEntry(agentID, "Group", "ActiveGroup", out UserActiveGroup))
775 {
776 GroupID = UserActiveGroup["GroupID"].AsUUID();
777 }
778
779 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Active GroupID : {0}", GroupID.ToString());
780 return GetAgentGroupMembership(requestingAgentID, agentID, GroupID);
781 }
782
783 public List<GroupMembershipData> GetAgentGroupMemberships(UUID requestingAgentID, UUID agentID)
784 {
785 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
786
787 List<GroupMembershipData> memberships = new List<GroupMembershipData>();
788
789 Dictionary<string,OSDMap> GroupMemberShips;
790 if (SimianGetGenericEntries(agentID, "GroupMember", out GroupMemberShips))
791 {
792 foreach (string key in GroupMemberShips.Keys)
793 {
794 memberships.Add(GetAgentGroupMembership(requestingAgentID, agentID, UUID.Parse(key)));
795 }
796 }
797
798 return memberships;
799 }
800
801 public List<GroupRolesData> GetAgentGroupRoles(UUID requestingAgentID, UUID agentID, UUID groupID)
802 {
803 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
804
805 List<GroupRolesData> Roles = new List<GroupRolesData>();
806
807 Dictionary<string, OSDMap> GroupRoles;
808 if (SimianGetGenericEntries(groupID, "GroupRole", out GroupRoles))
809 {
810 Dictionary<string, OSDMap> MemberRoles;
811 if (SimianGetGenericEntries(agentID, "GroupRole" + groupID.ToString(), out MemberRoles))
812 {
813 foreach (KeyValuePair<string, OSDMap> kvp in MemberRoles)
814 {
815 GroupRolesData data = new GroupRolesData();
816 data.RoleID = UUID.Parse(kvp.Key);
817 data.Name = GroupRoles[kvp.Key]["Name"].AsString();
818 data.Description = GroupRoles[kvp.Key]["Description"].AsString();
819 data.Title = GroupRoles[kvp.Key]["Title"].AsString();
820 data.Powers = GroupRoles[kvp.Key]["Powers"].AsULong();
821
822 Roles.Add(data);
823 }
824 }
825 }
826 return Roles;
827 }
828
829 public List<GroupRolesData> GetGroupRoles(UUID requestingAgentID, UUID groupID)
830 {
831 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
832
833 List<GroupRolesData> Roles = new List<GroupRolesData>();
834
835 Dictionary<string, OSDMap> GroupRoles;
836 if (SimianGetGenericEntries(groupID, "GroupRole", out GroupRoles))
837 {
838 foreach (KeyValuePair<string, OSDMap> role in GroupRoles)
839 {
840 GroupRolesData data = new GroupRolesData();
841
842 data.RoleID = UUID.Parse(role.Key);
843
844 data.Name = role.Value["Name"].AsString();
845 data.Description = role.Value["Description"].AsString();
846 data.Title = role.Value["Title"].AsString();
847 data.Powers = role.Value["Powers"].AsULong();
848
849 Dictionary<UUID, OSDMap> GroupRoleMembers;
850 if (SimianGetGenericEntries("GroupRole" + groupID.ToString(), role.Key, out GroupRoleMembers))
851 {
852 data.Members = GroupRoleMembers.Count;
853 }
854 else
855 {
856 data.Members = 0;
857 }
858
859 Roles.Add(data);
860 }
861 }
862
863 return Roles;
864
865 }
866
867
868
869 public List<GroupMembersData> GetGroupMembers(UUID requestingAgentID, UUID GroupID)
870 {
871 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
872
873 List<GroupMembersData> members = new List<GroupMembersData>();
874
875 OSDMap GroupInfo;
876 string GroupName;
877 UUID GroupOwnerRoleID = UUID.Zero;
878 if (!SimianGetFirstGenericEntry(GroupID, "Group", out GroupName, out GroupInfo))
879 {
880 return members;
881 }
882 GroupOwnerRoleID = GroupInfo["OwnerRoleID"].AsUUID();
883
884 // Locally cache group roles, since we'll be needing this data for each member
885 Dictionary<string,OSDMap> GroupRoles;
886 SimianGetGenericEntries(GroupID, "GroupRole", out GroupRoles);
887
888 // Locally cache list of group owners
889 Dictionary<UUID, OSDMap> GroupOwners;
890 SimianGetGenericEntries("GroupRole" + GroupID.ToString(), GroupOwnerRoleID.ToString(), out GroupOwners);
891
892
893 Dictionary<UUID, OSDMap> GroupMembers;
894 if (SimianGetGenericEntries("GroupMember", GroupID.ToString(), out GroupMembers))
895 {
896 foreach (KeyValuePair<UUID, OSDMap> member in GroupMembers)
897 {
898 GroupMembersData data = new GroupMembersData();
899
900 data.AgentID = member.Key;
901
902 UUID SelectedRoleID = member.Value["SelectedRoleID"].AsUUID();
903
904 data.AcceptNotices = member.Value["AcceptNotices"].AsBoolean();
905 data.ListInProfile = member.Value["ListInProfile"].AsBoolean();
906 data.Contribution = member.Value["Contribution"].AsInteger();
907
908 data.IsOwner = GroupOwners.ContainsKey(member.Key);
909
910 OSDMap GroupRoleInfo = GroupRoles[SelectedRoleID.ToString()];
911 data.Title = GroupRoleInfo["Title"].AsString();
912 data.AgentPowers = GroupRoleInfo["Powers"].AsULong();
913
914 members.Add(data);
915 }
916 }
917
918 return members;
919
920 }
921
922 public List<GroupRoleMembersData> GetGroupRoleMembers(UUID requestingAgentID, UUID groupID)
923 {
924 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
925
926 List<GroupRoleMembersData> members = new List<GroupRoleMembersData>();
927
928 Dictionary<string, OSDMap> GroupRoles;
929 if (SimianGetGenericEntries(groupID, "GroupRole", out GroupRoles))
930 {
931 foreach( KeyValuePair<string, OSDMap> Role in GroupRoles )
932 {
933 Dictionary<UUID, OSDMap> GroupRoleMembers;
934 if( SimianGetGenericEntries("GroupRole"+groupID.ToString(), Role.Key, out GroupRoleMembers) )
935 {
936 foreach( KeyValuePair<UUID, OSDMap> GroupRoleMember in GroupRoleMembers )
937 {
938 GroupRoleMembersData data = new GroupRoleMembersData();
939
940 data.MemberID = GroupRoleMember.Key;
941 data.RoleID = UUID.Parse(Role.Key);
942
943 members.Add(data);
944 }
945 }
946 }
947 }
948
949 return members;
950 }
951
952 public List<GroupNoticeData> GetGroupNotices(UUID requestingAgentID, UUID GroupID)
953 {
954 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
955
956 List<GroupNoticeData> values = new List<GroupNoticeData>();
957
958 Dictionary<string, OSDMap> Notices;
959 if (SimianGetGenericEntries(GroupID, "GroupNotice", out Notices))
960 {
961 foreach (KeyValuePair<string, OSDMap> Notice in Notices)
962 {
963 GroupNoticeData data = new GroupNoticeData();
964 data.NoticeID = UUID.Parse(Notice.Key);
965 data.Timestamp = Notice.Value["TimeStamp"].AsUInteger();
966 data.FromName = Notice.Value["FromName"].AsString();
967 data.Subject = Notice.Value["Subject"].AsString();
968 data.HasAttachment = Notice.Value["BinaryBucket"].AsBinary().Length > 0;
969
970 //TODO: Figure out how to get this
971 data.AssetType = 0;
972
973 values.Add(data);
974 }
975 }
976
977 return values;
978
979 }
980 public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID)
981 {
982 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
983
984 OSDMap GroupNotice;
985 UUID GroupID;
986 if (SimianGetFirstGenericEntry("GroupNotice", noticeID.ToString(), out GroupID, out GroupNotice))
987 {
988 GroupNoticeInfo data = new GroupNoticeInfo();
989 data.GroupID = GroupID;
990 data.Message = GroupNotice["Message"].AsString();
991 data.BinaryBucket = GroupNotice["BinaryBucket"].AsBinary();
992 data.noticeData.NoticeID = noticeID;
993 data.noticeData.Timestamp = GroupNotice["TimeStamp"].AsUInteger();
994 data.noticeData.FromName = GroupNotice["FromName"].AsString();
995 data.noticeData.Subject = GroupNotice["Subject"].AsString();
996 data.noticeData.HasAttachment = data.BinaryBucket.Length > 0;
997 data.noticeData.AssetType = 0;
998
999 if (data.Message == null)
1000 {
1001 data.Message = string.Empty;
1002 }
1003
1004 return data;
1005 }
1006 return null;
1007 }
1008 public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket)
1009 {
1010 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1011
1012 OSDMap Notice = new OSDMap();
1013 Notice["TimeStamp"] = OSD.FromUInteger((uint)Util.UnixTimeSinceEpoch());
1014 Notice["FromName"] = OSD.FromString(fromName);
1015 Notice["Subject"] = OSD.FromString(subject);
1016 Notice["Message"] = OSD.FromString(message);
1017 Notice["BinaryBucket"] = OSD.FromBinary(binaryBucket);
1018
1019 SimianAddGeneric(groupID, "GroupNotice", noticeID.ToString(), Notice);
1020
1021 }
1022 #endregion
1023
1024 #region GroupSessionTracking
1025
1026 public void ResetAgentGroupChatSessions(UUID agentID)
1027 {
1028 Dictionary<string, OSDMap> agentSessions;
1029
1030 if (SimianGetGenericEntries(agentID, "GroupSessionDropped", out agentSessions))
1031 {
1032 foreach (string GroupID in agentSessions.Keys)
1033 {
1034 SimianRemoveGenericEntry(agentID, "GroupSessionDropped", GroupID);
1035 }
1036 }
1037
1038 if (SimianGetGenericEntries(agentID, "GroupSessionInvited", out agentSessions))
1039 {
1040 foreach (string GroupID in agentSessions.Keys)
1041 {
1042 SimianRemoveGenericEntry(agentID, "GroupSessionInvited", GroupID);
1043 }
1044 }
1045 }
1046
1047 public bool hasAgentDroppedGroupChatSession(UUID agentID, UUID groupID)
1048 {
1049 OSDMap session;
1050 return SimianGetGenericEntry(agentID, "GroupSessionDropped", groupID.ToString(), out session);
1051 }
1052
1053 public void AgentDroppedFromGroupChatSession(UUID agentID, UUID groupID)
1054 {
1055 SimianAddGeneric(agentID, "GroupSessionDropped", groupID.ToString(), new OSDMap());
1056 }
1057
1058 public void AgentInvitedToGroupChatSession(UUID agentID, UUID groupID)
1059 {
1060 SimianAddGeneric(agentID, "GroupSessionInvited", groupID.ToString(), new OSDMap());
1061 }
1062
1063 public bool hasAgentBeenInvitedToGroupChatSession(UUID agentID, UUID groupID)
1064 {
1065 OSDMap session;
1066 return SimianGetGenericEntry(agentID, "GroupSessionDropped", groupID.ToString(), out session);
1067 }
1068
1069 #endregion
1070
1071 private void EnsureRoleNotSelectedByMember(UUID groupID, UUID roleID, UUID userID)
1072 {
1073 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1074
1075 // If member's SelectedRole is roleID, change their selected role to Everyone
1076 // before removing them from the role
1077 OSDMap UserGroupInfo;
1078 if (SimianGetGenericEntry(userID, "GroupMember", groupID.ToString(), out UserGroupInfo))
1079 {
1080 if (UserGroupInfo["SelectedRoleID"].AsUUID() == roleID)
1081 {
1082 UserGroupInfo["SelectedRoleID"] = OSD.FromUUID(UUID.Zero);
1083 }
1084 SimianAddGeneric(userID, "GroupMember", groupID.ToString(), UserGroupInfo);
1085 }
1086 }
1087
1088
1089 #region Simian Util Methods
1090 private bool SimianAddGeneric(UUID ownerID, string type, string key, OSDMap map)
1091 {
1092 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called ({1},{2},{3})", System.Reflection.MethodBase.GetCurrentMethod().Name, ownerID, type, key);
1093
1094 string value = OSDParser.SerializeJsonString(map);
1095
1096 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] value: {0}", value);
1097
1098 NameValueCollection RequestArgs = new NameValueCollection
1099 {
1100 { "RequestMethod", "AddGeneric" },
1101 { "OwnerID", ownerID.ToString() },
1102 { "Type", type },
1103 { "Key", key },
1104 { "Value", value}
1105 };
1106
1107
1108 OSDMap Response = CachedPostRequest(RequestArgs);
1109 if (Response["Success"].AsBoolean())
1110 {
1111 return true;
1112 }
1113 else
1114 {
1115 m_log.WarnFormat("[SIMIAN GROUPS CONNECTOR]: Error {0}, {1}, {2}, {3}", ownerID, type, key, Response["Message"]);
1116 return false;
1117 }
1118 }
1119
1120 /// <summary>
1121 /// Returns the first of possibly many entries for Owner/Type pair
1122 /// </summary>
1123 private bool SimianGetFirstGenericEntry(UUID ownerID, string type, out string key, out OSDMap map)
1124 {
1125 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called ({1},{2})", System.Reflection.MethodBase.GetCurrentMethod().Name, ownerID, type);
1126
1127 NameValueCollection RequestArgs = new NameValueCollection
1128 {
1129 { "RequestMethod", "GetGenerics" },
1130 { "OwnerID", ownerID.ToString() },
1131 { "Type", type }
1132 };
1133
1134
1135 OSDMap Response = CachedPostRequest(RequestArgs);
1136 if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray)
1137 {
1138 OSDArray entryArray = (OSDArray)Response["Entries"];
1139 if (entryArray.Count >= 1)
1140 {
1141 OSDMap entryMap = entryArray[0] as OSDMap;
1142 key = entryMap["Key"].AsString();
1143 map = (OSDMap)OSDParser.DeserializeJson(entryMap["Value"].AsString());
1144
1145 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Generics Result {0}", entryMap["Value"].AsString());
1146
1147 return true;
1148 }
1149 else
1150 {
1151 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] No Generics Results");
1152 }
1153 }
1154 else
1155 {
1156 m_log.WarnFormat("[SIMIAN GROUPS CONNECTOR]: Error retrieving group info ({0})", Response["Message"]);
1157 }
1158 key = null;
1159 map = null;
1160 return false;
1161 }
1162 private bool SimianGetFirstGenericEntry(string type, string key, out UUID ownerID, out OSDMap map)
1163 {
1164 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called ({1},{2})", System.Reflection.MethodBase.GetCurrentMethod().Name, type, key);
1165
1166
1167 NameValueCollection RequestArgs = new NameValueCollection
1168 {
1169 { "RequestMethod", "GetGenerics" },
1170 { "Type", type },
1171 { "Key", key}
1172 };
1173
1174
1175 OSDMap Response = CachedPostRequest(RequestArgs);
1176 if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray)
1177 {
1178 OSDArray entryArray = (OSDArray)Response["Entries"];
1179 if (entryArray.Count >= 1)
1180 {
1181 OSDMap entryMap = entryArray[0] as OSDMap;
1182 ownerID = entryMap["OwnerID"].AsUUID();
1183 map = (OSDMap)OSDParser.DeserializeJson(entryMap["Value"].AsString());
1184
1185 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Generics Result {0}", entryMap["Value"].AsString());
1186
1187 return true;
1188 }
1189 else
1190 {
1191 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] No Generics Results");
1192 }
1193 }
1194 else
1195 {
1196 m_log.WarnFormat("[SIMIAN GROUPS CONNECTOR]: Error retrieving group info ({0})", Response["Message"]);
1197 }
1198 ownerID = UUID.Zero;
1199 map = null;
1200 return false;
1201 }
1202
1203 private bool SimianGetGenericEntry(UUID ownerID, string type, string key, out OSDMap map)
1204 {
1205 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called ({1},{2},{3})", System.Reflection.MethodBase.GetCurrentMethod().Name, ownerID, type, key);
1206
1207 NameValueCollection RequestArgs = new NameValueCollection
1208 {
1209 { "RequestMethod", "GetGenerics" },
1210 { "OwnerID", ownerID.ToString() },
1211 { "Type", type },
1212 { "Key", key}
1213 };
1214
1215
1216 OSDMap Response = CachedPostRequest(RequestArgs);
1217 if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray)
1218 {
1219 OSDArray entryArray = (OSDArray)Response["Entries"];
1220 if (entryArray.Count == 1)
1221 {
1222 OSDMap entryMap = entryArray[0] as OSDMap;
1223 key = entryMap["Key"].AsString();
1224 map = (OSDMap)OSDParser.DeserializeJson(entryMap["Value"].AsString());
1225
1226 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Generics Result {0}", entryMap["Value"].AsString());
1227
1228 return true;
1229 }
1230 else
1231 {
1232 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] No Generics Results");
1233 }
1234 }
1235 else
1236 {
1237 m_log.WarnFormat("[SIMIAN GROUPS CONNECTOR]: Error retrieving group info ({0})", Response["Message"]);
1238 }
1239 map = null;
1240 return false;
1241 }
1242
1243 private bool SimianGetGenericEntries(UUID ownerID, string type, out Dictionary<string, OSDMap> maps)
1244 {
1245 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called ({1},{2})", System.Reflection.MethodBase.GetCurrentMethod().Name,ownerID, type);
1246
1247 NameValueCollection requestArgs = new NameValueCollection
1248 {
1249 { "RequestMethod", "GetGenerics" },
1250 { "OwnerID", ownerID.ToString() },
1251 { "Type", type }
1252 };
1253
1254
1255
1256 OSDMap response = CachedPostRequest(requestArgs);
1257 if (response["Success"].AsBoolean() && response["Entries"] is OSDArray)
1258 {
1259 maps = new Dictionary<string, OSDMap>();
1260
1261 OSDArray entryArray = (OSDArray)response["Entries"];
1262 foreach (OSDMap entryMap in entryArray)
1263 {
1264 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Generics Result {0}", entryMap["Value"].AsString());
1265 maps.Add(entryMap["Key"].AsString(), (OSDMap)OSDParser.DeserializeJson(entryMap["Value"].AsString()));
1266 }
1267 if(maps.Count == 0)
1268 {
1269 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] No Generics Results");
1270 }
1271
1272 return true;
1273 }
1274 else
1275 {
1276 maps = null;
1277 m_log.WarnFormat("[SIMIAN GROUPS CONNECTOR]: Error retrieving group info ({0})", response["Message"]);
1278 }
1279 return false;
1280 }
1281 private bool SimianGetGenericEntries(string type, string key, out Dictionary<UUID, OSDMap> maps)
1282 {
1283 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called ({1},{2})", System.Reflection.MethodBase.GetCurrentMethod().Name, type, key);
1284
1285 NameValueCollection requestArgs = new NameValueCollection
1286 {
1287 { "RequestMethod", "GetGenerics" },
1288 { "Type", type },
1289 { "Key", key }
1290 };
1291
1292
1293
1294 OSDMap response = CachedPostRequest(requestArgs);
1295 if (response["Success"].AsBoolean() && response["Entries"] is OSDArray)
1296 {
1297 maps = new Dictionary<UUID, OSDMap>();
1298
1299 OSDArray entryArray = (OSDArray)response["Entries"];
1300 foreach (OSDMap entryMap in entryArray)
1301 {
1302 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Generics Result {0}", entryMap["Value"].AsString());
1303 maps.Add(entryMap["OwnerID"].AsUUID(), (OSDMap)OSDParser.DeserializeJson(entryMap["Value"].AsString()));
1304 }
1305 if (maps.Count == 0)
1306 {
1307 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] No Generics Results");
1308 }
1309 return true;
1310 }
1311 else
1312 {
1313 maps = null;
1314 m_log.WarnFormat("[SIMIAN-GROUPS-CONNECTOR]: Error retrieving group info ({0})", response["Message"]);
1315 }
1316 return false;
1317 }
1318
1319 private bool SimianRemoveGenericEntry(UUID ownerID, string type, string key)
1320 {
1321 if (m_debugEnabled) m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] {0} called ({1},{2},{3})", System.Reflection.MethodBase.GetCurrentMethod().Name, ownerID, type, key);
1322
1323 NameValueCollection requestArgs = new NameValueCollection
1324 {
1325 { "RequestMethod", "RemoveGeneric" },
1326 { "OwnerID", ownerID.ToString() },
1327 { "Type", type },
1328 { "Key", key }
1329 };
1330
1331
1332 OSDMap response = CachedPostRequest(requestArgs);
1333 if (response["Success"].AsBoolean())
1334 {
1335 return true;
1336 }
1337 else
1338 {
1339 m_log.WarnFormat("[SIMIAN GROUPS CONNECTOR]: Error {0}, {1}, {2}, {3}", ownerID, type, key, response["Message"]);
1340 return false;
1341 }
1342 }
1343 #endregion
1344
1345 #region CheesyCache
1346 OSDMap CachedPostRequest(NameValueCollection requestArgs)
1347 {
1348 // Immediately forward the request if the cache is disabled.
1349 if (m_cacheTimeout == 0)
1350 {
1351 return WebUtil.PostToService(m_groupsServerURI, requestArgs);
1352 }
1353
1354 // Check if this is an update or a request
1355 if ( requestArgs["RequestMethod"] == "RemoveGeneric"
1356 || requestArgs["RequestMethod"] == "AddGeneric"
1357 )
1358
1359 {
1360 // Any and all updates cause the cache to clear
1361 m_memoryCache.Clear();
1362
1363 // Send update to server, return the response without caching it
1364 return WebUtil.PostToService(m_groupsServerURI, requestArgs);
1365
1366 }
1367
1368 // If we're not doing an update, we must be requesting data
1369
1370 // Create the cache key for the request and see if we have it cached
1371 string CacheKey = WebUtil.BuildQueryString(requestArgs);
1372 OSDMap response = null;
1373 if (!m_memoryCache.TryGetValue(CacheKey, out response))
1374 {
1375 // if it wasn't in the cache, pass the request to the Simian Grid Services
1376 response = WebUtil.PostToService(m_groupsServerURI, requestArgs);
1377
1378 // and cache the response
1379 m_memoryCache.AddOrUpdate(CacheKey, response, TimeSpan.FromSeconds(m_cacheTimeout));
1380 }
1381
1382 // return cached response
1383 return response;
1384 }
1385 #endregion
1386
1387 }
1388
1389}
1390