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;
44 namespace OpenSim.
Region.OptionalModules.
Avatar.XmlRpcGroups
46 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"GroupsModule")]
74 private static readonly ILog m_log =
75 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 private List<Scene> m_sceneList =
new List<Scene>();
86 private bool m_groupsEnabled =
false;
87 private bool m_groupNoticesEnabled =
true;
88 private bool m_debugEnabled =
false;
89 private int m_levelGroupCreate = 0;
91 #region Region Module interfaceBase Members
95 IConfig groupsConfig = config.Configs[
"Groups"];
97 if (groupsConfig == null)
104 m_groupsEnabled = groupsConfig.GetBoolean(
"Enabled",
false);
105 if (!m_groupsEnabled)
110 if (groupsConfig.GetString(
"Module",
"Default") != Name)
112 m_groupsEnabled =
false;
117 m_log.InfoFormat(
"[GROUPS]: Initializing {0}", this.Name);
119 m_groupNoticesEnabled = groupsConfig.GetBoolean(
"NoticesEnabled",
true);
120 m_debugEnabled = groupsConfig.GetBoolean(
"DebugEnabled",
false);
121 m_levelGroupCreate = groupsConfig.GetInt(
"LevelGroupCreate", 0);
133 "debug groups verbose",
134 "debug groups verbose <true|false>",
135 "This setting turns on very verbose groups debugging",
136 HandleDebugGroupsVerbose);
140 private void HandleDebugGroupsVerbose(
object modules,
string[] args)
144 MainConsole.Instance.Output(
"Usage: debug groups verbose <true|false>");
148 bool verbose =
false;
149 if (!
bool.TryParse(args[3], out verbose))
151 MainConsole.Instance.Output(
"Usage: debug groups verbose <true|false>");
155 m_debugEnabled = verbose;
157 MainConsole.Instance.OutputFormat(
"{0} verbose logging set to {1}", Name, m_debugEnabled);
162 if (!m_groupsEnabled)
165 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
167 if (m_groupData == null)
172 if (m_groupData == null)
174 m_groupsEnabled =
false;
175 m_log.Error(
"[GROUPS]: Could not get IGroupsServicesConnector");
181 if (m_msgTransferModule == null)
186 if (m_msgTransferModule == null)
188 m_groupsEnabled =
false;
189 m_log.Warn(
"[GROUPS]: Could not get IMessageTransferModule");
193 if (m_groupsMessagingModule == null)
198 if (m_groupsMessagingModule == null)
199 m_log.Warn(
"[GROUPS]: Could not get IGroupsMessagingModule");
204 m_sceneList.Add(scene);
207 scene.EventManager.OnNewClient += OnNewClient;
208 scene.EventManager.OnMakeRootAgent += OnMakeRoot;
209 scene.EventManager.OnMakeChildAgent += OnMakeChild;
210 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
211 scene.EventManager.OnClientClosed += OnClientClosed;
217 if (!m_groupsEnabled)
220 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
224 m_sceneList.Remove(scene);
230 if (!m_groupsEnabled)
233 if (m_debugEnabled) m_log.Debug(
"[GROUPS]: Shutting down Groups module.");
236 public Type ReplaceableInterface
243 get {
return "GroupsModule"; }
248 #region ISharedRegionModule Members
257 #region EventHandlers
261 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
263 sp.ControllingClient.OnUUIDGroupNameRequest += HandleUUIDGroupNameRequest;
265 sp.ControllingClient.OnInstantMessage += OnInstantMessage;
277 if (m_debugEnabled) m_log.DebugFormat(
"[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
279 sp.ControllingClient.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
280 sp.ControllingClient.OnInstantMessage -= OnInstantMessage;
285 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
287 client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
288 client.OnRequestAvatarProperties += OnRequestAvatarProperties;
317 private void OnRequestAvatarProperties(
IClientAPI remoteClient, UUID avatarID)
319 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
321 GroupMembershipData[] avatarGroups = GetProfileListedGroupMemberships(remoteClient, avatarID);
322 remoteClient.SendAvatarGroupsReply(avatarID, avatarGroups);
326 private void OnClientClosed(UUID AgentId,
Scene scene)
328 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
336 client.OnAgentDataUpdateRequest -= OnAgentDataUpdateRequest;
337 client.OnRequestAvatarProperties -= OnRequestAvatarProperties;
339 client.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
340 client.OnInstantMessage -= OnInstantMessage;
364 private void OnAgentDataUpdateRequest(
IClientAPI remoteClient, UUID dataForAgentID, UUID sessionID)
367 if (dataForAgentID != GetRequestingAgentID(remoteClient))
370 SendAgentGroupDataUpdate(remoteClient,
false);
375 private void HandleUUIDGroupNameRequest(UUID GroupID,
IClientAPI remoteClient)
377 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
381 GroupRecord group = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), GroupID, null);
384 GroupName = group.GroupName;
388 GroupName =
"Unknown";
391 remoteClient.SendGroupNameReply(GroupID, GroupName);
398 "[GROUPS]: {0} called for {1}, message type {2}",
399 System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.
Name, (InstantMessageDialog)im.dialog);
402 if ((im.
dialog == (byte)InstantMessageDialog.GroupInvitationAccept) || (im.
dialog == (byte)InstantMessageDialog.GroupInvitationDecline))
405 GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(GetRequestingAgentID(remoteClient), inviteID);
407 if (inviteInfo == null)
409 if (m_debugEnabled) m_log.WarnFormat(
"[GROUPS]: Received an Invite IM for an invite that does not exist {0}.", inviteID);
413 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: Invite is for Agent {0} to Group {1}.", inviteInfo.AgentID, inviteInfo.GroupID);
416 if ((inviteInfo != null) && (fromAgentID == inviteInfo.AgentID))
419 if (im.
dialog == (byte)InstantMessageDialog.GroupInvitationAccept)
421 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: Received an accept invite notice.");
424 m_groupData.AddAgentToGroup(GetRequestingAgentID(remoteClient), inviteInfo.AgentID, inviteInfo.GroupID, inviteInfo.RoleID);
427 msg.imSessionID = UUID.Zero.Guid;
428 msg.fromAgentID = UUID.Zero.Guid;
429 msg.toAgentID = inviteInfo.AgentID.Guid;
430 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
431 msg.fromAgentName =
"Groups";
432 msg.message = string.Format(
"You have been added to the group.");
433 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageBox;
434 msg.fromGroup =
false;
435 msg.offline = (byte)0;
436 msg.ParentEstateID = 0;
437 msg.Position = Vector3.Zero;
438 msg.RegionID = UUID.Zero.Guid;
439 msg.binaryBucket =
new byte[0];
441 OutgoingInstantMessage(msg, inviteInfo.AgentID);
443 IClientAPI client = GetActiveClient(inviteInfo.AgentID);
445 SendDataUpdate(remoteClient,
true);
450 m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentID(remoteClient), inviteID);
454 if (im.
dialog == (byte)InstantMessageDialog.GroupInvitationDecline)
456 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: Received a reject invite notice.");
457 m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentID(remoteClient), inviteID);
463 if ((im.
dialog == (byte)InstantMessageDialog.GroupNotice))
465 if (!m_groupNoticesEnabled)
471 if (m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), GroupID, null) != null)
473 UUID NoticeID = UUID.Random();
474 string Subject = im.message.Substring(0, im.message.IndexOf(
'|'));
475 string Message = im.message.Substring(Subject.Length + 1);
478 bool hasAttachment =
false;
479 UUID itemID = UUID.Zero;
480 UUID ownerID = UUID.Zero;
485 string binBucket = OpenMetaverse.Utils.BytesToString(im.binaryBucket);
486 binBucket = binBucket.Remove(0, 14).Trim();
488 OSDMap binBucketOSD = (
OSDMap)OSDParser.DeserializeLLSDXml(binBucket);
489 if (binBucketOSD is
OSD)
493 itemID = binBucketMap[
"item_id"].AsUUID();
494 ownerID = binBucketMap[
"owner_id"].AsUUID();
502 item = scene.InventoryService.GetItem(item);
507 hasAttachment =
true;
512 m_log.DebugFormat(
"[Groups]: Received OSD with unexpected type: {0}", binBucketOSD.GetType());
528 byte[] name = Encoding.UTF8.GetBytes(item.Name);
529 bucket =
new byte[51 + name.Length];
531 bucket[1] = (byte)item.InvType;
532 GroupID.ToBytes(bucket, 2);
533 ownerID.ToBytes(bucket, 18);
534 itemID.ToBytes(bucket, 34);
535 name.CopyTo(bucket, 50);
539 bucket =
new byte[19];
542 GroupID.ToBytes(bucket, 2);
546 m_groupData.AddGroupNotice(GetRequestingAgentID(remoteClient), GroupID, NoticeID, im.fromAgentName, Subject, Message, bucket);
547 if (OnNewGroupNotice != null)
549 OnNewGroupNotice(GroupID, NoticeID);
554 foreach (
GroupMembersData member
in m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), GroupID))
559 = m_sceneList[0].UserAccountService.GetUserAccount(
560 remoteClient.Scene.RegionInfo.ScopeID, member.AgentID);
562 if (targetUser != null)
565 "[GROUPS]: Prepping group notice {0} for agent: {1} who Accepts Notices ({2})",
566 NoticeID, targetUser.FirstName +
" " + targetUser.LastName, member.AcceptNotices);
571 "[GROUPS]: Prepping group notice {0} for agent: {1} who Accepts Notices ({2})",
572 NoticeID, member.AgentID, member.AcceptNotices);
579 = CreateGroupNoticeIM(
UUID.Zero, NoticeID, (byte)OpenMetaverse.InstantMessageDialog.GroupNotice);
581 if (m_groupsMessagingModule != null)
582 m_groupsMessagingModule.SendMessageToGroup(
583 msg, GroupID, remoteClient.AgentId, gmd => gmd.AcceptNotices);
587 if (im.
dialog == (byte)InstantMessageDialog.GroupNoticeInventoryAccepted)
596 m_log.DebugFormat(
"[GROUPS]: Requesting notice {0} for {1}", noticeID, remoteClient.AgentId);
598 GroupNoticeInfo notice = m_groupData.GetGroupNotice(GetRequestingAgentID(remoteClient), noticeID);
601 UUID giver =
new UUID(notice.BinaryBucket, 18);
602 UUID attachmentUUID =
new UUID(notice.BinaryBucket, 34);
605 m_log.DebugFormat(
"[Groups]: Giving inventory from {0} to {1}", giver, remoteClient.AgentId);
609 giver, attachmentUUID, out message);
611 if (itemCopy == null)
613 remoteClient.SendAgentAlertMessage(message,
false);
617 remoteClient.SendInventoryItemCreateUpdate(itemCopy, 0);
623 "[GROUPS]: Could not find notice {0} for {1} on GroupNoticeInventoryAccepted.",
624 noticeID, remoteClient.AgentId);
641 im.dialog = (byte)InstantMessageDialog.MessageFromAgent;
642 OutgoingInstantMessage(im, ejecteeID);
644 IClientAPI ejectee = GetActiveClient(ejecteeID);
648 ejectee.SendAgentDropGroup(groupID);
655 if (m_debugEnabled) m_log.InfoFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
658 OnInstantMessage(null, msg);
665 case (byte)InstantMessageDialog.GroupInvitation:
666 case (byte)InstantMessageDialog.GroupNotice:
668 IClientAPI localClient = GetActiveClient(toAgentID);
669 if (localClient != null)
671 localClient.SendInstantMessage(msg);
680 #region IGroupsModule Members
686 return m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
691 return m_groupData.GetGroupRecord(UUID.Zero, UUID.Zero, name);
696 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
698 UUID agentID = GetRequestingAgentID(remoteClient);
699 m_groupData.SetAgentActiveGroup(agentID, agentID, groupID);
702 SendAgentGroupDataUpdate(remoteClient,
true);
710 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
712 List<GroupRolesData> agentRoles = m_groupData.GetAgentGroupRoles(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
713 GroupMembershipData agentMembership = m_groupData.GetAgentGroupMembership(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
715 List<GroupTitlesData> titles =
new List<GroupTitlesData>();
719 title.Name = role.Name;
720 if (agentMembership != null)
722 title.Selected = agentMembership.ActiveRole == role.RoleID;
724 title.UUID = role.RoleID;
736 "[GROUPS]: GroupMembersRequest called for {0} from client {1}", groupID, remoteClient.Name);
738 List<GroupMembersData> data = m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), groupID);
744 m_log.DebugFormat(
"[GROUPS]: Member({0}) - IsOwner({1})", member.AgentID, member.IsOwner);
753 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
755 List<GroupRolesData> data = m_groupData.GetGroupRoles(GetRequestingAgentID(remoteClient), groupID);
762 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
764 List<GroupRoleMembersData> data = m_groupData.GetGroupRoleMembers(GetRequestingAgentID(remoteClient), groupID);
770 m_log.DebugFormat(
"[GROUPS]: Member({0}) - Role({1})", member.MemberID, member.RoleID);
778 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
783 GroupRecord groupInfo = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), groupID, null);
784 if (groupInfo != null)
786 profile.AllowPublish = groupInfo.AllowPublish;
787 profile.Charter = groupInfo.Charter;
788 profile.FounderID = groupInfo.FounderID;
789 profile.GroupID = groupID;
790 profile.GroupMembershipCount = m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), groupID).Count;
791 profile.GroupRolesCount = m_groupData.GetGroupRoles(GetRequestingAgentID(remoteClient), groupID).Count;
792 profile.InsigniaID = groupInfo.GroupPicture;
793 profile.MaturePublish = groupInfo.MaturePublish;
794 profile.MembershipFee = groupInfo.MembershipFee;
796 profile.Name = groupInfo.GroupName;
797 profile.OpenEnrollment = groupInfo.OpenEnrollment;
798 profile.OwnerRole = groupInfo.OwnerRoleID;
799 profile.ShowInList = groupInfo.ShowInList;
802 GroupMembershipData memberInfo = m_groupData.GetAgentGroupMembership(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
803 if (memberInfo != null)
805 profile.MemberTitle = memberInfo.GroupTitle;
806 profile.PowersMask = memberInfo.GroupPowers;
814 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
816 return m_groupData.GetAgentGroupMemberships(UUID.Zero, agentID).ToArray();
823 "[GROUPS]: {0} called with groupID={1}, agentID={2}",
824 System.Reflection.MethodBase.GetCurrentMethod().Name, groupID, agentID);
826 return m_groupData.GetAgentGroupMembership(UUID.Zero, agentID, groupID);
829 public void UpdateGroupInfo(
IClientAPI remoteClient, UUID groupID,
string charter,
bool showInList, UUID insigniaID,
int membershipFee,
bool openEnrollment,
bool allowPublish,
bool maturePublish)
831 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
834 m_groupData.UpdateGroup(GetRequestingAgentID(remoteClient), groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish);
840 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
842 m_groupData.SetAgentGroupInfo(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, acceptNotices, listInProfile);
845 public UUID CreateGroup(
IClientAPI remoteClient,
string name,
string charter,
bool showInList, UUID insigniaID,
int membershipFee,
bool openEnrollment,
bool allowPublish,
bool maturePublish)
847 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
849 if (m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient),
UUID.Zero, name) != null)
851 remoteClient.SendCreateGroupReply(UUID.Zero,
false,
"A group with the same name already exists.");
862 if (avatar.UserLevel < m_levelGroupCreate)
864 remoteClient.SendCreateGroupReply(UUID.Zero,
false,
"You have got insufficient permissions to create a group.");
876 remoteClient.SendCreateGroupReply(UUID.Zero,
false,
"You have got insufficient funds to create a group.");
879 money.ApplyCharge(GetRequestingAgentID(remoteClient), money.GroupCreationCharge, MoneyTransactionType.GroupCreate);
881 UUID groupID = m_groupData.CreateGroup(GetRequestingAgentID(remoteClient), name, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish, GetRequestingAgentID(remoteClient));
883 remoteClient.SendCreateGroupReply(groupID,
true,
"Group created successfullly");
886 SendAgentGroupDataUpdate(remoteClient,
false);
893 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
897 return m_groupData.GetGroupNotices(GetRequestingAgentID(remoteClient), groupID).ToArray();
905 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
907 GroupMembershipData membership = m_groupData.GetAgentActiveMembership(UUID.Zero, avatarID);
908 if (membership != null)
910 return membership.GroupTitle;
920 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
922 m_groupData.SetAgentActiveGroupRole(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, titleRoleID);
928 SendDataUpdate(remoteClient,
true);
931 public void GroupRoleUpdate(
IClientAPI remoteClient, UUID groupID, UUID roleID,
string name,
string description,
string title, ulong powers, byte updateType)
933 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
937 switch ((OpenMetaverse.GroupRoleUpdate)updateType)
939 case OpenMetaverse.GroupRoleUpdate.Create:
940 m_groupData.AddGroupRole(GetRequestingAgentID(remoteClient), groupID, UUID.Random(), name, description, title, powers);
943 case OpenMetaverse.GroupRoleUpdate.Delete:
944 m_groupData.RemoveGroupRole(GetRequestingAgentID(remoteClient), groupID, roleID);
947 case OpenMetaverse.GroupRoleUpdate.UpdateAll:
948 case OpenMetaverse.GroupRoleUpdate.UpdateData:
949 case OpenMetaverse.GroupRoleUpdate.UpdatePowers:
952 GroupPowers gp = (GroupPowers)powers;
953 m_log.DebugFormat(
"[GROUPS]: Role ({0}) updated with Powers ({1}) ({2})", name, powers.ToString(), gp.ToString());
955 m_groupData.UpdateGroupRole(GetRequestingAgentID(remoteClient), groupID, roleID, name, description, title, powers);
958 case OpenMetaverse.GroupRoleUpdate.NoUpdate:
966 SendAgentGroupDataUpdate(remoteClient,
false);
971 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
978 m_groupData.AddAgentToGroupRole(GetRequestingAgentID(remoteClient), memberID, groupID, roleID);
983 m_groupData.RemoveAgentFromGroupRole(GetRequestingAgentID(remoteClient), memberID, groupID, roleID);
987 m_log.ErrorFormat(
"[GROUPS]: {0} does not understand changes == {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, changes);
992 SendAgentGroupDataUpdate(remoteClient,
false);
997 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
999 GroupNoticeInfo data = m_groupData.GetGroupNotice(GetRequestingAgentID(remoteClient), groupNoticeID);
1003 GridInstantMessage msg = CreateGroupNoticeIM(remoteClient.
AgentId, groupNoticeID, (byte)InstantMessageDialog.GroupNoticeRequested);
1005 OutgoingInstantMessage(msg, GetRequestingAgentID(remoteClient));
1011 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1016 msg.imSessionID = groupNoticeID.Guid;
1017 msg.toAgentID = agentID.Guid;
1018 msg.dialog = dialog;
1019 msg.fromGroup =
true;
1020 msg.offline = (byte)1;
1021 msg.ParentEstateID = 0;
1022 msg.Position = Vector3.Zero;
1023 msg.RegionID = UUID.Zero.Guid;
1025 GroupNoticeInfo info = m_groupData.GetGroupNotice(agentID, groupNoticeID);
1028 msg.fromAgentID = info.GroupID.Guid;
1029 msg.timestamp = info.noticeData.Timestamp;
1030 msg.fromAgentName = info.noticeData.FromName;
1031 msg.message = info.noticeData.Subject +
"|" + info.Message;
1040 bucket =
new byte[info.BinaryBucket.Length-32];
1042 bucket[1] = info.BinaryBucket[1];
1043 Array.Copy(info.BinaryBucket, 50,
1044 bucket, 18, info.BinaryBucket.Length-50);
1048 bucket =
new byte[19];
1054 info.GroupID.ToBytes(bucket, 2);
1055 msg.binaryBucket = bucket;
1060 m_log.DebugFormat(
"[GROUPS]: Group Notice {0} not found, composing empty message.", groupNoticeID);
1062 msg.fromAgentID = UUID.Zero.Guid;
1063 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
1064 msg.fromAgentName = string.Empty;
1065 msg.message = string.Empty;
1066 msg.binaryBucket =
new byte[0];
1074 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1077 m_groupData.AddAgentToGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, UUID.Zero);
1079 remoteClient.SendJoinGroupReply(groupID,
true);
1081 SendAgentGroupDataUpdate(remoteClient,
true);
1086 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1088 m_groupData.RemoveAgentFromGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
1090 remoteClient.SendLeaveGroupReply(groupID,
true);
1092 remoteClient.SendAgentDropGroup(groupID);
1096 SendAgentGroupDataUpdate(remoteClient,
true);
1101 EjectGroupMember(remoteClient, GetRequestingAgentID(remoteClient), groupID, ejecteeID);
1106 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1109 m_groupData.RemoveAgentFromGroup(agentID, ejecteeID, groupID);
1115 if (remoteClient != null)
1117 agentName = remoteClient.Name;
1119 remoteClient.SendEjectGroupMemberReply(agentID, groupID,
true);
1123 IClientAPI client = GetActiveClient(agentID);
1127 agentName = client.Name;
1129 client.SendEjectGroupMemberReply(agentID, groupID,
true);
1134 UserAccount acc = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);
1138 agentName = acc.FirstName +
" " + acc.LastName;
1142 agentName =
"Unknown member";
1147 GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID, groupID, null);
1149 UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, ejecteeID);
1150 if ((groupInfo == null) || (account == null))
1158 msg.imSessionID = UUID.Zero.Guid;
1159 msg.fromAgentID = agentID.Guid;
1161 msg.toAgentID = ejecteeID.Guid;
1164 msg.fromAgentName = agentName;
1165 msg.message = string.Format(
"You have been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName);
1166 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
1169 msg.ParentEstateID = 0;
1170 msg.Position = Vector3.Zero;
1171 msg.RegionID = regionInfo.RegionID.Guid;
1172 msg.binaryBucket =
new byte[0];
1173 OutgoingInstantMessage(msg, ejecteeID);
1183 msg.imSessionID = UUID.Zero.Guid;
1184 msg.fromAgentID = agentID.Guid;
1185 msg.toAgentID = agentID.Guid;
1187 msg.fromAgentName = agentName;
1188 if (account != null)
1190 msg.message = string.Format(
"{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName, account.FirstName +
" " + account.LastName);
1194 msg.message = string.Format(
"{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName,
"Unknown member");
1196 msg.dialog = (byte)210;
1197 msg.fromGroup =
false;
1198 msg.offline = (byte)0;
1199 msg.ParentEstateID = 0;
1200 msg.Position = Vector3.Zero;
1201 msg.RegionID = regionInfo.RegionID.Guid;
1202 msg.binaryBucket =
new byte[0];
1203 OutgoingInstantMessage(msg, agentID);
1208 SendAgentGroupDataUpdate(remoteClient,
false);
1214 InviteGroup(remoteClient, GetRequestingAgentID(remoteClient), groupID, invitedAgentID, roleID);
1219 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1225 if (remoteClient != null)
1227 agentName = remoteClient.Name;
1232 IClientAPI client = GetActiveClient(agentID);
1236 agentName = client.Name;
1242 UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);
1244 if (account != null)
1246 agentName = account.FirstName +
" " + account.LastName;
1250 agentName =
"Unknown member";
1256 UUID InviteID = UUID.Random();
1258 m_groupData.AddAgentToGroupInvite(agentID, InviteID, groupID, roleID, invitedAgentID);
1262 GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(agentID, InviteID);
1264 if (inviteInfo != null)
1266 if (m_msgTransferModule != null)
1268 Guid inviteUUID = InviteID.Guid;
1272 msg.imSessionID = inviteUUID;
1275 msg.fromAgentID = groupID.Guid;
1276 msg.toAgentID = invitedAgentID.Guid;
1279 msg.fromAgentName = agentName;
1280 msg.message = string.Format(
"{0} has invited you to join a group. There is no cost to join this group.", agentName);
1281 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupInvitation;
1284 msg.ParentEstateID = 0;
1285 msg.Position = Vector3.Zero;
1286 msg.RegionID = regionInfo.RegionID.Guid;
1287 msg.binaryBucket =
new byte[20];
1289 OutgoingInstantMessage(msg, invitedAgentID);
1296 return m_groupData.FindGroups(GetRequestingAgentID(remoteClient), query);
1302 #region Client/Update Tools
1307 private IClientAPI GetActiveClient(UUID agentID)
1312 foreach (
Scene scene
in m_sceneList)
1319 return sp.ControllingClient;
1323 child = sp.ControllingClient;
1332 private void SendScenePresenceUpdate(UUID AgentID,
string Title)
1334 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: Updating scene title for {0} with title: {1}", AgentID, Title);
1338 foreach (
Scene scene
in m_sceneList)
1340 presence = scene.GetScenePresence(AgentID);
1341 if (presence != null)
1343 if (presence.Grouptitle != Title)
1345 presence.Grouptitle = Title;
1347 if (! presence.IsChildAgent)
1348 presence.SendAvatarDataToAllAgents();
1356 SendAgentGroupDataUpdate(remoteClient,
true);
1362 private void SendAgentGroupDataUpdate(
IClientAPI remoteClient,
bool tellOthers)
1364 if (m_debugEnabled) m_log.InfoFormat(
"[GROUPS]: {0} called for {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.
Name);
1368 UUID agentID = GetRequestingAgentID(remoteClient);
1370 SendDataUpdate(remoteClient, tellOthers);
1372 GroupMembershipData[] membershipArray = GetProfileListedGroupMemberships(remoteClient, agentID);
1373 remoteClient.SendAgentGroupDataUpdate(agentID, membershipArray);
1375 remoteClient.RefreshGroupMembership();
1386 List<GroupMembershipData> membershipData = m_groupData.GetAgentGroupMemberships(requestingClient.AgentId, dataForAgentID);
1396 membershipArray = membershipData.ToArray();
1400 if (requestingClient.
AgentId != dataForAgentID)
1404 return membership.ListInProfile;
1407 membershipArray = membershipData.FindAll(showInProfile).ToArray();
1411 membershipArray = membershipData.ToArray();
1417 m_log.InfoFormat(
"[GROUPS]: Get group membership information for {0} requested by {1}", dataForAgentID, requestingClient.AgentId);
1420 m_log.InfoFormat(
"[GROUPS]: {0} :: {1} - {2} - {3}", dataForAgentID, membership.GroupName, membership.GroupTitle, membership.GroupPowers);
1424 return membershipArray;
1428 private void SendDataUpdate(
IClientAPI remoteClient,
bool tellOthers)
1430 if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1432 UUID activeGroupID = UUID.Zero;
1433 string activeGroupTitle = string.Empty;
1434 string activeGroupName = string.Empty;
1435 ulong activeGroupPowers = (ulong)GroupPowers.None;
1437 UUID agentID = GetRequestingAgentID(remoteClient);
1439 if (membership != null)
1441 activeGroupID = membership.GroupID;
1442 activeGroupTitle = membership.GroupTitle;
1443 activeGroupPowers = membership.GroupPowers;
1444 activeGroupName = membership.GroupName;
1447 UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(remoteClient.Scene.RegionInfo.ScopeID, agentID);
1448 string firstname, lastname;
1449 if (account != null)
1451 firstname = account.FirstName;
1452 lastname = account.LastName;
1456 firstname =
"Unknown";
1457 lastname =
"Unknown";
1460 remoteClient.SendAgentDataUpdate(agentID, activeGroupID, firstname,
1461 lastname, activeGroupPowers, activeGroupName,
1465 SendScenePresenceUpdate(agentID, activeGroupTitle);
1469 sp.Grouptitle = activeGroupTitle;
1474 #region IM Backed Processes
1478 if (m_debugEnabled) m_log.InfoFormat(
"[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1480 IClientAPI localClient = GetActiveClient(msgTo);
1481 if (localClient != null)
1483 if (m_debugEnabled) m_log.InfoFormat(
"[GROUPS]: MsgTo ({0}) is local, delivering directly", localClient.Name);
1484 localClient.SendInstantMessage(msg);
1486 else if (m_msgTransferModule != null)
1488 if (m_debugEnabled) m_log.InfoFormat(
"[GROUPS]: MsgTo ({0}) is not local, delivering via TransferModule", msgTo);
1489 m_msgTransferModule.SendInstantMessage(msg, delegate(
bool success) {
if (m_debugEnabled) m_log.DebugFormat(
"[GROUPS]: Message Sent: {0}", success?
"Succeeded":
"Failed"); });
1504 UUID requestingAgentID = UUID.Zero;
1507 requestingAgentID = client.AgentId;
1509 return requestingAgentID;
1517 public string Message = string.Empty;
1518 public byte[] BinaryBucket =
new byte[0];
void GroupRoleUpdate(IClientAPI remoteClient, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, byte updateType)
void GroupNoticeRequest(IClientAPI remoteClient, UUID groupNoticeID)
string GetGroupTitle(UUID avatarID)
Get the title of the agent's current role.
void GroupRoleChanges(IClientAPI remoteClient, UUID groupID, UUID roleID, UUID memberID, uint changes)
GroupNoticeData[] GroupNoticesListRequest(IClientAPI remoteClient, UUID groupID)
bool AmountCovered(UUID agentID, int amount)
GroupProfileData GroupProfileRequest(IClientAPI remoteClient, UUID groupID)
delegate void NewGroupNotice(UUID groupID, UUID noticeID)
OpenSim.Framework.RegionInfo RegionInfo
Provide mechanisms for messaging groups.
List< DirGroupsReplyData > FindGroups(IClientAPI remoteClient, string query)
string Name
Returns the full name of the agent/avatar represented by this client
OpenMetaverse.StructuredData.OSDMap OSDMap
GroupMembershipData GetMembershipData(UUID groupID, UUID agentID)
List< GroupRoleMembersData > GroupRoleMembersRequest(IClientAPI remoteClient, UUID groupID)
void InviteGroup(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID invitedAgentID, UUID roleID)
void EjectGroupMember(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID ejecteeID)
GroupMembershipData[] GetMembershipData(UUID agentID)
List< GroupMembersData > GroupMembersRequest(IClientAPI remoteClient, UUID groupID)
ISceneAgent SceneAgent
The scene agent for this client. This will only be set if the client has an agent in a scene (i...
UUID CreateGroup(IClientAPI remoteClient, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
Create a group
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void InviteGroupRequest(IClientAPI remoteClient, UUID groupID, UUID invitedAgentID, UUID roleID)
void JoinGroupRequest(IClientAPI remoteClient, UUID groupID)
List< GroupTitlesData > GroupTitlesRequest(IClientAPI remoteClient, UUID groupID)
Get the Role Titles for an Agent, for a specific group
GroupRecord GetGroupRecord(UUID GroupID)
Get a group
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
List< GroupRolesData > GroupRoleDataRequest(IClientAPI remoteClient, UUID groupID)
void EjectGroupMemberRequest(IClientAPI remoteClient, UUID groupID, UUID ejecteeID)
Inventory Item - contains all the properties associated with an individual inventory piece...
void GroupTitleUpdate(IClientAPI remoteClient, UUID groupID, UUID titleRoleID)
Change the current Active Group Role for Agent
ScenePermissions Permissions
void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID)
void SetGroupAcceptNotices(IClientAPI remoteClient, UUID groupID, bool acceptNotices, bool listInProfile)
OpenMetaverse.StructuredData.OSD OSD
GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog)
override bool TryGetScenePresence(UUID agentID, out ScenePresence sp)
Try to get a scene presence from the scene
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void UpdateGroupInfo(IClientAPI remoteClient, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
NewGroupNotice OnNewGroupNotice
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
void ActivateGroup(IClientAPI remoteClient, UUID groupID)
GroupRecord GetGroupRecord(string name)
Get a group
void NotifyChange(UUID groupID)
OpenMetaverse.DirectoryManager.DirFindFlags DirFindFlags
void SendAgentGroupDataUpdate(IClientAPI remoteClient)