29 using System.Collections.Generic;
30 using System.Reflection;
36 using OpenMetaverse.StructuredData;
37 using OpenSim.Framework;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Region.Framework.Scenes;
40 using OpenSim.Services.Interfaces;
43 namespace OpenSim.Groups
45 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"GroupsModule")]
48 private static readonly ILog m_log =
49 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private List<Scene> m_sceneList =
new List<Scene>();
59 private bool m_groupsEnabled =
false;
60 private bool m_groupNoticesEnabled =
true;
61 private bool m_debugEnabled =
false;
62 private int m_levelGroupCreate = 0;
64 #region Region Module interfaceBase Members
68 IConfig groupsConfig = config.Configs[
"Groups"];
70 if (groupsConfig == null)
77 m_groupsEnabled = groupsConfig.GetBoolean(
"Enabled",
false);
83 if (groupsConfig.GetString(
"Module",
"Default") != Name)
85 m_groupsEnabled =
false;
90 m_log.InfoFormat(
"[Groups]: Initializing {0}", this.Name);
92 m_groupNoticesEnabled = groupsConfig.GetBoolean(
"NoticesEnabled",
true);
93 m_debugEnabled = groupsConfig.GetBoolean(
"DebugEnabled",
false);
94 m_levelGroupCreate = groupsConfig.GetInt(
"LevelGroupCreate", 0);
106 "debug groups verbose",
107 "debug groups verbose <true|false>",
108 "This setting turns on very verbose groups debugging",
109 HandleDebugGroupsVerbose);
113 private void HandleDebugGroupsVerbose(
object modules,
string[] args)
117 MainConsole.Instance.Output(
"Usage: debug groups verbose <true|false>");
121 bool verbose =
false;
122 if (!
bool.TryParse(args[3], out verbose))
124 MainConsole.Instance.Output(
"Usage: debug groups verbose <true|false>");
128 m_debugEnabled = verbose;
130 MainConsole.Instance.OutputFormat(
"{0} verbose logging set to {1}", Name, m_debugEnabled);
135 if (!m_groupsEnabled)
138 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
141 if (m_groupData == null)
146 if (m_groupData == null)
148 m_groupsEnabled =
false;
149 m_log.Error(
"[Groups]: Could not get IGroupsServicesConnector");
155 if (m_msgTransferModule == null)
160 if (m_msgTransferModule == null)
162 m_log.Warn(
"[Groups]: Could not get MessageTransferModule");
166 if (m_UserManagement == null)
169 if (m_UserManagement == null)
170 m_log.Warn(
"[Groups]: Could not get UserManagementModule");
175 m_sceneList.Add(scene);
178 scene.EventManager.OnNewClient += OnNewClient;
179 scene.EventManager.OnMakeRootAgent += OnMakeRoot;
180 scene.EventManager.OnMakeChildAgent += OnMakeChild;
181 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
190 if (!m_groupsEnabled)
193 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
195 scene.EventManager.OnNewClient -= OnNewClient;
196 scene.EventManager.OnMakeRootAgent -= OnMakeRoot;
197 scene.EventManager.OnMakeChildAgent -= OnMakeChild;
198 scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
202 m_sceneList.Remove(scene);
208 if (!m_groupsEnabled)
211 if (m_debugEnabled) m_log.Debug(
"[Groups]: Shutting down Groups module.");
214 public Type ReplaceableInterface
221 get {
return "Groups Module V2"; }
231 #region EventHandlers
234 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
236 client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
237 client.OnRequestAvatarProperties += OnRequestAvatarProperties;
243 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
245 sp.ControllingClient.OnUUIDGroupNameRequest += HandleUUIDGroupNameRequest;
247 sp.ControllingClient.OnInstantMessage += OnInstantMessage;
256 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
258 sp.ControllingClient.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
260 sp.ControllingClient.OnInstantMessage -= OnInstantMessage;
263 private void OnRequestAvatarProperties(
IClientAPI remoteClient, UUID avatarID)
265 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
267 GroupMembershipData[] avatarGroups = GetProfileListedGroupMemberships(remoteClient, avatarID);
268 remoteClient.SendAvatarGroupsReply(avatarID, avatarGroups);
271 private void OnClientClosed(UUID AgentId,
Scene scene)
273 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
281 client.OnAgentDataUpdateRequest -= OnAgentDataUpdateRequest;
282 client.OnRequestAvatarProperties -= OnRequestAvatarProperties;
284 client.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
285 client.OnInstantMessage -= OnInstantMessage;
311 private void OnAgentDataUpdateRequest(
IClientAPI remoteClient, UUID dataForAgentID, UUID sessionID)
314 if (dataForAgentID != GetRequestingAgentID(remoteClient))
317 SendAgentGroupDataUpdate(remoteClient,
false);
322 private void HandleUUIDGroupNameRequest(UUID GroupID,
IClientAPI remoteClient)
324 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
328 GroupRecord group = m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient), GroupID, null);
331 GroupName = group.GroupName;
335 GroupName =
"Unknown";
338 remoteClient.SendGroupNameReply(GroupID, GroupName);
343 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
347 if ((im.
dialog == (byte)InstantMessageDialog.GroupInvitationAccept) || (im.
dialog == (byte)InstantMessageDialog.GroupInvitationDecline))
350 GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);
352 if (inviteInfo == null)
354 if (m_debugEnabled) m_log.WarnFormat(
"[Groups]: Received an Invite IM for an invite that does not exist {0}.", inviteID);
361 UUID invitee = UUID.Zero;
362 string tmp = string.Empty;
363 Util.ParseUniversalUserIdentifier(inviteInfo.AgentID, out invitee, out tmp, out tmp, out tmp, out tmp);
364 if ((inviteInfo != null) && (fromAgentID == invitee))
367 if (im.
dialog == (byte)InstantMessageDialog.GroupInvitationAccept)
372 string reason = string.Empty;
373 if (!m_groupData.AddAgentToGroup(GetRequestingAgentIDStr(remoteClient), invitee.ToString(), inviteInfo.GroupID, inviteInfo.RoleID, string.Empty, out reason))
374 remoteClient.SendAgentAlertMessage(
"Unable to add you to the group: " + reason,
false);
378 msg.imSessionID = UUID.Zero.Guid;
379 msg.fromAgentID = UUID.Zero.Guid;
380 msg.toAgentID = invitee.Guid;
381 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
382 msg.fromAgentName =
"Groups";
383 msg.message = string.Format(
"You have been added to the group.");
384 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageBox;
387 msg.ParentEstateID = 0;
388 msg.Position = Vector3.Zero;
389 msg.RegionID = UUID.Zero.Guid;
390 msg.binaryBucket =
new byte[0];
392 OutgoingInstantMessage(msg, invitee);
396 SendDataUpdate(remoteClient,
true);
399 m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);
403 if (im.
dialog == (byte)InstantMessageDialog.GroupInvitationDecline)
405 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: Received a reject invite notice.");
406 m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);
408 m_groupData.RemoveAgentFromGroup(GetRequestingAgentIDStr(remoteClient), inviteInfo.AgentID, inviteInfo.GroupID);
414 if ((im.
dialog == (byte)InstantMessageDialog.GroupNotice))
416 if (!m_groupNoticesEnabled)
422 if (m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient), GroupID, null) != null)
424 UUID NoticeID = UUID.Random();
425 string Subject = im.message.Substring(0, im.message.IndexOf(
'|'));
426 string Message = im.message.Substring(Subject.Length + 1);
429 bool hasAttachment =
false;
433 hasAttachment =
true;
434 string binBucket = OpenMetaverse.Utils.BytesToString(im.binaryBucket);
435 binBucket = binBucket.Remove(0, 14).Trim();
437 OSD binBucketOSD = OSDParser.DeserializeLLSDXml(binBucket);
438 if (binBucketOSD is
OSDMap)
440 OSDMap binBucketMap = (
OSDMap)binBucketOSD;
442 UUID itemID = binBucketMap[
"item_id"].AsUUID();
443 UUID ownerID = binBucketMap[
"owner_id"].AsUUID();
445 item = m_sceneList[0].InventoryService.GetItem(item);
448 m_log.DebugFormat(
"[Groups]: Received OSD with unexpected type: {0}", binBucketOSD.GetType());
451 if (m_groupData.AddGroupNotice(GetRequestingAgentIDStr(remoteClient), GroupID, NoticeID, im.
fromAgentName, Subject, Message,
453 (byte)(item == null ? 0 : item.AssetType),
454 item == null ? null : item.Name,
455 item == null ?
UUID.Zero : item.ID,
456 item == null ?
UUID.Zero.ToString() : item.Owner.ToString()))
458 if (OnNewGroupNotice != null)
460 OnNewGroupNotice(GroupID, NoticeID);
464 foreach (
GroupMembersData member
in m_groupData.GetGroupMembers(GetRequestingAgentIDStr(remoteClient), GroupID))
469 GridInstantMessage msg = CreateGroupNoticeIM(
UUID.Zero, NoticeID, (byte)OpenMetaverse.InstantMessageDialog.GroupNotice);
470 msg.toAgentID = member.AgentID.Guid;
471 OutgoingInstantMessage(msg, member.
AgentID);
478 if (im.
dialog == (byte)InstantMessageDialog.GroupNoticeInventoryAccepted)
487 GroupNoticeInfo notice = m_groupData.GetGroupNotice(remoteClient.AgentId.ToString(), noticeID);
491 string tmp = string.Empty;
492 Util.ParseUniversalUserIdentifier(notice.noticeData.AttachmentOwnerID, out giver, out tmp, out tmp, out tmp, out tmp);
494 m_log.DebugFormat(
"[Groups]: Giving inventory from {0} to {1}", giver, remoteClient.AgentId);
497 giver, notice.noticeData.AttachmentItemID, out message);
499 if (itemCopy == null)
501 remoteClient.SendAgentAlertMessage(message,
false);
505 remoteClient.SendInventoryItemCreateUpdate(itemCopy, 0);
522 im.dialog = (byte)InstantMessageDialog.MessageFromAgent;
523 OutgoingInstantMessage(im, ejecteeID);
525 IClientAPI ejectee = GetActiveClient(ejecteeID);
529 ejectee.SendAgentDropGroup(groupID);
536 if (m_debugEnabled) m_log.InfoFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
539 OnInstantMessage(null, msg);
546 case (byte)InstantMessageDialog.GroupInvitation:
547 case (byte)InstantMessageDialog.GroupNotice:
549 IClientAPI localClient = GetActiveClient(toAgentID);
550 if (localClient != null)
552 localClient.SendInstantMessage(msg);
561 #region IGroupsModule Members
567 return m_groupData.GetGroupRecord(UUID.Zero.ToString(), GroupID, null);
572 return m_groupData.GetGroupRecord(UUID.Zero.ToString(),
UUID.Zero, name);
577 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
579 m_groupData.SetAgentActiveGroup(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
581 SendAgentGroupDataUpdate(remoteClient,
true);
589 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
591 List<GroupRolesData> agentRoles = m_groupData.GetAgentGroupRoles(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
592 GroupMembershipData agentMembership = m_groupData.GetAgentGroupMembership(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
594 List<GroupTitlesData> titles =
new List<GroupTitlesData>();
598 title.Name = role.Name;
599 if (agentMembership != null)
601 title.Selected = agentMembership.ActiveRole == role.RoleID;
603 title.UUID = role.RoleID;
615 "[Groups]: GroupMembersRequest called for {0} from client {1}", groupID, remoteClient.Name);
617 List<GroupMembersData> data = m_groupData.GetGroupMembers(GetRequestingAgentIDStr(remoteClient), groupID);
623 m_log.DebugFormat(
"[Groups]: Member({0}) - IsOwner({1})", member.AgentID, member.IsOwner);
632 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
634 List<GroupRolesData> data = m_groupData.GetGroupRoles(GetRequestingAgentIDStr(remoteClient), groupID);
641 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
643 List<GroupRoleMembersData> data = m_groupData.GetGroupRoleMembers(GetRequestingAgentIDStr(remoteClient), groupID);
649 m_log.DebugFormat(
"[Groups]: Member({0}) - Role({1})", member.MemberID, member.RoleID);
657 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
662 ExtendedGroupRecord groupInfo = m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient), groupID, string.Empty);
663 GroupMembershipData memberInfo = m_groupData.GetAgentGroupMembership(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
664 if (groupInfo != null)
666 profile.AllowPublish = groupInfo.AllowPublish;
667 profile.Charter = groupInfo.Charter;
668 profile.FounderID = groupInfo.FounderID;
669 profile.GroupID = groupID;
670 profile.GroupMembershipCount = groupInfo.MemberCount;
671 profile.GroupRolesCount = groupInfo.RoleCount;
672 profile.InsigniaID = groupInfo.GroupPicture;
673 profile.MaturePublish = groupInfo.MaturePublish;
674 profile.MembershipFee = groupInfo.MembershipFee;
676 profile.Name = groupInfo.GroupName;
677 profile.OpenEnrollment = groupInfo.OpenEnrollment;
678 profile.OwnerRole = groupInfo.OwnerRoleID;
679 profile.ShowInList = groupInfo.ShowInList;
681 if (memberInfo != null)
683 profile.MemberTitle = memberInfo.GroupTitle;
684 profile.PowersMask = memberInfo.GroupPowers;
692 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
694 return m_groupData.GetAgentGroupMemberships(UUID.Zero.ToString(), agentID.ToString()).ToArray();
701 "[Groups]: {0} called with groupID={1}, agentID={2}",
702 System.Reflection.MethodBase.GetCurrentMethod().Name, groupID, agentID);
704 return m_groupData.GetAgentGroupMembership(UUID.Zero.ToString(), agentID.ToString(), groupID);
707 public void UpdateGroupInfo(
IClientAPI remoteClient, UUID groupID,
string charter,
bool showInList, UUID insigniaID,
int membershipFee,
bool openEnrollment,
bool allowPublish,
bool maturePublish)
709 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
712 string reason = string.Empty;
713 if (!m_groupData.UpdateGroup(GetRequestingAgentIDStr(remoteClient), groupID, charter, showInList, insigniaID, membershipFee,
714 openEnrollment, allowPublish, maturePublish, out reason))
721 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
723 m_groupData.UpdateMembership(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID, acceptNotices, listInProfile);
726 public UUID CreateGroup(
IClientAPI remoteClient,
string name,
string charter,
bool showInList, UUID insigniaID,
int membershipFee,
bool openEnrollment,
bool allowPublish,
bool maturePublish)
728 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called in {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.
Scene.
RegionInfo.
RegionName);
730 if (m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient),
UUID.Zero, name) != null)
732 remoteClient.SendCreateGroupReply(UUID.Zero,
false,
"A group with the same name already exists.");
743 if (avatar.UserLevel < m_levelGroupCreate)
745 remoteClient.SendCreateGroupReply(UUID.Zero,
false, String.Format(
"Insufficient permissions to create a group. Requires level {0}", m_levelGroupCreate));
757 remoteClient.SendCreateGroupReply(UUID.Zero,
false,
"Insufficient funds to create a group.");
762 string reason = string.Empty;
763 UUID groupID = m_groupData.CreateGroup(remoteClient.AgentId, name, charter, showInList, insigniaID, membershipFee, openEnrollment,
764 allowPublish, maturePublish, remoteClient.AgentId, out reason);
766 if (groupID !=
UUID.Zero)
769 money.ApplyCharge(remoteClient.AgentId, money.GroupCreationCharge, MoneyTransactionType.GroupCreate);
771 remoteClient.SendCreateGroupReply(groupID,
true,
"Group created successfullly");
774 SendAgentGroupDataUpdate(remoteClient,
false);
777 remoteClient.SendCreateGroupReply(groupID,
false, reason);
784 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
788 List<ExtendedGroupNoticeData> notices = m_groupData.GetGroupNotices(GetRequestingAgentIDStr(remoteClient), groupID);
789 List<GroupNoticeData> os_notices =
new List<GroupNoticeData>();
796 return os_notices.ToArray();
804 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
806 GroupMembershipData membership = m_groupData.GetAgentActiveMembership(UUID.Zero.ToString(), avatarID.ToString());
807 if (membership != null)
809 return membership.GroupTitle;
819 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
821 m_groupData.SetAgentActiveGroupRole(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID, titleRoleID);
827 SendDataUpdate(remoteClient,
true);
831 public void GroupRoleUpdate(
IClientAPI remoteClient, UUID groupID, UUID roleID,
string name,
string description,
string title, ulong powers, byte updateType)
833 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
837 switch ((OpenMetaverse.GroupRoleUpdate)updateType)
839 case OpenMetaverse.GroupRoleUpdate.Create:
840 string reason = string.Empty;
841 if (!m_groupData.AddGroupRole(GetRequestingAgentIDStr(remoteClient), groupID,
UUID.Random(), name, description, title, powers, out reason))
842 remoteClient.SendAgentAlertMessage(
"Unable to create role: " + reason,
false);
845 case OpenMetaverse.GroupRoleUpdate.Delete:
846 m_groupData.RemoveGroupRole(GetRequestingAgentIDStr(remoteClient), groupID, roleID);
849 case OpenMetaverse.GroupRoleUpdate.UpdateAll:
850 case OpenMetaverse.GroupRoleUpdate.UpdateData:
851 case OpenMetaverse.GroupRoleUpdate.UpdatePowers:
854 GroupPowers gp = (GroupPowers)powers;
855 m_log.DebugFormat(
"[Groups]: Role ({0}) updated with Powers ({1}) ({2})", name, powers.ToString(), gp.ToString());
857 m_groupData.UpdateGroupRole(GetRequestingAgentIDStr(remoteClient), groupID, roleID, name, description, title, powers);
860 case OpenMetaverse.GroupRoleUpdate.NoUpdate:
868 SendDataUpdate(remoteClient,
true);
873 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
880 m_groupData.AddAgentToGroupRole(GetRequestingAgentIDStr(remoteClient), memberID.ToString(), groupID, roleID);
885 m_groupData.RemoveAgentFromGroupRole(GetRequestingAgentIDStr(remoteClient), memberID.ToString(), groupID, roleID);
889 m_log.ErrorFormat(
"[Groups]: {0} does not understand changes == {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, changes);
894 SendDataUpdate(remoteClient,
true);
899 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called for notice {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, groupNoticeID);
901 GridInstantMessage msg = CreateGroupNoticeIM(remoteClient.
AgentId, groupNoticeID, (byte)InstantMessageDialog.GroupNoticeRequested);
903 OutgoingInstantMessage(msg, GetRequestingAgentID(remoteClient));
908 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
913 msg.imSessionID = groupNoticeID.Guid;
914 msg.toAgentID = agentID.Guid;
917 msg.fromGroup =
true;
918 msg.offline = (byte)0;
919 msg.ParentEstateID = 0;
920 msg.Position = Vector3.Zero;
921 msg.RegionID = UUID.Zero.Guid;
923 GroupNoticeInfo info = m_groupData.GetGroupNotice(agentID.ToString(), groupNoticeID);
926 msg.fromAgentID = info.GroupID.Guid;
927 msg.timestamp = info.noticeData.Timestamp;
928 msg.fromAgentName = info.noticeData.FromName;
929 msg.message = info.noticeData.Subject +
"|" + info.Message;
932 byte[] name = System.Text.Encoding.UTF8.GetBytes(info.noticeData.AttachmentName);
933 bucket =
new byte[19 + name.Length];
935 bucket[1] = info.noticeData.AttachmentType;
936 name.CopyTo(bucket, 18);
940 bucket =
new byte[19];
946 info.GroupID.ToBytes(bucket, 2);
947 msg.binaryBucket = bucket;
951 m_log.DebugFormat(
"[Groups]: Group Notice {0} not found, composing empty message.", groupNoticeID);
952 msg.fromAgentID = UUID.Zero.Guid;
953 msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); ;
954 msg.fromAgentName = string.Empty;
955 msg.message = string.Empty;
956 msg.binaryBucket =
new byte[0];
964 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
966 string reason = string.Empty;
968 if (m_groupData.AddAgentToGroup(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID,
UUID.Zero,
string.Empty, out reason))
971 remoteClient.SendJoinGroupReply(groupID,
true);
974 SendAgentGroupDataUpdate(remoteClient,
true);
976 if (reason !=
string.Empty)
978 remoteClient.SendAlertMessage(
"Warning: " + reason);
981 remoteClient.SendJoinGroupReply(groupID,
false);
986 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
988 m_groupData.RemoveAgentFromGroup(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
990 remoteClient.SendLeaveGroupReply(groupID,
true);
992 remoteClient.SendAgentDropGroup(groupID);
996 SendAgentGroupDataUpdate(remoteClient,
true);
1001 EjectGroupMember(remoteClient, GetRequestingAgentID(remoteClient), groupID, ejecteeID);
1006 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1009 m_groupData.RemoveAgentFromGroup(agentID.ToString(), ejecteeID.ToString(), groupID);
1015 if (remoteClient != null)
1017 agentName = remoteClient.Name;
1019 remoteClient.SendEjectGroupMemberReply(agentID, groupID,
true);
1023 IClientAPI client = GetActiveClient(agentID);
1027 agentName = client.Name;
1029 client.SendEjectGroupMemberReply(agentID, groupID,
true);
1034 UserAccount acc = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);
1038 agentName = acc.FirstName +
" " + acc.LastName;
1042 agentName =
"Unknown member";
1047 GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID.ToString(), groupID, null);
1049 UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, ejecteeID);
1050 if ((groupInfo == null) || (account == null))
1058 msg.imSessionID = UUID.Zero.Guid;
1059 msg.fromAgentID = agentID.Guid;
1061 msg.toAgentID = ejecteeID.Guid;
1064 msg.fromAgentName = agentName;
1065 msg.message = string.Format(
"You have been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName);
1066 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
1069 msg.ParentEstateID = 0;
1070 msg.Position = Vector3.Zero;
1071 msg.RegionID = regionInfo.RegionID.Guid;
1072 msg.binaryBucket =
new byte[0];
1073 OutgoingInstantMessage(msg, ejecteeID);
1083 msg.imSessionID = UUID.Zero.Guid;
1084 msg.fromAgentID = agentID.Guid;
1085 msg.toAgentID = agentID.Guid;
1087 msg.fromAgentName = agentName;
1088 if (account != null)
1090 msg.message = string.Format(
"{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName, account.FirstName +
" " + account.LastName);
1094 msg.message = string.Format(
"{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName,
"Unknown member");
1096 msg.dialog = (byte)210;
1097 msg.fromGroup =
false;
1098 msg.offline = (byte)0;
1099 msg.ParentEstateID = 0;
1100 msg.Position = Vector3.Zero;
1101 msg.RegionID = regionInfo.RegionID.Guid;
1102 msg.binaryBucket =
new byte[0];
1103 OutgoingInstantMessage(msg, agentID);
1108 SendAgentGroupDataUpdate(remoteClient,
false);
1113 InviteGroup(remoteClient, GetRequestingAgentID(remoteClient), groupID, invitedAgentID, roleID);
1118 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1120 string agentName = m_UserManagement.GetUserName(agentID);
1123 GroupRecord group = m_groupData.GetGroupRecord(agentID.ToString(), groupID, null);
1126 m_log.DebugFormat(
"[Groups]: No such group {0}", groupID);
1131 UUID InviteID = UUID.Random();
1133 if (m_groupData.AddAgentToGroupInvite(agentID.ToString(), InviteID, groupID, roleID, invitedAgentID.ToString()))
1135 if (m_msgTransferModule != null)
1137 Guid inviteUUID = InviteID.Guid;
1141 msg.imSessionID = inviteUUID;
1144 msg.fromAgentID = groupID.Guid;
1145 msg.toAgentID = invitedAgentID.Guid;
1148 msg.fromAgentName = agentName;
1149 msg.message = string.Format(
"{0} has invited you to join a group called {1}. There is no cost to join this group.", agentName, group.GroupName);
1150 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupInvitation;
1153 msg.ParentEstateID = 0;
1154 msg.Position = Vector3.Zero;
1155 msg.RegionID = regionInfo.RegionID.Guid;
1156 msg.binaryBucket =
new byte[20];
1158 OutgoingInstantMessage(msg, invitedAgentID);
1165 return m_groupData.FindGroups(GetRequestingAgentIDStr(remoteClient), query);
1170 #region Client/Update Tools
1175 private IClientAPI GetActiveClient(UUID agentID)
1180 foreach (
Scene scene
in m_sceneList)
1187 return sp.ControllingClient;
1191 child = sp.ControllingClient;
1200 private void SendScenePresenceUpdate(UUID AgentID,
string Title)
1202 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: Updating scene title for {0} with title: {1}", AgentID, Title);
1206 foreach (
Scene scene
in m_sceneList)
1208 presence = scene.GetScenePresence(AgentID);
1209 if (presence != null)
1211 if (presence.Grouptitle != Title)
1213 presence.Grouptitle = Title;
1215 if (! presence.IsChildAgent)
1216 presence.SendAvatarDataToAllAgents();
1224 SendAgentGroupDataUpdate(remoteClient,
true);
1230 private void SendAgentGroupDataUpdate(
IClientAPI remoteClient,
bool tellOthers)
1232 if (m_debugEnabled) m_log.InfoFormat(
"[Groups]: {0} called for {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.
Name);
1236 UUID agentID = GetRequestingAgentID(remoteClient);
1238 SendDataUpdate(remoteClient, tellOthers);
1240 GroupMembershipData[] membershipArray = GetProfileListedGroupMemberships(remoteClient, agentID);
1241 remoteClient.SendAgentGroupDataUpdate(agentID, membershipArray);
1243 remoteClient.RefreshGroupMembership();
1254 List<GroupMembershipData> membershipData = m_groupData.GetAgentGroupMemberships(requestingClient.AgentId.ToString(), dataForAgentID.ToString());
1264 membershipArray = membershipData.ToArray();
1268 if (requestingClient.
AgentId != dataForAgentID)
1272 return membership.ListInProfile;
1275 membershipArray = membershipData.FindAll(showInProfile).ToArray();
1279 membershipArray = membershipData.ToArray();
1285 m_log.InfoFormat(
"[Groups]: Get group membership information for {0} requested by {1}", dataForAgentID, requestingClient.AgentId);
1288 m_log.InfoFormat(
"[Groups]: {0} :: {1} - {2} - {3}", dataForAgentID, membership.GroupName, membership.GroupTitle, membership.GroupPowers);
1292 return membershipArray;
1296 private void SendDataUpdate(
IClientAPI remoteClient,
bool tellOthers)
1298 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1300 UUID activeGroupID = UUID.Zero;
1301 string activeGroupTitle = string.Empty;
1302 string activeGroupName = string.Empty;
1303 ulong activeGroupPowers = (ulong)GroupPowers.None;
1305 UUID agentID = GetRequestingAgentID(remoteClient);
1306 GroupMembershipData membership = m_groupData.GetAgentActiveMembership(agentID.ToString(), agentID.ToString());
1307 if (membership != null)
1309 activeGroupID = membership.GroupID;
1310 activeGroupTitle = membership.GroupTitle;
1311 activeGroupPowers = membership.GroupPowers;
1312 activeGroupName = membership.GroupName;
1315 UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(remoteClient.Scene.RegionInfo.ScopeID, agentID);
1316 string firstname, lastname;
1317 if (account != null)
1319 firstname = account.FirstName;
1320 lastname = account.LastName;
1324 firstname =
"Unknown";
1325 lastname =
"Unknown";
1328 remoteClient.SendAgentDataUpdate(agentID, activeGroupID, firstname,
1329 lastname, activeGroupPowers, activeGroupName,
1333 SendScenePresenceUpdate(agentID, activeGroupTitle);
1337 sp.Grouptitle = activeGroupTitle;
1342 #region IM Backed Processes
1346 if (m_debugEnabled) m_log.InfoFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1348 IClientAPI localClient = GetActiveClient(msgTo);
1349 if (localClient != null)
1351 if (m_debugEnabled) m_log.InfoFormat(
"[Groups]: MsgTo ({0}) is local, delivering directly", localClient.Name);
1352 localClient.SendInstantMessage(msg);
1354 else if (m_msgTransferModule != null)
1356 if (m_debugEnabled) m_log.InfoFormat(
"[Groups]: MsgTo ({0}) is not local, delivering via TransferModule", msgTo);
1357 m_msgTransferModule.SendInstantMessage(msg, delegate(
bool success) {
if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: Message Sent: {0}", success?
"Succeeded":
"Failed"); });
1370 private string GetRequestingAgentIDStr(
IClientAPI client)
1372 return GetRequestingAgentID(client).ToString();
1377 UUID requestingAgentID = UUID.Zero;
1380 requestingAgentID = client.AgentId;
1382 return requestingAgentID;
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void SetGroupAcceptNotices(IClientAPI remoteClient, UUID groupID, bool acceptNotices, bool listInProfile)
string GetGroupTitle(UUID avatarID)
Get the title of the agent's current role.
ExtendedGroupNoticeData noticeData
void GroupTitleUpdate(IClientAPI remoteClient, UUID groupID, UUID titleRoleID)
Change the current Active Group Role for Agent
bool AmountCovered(UUID agentID, int amount)
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void ActivateGroup(IClientAPI remoteClient, UUID groupID)
delegate void NewGroupNotice(UUID groupID, UUID noticeID)
OpenSim.Framework.RegionInfo RegionInfo
void InviteGroup(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID invitedAgentID, UUID roleID)
string Name
Returns the full name of the agent/avatar represented by this client
OpenMetaverse.StructuredData.OSDMap OSDMap
void InviteGroupRequest(IClientAPI remoteClient, UUID groupID, UUID invitedAgentID, UUID roleID)
void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID)
NewGroupNotice OnNewGroupNotice
GroupRecord GetGroupRecord(string name)
Get a group
void JoinGroupRequest(IClientAPI remoteClient, UUID groupID)
void GroupRoleUpdate(IClientAPI remoteClient, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, byte updateType)
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
ISceneAgent SceneAgent
The scene agent for this client. This will only be set if the client has an agent in a scene (i...
GroupMembershipData GetMembershipData(UUID groupID, UUID agentID)
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
GroupRecord GetGroupRecord(UUID GroupID)
Get a group
void EjectGroupMemberRequest(IClientAPI remoteClient, UUID groupID, UUID ejecteeID)
List< DirGroupsReplyData > FindGroups(IClientAPI remoteClient, string query)
List< GroupRoleMembersData > GroupRoleMembersRequest(IClientAPI remoteClient, UUID groupID)
Inventory Item - contains all the properties associated with an individual inventory piece...
void GroupNoticeRequest(IClientAPI remoteClient, UUID groupNoticeID)
ScenePermissions Permissions
OpenMetaverse.StructuredData.OSD OSD
GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog)
void SendAgentGroupDataUpdate(IClientAPI remoteClient)
void SendAgentAlertMessage(string message, bool modal)
GroupNoticeData[] GroupNoticesListRequest(IClientAPI remoteClient, UUID groupID)
override bool TryGetScenePresence(UUID agentID, out ScenePresence sp)
Try to get a scene presence from the scene
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
List< GroupTitlesData > GroupTitlesRequest(IClientAPI remoteClient, UUID groupID)
Get the Role Titles for an Agent, for a specific group
GroupProfileData GroupProfileRequest(IClientAPI remoteClient, UUID groupID)
void EjectGroupMember(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID ejecteeID)
void NotifyChange(UUID groupID)
GroupMembershipData[] GetMembershipData(UUID agentID)
UUID CreateGroup(IClientAPI remoteClient, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
Create a group
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
List< GroupRolesData > GroupRoleDataRequest(IClientAPI remoteClient, UUID groupID)
List< GroupMembersData > GroupMembersRequest(IClientAPI remoteClient, UUID groupID)
This maintains the relationship between a UUID and a user name.
void GroupRoleChanges(IClientAPI remoteClient, UUID groupID, UUID roleID, UUID memberID, uint changes)
void UpdateGroupInfo(IClientAPI remoteClient, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
OpenMetaverse.DirectoryManager.DirFindFlags DirFindFlags