29 using System.Collections.Generic;
30 using System.Reflection;
37 using OpenSim.Framework;
38 using OpenSim.Services.Interfaces;
40 namespace OpenSim.Groups
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 private string m_HomeURI;
51 : base(config, string.Empty)
54 m_UserAccounts = users;
56 if (!m_HomeURI.EndsWith(
"/"))
61 #region HG specific operations
63 public bool CreateGroupProxy(
string RequestingAgentID,
string agentID,
string accessToken, UUID groupID,
string serviceLocation,
string name, out
string reason)
65 reason = string.Empty;
69 uri =
new Uri(serviceLocation);
71 catch (UriFormatException)
73 reason =
"Bad location for group proxy";
78 GroupData grec = m_Database.RetrieveGroup(groupID);
80 (grec != null && grec.
Data[
"Location"] !=
string.Empty && grec.
Data[
"Location"].ToLower() != serviceLocation.ToLower()))
84 grec.GroupID = groupID;
85 grec.Data =
new Dictionary<string, string>();
86 grec.Data[
"Name"] = name +
" @ " + uri.Authority;
87 grec.Data[
"Location"] = serviceLocation;
88 grec.Data[
"Charter"] = string.Empty;
89 grec.Data[
"InsigniaID"] = UUID.Zero.ToString();
90 grec.Data[
"FounderID"] = UUID.Zero.ToString();
91 grec.Data[
"MembershipFee"] =
"0";
92 grec.Data[
"OpenEnrollment"] =
"0";
93 grec.Data[
"ShowInList"] =
"0";
94 grec.Data[
"AllowPublish"] =
"0";
95 grec.Data[
"MaturePublish"] =
"0";
96 grec.Data[
"OwnerRoleID"] = UUID.Zero.ToString();
99 if (!m_Database.StoreGroup(grec))
103 if (grec.
Data[
"Location"] ==
string.Empty)
105 reason =
"Cannot add proxy membership to non-proxy group";
109 UUID uid = UUID.Zero;
110 string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
111 Util.ParseUniversalUserIdentifier(RequestingAgentID, out uid, out url, out first, out last, out tmp);
112 string fromName = first +
"." + last +
"@" + url;
115 InviteToGroup(fromName, groupID,
new UUID(agentID), grec.
Data[
"Name"]);
120 membership.PrincipalID = agentID;
121 membership.GroupID = groupID;
122 membership.Data =
new Dictionary<string, string>();
123 membership.Data[
"SelectedRoleID"] = UUID.Zero.ToString();
124 membership.Data[
"Contribution"] =
"0";
125 membership.Data[
"ListInProfile"] =
"1";
126 membership.Data[
"AcceptNotices"] =
"1";
127 membership.Data[
"AccessToken"] = accessToken;
129 m_Database.StoreMember(membership);
137 MembershipData membership = m_Database.RetrieveMember(GroupID, AgentID);
138 if (membership != null)
140 if (token !=
string.Empty && token.Equals(membership.
Data[
"AccessToken"]))
142 return RemoveAgentFromGroup(RequestingAgentID, AgentID, GroupID);
146 m_log.DebugFormat(
"[Groups.HGGroupsService]: access token {0} did not match stored one {1}", token, membership.Data[
"AccessToken"]);
152 m_log.DebugFormat(
"[Groups.HGGroupsService]: membership not found for {0}", AgentID);
160 if (!VerifyToken(GroupID, RequestingAgentID, token))
164 if (GroupID == UUID.Zero)
165 grec = GetGroupRecord(RequestingAgentID, groupName);
167 grec = GetGroupRecord(RequestingAgentID, GroupID);
170 FillFounderUUI(grec);
175 public List<ExtendedGroupMembersData>
GetGroupMembers(
string RequestingAgentID, UUID GroupID,
string token)
177 if (!VerifyToken(GroupID, RequestingAgentID, token))
178 return new List<ExtendedGroupMembersData>();
180 List<ExtendedGroupMembersData> members = GetGroupMembers(RequestingAgentID, GroupID);
185 if (m.
AgentID.ToString().Length == 36)
189 m.AgentID = Util.UniversalIdentifier(account.PrincipalID, account.FirstName, account.LastName, m_HomeURI);
196 public List<GroupRolesData>
GetGroupRoles(
string RequestingAgentID, UUID GroupID,
string token)
198 if (!VerifyToken(GroupID, RequestingAgentID, token))
199 return new List<GroupRolesData>();
201 return GetGroupRoles(RequestingAgentID, GroupID);
204 public List<ExtendedGroupRoleMembersData>
GetGroupRoleMembers(
string RequestingAgentID, UUID GroupID,
string token)
206 if (!VerifyToken(GroupID, RequestingAgentID, token))
207 return new List<ExtendedGroupRoleMembersData>();
209 List<ExtendedGroupRoleMembersData> rolemembers = GetGroupRoleMembers(RequestingAgentID, GroupID);
214 if (m.
MemberID.ToString().Length == 36)
218 m.MemberID = Util.UniversalIdentifier(account.PrincipalID, account.FirstName, account.LastName, m_HomeURI);
225 public bool AddNotice(
string RequestingAgentID, UUID groupID, UUID noticeID,
string fromName,
string subject,
string message,
226 bool hasAttachment, byte attType,
string attName, UUID attItemID,
string attOwnerID)
232 m_log.DebugFormat(
"[Groups.HGGroupsService]: attempt at adding notice to non-existent group proxy");
239 m_log.DebugFormat(
"[Groups.HGGroupsService]: attempt at adding notice to local (non-proxy) group");
244 if (GetGroupNotice(RequestingAgentID, noticeID) != null)
246 m_log.DebugFormat(
"[Groups.HGGroupsService]: a notice with the same ID already exists", grec.ServiceLocation);
263 return _AddNotice(groupID, noticeID, fromName, subject, message, hasAttachment, attType, attName, attItemID, attOwnerID);
281 private void InviteToGroup(
string fromName, UUID groupID, UUID invitedAgentID,
string groupName)
284 UUID InviteID = UUID.Random();
286 if (AddAgentToGroupInvite(InviteID, groupID, invitedAgentID.ToString()))
288 Guid inviteUUID = InviteID.Guid;
292 msg.imSessionID = inviteUUID;
295 msg.fromAgentID = groupID.Guid;
296 msg.toAgentID = invitedAgentID.Guid;
299 msg.fromAgentName = fromName;
300 msg.message = string.Format(
"Please confirm your acceptance to join group {0}.", groupName);
301 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupInvitation;
304 msg.ParentEstateID = 0;
305 msg.Position = Vector3.Zero;
306 msg.RegionID = UUID.Zero.Guid;
307 msg.binaryBucket =
new byte[20];
309 string reason = string.Empty;
310 m_OfflineIM.StoreMessage(msg, out reason);
315 private bool AddAgentToGroupInvite(UUID inviteID, UUID groupID,
string agentID)
323 InvitationData invite = m_Database.RetrieveInvitation(groupID, agentID);
325 m_Database.DeleteInvite(invite.InviteID);
328 invite.InviteID = inviteID;
329 invite.PrincipalID = agentID;
330 invite.GroupID = groupID;
331 invite.RoleID = UUID.Zero;
332 invite.Data =
new Dictionary<string, string>();
334 return m_Database.StoreInvitation(invite);
337 private void FillFounderUUI(ExtendedGroupRecord grec)
339 UserAccount account = m_UserAccounts.GetUserAccount(UUID.Zero, grec.FounderID);
341 grec.FounderUUI = Util.UniversalIdentifier(account.PrincipalID, account.FirstName, account.LastName, m_HomeURI);
344 private bool VerifyToken(UUID groupID,
string agentID,
string token)
347 MembershipData membership = m_Database.RetrieveMember(groupID, agentID);
348 if (membership != null)
350 if (token !=
string.Empty && token.Equals(membership.
Data[
"AccessToken"]))
353 m_log.DebugFormat(
"[Groups.HGGroupsService]: access token {0} did not match stored one {1}", token, membership.Data[
"AccessToken"]);
356 m_log.DebugFormat(
"[Groups.HGGroupsService]: membership not found for {0}", agentID);
HGGroupsService(IConfigSource config, IOfflineIMService im, IUserAccountService users, string homeURI)
bool VerifyNotice(UUID noticeID, UUID groupID)
List< GroupRolesData > GetGroupRoles(string RequestingAgentID, UUID GroupID, string token)
List< ExtendedGroupMembersData > GetGroupMembers(string RequestingAgentID, UUID GroupID, string token)
List< ExtendedGroupRoleMembersData > GetGroupRoleMembers(string RequestingAgentID, UUID GroupID, string token)
Dictionary< string, string > Data
bool RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID, string token)
ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string groupName, string token)
bool AddNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
bool CreateGroupProxy(string RequestingAgentID, string agentID, string accessToken, UUID groupID, string serviceLocation, string name, out string reason)
Dictionary< string, string > Data