2009-04-21 15:30:03 +00:00
/ *
* Copyright ( c ) Contributors , http : //opensimulator.org/
* See CONTRIBUTORS . TXT for a full list of copyright holders .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
2009-06-01 06:37:14 +00:00
* * Neither the name of the OpenSimulator Project nor the
2009-04-21 15:30:03 +00:00
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ` ` AS IS ' ' AND ANY
* EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED . IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
* ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
* LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Reflection ;
2010-05-06 15:38:23 +00:00
using System.Text ;
2009-04-21 15:30:03 +00:00
using Nwc.XmlRpc ;
using log4net ;
2009-08-05 20:20:46 +00:00
using Mono.Addins ;
2009-08-05 18:15:53 +00:00
using Nini.Config ;
2009-04-21 15:30:03 +00:00
using OpenMetaverse ;
using OpenMetaverse.StructuredData ;
using OpenSim.Framework ;
2009-08-05 18:15:53 +00:00
using OpenSim.Region.Framework.Interfaces ;
2010-04-02 13:53:10 +00:00
using OpenSim.Services.Interfaces ;
2009-04-21 15:30:03 +00:00
namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
{
2012-11-13 02:08:02 +00:00
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XmlRpcGroupsServicesConnectorModule")]
2009-08-05 18:15:53 +00:00
public class XmlRpcGroupsServicesConnectorModule : ISharedRegionModule , IGroupsServicesConnector
2009-04-21 15:30:03 +00:00
{
2010-03-25 23:53:05 +00:00
private static readonly ILog m_log = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2009-04-21 15:30:03 +00:00
2011-12-16 20:53:50 +00:00
private bool m_debugEnabled = false ;
2017-01-05 19:07:37 +00:00
public const GroupPowers DefaultEveryonePowers
= GroupPowers . AllowSetHome
| GroupPowers . Accountable
| GroupPowers . JoinChat
| GroupPowers . AllowVoiceChat
| GroupPowers . ReceiveNotices
| GroupPowers . StartProposal
2012-11-24 02:43:31 +00:00
| GroupPowers . VoteOnProposal ;
// Would this be cleaner as (GroupPowers)ulong.MaxValue?
2017-01-05 19:07:37 +00:00
public const GroupPowers DefaultOwnerPowers
2012-11-24 02:43:31 +00:00
= GroupPowers . Accountable
| GroupPowers . AllowEditLand
| GroupPowers . AllowFly
| GroupPowers . AllowLandmark
| GroupPowers . AllowRez
| GroupPowers . AllowSetHome
| GroupPowers . AllowVoiceChat
| GroupPowers . AssignMember
| GroupPowers . AssignMemberLimited
| GroupPowers . ChangeActions
| GroupPowers . ChangeIdentity
| GroupPowers . ChangeMedia
| GroupPowers . ChangeOptions
| GroupPowers . CreateRole
| GroupPowers . DeedObject
| GroupPowers . DeleteRole
| GroupPowers . Eject
| GroupPowers . FindPlaces
| GroupPowers . Invite
| GroupPowers . JoinChat
| GroupPowers . LandChangeIdentity
| GroupPowers . LandDeed
| GroupPowers . LandDivideJoin
| GroupPowers . LandEdit
| GroupPowers . LandEjectAndFreeze
| GroupPowers . LandGardening
| GroupPowers . LandManageAllowed
| GroupPowers . LandManageBanned
| GroupPowers . LandManagePasses
| GroupPowers . LandOptions
| GroupPowers . LandRelease
| GroupPowers . LandSetSale
| GroupPowers . ModerateChat
| GroupPowers . ObjectManipulate
| GroupPowers . ObjectSetForSale
| GroupPowers . ReceiveNotices
| GroupPowers . RemoveMember
| GroupPowers . ReturnGroupOwned
| GroupPowers . ReturnGroupSet
| GroupPowers . ReturnNonGroup
| GroupPowers . RoleProperties
| GroupPowers . SendNotices
| GroupPowers . SetLandingPoint
| GroupPowers . StartProposal
| GroupPowers . VoteOnProposal ;
2009-04-21 15:30:03 +00:00
2009-08-05 18:15:53 +00:00
private bool m_connectorEnabled = false ;
2010-05-06 15:38:23 +00:00
private string m_groupsServerURI = string . Empty ;
2009-08-05 18:15:53 +00:00
2015-12-19 15:24:43 +00:00
private bool m_disableKeepAlive = true ;
2009-04-21 20:44:17 +00:00
2009-04-29 22:31:00 +00:00
private string m_groupReadKey = string . Empty ;
private string m_groupWriteKey = string . Empty ;
2010-04-06 02:56:03 +00:00
private IUserAccountService m_accountService = null ;
2010-05-06 15:38:23 +00:00
private ExpiringCache < string , XmlRpcResponse > m_memoryCache ;
private int m_cacheTimeout = 30 ;
// Used to track which agents are have dropped from a group chat session
// Should be reset per agent, on logon
// TODO: move this to Flotsam XmlRpc Service
// SessionID, List<AgentID>
private Dictionary < UUID , List < UUID > > m_groupsAgentsDroppedFromChatSession = new Dictionary < UUID , List < UUID > > ( ) ;
private Dictionary < UUID , List < UUID > > m_groupsAgentsInvitedToChatSession = new Dictionary < UUID , List < UUID > > ( ) ;
2012-11-12 19:18:20 +00:00
#region Region Module interfaceBase Members
2009-08-05 18:15:53 +00:00
public string Name
{
get { return "XmlRpcGroupsServicesConnector" ; }
}
// this module is not intended to be replaced, but there should only be 1 of them.
2009-08-10 22:08:22 +00:00
public Type ReplaceableInterface
2009-04-21 15:30:03 +00:00
{
2009-08-05 18:15:53 +00:00
get { return null ; }
}
2009-04-21 20:44:17 +00:00
2009-08-05 18:15:53 +00:00
public void Initialise ( IConfigSource config )
{
IConfig groupsConfig = config . Configs [ "Groups" ] ;
if ( groupsConfig = = null )
2009-04-21 20:44:17 +00:00
{
2009-08-05 18:15:53 +00:00
// Do not run this module by default.
return ;
2009-04-21 20:44:17 +00:00
}
2009-08-05 18:15:53 +00:00
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
2009-08-08 15:43:13 +00:00
if ( ( groupsConfig . GetBoolean ( "Enabled" , false ) = = false )
2011-06-13 13:09:03 +00:00
| | ( groupsConfig . GetString ( "ServicesConnectorModule" , "XmlRpcGroupsServicesConnector" ) ! = Name ) )
2009-08-05 18:15:53 +00:00
{
m_connectorEnabled = false ;
return ;
}
2011-12-16 20:53:50 +00:00
m_log . DebugFormat ( "[XMLRPC-GROUPS-CONNECTOR]: Initializing {0}" , this . Name ) ;
2010-04-06 02:56:03 +00:00
2010-05-06 15:38:23 +00:00
m_groupsServerURI = groupsConfig . GetString ( "GroupsServerURI" , string . Empty ) ;
2013-11-15 21:45:08 +00:00
if ( string . IsNullOrEmpty ( m_groupsServerURI ) )
2010-04-06 02:56:03 +00:00
{
2010-05-06 15:38:23 +00:00
m_log . ErrorFormat ( "Please specify a valid URL for GroupsServerURI in OpenSim.ini, [Groups]" ) ;
2009-08-05 18:15:53 +00:00
m_connectorEnabled = false ;
return ;
}
2015-12-19 15:24:43 +00:00
m_disableKeepAlive = groupsConfig . GetBoolean ( "XmlRpcDisableKeepAlive" , true ) ;
2009-04-29 22:31:00 +00:00
2009-08-05 18:15:53 +00:00
m_groupReadKey = groupsConfig . GetString ( "XmlRpcServiceReadKey" , string . Empty ) ;
m_groupWriteKey = groupsConfig . GetString ( "XmlRpcServiceWriteKey" , string . Empty ) ;
2010-05-06 15:38:23 +00:00
m_cacheTimeout = groupsConfig . GetInt ( "GroupsCacheTimeout" , 30 ) ;
2016-07-01 15:24:42 +00:00
2010-05-06 15:38:23 +00:00
if ( m_cacheTimeout = = 0 )
{
m_log . WarnFormat ( "[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Disabled." ) ;
}
else
{
m_log . InfoFormat ( "[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Timeout set to {0}." , m_cacheTimeout ) ;
}
2010-04-02 13:53:10 +00:00
2011-12-16 20:53:50 +00:00
m_debugEnabled = groupsConfig . GetBoolean ( "DebugEnabled" , false ) ;
2009-08-05 18:15:53 +00:00
// If we got all the config options we need, lets start'er'up
2010-05-06 15:38:23 +00:00
m_memoryCache = new ExpiringCache < string , XmlRpcResponse > ( ) ;
2009-08-05 18:15:53 +00:00
m_connectorEnabled = true ;
}
}
public void Close ( )
{
2009-04-21 15:30:03 +00:00
}
2009-08-05 18:15:53 +00:00
public void AddRegion ( OpenSim . Region . Framework . Scenes . Scene scene )
{
if ( m_connectorEnabled )
2010-04-02 13:53:10 +00:00
{
if ( m_accountService = = null )
{
m_accountService = scene . UserAccountService ;
}
2009-08-05 18:15:53 +00:00
scene . RegisterModuleInterface < IGroupsServicesConnector > ( this ) ;
2010-04-02 13:53:10 +00:00
}
2009-08-05 18:15:53 +00:00
}
public void RemoveRegion ( OpenSim . Region . Framework . Scenes . Scene scene )
{
if ( scene . RequestModuleInterface < IGroupsServicesConnector > ( ) = = this )
2010-04-02 13:53:10 +00:00
{
2009-08-05 18:15:53 +00:00
scene . UnregisterModuleInterface < IGroupsServicesConnector > ( this ) ;
2010-04-02 13:53:10 +00:00
}
2009-08-05 18:15:53 +00:00
}
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
2009-04-21 15:30:03 +00:00
/// <summary>
/// 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.
/// </summary>
2012-07-29 21:02:10 +00:00
public UUID CreateGroup ( UUID requestingAgentID , string name , string charter , bool showInList , UUID insigniaID ,
int membershipFee , bool openEnrollment , bool allowPublish ,
2009-04-22 18:00:59 +00:00
bool maturePublish , UUID founderID )
2009-04-21 15:30:03 +00:00
{
UUID GroupID = UUID . Random ( ) ;
UUID OwnerRoleID = UUID . Random ( ) ;
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
param [ "Name" ] = name ;
param [ "Charter" ] = charter ;
param [ "ShowInList" ] = showInList = = true ? 1 : 0 ;
param [ "InsigniaID" ] = insigniaID . ToString ( ) ;
2012-07-29 21:02:10 +00:00
param [ "MembershipFee" ] = membershipFee ;
2009-04-21 15:30:03 +00:00
param [ "OpenEnrollment" ] = openEnrollment = = true ? 1 : 0 ;
param [ "AllowPublish" ] = allowPublish = = true ? 1 : 0 ;
param [ "MaturePublish" ] = maturePublish = = true ? 1 : 0 ;
param [ "FounderID" ] = founderID . ToString ( ) ;
2012-11-24 02:43:31 +00:00
param [ "EveryonePowers" ] = ( ( ulong ) DefaultEveryonePowers ) . ToString ( ) ;
2009-04-21 15:30:03 +00:00
param [ "OwnerRoleID" ] = OwnerRoleID . ToString ( ) ;
2012-11-24 02:43:31 +00:00
param [ "OwnersPowers" ] = ( ( ulong ) DefaultOwnerPowers ) . ToString ( ) ;
2009-04-29 22:31:00 +00:00
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.createGroup" , param ) ;
2009-04-21 15:30:03 +00:00
if ( respData . Contains ( "error" ) )
{
2009-04-21 20:44:17 +00:00
// UUID is not nullable
2009-04-25 18:58:18 +00:00
2009-04-21 20:44:17 +00:00
return UUID . Zero ;
2009-04-21 15:30:03 +00:00
}
return UUID . Parse ( ( string ) respData [ "GroupID" ] ) ;
}
2012-07-29 21:02:10 +00:00
public void UpdateGroup ( UUID requestingAgentID , UUID groupID , string charter , bool showInList ,
UUID insigniaID , int membershipFee , bool openEnrollment ,
2009-04-22 18:00:59 +00:00
bool allowPublish , bool maturePublish )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = groupID . ToString ( ) ;
param [ "Charter" ] = charter ;
param [ "ShowInList" ] = showInList = = true ? 1 : 0 ;
param [ "InsigniaID" ] = insigniaID . ToString ( ) ;
param [ "MembershipFee" ] = membershipFee ;
param [ "OpenEnrollment" ] = openEnrollment = = true ? 1 : 0 ;
param [ "AllowPublish" ] = allowPublish = = true ? 1 : 0 ;
param [ "MaturePublish" ] = maturePublish = = true ? 1 : 0 ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.updateGroup" , param ) ;
2009-04-21 15:30:03 +00:00
}
2012-07-29 21:02:10 +00:00
public void AddGroupRole ( UUID requestingAgentID , UUID groupID , UUID roleID , string name , string description ,
2009-04-22 18:00:59 +00:00
string title , ulong powers )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = groupID . ToString ( ) ;
param [ "RoleID" ] = roleID . ToString ( ) ;
param [ "Name" ] = name ;
param [ "Description" ] = description ;
param [ "Title" ] = title ;
param [ "Powers" ] = powers . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.addRoleToGroup" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public void RemoveGroupRole ( UUID requestingAgentID , UUID groupID , UUID roleID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = groupID . ToString ( ) ;
param [ "RoleID" ] = roleID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.removeRoleFromGroup" , param ) ;
2009-04-21 15:30:03 +00:00
}
2012-07-29 21:02:10 +00:00
public void UpdateGroupRole ( UUID requestingAgentID , UUID groupID , UUID roleID , string name , string description ,
2009-04-22 18:00:59 +00:00
string title , ulong powers )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = groupID . ToString ( ) ;
param [ "RoleID" ] = roleID . ToString ( ) ;
if ( name ! = null )
{
param [ "Name" ] = name ;
}
if ( description ! = null )
{
param [ "Description" ] = description ;
}
if ( title ! = null )
{
param [ "Title" ] = title ;
}
param [ "Powers" ] = powers . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.updateGroupRole" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public GroupRecord GetGroupRecord ( UUID requestingAgentID , UUID GroupID , string GroupName )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
2009-04-29 18:11:41 +00:00
if ( GroupID ! = UUID . Zero )
2009-04-21 15:30:03 +00:00
{
param [ "GroupID" ] = GroupID . ToString ( ) ;
}
2013-11-15 21:45:08 +00:00
if ( ! string . IsNullOrEmpty ( GroupName ) )
2009-04-21 15:30:03 +00:00
{
param [ "Name" ] = GroupName . ToString ( ) ;
}
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getGroup" , param ) ;
2009-04-21 15:30:03 +00:00
if ( respData . Contains ( "error" ) )
{
return null ;
}
return GroupProfileHashtableToGroupRecord ( respData ) ;
2009-04-29 22:31:00 +00:00
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public GroupProfileData GetMemberGroupProfile ( UUID requestingAgentID , UUID GroupID , UUID AgentID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getGroup" , param ) ;
2009-04-21 15:30:03 +00:00
if ( respData . Contains ( "error" ) )
{
2009-04-21 20:44:17 +00:00
// GroupProfileData is not nullable
2009-04-21 15:30:03 +00:00
return new GroupProfileData ( ) ;
}
2010-04-02 13:53:10 +00:00
GroupMembershipData MemberInfo = GetAgentGroupMembership ( requestingAgentID , AgentID , GroupID ) ;
2009-04-21 15:30:03 +00:00
GroupProfileData MemberGroupProfile = GroupProfileHashtableToGroupProfileData ( respData ) ;
2016-07-01 22:26:16 +00:00
if ( MemberInfo ! = null )
{
MemberGroupProfile . MemberTitle = MemberInfo . GroupTitle ;
MemberGroupProfile . PowersMask = MemberInfo . GroupPowers ;
}
2009-04-21 15:30:03 +00:00
return MemberGroupProfile ;
}
2010-04-02 13:53:10 +00:00
public void SetAgentActiveGroup ( UUID requestingAgentID , UUID AgentID , UUID GroupID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.setAgentActiveGroup" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public void SetAgentActiveGroupRole ( UUID requestingAgentID , UUID AgentID , UUID GroupID , UUID RoleID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
param [ "SelectedRoleID" ] = RoleID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.setAgentGroupInfo" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public void SetAgentGroupInfo ( UUID requestingAgentID , UUID AgentID , UUID GroupID , bool AcceptNotices , bool ListInProfile )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
param [ "AcceptNotices" ] = AcceptNotices ? "1" : "0" ;
param [ "ListInProfile" ] = ListInProfile ? "1" : "0" ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.setAgentGroupInfo" , param ) ;
2009-04-29 22:31:00 +00:00
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public void AddAgentToGroupInvite ( UUID requestingAgentID , UUID inviteID , UUID groupID , UUID roleID , UUID agentID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "InviteID" ] = inviteID . ToString ( ) ;
param [ "AgentID" ] = agentID . ToString ( ) ;
param [ "RoleID" ] = roleID . ToString ( ) ;
param [ "GroupID" ] = groupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.addAgentToGroupInvite" , param ) ;
2009-04-29 22:31:00 +00:00
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public GroupInviteInfo GetAgentToGroupInvite ( UUID requestingAgentID , UUID inviteID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "InviteID" ] = inviteID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getAgentToGroupInvite" , param ) ;
2009-04-21 15:30:03 +00:00
if ( respData . Contains ( "error" ) )
{
return null ;
}
GroupInviteInfo inviteInfo = new GroupInviteInfo ( ) ;
inviteInfo . InviteID = inviteID ;
inviteInfo . GroupID = UUID . Parse ( ( string ) respData [ "GroupID" ] ) ;
inviteInfo . RoleID = UUID . Parse ( ( string ) respData [ "RoleID" ] ) ;
inviteInfo . AgentID = UUID . Parse ( ( string ) respData [ "AgentID" ] ) ;
return inviteInfo ;
}
2010-04-02 13:53:10 +00:00
public void RemoveAgentToGroupInvite ( UUID requestingAgentID , UUID inviteID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "InviteID" ] = inviteID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.removeAgentToGroupInvite" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public void AddAgentToGroup ( UUID requestingAgentID , UUID AgentID , UUID GroupID , UUID RoleID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
param [ "RoleID" ] = RoleID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.addAgentToGroup" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public void RemoveAgentFromGroup ( UUID requestingAgentID , UUID AgentID , UUID GroupID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.removeAgentFromGroup" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public void AddAgentToGroupRole ( UUID requestingAgentID , UUID AgentID , UUID GroupID , UUID RoleID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
param [ "RoleID" ] = RoleID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.addAgentToGroupRole" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public void RemoveAgentFromGroupRole ( UUID requestingAgentID , UUID AgentID , UUID GroupID , UUID RoleID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
param [ "RoleID" ] = RoleID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.removeAgentFromGroupRole" , param ) ;
2009-04-21 15:30:03 +00:00
}
2010-04-02 13:53:10 +00:00
public List < DirGroupsReplyData > FindGroups ( UUID requestingAgentID , string search )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "Search" ] = search ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.findGroups" , param ) ;
2009-04-21 15:30:03 +00:00
List < DirGroupsReplyData > findings = new List < DirGroupsReplyData > ( ) ;
2009-04-21 20:44:17 +00:00
if ( ! respData . Contains ( "error" ) )
2009-04-21 15:30:03 +00:00
{
Hashtable results = ( Hashtable ) respData [ "results" ] ;
foreach ( Hashtable groupFind in results . Values )
{
DirGroupsReplyData data = new DirGroupsReplyData ( ) ;
data . groupID = new UUID ( ( string ) groupFind [ "GroupID" ] ) ; ;
data . groupName = ( string ) groupFind [ "Name" ] ;
data . members = int . Parse ( ( string ) groupFind [ "Members" ] ) ;
// data.searchOrder = order;
findings . Add ( data ) ;
}
}
return findings ;
}
2010-04-02 13:53:10 +00:00
public GroupMembershipData GetAgentGroupMembership ( UUID requestingAgentID , UUID AgentID , UUID GroupID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getAgentGroupMembership" , param ) ;
2009-04-21 15:30:03 +00:00
if ( respData . Contains ( "error" ) )
{
return null ;
}
GroupMembershipData data = HashTableToGroupMembershipData ( respData ) ;
return data ;
}
2010-04-02 13:53:10 +00:00
public GroupMembershipData GetAgentActiveMembership ( UUID requestingAgentID , UUID AgentID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getAgentActiveMembership" , param ) ;
2009-04-21 15:30:03 +00:00
if ( respData . Contains ( "error" ) )
{
2009-04-22 18:00:59 +00:00
return null ;
}
2009-04-21 15:30:03 +00:00
2009-04-21 20:44:17 +00:00
return HashTableToGroupMembershipData ( respData ) ;
2009-04-22 18:00:59 +00:00
}
2009-04-21 15:30:03 +00:00
2010-04-02 13:53:10 +00:00
public List < GroupMembershipData > GetAgentGroupMemberships ( UUID requestingAgentID , UUID AgentID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getAgentGroupMemberships" , param ) ;
2009-04-21 15:30:03 +00:00
List < GroupMembershipData > memberships = new List < GroupMembershipData > ( ) ;
2009-04-21 20:44:17 +00:00
if ( ! respData . Contains ( "error" ) )
2009-04-21 15:30:03 +00:00
{
foreach ( object membership in respData . Values )
{
memberships . Add ( HashTableToGroupMembershipData ( ( Hashtable ) membership ) ) ;
}
}
2012-07-29 21:02:10 +00:00
2009-04-21 15:30:03 +00:00
return memberships ;
}
2010-04-02 13:53:10 +00:00
public List < GroupRolesData > GetAgentGroupRoles ( UUID requestingAgentID , UUID AgentID , UUID GroupID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "AgentID" ] = AgentID . ToString ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getAgentRoles" , param ) ;
2009-04-21 15:30:03 +00:00
List < GroupRolesData > Roles = new List < GroupRolesData > ( ) ;
if ( respData . Contains ( "error" ) )
{
return Roles ;
}
foreach ( Hashtable role in respData . Values )
{
GroupRolesData data = new GroupRolesData ( ) ;
data . RoleID = new UUID ( ( string ) role [ "RoleID" ] ) ;
data . Name = ( string ) role [ "Name" ] ;
data . Description = ( string ) role [ "Description" ] ;
data . Powers = ulong . Parse ( ( string ) role [ "Powers" ] ) ;
data . Title = ( string ) role [ "Title" ] ;
Roles . Add ( data ) ;
}
return Roles ;
}
2010-04-02 13:53:10 +00:00
public List < GroupRolesData > GetGroupRoles ( UUID requestingAgentID , UUID GroupID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getGroupRoles" , param ) ;
2009-04-21 20:44:17 +00:00
List < GroupRolesData > Roles = new List < GroupRolesData > ( ) ;
2009-04-21 15:30:03 +00:00
if ( respData . Contains ( "error" ) )
{
2009-04-21 20:44:17 +00:00
return Roles ;
2009-04-21 15:30:03 +00:00
}
foreach ( Hashtable role in respData . Values )
{
GroupRolesData data = new GroupRolesData ( ) ;
data . Description = ( string ) role [ "Description" ] ;
data . Members = int . Parse ( ( string ) role [ "Members" ] ) ;
data . Name = ( string ) role [ "Name" ] ;
data . Powers = ulong . Parse ( ( string ) role [ "Powers" ] ) ;
data . RoleID = new UUID ( ( string ) role [ "RoleID" ] ) ;
data . Title = ( string ) role [ "Title" ] ;
Roles . Add ( data ) ;
}
return Roles ;
}
2010-04-02 13:53:10 +00:00
public List < GroupMembersData > GetGroupMembers ( UUID requestingAgentID , UUID GroupID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getGroupMembers" , param ) ;
2009-04-21 20:44:17 +00:00
List < GroupMembersData > members = new List < GroupMembersData > ( ) ;
2009-04-21 15:30:03 +00:00
if ( respData . Contains ( "error" ) )
{
2009-04-21 20:44:17 +00:00
return members ;
2009-04-21 15:30:03 +00:00
}
foreach ( Hashtable membership in respData . Values )
{
GroupMembersData data = new GroupMembersData ( ) ;
data . AcceptNotices = ( ( string ) membership [ "AcceptNotices" ] ) = = "1" ;
data . AgentID = new UUID ( ( string ) membership [ "AgentID" ] ) ;
data . Contribution = int . Parse ( ( string ) membership [ "Contribution" ] ) ;
data . IsOwner = ( ( string ) membership [ "IsOwner" ] ) = = "1" ;
data . ListInProfile = ( ( string ) membership [ "ListInProfile" ] ) = = "1" ;
data . AgentPowers = ulong . Parse ( ( string ) membership [ "AgentPowers" ] ) ;
data . Title = ( string ) membership [ "Title" ] ;
members . Add ( data ) ;
}
return members ;
}
2010-04-02 13:53:10 +00:00
public List < GroupRoleMembersData > GetGroupRoleMembers ( UUID requestingAgentID , UUID GroupID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getGroupRoleMembers" , param ) ;
2009-04-21 15:30:03 +00:00
List < GroupRoleMembersData > members = new List < GroupRoleMembersData > ( ) ;
2009-04-21 20:44:17 +00:00
if ( ! respData . Contains ( "error" ) )
{
2009-04-22 18:00:59 +00:00
foreach ( Hashtable membership in respData . Values )
{
GroupRoleMembersData data = new GroupRoleMembersData ( ) ;
2009-04-25 18:58:18 +00:00
2009-04-22 18:00:59 +00:00
data . MemberID = new UUID ( ( string ) membership [ "AgentID" ] ) ;
data . RoleID = new UUID ( ( string ) membership [ "RoleID" ] ) ;
2009-04-25 18:58:18 +00:00
2009-04-22 18:00:59 +00:00
members . Add ( data ) ;
}
2009-04-21 20:44:17 +00:00
}
2009-04-21 15:30:03 +00:00
return members ;
}
2010-04-02 13:53:10 +00:00
public List < GroupNoticeData > GetGroupNotices ( UUID requestingAgentID , UUID GroupID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = GroupID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getGroupNotices" , param ) ;
2009-04-21 15:30:03 +00:00
List < GroupNoticeData > values = new List < GroupNoticeData > ( ) ;
2009-04-21 20:44:17 +00:00
if ( ! respData . Contains ( "error" ) )
2009-04-21 15:30:03 +00:00
{
foreach ( Hashtable value in respData . Values )
{
GroupNoticeData data = new GroupNoticeData ( ) ;
data . NoticeID = UUID . Parse ( ( string ) value [ "NoticeID" ] ) ;
data . Timestamp = uint . Parse ( ( string ) value [ "Timestamp" ] ) ;
data . FromName = ( string ) value [ "FromName" ] ;
data . Subject = ( string ) value [ "Subject" ] ;
data . HasAttachment = false ;
data . AssetType = 0 ;
values . Add ( data ) ;
}
}
2009-04-29 22:31:00 +00:00
2012-11-24 02:43:31 +00:00
return values ;
2009-04-21 15:30:03 +00:00
}
2012-11-24 02:43:31 +00:00
2010-04-02 13:53:10 +00:00
public GroupNoticeInfo GetGroupNotice ( UUID requestingAgentID , UUID noticeID )
2009-04-21 15:30:03 +00:00
{
Hashtable param = new Hashtable ( ) ;
param [ "NoticeID" ] = noticeID . ToString ( ) ;
2010-04-02 13:53:10 +00:00
Hashtable respData = XmlRpcCall ( requestingAgentID , "groups.getGroupNotice" , param ) ;
2009-04-21 15:30:03 +00:00
2009-04-25 18:58:18 +00:00
if ( respData . Contains ( "error" ) )
2009-04-21 15:30:03 +00:00
{
2009-04-22 18:00:59 +00:00
return null ;
}
2009-04-21 15:30:03 +00:00
GroupNoticeInfo data = new GroupNoticeInfo ( ) ;
data . GroupID = UUID . Parse ( ( string ) respData [ "GroupID" ] ) ;
data . Message = ( string ) respData [ "Message" ] ;
data . BinaryBucket = Utils . HexStringToBytes ( ( string ) respData [ "BinaryBucket" ] , true ) ;
data . noticeData . NoticeID = UUID . Parse ( ( string ) respData [ "NoticeID" ] ) ;
data . noticeData . Timestamp = uint . Parse ( ( string ) respData [ "Timestamp" ] ) ;
data . noticeData . FromName = ( string ) respData [ "FromName" ] ;
data . noticeData . Subject = ( string ) respData [ "Subject" ] ;
data . noticeData . HasAttachment = false ;
data . noticeData . AssetType = 0 ;
if ( data . Message = = null )
{
data . Message = string . Empty ;
}
return data ;
}
2012-11-24 02:43:31 +00:00
2010-04-02 13:53:10 +00:00
public void AddGroupNotice ( UUID requestingAgentID , UUID groupID , UUID noticeID , string fromName , string subject , string message , byte [ ] binaryBucket )
2009-04-21 15:30:03 +00:00
{
string binBucket = OpenMetaverse . Utils . BytesToHexString ( binaryBucket , "" ) ;
Hashtable param = new Hashtable ( ) ;
param [ "GroupID" ] = groupID . ToString ( ) ;
param [ "NoticeID" ] = noticeID . ToString ( ) ;
param [ "FromName" ] = fromName ;
param [ "Subject" ] = subject ;
param [ "Message" ] = message ;
param [ "BinaryBucket" ] = binBucket ;
param [ "TimeStamp" ] = ( ( uint ) Util . UnixTimeSinceEpoch ( ) ) . ToString ( ) ;
2010-04-02 13:53:10 +00:00
XmlRpcCall ( requestingAgentID , "groups.addGroupNotice" , param ) ;
2009-04-21 20:44:17 +00:00
}
2010-05-06 15:38:23 +00:00
# endregion
#region GroupSessionTracking
public void ResetAgentGroupChatSessions ( UUID agentID )
{
foreach ( List < UUID > agentList in m_groupsAgentsDroppedFromChatSession . Values )
{
agentList . Remove ( agentID ) ;
}
}
public bool hasAgentBeenInvitedToGroupChatSession ( UUID agentID , UUID groupID )
{
// If we're tracking this group, and we can find them in the tracking, then they've been invited
return m_groupsAgentsInvitedToChatSession . ContainsKey ( groupID )
& & m_groupsAgentsInvitedToChatSession [ groupID ] . Contains ( agentID ) ;
}
public bool hasAgentDroppedGroupChatSession ( UUID agentID , UUID groupID )
{
2012-07-29 21:02:10 +00:00
// If we're tracking drops for this group,
2010-05-06 15:38:23 +00:00
// and we find them, well... then they've dropped
2012-07-29 21:02:10 +00:00
return m_groupsAgentsDroppedFromChatSession . ContainsKey ( groupID )
2010-05-06 15:38:23 +00:00
& & m_groupsAgentsDroppedFromChatSession [ groupID ] . Contains ( agentID ) ;
}
public void AgentDroppedFromGroupChatSession ( UUID agentID , UUID groupID )
{
if ( m_groupsAgentsDroppedFromChatSession . ContainsKey ( groupID ) )
{
2016-07-23 20:09:34 +00:00
if ( m_groupsAgentsInvitedToChatSession [ groupID ] . Contains ( agentID ) )
m_groupsAgentsInvitedToChatSession [ groupID ] . Remove ( agentID ) ;
2010-05-06 15:38:23 +00:00
// If not in dropped list, add
if ( ! m_groupsAgentsDroppedFromChatSession [ groupID ] . Contains ( agentID ) )
m_groupsAgentsDroppedFromChatSession [ groupID ] . Add ( agentID ) ;
}
}
public void AgentInvitedToGroupChatSession ( UUID agentID , UUID groupID )
{
// Add Session Status if it doesn't exist for this session
CreateGroupChatSessionTracking ( groupID ) ;
// If nessesary, remove from dropped list
if ( m_groupsAgentsDroppedFromChatSession [ groupID ] . Contains ( agentID ) )
m_groupsAgentsDroppedFromChatSession [ groupID ] . Remove ( agentID ) ;
2016-07-23 20:09:34 +00:00
if ( ! m_groupsAgentsInvitedToChatSession [ groupID ] . Contains ( agentID ) )
m_groupsAgentsInvitedToChatSession [ groupID ] . Add ( agentID ) ;
2017-01-05 19:07:37 +00:00
}
2010-05-06 15:38:23 +00:00
private void CreateGroupChatSessionTracking ( UUID groupID )
{
if ( ! m_groupsAgentsDroppedFromChatSession . ContainsKey ( groupID ) )
{
m_groupsAgentsDroppedFromChatSession . Add ( groupID , new List < UUID > ( ) ) ;
m_groupsAgentsInvitedToChatSession . Add ( groupID , new List < UUID > ( ) ) ;
}
}
2010-04-06 02:56:03 +00:00
# endregion
2009-08-05 18:15:53 +00:00
#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 ;
}
2012-07-29 21:02:10 +00:00
2009-08-05 18:15:53 +00:00
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" ) ;
2012-07-29 21:02:10 +00:00
2009-08-05 18:15:53 +00:00
return data ;
}
# endregion
2009-04-21 20:44:17 +00:00
2009-08-05 18:15:53 +00:00
/// <summary>
/// Encapsulate the XmlRpc call to standardize security and error handling.
/// </summary>
2010-04-02 13:53:10 +00:00
private Hashtable XmlRpcCall ( UUID requestingAgentID , string function , Hashtable param )
{
2010-05-06 15:38:23 +00:00
XmlRpcResponse resp = null ;
string CacheKey = null ;
2009-04-29 22:31:00 +00:00
2010-05-06 15:38:23 +00:00
// Only bother with the cache if it isn't disabled.
if ( m_cacheTimeout > 0 )
{
if ( ! function . StartsWith ( "groups.get" ) )
{
// Any and all updates cause the cache to clear
m_memoryCache . Clear ( ) ;
}
else
{
StringBuilder sb = new StringBuilder ( requestingAgentID + function ) ;
foreach ( object key in param . Keys )
{
if ( param [ key ] ! = null )
{
sb . AppendFormat ( ",{0}:{1}" , key . ToString ( ) , param [ key ] . ToString ( ) ) ;
}
}
CacheKey = sb . ToString ( ) ;
m_memoryCache . TryGetValue ( CacheKey , out resp ) ;
}
}
2012-07-29 21:02:10 +00:00
2010-09-12 17:43:49 +00:00
if ( resp = = null )
2010-05-06 15:38:23 +00:00
{
2011-12-16 20:53:50 +00:00
if ( m_debugEnabled )
m_log . DebugFormat ( "[XMLRPC-GROUPS-CONNECTOR]: Cache miss for key {0}" , CacheKey ) ;
2010-05-06 15:38:23 +00:00
string UserService ;
UUID SessionID ;
GetClientGroupRequestID ( requestingAgentID , out UserService , out SessionID ) ;
2012-07-29 21:02:10 +00:00
2010-09-17 22:48:44 +00:00
param . Add ( "RequestingAgentID" , requestingAgentID . ToString ( ) ) ;
2010-05-06 15:38:23 +00:00
param . Add ( "RequestingAgentUserService" , UserService ) ;
param . Add ( "RequestingSessionID" , SessionID . ToString ( ) ) ;
param . Add ( "ReadKey" , m_groupReadKey ) ;
param . Add ( "WriteKey" , m_groupWriteKey ) ;
2009-08-20 16:41:14 +00:00
2010-05-06 15:38:23 +00:00
IList parameters = new ArrayList ( ) ;
parameters . Add ( param ) ;
ConfigurableKeepAliveXmlRpcRequest req ;
req = new ConfigurableKeepAliveXmlRpcRequest ( function , parameters , m_disableKeepAlive ) ;
2010-04-15 02:48:40 +00:00
2010-05-06 15:38:23 +00:00
try
2010-05-05 15:12:52 +00:00
{
2016-07-01 22:26:16 +00:00
resp = req . Send ( m_groupsServerURI ) ;
2010-05-06 15:38:23 +00:00
}
catch ( Exception e )
2009-04-29 18:22:49 +00:00
{
2010-10-18 22:21:34 +00:00
m_log . ErrorFormat (
2015-12-19 15:24:43 +00:00
"[XMLRPC-GROUPS-CONNECTOR]: An error has occured while attempting to access the XmlRpcGroups server method {0} at {1}: {2}" ,
function , m_groupsServerURI , e . Message ) ;
2010-05-06 15:38:23 +00:00
2015-12-19 15:24:43 +00:00
if ( m_debugEnabled )
2010-05-06 15:38:23 +00:00
{
2015-12-19 15:24:43 +00:00
m_log . ErrorFormat ( "[XMLRPC-GROUPS-CONNECTOR]: {0}" , e . StackTrace ) ;
2010-05-06 15:38:23 +00:00
2015-12-19 15:24:43 +00:00
foreach ( string ResponseLine in req . RequestResponse . Split ( new string [ ] { Environment . NewLine } , StringSplitOptions . None ) )
{
m_log . ErrorFormat ( "[XMLRPC-GROUPS-CONNECTOR]: {0} " , ResponseLine ) ;
}
2010-05-06 15:38:23 +00:00
2015-12-19 15:24:43 +00:00
foreach ( string key in param . Keys )
{
m_log . WarnFormat ( "[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}" , key , param [ key ] . ToString ( ) ) ;
}
}
2016-07-01 22:26:16 +00:00
if ( ( m_cacheTimeout > 0 ) & & ( CacheKey ! = null ) )
{
m_memoryCache . AddOrUpdate ( CacheKey , resp , 10.0 ) ;
}
2010-05-06 15:38:23 +00:00
Hashtable respData = new Hashtable ( ) ;
respData . Add ( "error" , e . ToString ( ) ) ;
return respData ;
2009-04-29 18:22:49 +00:00
}
2009-04-21 15:30:03 +00:00
2016-08-11 03:52:25 +00:00
if ( ( m_cacheTimeout > 0 ) & & ( CacheKey ! = null ) )
{
2016-08-11 07:38:39 +00:00
m_memoryCache . AddOrUpdate ( CacheKey , resp , 10.0 ) ;
2016-08-11 03:52:25 +00:00
}
2016-07-01 22:26:16 +00:00
}
2009-04-24 00:58:48 +00:00
if ( resp . Value is Hashtable )
2009-04-21 20:44:17 +00:00
{
Hashtable respData = ( Hashtable ) resp . Value ;
if ( respData . Contains ( "error" ) & & ! respData . Contains ( "succeed" ) )
{
2014-02-14 21:28:45 +00:00
LogRespDataToConsoleError ( requestingAgentID , function , param , respData ) ;
2009-04-21 20:44:17 +00:00
}
2009-04-21 15:30:03 +00:00
2009-04-21 20:44:17 +00:00
return respData ;
}
2010-05-06 15:38:23 +00:00
m_log . ErrorFormat ( "[XMLRPC-GROUPS-CONNECTOR]: The XmlRpc server returned a {1} instead of a hashtable for {0}" , function , resp . Value . GetType ( ) . ToString ( ) ) ;
2009-04-21 20:44:17 +00:00
if ( resp . Value is ArrayList )
2009-04-21 15:30:03 +00:00
{
2009-04-21 20:44:17 +00:00
ArrayList al = ( ArrayList ) resp . Value ;
2010-05-06 15:38:23 +00:00
m_log . ErrorFormat ( "[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements" , al . Count ) ;
2009-04-21 20:44:17 +00:00
foreach ( object o in al )
{
2010-05-06 15:38:23 +00:00
m_log . ErrorFormat ( "[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}" , o . GetType ( ) . ToString ( ) , o . ToString ( ) ) ;
2009-04-21 20:44:17 +00:00
}
2009-04-21 15:30:03 +00:00
}
2009-04-21 20:44:17 +00:00
else
{
2010-05-06 15:38:23 +00:00
m_log . ErrorFormat ( "[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}" , resp . Value . ToString ( ) ) ;
2009-04-21 20:44:17 +00:00
}
Hashtable error = new Hashtable ( ) ;
error . Add ( "error" , "invalid return value" ) ;
return error ;
2009-04-25 18:58:18 +00:00
}
2009-04-21 20:44:17 +00:00
2014-02-14 21:28:45 +00:00
private void LogRespDataToConsoleError ( UUID requestingAgentID , string function , Hashtable param , Hashtable respData )
2009-04-21 20:44:17 +00:00
{
2014-02-14 21:28:45 +00:00
m_log . ErrorFormat (
2017-01-05 19:07:37 +00:00
"[XMLRPC-GROUPS-CONNECTOR]: Error when calling {0} for {1} with params {2}. Response params are {3}" ,
2014-02-14 21:28:45 +00:00
function , requestingAgentID , Util . PrettyFormatToSingleLine ( param ) , Util . PrettyFormatToSingleLine ( respData ) ) ;
2009-04-21 20:44:17 +00:00
}
2012-07-29 21:02:10 +00:00
2010-04-02 13:53:10 +00:00
/// <summary>
2012-07-29 21:02:10 +00:00
/// Group Request Tokens are an attempt to allow the groups service to authenticate
2010-09-12 17:43:49 +00:00
/// requests.
2010-05-06 15:38:23 +00:00
/// TODO: This broke after the big grid refactor, either find a better way, or discard this
2010-04-02 13:53:10 +00:00
/// </summary>
/// <param name="client"></param>
/// <returns></returns>
private void GetClientGroupRequestID ( UUID AgentID , out string UserServiceURL , out UUID SessionID )
{
UserServiceURL = "" ;
SessionID = UUID . Zero ;
2009-08-05 18:15:53 +00:00
2009-04-21 15:30:03 +00:00
2010-04-02 13:53:10 +00:00
// Need to rework this based on changes to User Services
/ *
UserAccount userAccount = m_accountService . GetUserAccount ( UUID . Zero , AgentID ) ;
if ( userAccount = = null )
{
// This should be impossible. If I've been passed a reference to a client
// that client should be registered with the UserService. So something
// is horribly wrong somewhere.
m_log . WarnFormat ( "[GROUPS]: Could not find a UserServiceURL for {0}" , AgentID ) ;
}
else if ( userProfile is ForeignUserProfileData )
{
// They aren't from around here
ForeignUserProfileData fupd = ( ForeignUserProfileData ) userProfile ;
UserServiceURL = fupd . UserServerURI ;
SessionID = fupd . CurrentAgent . SessionID ;
}
else
{
// They're a local user, use this:
UserServiceURL = m_commManager . NetworkServersInfo . UserURL ;
SessionID = userProfile . CurrentAgent . SessionID ;
}
* /
}
2012-07-29 21:02:10 +00:00
2009-04-21 15:30:03 +00:00
}
}
2009-04-21 20:44:17 +00:00
namespace Nwc.XmlRpc
{
using System ;
using System.Collections ;
using System.IO ;
using System.Xml ;
using System.Net ;
using System.Text ;
using System.Reflection ;
/// <summary>Class supporting the request side of an XML-RPC transaction.</summary>
2009-08-20 16:41:14 +00:00
public class ConfigurableKeepAliveXmlRpcRequest : XmlRpcRequest
2009-04-21 20:44:17 +00:00
{
private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer ( ) ;
private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer ( ) ;
2009-08-20 16:41:14 +00:00
private bool _disableKeepAlive = true ;
public string RequestResponse = String . Empty ;
2009-04-21 20:44:17 +00:00
/// <summary>Instantiate an <c>XmlRpcRequest</c> for a specified method and parameters.</summary>
/// <param name="methodName"><c>String</c> designating the <i>object.method</i> on the server the request
/// should be directed to.</param>
/// <param name="parameters"><c>ArrayList</c> of XML-RPC type parameters to invoke the request with.</param>
2009-08-20 16:41:14 +00:00
public ConfigurableKeepAliveXmlRpcRequest ( String methodName , IList parameters , bool disableKeepAlive )
2009-04-21 20:44:17 +00:00
{
MethodName = methodName ;
_params = parameters ;
2009-08-20 16:41:14 +00:00
_disableKeepAlive = disableKeepAlive ;
2009-04-21 20:44:17 +00:00
}
/// <summary>Send the request to the server.</summary>
/// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
/// <returns><c>XmlRpcResponse</c> The response generated.</returns>
public XmlRpcResponse Send ( String url )
{
HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( url ) ;
if ( request = = null )
throw new XmlRpcException ( XmlRpcErrorCodes . TRANSPORT_ERROR ,
XmlRpcErrorCodes . TRANSPORT_ERROR_MSG + ": Could not create request with " + url ) ;
request . Method = "POST" ;
request . ContentType = "text/xml" ;
request . AllowWriteStreamBuffering = true ;
2009-08-20 16:41:14 +00:00
request . KeepAlive = ! _disableKeepAlive ;
2016-07-01 22:26:16 +00:00
request . Timeout = 30000 ;
2009-04-21 20:44:17 +00:00
2013-02-27 00:21:02 +00:00
using ( Stream stream = request . GetRequestStream ( ) )
2009-08-20 16:41:14 +00:00
{
2013-02-27 00:21:02 +00:00
using ( XmlTextWriter xml = new XmlTextWriter ( stream , Encoding . ASCII ) )
{
_serializer . Serialize ( xml , this ) ;
xml . Flush ( ) ;
2017-01-05 19:07:37 +00:00
}
2009-08-20 16:41:14 +00:00
}
2013-02-27 00:21:02 +00:00
XmlRpcResponse resp ;
using ( HttpWebResponse response = ( HttpWebResponse ) request . GetResponse ( ) )
2009-08-20 16:41:14 +00:00
{
2013-02-27 00:21:02 +00:00
using ( Stream s = response . GetResponseStream ( ) )
{
using ( StreamReader input = new StreamReader ( s ) )
{
string inputXml = input . ReadToEnd ( ) ;
try
{
resp = ( XmlRpcResponse ) _deserializer . Deserialize ( inputXml ) ;
}
catch ( Exception e )
{
RequestResponse = inputXml ;
throw e ;
}
}
}
2009-08-20 16:41:14 +00:00
}
2013-02-27 00:21:02 +00:00
2009-04-21 20:44:17 +00:00
return resp ;
}
}
}