29 using System.Collections.Generic;
31 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Monitoring;
36 using OpenSim.Framework.Servers;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Services.Interfaces;
46 namespace OpenSim.Groups
48 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"GroupsServiceHGConnectorModule")]
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 private bool m_Enabled =
false;
55 private string m_LocalGroupsServiceLocation;
59 private List<Scene> m_Scenes;
61 private string m_ServiceLocation;
62 private IConfigSource m_Config;
64 private Dictionary<string, GroupsServiceHGConnector> m_NetworkConnectors =
new Dictionary<string, GroupsServiceHGConnector>();
67 #region ISharedRegionModule
71 IConfig groupsConfig = config.Configs[
"Groups"];
72 if (groupsConfig == null)
75 if ((groupsConfig.GetBoolean(
"Enabled",
false) ==
false)
76 || (groupsConfig.GetString(
"ServicesConnectorModule",
string.Empty) != Name))
82 m_ServiceLocation = groupsConfig.GetString(
"LocalService",
"local");
83 m_LocalGroupsServiceLocation = groupsConfig.GetString(
"GroupsExternalURI",
"http://127.0.0.1");
84 m_Scenes =
new List<Scene>();
88 m_log.DebugFormat(
"[Groups]: Initializing {0} with LocalService {1}", this.Name, m_ServiceLocation);
93 get {
return "Groups HG Service Connector"; }
96 public Type ReplaceableInterface
106 m_log.DebugFormat(
"[Groups]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName);
110 scene.EventManager.OnNewClient += OnNewClient;
119 m_Scenes.Remove(scene);
127 if (m_UserManagement == null)
134 if (m_ServiceLocation.Equals(
"local"))
162 client.OnCompleteMovementToRegion += OnCompleteMovementToRegion;
165 void OnCompleteMovementToRegion(
IClientAPI client,
bool arg2)
173 if (aCircuit != null && (aCircuit.
teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 &&
174 m_OfflineIM != null && m_Messaging != null)
176 List<GridInstantMessage> ims = m_OfflineIM.GetMessages(aCircuit.AgentID);
177 if (ims != null && ims.Count > 0)
179 m_Messaging.SendInstantMessage(im, delegate(
bool success) { });
185 #region IGroupsServicesConnector
187 public UUID CreateGroup(UUID RequestingAgentID,
string name,
string charter,
bool showInList, UUID insigniaID,
int membershipFee,
bool openEnrollment,
188 bool allowPublish,
bool maturePublish, UUID founderID, out
string reason)
190 reason = string.Empty;
191 if (m_UserManagement.IsLocalGridUser(RequestingAgentID))
192 return m_LocalGroupsConnector.CreateGroup(RequestingAgentID, name, charter, showInList, insigniaID,
193 membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out reason);
196 reason =
"Only local grid users are allowed to create a new group";
201 public bool UpdateGroup(
string RequestingAgentID, UUID groupID,
string charter,
bool showInList, UUID insigniaID,
int membershipFee,
202 bool openEnrollment,
bool allowPublish,
bool maturePublish, out
string reason)
204 reason = string.Empty;
205 string url = string.Empty;
206 string name = string.Empty;
207 if (IsLocal(groupID, out url, out name))
208 return m_LocalGroupsConnector.UpdateGroup(AgentUUI(RequestingAgentID), groupID, charter, showInList, insigniaID, membershipFee,
209 openEnrollment, allowPublish, maturePublish, out reason);
212 reason =
"Changes to remote group not allowed. Please go to the group's original world.";
219 string url = string.Empty;
220 string name = string.Empty;
221 if (IsLocal(GroupID, out url, out name))
222 return m_LocalGroupsConnector.GetGroupRecord(AgentUUI(RequestingAgentID), GroupID, GroupName);
223 else if (url !=
string.Empty)
225 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID);
226 string accessToken = string.Empty;
227 if (membership != null)
228 accessToken = membership.AccessToken;
235 ExtendedGroupRecord grec = m_CacheWrapper.GetGroupRecord(RequestingAgentID, GroupID, GroupName, delegate
237 return c.GetGroupRecord(AgentUUIForOutside(RequestingAgentID), GroupID, GroupName, accessToken);
249 public List<DirGroupsReplyData>
FindGroups(
string RequestingAgentID,
string search)
251 return m_LocalGroupsConnector.FindGroups(AgentUUI(RequestingAgentID), search);
256 string url = string.Empty, gname = string.Empty;
257 if (IsLocal(GroupID, out url, out gname))
259 string agentID = AgentUUI(RequestingAgentID);
260 return m_LocalGroupsConnector.GetGroupMembers(agentID, GroupID);
262 else if (!
string.IsNullOrEmpty(url))
264 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID);
265 string accessToken = string.Empty;
266 if (membership != null)
267 accessToken = membership.AccessToken;
274 return m_CacheWrapper.GetGroupMembers(RequestingAgentID, GroupID, delegate
276 return c.GetGroupMembers(AgentUUIForOutside(RequestingAgentID), GroupID, accessToken);
281 return new List<GroupMembersData>();
284 public bool AddGroupRole(
string RequestingAgentID, UUID groupID, UUID roleID,
string name,
string description,
string title, ulong powers, out
string reason)
286 reason = string.Empty;
287 string url = string.Empty, gname = string.Empty;
289 if (IsLocal(groupID, out url, out gname))
290 return m_LocalGroupsConnector.AddGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers, out reason);
293 reason =
"Operation not allowed outside this group's origin world.";
298 public bool UpdateGroupRole(
string RequestingAgentID, UUID groupID, UUID roleID,
string name,
string description,
string title, ulong powers)
300 string url = string.Empty, gname = string.Empty;
302 if (IsLocal(groupID, out url, out gname))
303 return m_LocalGroupsConnector.UpdateGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers);
313 string url = string.Empty, gname = string.Empty;
315 if (IsLocal(groupID, out url, out gname))
316 m_LocalGroupsConnector.RemoveGroupRole(AgentUUI(RequestingAgentID), groupID, roleID);
323 public List<GroupRolesData>
GetGroupRoles(
string RequestingAgentID, UUID groupID)
325 string url = string.Empty, gname = string.Empty;
327 if (IsLocal(groupID, out url, out gname))
328 return m_LocalGroupsConnector.GetGroupRoles(AgentUUI(RequestingAgentID), groupID);
329 else if (!
string.IsNullOrEmpty(url))
331 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID);
332 string accessToken = string.Empty;
333 if (membership != null)
334 accessToken = membership.AccessToken;
341 return m_CacheWrapper.GetGroupRoles(RequestingAgentID, groupID, delegate
343 return c.GetGroupRoles(AgentUUIForOutside(RequestingAgentID), groupID, accessToken);
349 return new List<GroupRolesData>();
354 string url = string.Empty, gname = string.Empty;
356 if (IsLocal(groupID, out url, out gname))
357 return m_LocalGroupsConnector.GetGroupRoleMembers(AgentUUI(RequestingAgentID), groupID);
358 else if (!
string.IsNullOrEmpty(url))
360 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID);
361 string accessToken = string.Empty;
362 if (membership != null)
363 accessToken = membership.AccessToken;
370 return m_CacheWrapper.GetGroupRoleMembers(RequestingAgentID, groupID, delegate
372 return c.GetGroupRoleMembers(AgentUUIForOutside(RequestingAgentID), groupID, accessToken);
378 return new List<GroupRoleMembersData>();
381 public bool AddAgentToGroup(
string RequestingAgentID,
string AgentID, UUID GroupID, UUID RoleID,
string token, out
string reason)
383 string url = string.Empty;
384 string name = string.Empty;
385 reason = string.Empty;
388 if (IsLocal(GroupID, out url, out name))
390 if (m_UserManagement.IsLocalGridUser(uid))
393 return m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason);
398 token = UUID.Random().ToString();
399 bool success = m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason);
405 url = m_UserManagement.GetUserServerURL(uid,
"GroupsServerURI");
406 if (url ==
string.Empty)
408 reason =
"You don't have an accessible groups server in your home world. You membership to this group in only within this grid.";
414 c.CreateProxy(AgentUUI(RequestingAgentID), AgentID, token, GroupID, m_LocalGroupsServiceLocation, name, out reason);
420 else if (m_UserManagement.IsLocalGridUser(uid))
424 if (m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID) != null)
428 reason =
"Operation not allowed outside this group's origin world";
435 string url = string.Empty, name = string.Empty;
436 if (!IsLocal(GroupID, out url, out name) && url !=
string.Empty)
438 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
439 if (membership != null)
443 c.RemoveAgentFromGroup(AgentUUIForOutside(AgentID), GroupID, membership.AccessToken);
448 m_LocalGroupsConnector.RemoveAgentFromGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
451 public bool AddAgentToGroupInvite(
string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID,
string agentID)
453 string url = string.Empty, gname = string.Empty;
455 if (IsLocal(groupID, out url, out gname))
456 return m_LocalGroupsConnector.AddAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID, groupID, roleID, AgentUUI(agentID));
463 return m_LocalGroupsConnector.GetAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID); ;
468 m_LocalGroupsConnector.RemoveAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID);
473 string url = string.Empty, gname = string.Empty;
475 if (IsLocal(GroupID, out url, out gname))
476 m_LocalGroupsConnector.AddAgentToGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
482 string url = string.Empty, gname = string.Empty;
484 if (IsLocal(GroupID, out url, out gname))
485 m_LocalGroupsConnector.RemoveAgentFromGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
488 public List<GroupRolesData>
GetAgentGroupRoles(
string RequestingAgentID,
string AgentID, UUID GroupID)
490 string url = string.Empty, gname = string.Empty;
492 if (IsLocal(GroupID, out url, out gname))
493 return m_LocalGroupsConnector.GetAgentGroupRoles(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
495 return new List<GroupRolesData>();
500 string url = string.Empty, gname = string.Empty;
502 if (IsLocal(GroupID, out url, out gname))
503 m_LocalGroupsConnector.SetAgentActiveGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
508 return m_LocalGroupsConnector.GetAgentActiveMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID));
513 string url = string.Empty, gname = string.Empty;
515 if (IsLocal(GroupID, out url, out gname))
516 m_LocalGroupsConnector.SetAgentActiveGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
519 public void UpdateMembership(
string RequestingAgentID,
string AgentID, UUID GroupID,
bool AcceptNotices,
bool ListInProfile)
521 m_LocalGroupsConnector.UpdateMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, AcceptNotices, ListInProfile);
526 string url = string.Empty, gname = string.Empty;
528 if (IsLocal(GroupID, out url, out gname))
529 return m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
536 return m_LocalGroupsConnector.GetAgentGroupMemberships(AgentUUI(RequestingAgentID), AgentUUI(AgentID));
539 public bool AddGroupNotice(
string RequestingAgentID, UUID groupID, UUID noticeID,
string fromName,
string subject,
string message,
540 bool hasAttachment, byte attType,
string attName, UUID attItemID,
string attOwnerID)
542 string url = string.Empty, gname = string.Empty;
544 if (IsLocal(groupID, out url, out gname))
546 if (m_LocalGroupsConnector.AddGroupNotice(AgentUUI(RequestingAgentID), groupID, noticeID, fromName, subject, message,
547 hasAttachment, attType, attName, attItemID, AgentUUI(attOwnerID)))
550 List<GroupMembersData> members = m_LocalGroupsConnector.GetGroupMembers(AgentUUI(RequestingAgentID), groupID);
551 List<string> urls =
new List<string>();
554 if (!m_UserManagement.IsLocalGridUser(m.
AgentID))
556 string gURL = m_UserManagement.GetUserServerURL(m.AgentID,
"GroupsServerURI");
557 if (!urls.Contains(gURL))
564 WorkManager.RunInThread(delegate
566 foreach (
string u
in urls)
571 c.AddNotice(AgentUUIForOutside(RequestingAgentID), groupID, noticeID, fromName, subject, message,
572 hasAttachment, attType, attName, attItemID, AgentUUIForOutside(attOwnerID));
575 }, null, string.Format(
"AddGroupNotice (agent {0}, group {1})", RequestingAgentID, groupID));
588 GroupNoticeInfo notice = m_LocalGroupsConnector.GetGroupNotice(AgentUUI(RequestingAgentID), noticeID);
596 public List<ExtendedGroupNoticeData>
GetGroupNotices(
string RequestingAgentID, UUID GroupID)
598 return m_LocalGroupsConnector.GetGroupNotices(AgentUUI(RequestingAgentID), GroupID);
603 #region hypergrid groups
605 private string AgentUUI(
string AgentIDStr)
607 UUID AgentID = UUID.Zero;
610 AgentID =
new UUID(AgentIDStr);
612 catch (FormatException)
614 return AgentID.ToString();
617 if (m_UserManagement.IsLocalGridUser(AgentID))
618 return AgentID.ToString();
621 foreach (
Scene scene
in m_Scenes)
623 agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
628 return Util.ProduceUserUniversalIdentifier(agent);
632 return m_UserManagement.GetUserUUI(AgentID);
636 private string AgentUUIForOutside(
string AgentIDStr)
638 UUID AgentID = UUID.Zero;
641 AgentID =
new UUID(AgentIDStr);
643 catch (FormatException)
645 return AgentID.ToString();
649 foreach (
Scene scene
in m_Scenes)
651 agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
656 return AgentID.ToString();
658 return Util.ProduceUserUniversalIdentifier(agent);
661 private UUID ImportForeigner(
string uID)
663 UUID userID = UUID.Zero;
664 string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
665 if (Util.ParseUniversalUserIdentifier(uID, out userID, out url, out first, out last, out tmp))
666 m_UserManagement.AddUser(userID, first, last, url);
671 private bool IsLocal(UUID groupID, out
string serviceLocation, out
string name)
673 serviceLocation = string.Empty;
675 if (groupID.Equals(
UUID.Zero))
678 ExtendedGroupRecord group = m_LocalGroupsConnector.GetGroupRecord(UUID.Zero.ToString(), groupID,
string.Empty);
685 serviceLocation = group.ServiceLocation;
686 name = group.GroupName;
687 bool isLocal = (group.ServiceLocation == string.Empty);
692 private GroupsServiceHGConnector GetConnector(
string url)
694 lock (m_NetworkConnectors)
696 if (m_NetworkConnectors.ContainsKey(url))
697 return m_NetworkConnectors[url];
699 GroupsServiceHGConnector c =
new GroupsServiceHGConnector(url);
700 m_NetworkConnectors[url] = c;
703 return m_NetworkConnectors[url];
bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish, out string reason)
ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID)
List< DirGroupsReplyData > FindGroups(string RequestingAgentID, string search)
ExtendedGroupNoticeData noticeData
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
List< ExtendedGroupNoticeData > GetGroupNotices(string RequestingAgentID, UUID GroupID)
GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
PresenceType
Indicate the type of ScenePresence.
GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish, UUID founderID, out string reason)
void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
List< GroupRolesData > GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID)
Get information about a specific group to which the user belongs.
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
List< GroupRolesData > GetGroupRoles(string RequestingAgentID, UUID groupID)
void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
static BaseHttpServer Instance
Set the main HTTP server instance.
void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
List< GroupMembersData > GetGroupMembers(string RequestingAgentID, UUID GroupID)
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
List< GroupMembershipData > GetAgentGroupMemberships(string RequestingAgentID, string AgentID)
Get information about the groups to which a user belongs.
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
bool TryGetScenePresence(UUID agentID, out object scenePresence)
bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
uint teleportFlags
How this agent got here
This maintains the relationship between a UUID and a user name.
List< GroupRoleMembersData > GetGroupRoleMembers(string RequestingAgentID, UUID groupID)
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)