From 19d90af82d26e424171761f411cca7cede8738a9 Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 31 Jul 2019 20:22:55 +1000 Subject: Automatically add members to certain groups, and HGers from specific grids to certain other groups. It doesn't let them know, though the last group added will be their active group. This replaces a PHP script I used to use, that got broken by a PHP update. It also didn't let people know, no one complained. This is better. --- OpenSim/Addons/Groups/GroupsModule.cs | 9 ++ .../Region/Framework/Interfaces/IGroupsModule.cs | 1 + OpenSim/Region/Framework/Scenes/Scene.cs | 119 +++++++++++++++++++-- .../Avatar/XmlRpcGroups/GroupsModule.cs | 7 ++ 4 files changed, 130 insertions(+), 6 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Addons/Groups/GroupsModule.cs b/OpenSim/Addons/Groups/GroupsModule.cs index 5b76e0a..a4030aa 100644 --- a/OpenSim/Addons/Groups/GroupsModule.cs +++ b/OpenSim/Addons/Groups/GroupsModule.cs @@ -1015,6 +1015,15 @@ namespace OpenSim.Groups remoteClient.SendJoinGroupReply(groupID, false); } + public void JoinGroup(string agentID, UUID groupID) + { + string reason = string.Empty; + m_groupData.AddAgentToGroup(agentID, agentID, groupID, UUID.Zero, string.Empty, out reason); + if (reason != string.Empty) + // A warning + m_log.Warn("[Groups]: Join group warning - " + reason); + } + public void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID) { if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); diff --git a/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs b/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs index 0d1f4f4..61db1b8 100644 --- a/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs @@ -92,6 +92,7 @@ namespace OpenSim.Region.Framework.Interfaces GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog); void SendAgentGroupDataUpdate(IClientAPI remoteClient); void JoinGroupRequest(IClientAPI remoteClient, UUID GroupID); + void JoinGroup(string agentID, UUID GroupID); void LeaveGroupRequest(IClientAPI remoteClient, UUID GroupID); void EjectGroupMemberRequest(IClientAPI remoteClient, UUID GroupID, UUID EjecteeID); void EjectGroupMember(IClientAPI remoteClient, UUID agentID, UUID GroupID, UUID EjecteeID); diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index f3b76c8..b0a7300 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -334,6 +334,9 @@ namespace OpenSim.Region.Framework.Scenes protected ICapabilitiesModule m_capsModule; protected IGroupsModule m_groupsModule; + // The lists of groups to automatically add to logging in users. + private Dictionary m_AutoGroups; + private Dictionary m_extraSettings; /// @@ -1137,6 +1140,50 @@ namespace OpenSim.Region.Framework.Scenes #endregion Interest Management + #region Group + + IConfig groupsConfig = m_config.Configs["Groups"]; + m_AutoGroups = new Dictionary(); + if (groupsConfig != null) + { + string groups = groupsConfig.GetString("AddDefaultGroup", string.Empty); + if (groups.Length > 0) + { + try + { + m_AutoGroups.Add("local", groups.Split('|')); + } + catch (ArgumentException) + { + m_log.Warn("[SCENE]: Duplicated AddDefaultGroup option."); + } + } + string[] keys = groupsConfig.GetKeys(); + if (0 < keys.Length) + { + foreach (string k in keys) + { + if (k.StartsWith("AddHGDefaultGroup_")) + { + groups = groupsConfig.GetString(k, string.Empty); + if (groups.Length > 0) + { + try + { + m_AutoGroups.Add(k.Substring(18), groups.Split('|')); + } + catch (ArgumentException) + { + m_log.WarnFormat("[SCENE]: Duplicated {0} option.", k); + } + } + } + } + } + } + + #endregion Group + StatsReporter = new SimStatsReporter(this); StatsReporter.OnSendStatsResult += SendSimStatsPackets; @@ -4346,6 +4393,72 @@ namespace OpenSim.Region.Framework.Scenes return false; } + List agentGroups = new List(); + GroupMembershipData[] GroupMembership = m_groupsModule.GetMembershipData(agent.AgentID); + + if (null != GroupMembership) + { + for(int i = 0;i < GroupMembership.Length;i++) + agentGroups.Add(GroupMembership[i].GroupID); + // We get called twice, the first time the name is set to a single space. +// if (" " != agent.Name) + { + try + { + // Check for auto add groups here and add them if needed. + if (UserManagementModule.IsLocalGridUser(agent.AgentID)) + { + string[] groupIDs = m_AutoGroups["local"]; + foreach(string name in groupIDs) + { + GroupRecord g = m_groupsModule.GetGroupRecord(name); + if (null != g) + { + UUID group = g.GroupID; + if(!agentGroups.Contains(group)) + { + m_groupsModule.JoinGroup(agent.AgentID.ToString(), group); + agentGroups.Add(group); + m_log.InfoFormat("[CONNECTION BEGIN]: Automatically added {0} to group {1}.", agent.AgentID, name); + } + } + else + m_log.ErrorFormat("[CONNECTION BEGIN]: Bogus group {0}, not adding {1}.", name, agent.AgentID); + } + } + else + { + // agent.AgentID should look like this - @grid.com:8002 01234567-89ab-cdef-0123-456789abcdef + string grid = agent.AgentID.ToString().Split(':')[0]; + grid = grid.Substring(1); + m_log.InfoFormat("[CONNECTION BEGIN]: HYPERGRID agent {0} from grid {1}, checking auto groups.", agent.AgentID, grid); + string[] groupIDs = m_AutoGroups[grid]; + foreach(string name in groupIDs) + { + GroupRecord g = m_groupsModule.GetGroupRecord(name); + if (null != g) + { + UUID group = g.GroupID; + if(!agentGroups.Contains(group)) + { + m_groupsModule.JoinGroup(agent.AgentID.ToString(), group); + agentGroups.Add(group); + m_log.InfoFormat("[CONNECTION BEGIN]: Automatically added HYPERGRIDDER {0} @ {1} to group {2}.", agent.AgentID, grid, name); + } + } + else + m_log.ErrorFormat("[CONNECTION BEGIN]: Bogus group {0} for HYPERGRIDDERS, not adding {1}.", name, agent.AgentID); + } + } + } + catch (KeyNotFoundException) + { + // Do nothing. + } + + } + } + // public access if (RegionInfo.EstateSettings.PublicAccess) return true; @@ -4372,9 +4485,6 @@ namespace OpenSim.Region.Framework.Scenes if(estateGroups.Length == 0) goto Label_GroupsDone; - List agentGroups = new List(); - GroupMembershipData[] GroupMembership = m_groupsModule.GetMembershipData(agent.AgentID); - if(GroupMembership == null) { m_log.ErrorFormat("[CONNECTION BEGIN]: GroupMembership is null!"); @@ -4384,9 +4494,6 @@ namespace OpenSim.Region.Framework.Scenes if(GroupMembership.Length == 0) goto Label_GroupsDone; - for(int i = 0;i < GroupMembership.Length;i++) - agentGroups.Add(GroupMembership[i].GroupID); - foreach(UUID group in estateGroups) { if(agentGroups.Contains(group)) diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs index 65d50bb..20b7c5e 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs @@ -1113,6 +1113,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups SendAgentGroupDataUpdate(remoteClient, true); } + public void JoinGroup(string agentID, UUID groupID) + { + // Should check to see if OpenEnrollment, or if there's an outstanding invitation + UUID u = new UUID(agentID); + m_groupData.AddAgentToGroup(u, u, groupID, UUID.Zero); + } + public void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID) { if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); -- cgit v1.1