From 989517725d02d8a2d216e599856eb2625b454e25 Mon Sep 17 00:00:00 2001 From: Michael Cortez Date: Wed, 5 Aug 2009 11:15:53 -0700 Subject: [PATCH] Begin refactoring XmlRpcGroups to a more generic Groups module that allows for replaceable Groups Service Connectors. --- ...sMessaging.cs => GroupsMessagingModule.cs} | 2 +- ...{XmlRpcGroupsModule.cs => GroupsModule.cs} | 28 +- ...rovider.cs => IGroupsServicesConnector.cs} | 2 +- ...=> XmlRpcGroupsServicesConnectorModule.cs} | 283 ++++++++++++------ 4 files changed, 205 insertions(+), 110 deletions(-) rename OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/{XmlRpcGroupsMessaging.cs => GroupsMessagingModule.cs} (99%) rename OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/{XmlRpcGroupsModule.cs => GroupsModule.cs} (98%) rename OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/{IGroupDataProvider.cs => IGroupsServicesConnector.cs} (99%) rename OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/{XmlRpcGroupData.cs => XmlRpcGroupsServicesConnectorModule.cs} (91%) diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsMessaging.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs similarity index 99% rename from OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsMessaging.cs rename to OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs index 4095041d13..8fbda28b94 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsMessaging.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs @@ -46,7 +46,7 @@ using Caps = OpenSim.Framework.Capabilities.Caps; namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups { - public class XmlRpcGroupsMessaging : ISharedRegionModule + public class GroupsMessagingModule : ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs similarity index 98% rename from OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsModule.cs rename to OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs index 2cbc571aed..f0e386b7e4 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs @@ -49,7 +49,7 @@ using DirFindFlags = OpenMetaverse.DirectoryManager.DirFindFlags; namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups { - public class XmlRpcGroupsModule : ISharedRegionModule, IGroupsModule + public class GroupsModule : ISharedRegionModule, IGroupsModule { /// /// ; To use this module, you must specify the following in your OpenSim.ini @@ -78,7 +78,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups private IMessageTransferModule m_msgTransferModule = null; - private IGroupDataProvider m_groupData = null; + private IGroupsServicesConnector m_groupData = null; class GroupRequestIDInfo { @@ -91,7 +91,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups // Configuration settings - private const string m_defaultXmlRpcServiceURL = "http://osflotsam.org/xmlrpc.php"; private bool m_groupsEnabled = false; private bool m_groupNoticesEnabled = true; private bool m_debugEnabled = true; @@ -124,15 +123,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups m_log.InfoFormat("[GROUPS]: Initializing {0}", this.Name); - string ServiceURL = groupsConfig.GetString("XmlRpcServiceURL", m_defaultXmlRpcServiceURL); - bool DisableKeepAlive = groupsConfig.GetBoolean("XmlRpcDisableKeepAlive", false); - - string ServiceReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty); - string ServiceWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty); - - m_groupData = new XmlRpcGroupDataProvider(ServiceURL, DisableKeepAlive, ServiceReadKey, ServiceWriteKey); - m_log.InfoFormat("[GROUPS]: XmlRpc Service URL set to: {0}", ServiceURL); - m_groupNoticesEnabled = groupsConfig.GetBoolean("XmlRpcNoticesEnabled", true); m_debugEnabled = groupsConfig.GetBoolean("XmlRpcDebugEnabled", true); @@ -172,6 +162,20 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); + if (m_groupData == null) + { + m_groupData = scene.RequestModuleInterface(); + + // No Groups Service Connector, then nothing works... + if (m_groupData == null) + { + m_groupsEnabled = false; + m_log.Error("[GROUPS]: Could not get IGroupsServicesConnector"); + Close(); + return; + } + } + if (m_msgTransferModule == null) { m_msgTransferModule = scene.RequestModuleInterface(); diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupDataProvider.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupsServicesConnector.cs similarity index 99% rename from OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupDataProvider.cs rename to OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupsServicesConnector.cs index 302be4a213..9e0fa2de4a 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupDataProvider.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/IGroupsServicesConnector.cs @@ -34,7 +34,7 @@ using OpenSim.Framework; namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups { - interface IGroupDataProvider + interface IGroupsServicesConnector { UUID CreateGroup(GroupRequestID requestID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish, UUID founderID); void UpdateGroup(GroupRequestID requestID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish); diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs similarity index 91% rename from OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs rename to OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs index 1d4cde5ca3..03fe109c30 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs @@ -29,27 +29,25 @@ using System; using System.Collections; using System.Collections.Generic; using System.Reflection; -//using System.Text; using Nwc.XmlRpc; using log4net; -// using Nini.Config; +using Nini.Config; using OpenMetaverse; using OpenMetaverse.StructuredData; using OpenSim.Framework; -//using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Interfaces; namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups { - public class XmlRpcGroupDataProvider : IGroupDataProvider + public class XmlRpcGroupsServicesConnectorModule : ISharedRegionModule, IGroupsServicesConnector { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private string m_serviceURL = string.Empty; public const GroupPowers m_DefaultEveryonePowers = GroupPowers.AllowSetHome | GroupPowers.Accountable | @@ -59,26 +57,108 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups GroupPowers.StartProposal | GroupPowers.VoteOnProposal; + private bool m_connectorEnabled = false; + + private string m_serviceURL = string.Empty; + private bool m_disableKeepAlive = false; private string m_groupReadKey = string.Empty; private string m_groupWriteKey = string.Empty; - public XmlRpcGroupDataProvider(string serviceURL, bool disableKeepAlive, string groupReadKey, string groupWriteKey) + + #region IRegionModuleBase Members + + public string Name { - m_serviceURL = serviceURL.Trim(); - m_disableKeepAlive = disableKeepAlive; - - if ((serviceURL == null) || - (serviceURL == string.Empty)) - { - throw new Exception("Please specify a valid ServiceURL for XmlRpcGroupDataProvider in OpenSim.ini, [Groups], XmlRpcServiceURL"); - } - - m_groupReadKey = groupReadKey; - m_groupWriteKey = groupWriteKey; + get { return "XmlRpcGroupsServicesConnector"; } } + // this module is not intended to be replaced, but there should only be 1 of them. + public Type ReplacableInterface + { + get { return null; } + } + + public void Initialise(IConfigSource config) + { + IConfig groupsConfig = config.Configs["Groups"]; + + if (groupsConfig == null) + { + // Do not run this module by default. + return; + } + else + { + // if groups aren't enabled, we're not needed. + // if we're not specified as the connector to use, then we're not wanted + if ( (groupsConfig.GetBoolean("Enabled", false) == false) + || (groupsConfig.GetString("GroupsServicesConnectorModule", "Default") != Name)) + { + m_connectorEnabled = false; + return; + } + + m_log.InfoFormat("[GROUPS-CONNECTOR]: Initializing {0}", this.Name); + + m_serviceURL = groupsConfig.GetString("XmlRpcServiceURL", string.Empty); + if ((m_serviceURL == null) || + (m_serviceURL == string.Empty)) + { + m_log.ErrorFormat("Please specify a valid URL for XmlRpcServiceURL in OpenSim.ini, [Groups]"); + m_connectorEnabled = false; + return; + } + + m_disableKeepAlive = groupsConfig.GetBoolean("XmlRpcDisableKeepAlive", false); + + m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty); + m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty); + + // If we got all the config options we need, lets start'er'up + m_connectorEnabled = true; + } + } + + public void Close() + { + m_log.InfoFormat("[GROUPS-CONNECTOR]: Closing {0}", this.Name); + } + + public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) + { + if (m_connectorEnabled) + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(OpenSim.Region.Framework.Scenes.Scene scene) + { + if (scene.RequestModuleInterface() == this) + scene.UnregisterModuleInterface(this); + } + + public void RegionLoaded(OpenSim.Region.Framework.Scenes.Scene scene) + { + // TODO: May want to consider listenning for Agent Connections so we can pre-cache group info + // scene.EventManager.OnNewClient += OnNewClient; + } + + #endregion + + #region ISharedRegionModule Members + + public void PostInitialise() + { + // NoOp + } + + #endregion + + + + #region IGroupsServicesConnector Members + /// /// Create a Group, including Everyone and Owners Role, place FounderID in both groups, select Owner as selected role, and newly created group as agent's active role. /// @@ -275,53 +355,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups } - private GroupProfileData GroupProfileHashtableToGroupProfileData(Hashtable groupProfile) - { - GroupProfileData group = new GroupProfileData(); - group.GroupID = UUID.Parse((string)groupProfile["GroupID"]); - group.Name = (string)groupProfile["Name"]; - if (groupProfile["Charter"] != null) - { - group.Charter = (string)groupProfile["Charter"]; - } - - group.ShowInList = ((string)groupProfile["ShowInList"]) == "1"; - group.InsigniaID = UUID.Parse((string)groupProfile["InsigniaID"]); - group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]); - group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1"; - group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1"; - group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1"; - group.FounderID = UUID.Parse((string)groupProfile["FounderID"]); - group.OwnerRole = UUID.Parse((string)groupProfile["OwnerRoleID"]); - - group.GroupMembershipCount = int.Parse((string)groupProfile["GroupMembershipCount"]); - group.GroupRolesCount = int.Parse((string)groupProfile["GroupRolesCount"]); - - return group; - } - - private GroupRecord GroupProfileHashtableToGroupRecord(Hashtable groupProfile) - { - - GroupRecord group = new GroupRecord(); - group.GroupID = UUID.Parse((string)groupProfile["GroupID"]); - group.GroupName = groupProfile["Name"].ToString(); - if (groupProfile["Charter"] != null) - { - group.Charter = (string)groupProfile["Charter"]; - } - group.ShowInList = ((string)groupProfile["ShowInList"]) == "1"; - group.GroupPicture = UUID.Parse((string)groupProfile["InsigniaID"]); - group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]); - group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1"; - group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1"; - group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1"; - group.FounderID = UUID.Parse((string)groupProfile["FounderID"]); - group.OwnerRoleID = UUID.Parse((string)groupProfile["OwnerRoleID"]); - - return group; - } public void SetAgentActiveGroup(GroupRequestID requestID, UUID AgentID, UUID GroupID) { @@ -579,40 +613,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups } - private static GroupMembershipData HashTableToGroupMembershipData(Hashtable respData) - { - GroupMembershipData data = new GroupMembershipData(); - data.AcceptNotices = ((string)respData["AcceptNotices"] == "1"); - data.Contribution = int.Parse((string)respData["Contribution"]); - data.ListInProfile = ((string)respData["ListInProfile"] == "1"); - data.ActiveRole = new UUID((string)respData["SelectedRoleID"]); - data.GroupTitle = (string)respData["Title"]; - - data.GroupPowers = ulong.Parse((string)respData["GroupPowers"]); - - // Is this group the agent's active group - - data.GroupID = new UUID((string)respData["GroupID"]); - - UUID ActiveGroup = new UUID((string)respData["ActiveGroupID"]); - data.Active = data.GroupID.Equals(ActiveGroup); - - data.AllowPublish = ((string)respData["AllowPublish"] == "1"); - if (respData["Charter"] != null) - { - data.Charter = (string)respData["Charter"]; - } - data.FounderID = new UUID((string)respData["FounderID"]); - data.GroupID = new UUID((string)respData["GroupID"]); - data.GroupName = (string)respData["GroupName"]; - data.GroupPicture = new UUID((string)respData["InsigniaID"]); - data.MaturePublish = ((string)respData["MaturePublish"] == "1"); - data.MembershipFee = int.Parse((string)respData["MembershipFee"]); - data.OpenEnrollment = ((string)respData["OpenEnrollment"] == "1"); - data.ShowInList = ((string)respData["ShowInList"] == "1"); - return data; - } public List GetGroupMembers(GroupRequestID requestID, UUID GroupID) { @@ -744,7 +745,96 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups XmlRpcCall(requestID, "groups.addGroupNotice", param); } + #endregion + #region XmlRpcHashtableMarshalling + private GroupProfileData GroupProfileHashtableToGroupProfileData(Hashtable groupProfile) + { + GroupProfileData group = new GroupProfileData(); + group.GroupID = UUID.Parse((string)groupProfile["GroupID"]); + group.Name = (string)groupProfile["Name"]; + + if (groupProfile["Charter"] != null) + { + group.Charter = (string)groupProfile["Charter"]; + } + + group.ShowInList = ((string)groupProfile["ShowInList"]) == "1"; + group.InsigniaID = UUID.Parse((string)groupProfile["InsigniaID"]); + group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]); + group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1"; + group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1"; + group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1"; + group.FounderID = UUID.Parse((string)groupProfile["FounderID"]); + group.OwnerRole = UUID.Parse((string)groupProfile["OwnerRoleID"]); + + group.GroupMembershipCount = int.Parse((string)groupProfile["GroupMembershipCount"]); + group.GroupRolesCount = int.Parse((string)groupProfile["GroupRolesCount"]); + + return group; + } + + private GroupRecord GroupProfileHashtableToGroupRecord(Hashtable groupProfile) + { + + GroupRecord group = new GroupRecord(); + group.GroupID = UUID.Parse((string)groupProfile["GroupID"]); + group.GroupName = groupProfile["Name"].ToString(); + if (groupProfile["Charter"] != null) + { + group.Charter = (string)groupProfile["Charter"]; + } + group.ShowInList = ((string)groupProfile["ShowInList"]) == "1"; + group.GroupPicture = UUID.Parse((string)groupProfile["InsigniaID"]); + group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]); + group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1"; + group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1"; + group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1"; + group.FounderID = UUID.Parse((string)groupProfile["FounderID"]); + group.OwnerRoleID = UUID.Parse((string)groupProfile["OwnerRoleID"]); + + return group; + } + private static GroupMembershipData HashTableToGroupMembershipData(Hashtable respData) + { + GroupMembershipData data = new GroupMembershipData(); + data.AcceptNotices = ((string)respData["AcceptNotices"] == "1"); + data.Contribution = int.Parse((string)respData["Contribution"]); + data.ListInProfile = ((string)respData["ListInProfile"] == "1"); + + data.ActiveRole = new UUID((string)respData["SelectedRoleID"]); + data.GroupTitle = (string)respData["Title"]; + + data.GroupPowers = ulong.Parse((string)respData["GroupPowers"]); + + // Is this group the agent's active group + + data.GroupID = new UUID((string)respData["GroupID"]); + + UUID ActiveGroup = new UUID((string)respData["ActiveGroupID"]); + data.Active = data.GroupID.Equals(ActiveGroup); + + data.AllowPublish = ((string)respData["AllowPublish"] == "1"); + if (respData["Charter"] != null) + { + data.Charter = (string)respData["Charter"]; + } + data.FounderID = new UUID((string)respData["FounderID"]); + data.GroupID = new UUID((string)respData["GroupID"]); + data.GroupName = (string)respData["GroupName"]; + data.GroupPicture = new UUID((string)respData["InsigniaID"]); + data.MaturePublish = ((string)respData["MaturePublish"] == "1"); + data.MembershipFee = int.Parse((string)respData["MembershipFee"]); + data.OpenEnrollment = ((string)respData["OpenEnrollment"] == "1"); + data.ShowInList = ((string)respData["ShowInList"] == "1"); + return data; + } + + #endregion + + /// + /// Encapsulate the XmlRpc call to standardize security and error handling. + /// private Hashtable XmlRpcCall(GroupRequestID requestID, string function, Hashtable param) { if (requestID == null) @@ -846,6 +936,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups } } + } public class GroupNoticeInfo