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/Region/Framework/Scenes/Scene.cs | 119 +++++++++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/Scene.cs') 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)) -- cgit v1.1