2010-03-10 04:15:36 +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 .
* * Neither the name of the OpenSimulator Project nor the
* 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 ;
2010-01-29 03:19:42 +00:00
using System.Collections ;
using System.Collections.Generic ;
using System.IO ;
using System.Net ;
using System.Reflection ;
using System.Text ;
using OpenSim.Framework ;
using OpenSim.Services.Interfaces ;
using OpenSim.Services.Connectors.Simulation ;
using GridRegion = OpenSim . Services . Interfaces . GridRegion ;
using OpenMetaverse ;
using OpenMetaverse.StructuredData ;
using log4net ;
using Nwc.XmlRpc ;
using Nini.Config ;
namespace OpenSim.Services.Connectors.Hypergrid
{
2013-06-22 03:52:46 +00:00
public class UserAgentServiceConnector : SimulationServiceConnector , IUserAgentService
2010-01-29 03:19:42 +00:00
{
private static readonly ILog m_log =
LogManager . GetLogger (
MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2014-03-24 12:20:19 +00:00
private string m_ServerURLHost ;
2013-06-22 03:52:46 +00:00
private string m_ServerURL ;
private GridRegion m_Gatekeeper ;
2011-06-11 04:07:50 +00:00
public UserAgentServiceConnector ( string url ) : this ( url , true )
{
}
public UserAgentServiceConnector ( string url , bool dnsLookup )
2010-01-29 03:19:42 +00:00
{
2014-03-24 12:20:19 +00:00
m_ServerURL = m_ServerURLHost = url ;
2011-06-11 04:07:50 +00:00
if ( dnsLookup )
2010-08-16 21:36:20 +00:00
{
2011-06-11 04:07:50 +00:00
// Doing this here, because XML-RPC or mono have some strong ideas about
// caching DNS translations.
try
{
Uri m_Uri = new Uri ( m_ServerURL ) ;
IPAddress ip = Util . GetHostFromDNS ( m_Uri . Host ) ;
m_ServerURL = m_ServerURL . Replace ( m_Uri . Host , ip . ToString ( ) ) ;
if ( ! m_ServerURL . EndsWith ( "/" ) )
m_ServerURL + = "/" ;
}
catch ( Exception e )
{
2014-03-24 12:20:19 +00:00
m_log . DebugFormat ( "[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}" , url , e . Message ) ;
2011-06-11 04:07:50 +00:00
}
2010-08-16 21:36:20 +00:00
}
2014-02-13 23:55:38 +00:00
//m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0} ({1})", url, m_ServerURL);
2010-01-29 03:19:42 +00:00
}
public UserAgentServiceConnector ( IConfigSource config )
{
2010-09-04 23:39:03 +00:00
IConfig serviceConfig = config . Configs [ "UserAgentService" ] ;
if ( serviceConfig = = null )
{
m_log . Error ( "[USER AGENT CONNECTOR]: UserAgentService missing from ini" ) ;
throw new Exception ( "UserAgent connector init error" ) ;
}
2010-01-29 03:19:42 +00:00
2010-09-04 23:39:03 +00:00
string serviceURI = serviceConfig . GetString ( "UserAgentServerURI" ,
String . Empty ) ;
if ( serviceURI = = String . Empty )
{
m_log . Error ( "[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService" ) ;
throw new Exception ( "UserAgent connector init error" ) ;
}
2014-03-24 12:20:19 +00:00
m_ServerURL = m_ServerURLHost = serviceURI ;
2011-01-07 01:42:16 +00:00
if ( ! m_ServerURL . EndsWith ( "/" ) )
m_ServerURL + = "/" ;
2010-09-04 23:39:03 +00:00
2014-03-24 12:20:19 +00:00
//m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0}", m_ServerURL);
2010-08-20 01:55:30 +00:00
}
2013-06-22 03:52:46 +00:00
protected override string AgentPath ( )
{
return "homeagent/" ;
}
2010-09-04 23:39:03 +00:00
2013-06-22 03:52:46 +00:00
// The Login service calls this interface with fromLogin=true
// Sims call it with fromLogin=false
// Either way, this is verified by the handler
public bool LoginAgentToGrid ( AgentCircuitData aCircuit , GridRegion gatekeeper , GridRegion destination , bool fromLogin , out string reason )
2010-01-29 03:19:42 +00:00
{
reason = String . Empty ;
if ( destination = = null )
{
reason = "Destination is null" ;
m_log . Debug ( "[USER AGENT CONNECTOR]: Given destination is null" ) ;
return false ;
}
2013-06-22 03:52:46 +00:00
GridRegion home = new GridRegion ( ) ;
home . ServerURI = m_ServerURL ;
home . RegionID = destination . RegionID ;
home . RegionLocX = destination . RegionLocX ;
home . RegionLocY = destination . RegionLocY ;
2010-01-29 03:19:42 +00:00
2013-06-22 03:52:46 +00:00
m_Gatekeeper = gatekeeper ;
2010-01-29 03:19:42 +00:00
2013-06-22 03:52:46 +00:00
Console . WriteLine ( " >>> LoginAgentToGrid <<< " + home . ServerURI ) ;
2010-01-29 03:19:42 +00:00
2013-06-22 03:52:46 +00:00
uint flags = fromLogin ? ( uint ) TeleportFlags . ViaLogin : ( uint ) TeleportFlags . ViaHome ;
return CreateAgent ( home , aCircuit , flags , out reason ) ;
2010-01-29 03:19:42 +00:00
}
2010-09-04 23:39:03 +00:00
// The simulators call this interface
public bool LoginAgentToGrid ( AgentCircuitData aCircuit , GridRegion gatekeeper , GridRegion destination , out string reason )
{
2013-06-22 03:52:46 +00:00
return LoginAgentToGrid ( aCircuit , gatekeeper , destination , false , out reason ) ;
}
protected override void PackData ( OSDMap args , AgentCircuitData aCircuit , GridRegion destination , uint flags )
{
base . PackData ( args , aCircuit , destination , flags ) ;
args [ "gatekeeper_serveruri" ] = OSD . FromString ( m_Gatekeeper . ServerURI ) ;
args [ "gatekeeper_host" ] = OSD . FromString ( m_Gatekeeper . ExternalHostName ) ;
args [ "gatekeeper_port" ] = OSD . FromString ( m_Gatekeeper . HttpPort . ToString ( ) ) ;
args [ "destination_serveruri" ] = OSD . FromString ( destination . ServerURI ) ;
2010-09-04 23:39:03 +00:00
}
protected OSDMap PackCreateAgentArguments ( AgentCircuitData aCircuit , GridRegion gatekeeper , GridRegion destination , IPEndPoint ipaddress )
2010-01-29 03:19:42 +00:00
{
OSDMap args = null ;
try
{
args = aCircuit . PackAgentCircuitData ( ) ;
}
catch ( Exception e )
{
m_log . Debug ( "[USER AGENT CONNECTOR]: PackAgentCircuitData failed with exception: " + e . Message ) ;
}
2011-07-16 00:53:25 +00:00
2010-01-29 03:19:42 +00:00
// Add the input arguments
2010-10-22 03:22:15 +00:00
args [ "gatekeeper_serveruri" ] = OSD . FromString ( gatekeeper . ServerURI ) ;
2010-01-29 03:19:42 +00:00
args [ "gatekeeper_host" ] = OSD . FromString ( gatekeeper . ExternalHostName ) ;
args [ "gatekeeper_port" ] = OSD . FromString ( gatekeeper . HttpPort . ToString ( ) ) ;
args [ "destination_x" ] = OSD . FromString ( destination . RegionLocX . ToString ( ) ) ;
args [ "destination_y" ] = OSD . FromString ( destination . RegionLocY . ToString ( ) ) ;
args [ "destination_name" ] = OSD . FromString ( destination . RegionName ) ;
args [ "destination_uuid" ] = OSD . FromString ( destination . RegionID . ToString ( ) ) ;
2010-10-22 03:22:15 +00:00
args [ "destination_serveruri" ] = OSD . FromString ( destination . ServerURI ) ;
2010-10-04 03:01:59 +00:00
// 10/3/2010
// I added the client_ip up to the regular AgentCircuitData, so this doesn't need to be here.
// This need cleaning elsewhere...
//if (ipaddress != null)
// args["client_ip"] = OSD.FromString(ipaddress.Address.ToString());
2010-01-29 03:19:42 +00:00
return args ;
}
2010-05-16 02:25:14 +00:00
public void SetClientToken ( UUID sessionID , string token )
{
// no-op
}
2014-02-13 23:55:38 +00:00
private Hashtable CallServer ( string methodName , Hashtable hash )
2010-01-29 03:19:42 +00:00
{
IList paramList = new ArrayList ( ) ;
paramList . Add ( hash ) ;
2014-02-13 23:55:38 +00:00
XmlRpcRequest request = new XmlRpcRequest ( methodName , paramList ) ;
// Send and get reply
2010-01-29 03:19:42 +00:00
XmlRpcResponse response = null ;
try
{
response = request . Send ( m_ServerURL , 10000 ) ;
}
2014-02-13 23:55:38 +00:00
catch ( Exception e )
2010-01-29 03:19:42 +00:00
{
2014-03-24 12:20:19 +00:00
m_log . DebugFormat ( "[USER AGENT CONNECTOR]: {0} call to {1} failed: {2}" , methodName , m_ServerURLHost , e . Message ) ;
2014-02-13 23:55:38 +00:00
throw ;
2010-01-29 03:19:42 +00:00
}
if ( response . IsFault )
{
2014-03-24 12:20:19 +00:00
throw new Exception ( string . Format ( "[USER AGENT CONNECTOR]: {0} call to {1} returned an error: {2}" , methodName , m_ServerURLHost , response . FaultString ) ) ;
2010-01-29 03:19:42 +00:00
}
hash = ( Hashtable ) response . Value ;
2014-02-13 23:55:38 +00:00
if ( hash = = null )
2010-01-29 03:19:42 +00:00
{
2014-03-24 12:20:19 +00:00
throw new Exception ( string . Format ( "[USER AGENT CONNECTOR]: {0} call to {1} returned null" , methodName , m_ServerURLHost ) ) ;
2014-02-13 23:55:38 +00:00
}
2010-01-29 03:19:42 +00:00
2014-02-13 23:55:38 +00:00
return hash ;
}
2011-12-29 20:17:58 +00:00
2014-02-13 23:55:38 +00:00
public GridRegion GetHomeRegion ( UUID userID , out Vector3 position , out Vector3 lookAt )
{
position = Vector3 . UnitY ; lookAt = Vector3 . UnitY ;
2010-01-29 03:19:42 +00:00
2014-02-13 23:55:38 +00:00
Hashtable hash = new Hashtable ( ) ;
hash [ "userID" ] = userID . ToString ( ) ;
hash = CallServer ( "get_home_region" , hash ) ;
bool success ;
if ( ! Boolean . TryParse ( ( string ) hash [ "result" ] , out success ) | | ! success )
return null ;
2010-01-29 03:19:42 +00:00
2014-02-13 23:55:38 +00:00
GridRegion region = new GridRegion ( ) ;
UUID . TryParse ( ( string ) hash [ "uuid" ] , out region . RegionID ) ;
//m_log.Debug(">> HERE, uuid: " + region.RegionID);
int n = 0 ;
if ( hash [ "x" ] ! = null )
{
Int32 . TryParse ( ( string ) hash [ "x" ] , out n ) ;
region . RegionLocX = n ;
//m_log.Debug(">> HERE, x: " + region.RegionLocX);
2010-01-29 03:19:42 +00:00
}
2014-02-13 23:55:38 +00:00
if ( hash [ "y" ] ! = null )
2010-01-29 03:19:42 +00:00
{
2014-02-13 23:55:38 +00:00
Int32 . TryParse ( ( string ) hash [ "y" ] , out n ) ;
region . RegionLocY = n ;
//m_log.Debug(">> HERE, y: " + region.RegionLocY);
2010-01-29 03:19:42 +00:00
}
2014-03-26 02:34:22 +00:00
if ( hash [ "size_x" ] ! = null )
{
Int32 . TryParse ( ( string ) hash [ "size_x" ] , out n ) ;
region . RegionSizeX = n ;
//m_log.Debug(">> HERE, x: " + region.RegionLocX);
}
if ( hash [ "size_y" ] ! = null )
{
Int32 . TryParse ( ( string ) hash [ "size_y" ] , out n ) ;
region . RegionSizeY = n ;
//m_log.Debug(">> HERE, y: " + region.RegionLocY);
}
2014-02-13 23:55:38 +00:00
if ( hash [ "region_name" ] ! = null )
{
region . RegionName = ( string ) hash [ "region_name" ] ;
//m_log.Debug(">> HERE, name: " + region.RegionName);
}
if ( hash [ "hostname" ] ! = null )
region . ExternalHostName = ( string ) hash [ "hostname" ] ;
if ( hash [ "http_port" ] ! = null )
{
uint p = 0 ;
UInt32 . TryParse ( ( string ) hash [ "http_port" ] , out p ) ;
region . HttpPort = p ;
}
if ( hash . ContainsKey ( "server_uri" ) & & hash [ "server_uri" ] ! = null )
region . ServerURI = ( string ) hash [ "server_uri" ] ;
if ( hash [ "internal_port" ] ! = null )
{
int p = 0 ;
Int32 . TryParse ( ( string ) hash [ "internal_port" ] , out p ) ;
region . InternalEndPoint = new IPEndPoint ( IPAddress . Parse ( "0.0.0.0" ) , p ) ;
}
if ( hash [ "position" ] ! = null )
Vector3 . TryParse ( ( string ) hash [ "position" ] , out position ) ;
if ( hash [ "lookAt" ] ! = null )
Vector3 . TryParse ( ( string ) hash [ "lookAt" ] , out lookAt ) ;
2010-01-29 03:19:42 +00:00
2014-02-13 23:55:38 +00:00
// Successful return
return region ;
2010-01-29 03:19:42 +00:00
}
2011-12-04 16:24:16 +00:00
public bool IsAgentComingHome ( UUID sessionID , string thisGridExternalName )
2010-01-29 03:19:42 +00:00
{
Hashtable hash = new Hashtable ( ) ;
hash [ "sessionID" ] = sessionID . ToString ( ) ;
hash [ "externalName" ] = thisGridExternalName ;
IList paramList = new ArrayList ( ) ;
paramList . Add ( hash ) ;
XmlRpcRequest request = new XmlRpcRequest ( "agent_is_coming_home" , paramList ) ;
string reason = string . Empty ;
return GetBoolResponse ( request , out reason ) ;
}
public bool VerifyAgent ( UUID sessionID , string token )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "sessionID" ] = sessionID . ToString ( ) ;
hash [ "token" ] = token ;
IList paramList = new ArrayList ( ) ;
paramList . Add ( hash ) ;
XmlRpcRequest request = new XmlRpcRequest ( "verify_agent" , paramList ) ;
string reason = string . Empty ;
return GetBoolResponse ( request , out reason ) ;
}
public bool VerifyClient ( UUID sessionID , string token )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "sessionID" ] = sessionID . ToString ( ) ;
hash [ "token" ] = token ;
IList paramList = new ArrayList ( ) ;
paramList . Add ( hash ) ;
XmlRpcRequest request = new XmlRpcRequest ( "verify_client" , paramList ) ;
string reason = string . Empty ;
return GetBoolResponse ( request , out reason ) ;
}
public void LogoutAgent ( UUID userID , UUID sessionID )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "sessionID" ] = sessionID . ToString ( ) ;
hash [ "userID" ] = userID . ToString ( ) ;
IList paramList = new ArrayList ( ) ;
paramList . Add ( hash ) ;
XmlRpcRequest request = new XmlRpcRequest ( "logout_agent" , paramList ) ;
string reason = string . Empty ;
GetBoolResponse ( request , out reason ) ;
}
2012-03-21 17:35:06 +00:00
[Obsolete]
2011-06-08 02:36:04 +00:00
public List < UUID > StatusNotification ( List < string > friends , UUID userID , bool online )
2011-05-24 02:45:39 +00:00
{
Hashtable hash = new Hashtable ( ) ;
hash [ "userID" ] = userID . ToString ( ) ;
hash [ "online" ] = online . ToString ( ) ;
int i = 0 ;
foreach ( string s in friends )
{
hash [ "friend_" + i . ToString ( ) ] = s ;
i + + ;
}
IList paramList = new ArrayList ( ) ;
paramList . Add ( hash ) ;
XmlRpcRequest request = new XmlRpcRequest ( "status_notification" , paramList ) ;
2011-07-16 00:53:25 +00:00
// string reason = string.Empty;
2011-05-24 02:45:39 +00:00
2011-06-08 02:36:04 +00:00
// Send and get reply
List < UUID > friendsOnline = new List < UUID > ( ) ;
XmlRpcResponse response = null ;
try
{
2011-06-12 00:22:35 +00:00
response = request . Send ( m_ServerURL , 6000 ) ;
2011-06-08 02:36:04 +00:00
}
2011-07-16 00:53:25 +00:00
catch
2011-06-08 02:36:04 +00:00
{
2014-03-24 12:20:19 +00:00
m_log . DebugFormat ( "[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification" , m_ServerURLHost ) ;
2011-07-16 00:53:25 +00:00
// reason = "Exception: " + e.Message;
2011-06-08 02:36:04 +00:00
return friendsOnline ;
}
if ( response . IsFault )
{
2014-03-24 12:20:19 +00:00
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}" , m_ServerURLHost , response . FaultString ) ;
2011-07-16 00:53:25 +00:00
// reason = "XMLRPC Fault";
2011-06-08 02:36:04 +00:00
return friendsOnline ;
}
hash = ( Hashtable ) response . Value ;
//foreach (Object o in hash)
// m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
try
{
if ( hash = = null )
{
2014-03-24 12:20:19 +00:00
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD" , m_ServerURLHost ) ;
2011-07-16 00:53:25 +00:00
// reason = "Internal error 1";
2011-06-08 02:36:04 +00:00
return friendsOnline ;
}
// Here is the actual response
foreach ( object key in hash . Keys )
{
if ( key is string & & ( ( string ) key ) . StartsWith ( "friend_" ) & & hash [ key ] ! = null )
{
UUID uuid ;
if ( UUID . TryParse ( hash [ key ] . ToString ( ) , out uuid ) )
friendsOnline . Add ( uuid ) ;
}
}
}
2011-07-16 00:53:25 +00:00
catch
2011-06-08 02:36:04 +00:00
{
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response." ) ;
2011-07-16 00:53:25 +00:00
// reason = "Exception: " + e.Message;
2011-06-08 02:36:04 +00:00
}
return friendsOnline ;
2011-05-24 02:45:39 +00:00
}
2011-12-16 16:48:29 +00:00
[Obsolete]
2011-05-24 02:45:39 +00:00
public List < UUID > GetOnlineFriends ( UUID userID , List < string > friends )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "userID" ] = userID . ToString ( ) ;
int i = 0 ;
foreach ( string s in friends )
{
hash [ "friend_" + i . ToString ( ) ] = s ;
i + + ;
}
IList paramList = new ArrayList ( ) ;
paramList . Add ( hash ) ;
XmlRpcRequest request = new XmlRpcRequest ( "get_online_friends" , paramList ) ;
2011-07-16 00:53:25 +00:00
// string reason = string.Empty;
2011-05-24 02:45:39 +00:00
// Send and get reply
List < UUID > online = new List < UUID > ( ) ;
XmlRpcResponse response = null ;
try
{
response = request . Send ( m_ServerURL , 10000 ) ;
}
2011-07-16 00:53:25 +00:00
catch
2011-05-24 02:45:39 +00:00
{
2014-03-24 12:20:19 +00:00
m_log . DebugFormat ( "[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends" , m_ServerURLHost ) ;
2011-07-16 00:53:25 +00:00
// reason = "Exception: " + e.Message;
2011-05-24 02:45:39 +00:00
return online ;
}
if ( response . IsFault )
{
2014-03-24 12:20:19 +00:00
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}" , m_ServerURLHost , response . FaultString ) ;
2011-07-16 00:53:25 +00:00
// reason = "XMLRPC Fault";
2011-05-24 02:45:39 +00:00
return online ;
}
hash = ( Hashtable ) response . Value ;
//foreach (Object o in hash)
// m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
try
{
if ( hash = = null )
{
2014-03-24 12:20:19 +00:00
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD" , m_ServerURLHost ) ;
2011-07-16 00:53:25 +00:00
// reason = "Internal error 1";
2011-05-24 02:45:39 +00:00
return online ;
}
// Here is the actual response
foreach ( object key in hash . Keys )
{
if ( key is string & & ( ( string ) key ) . StartsWith ( "friend_" ) & & hash [ key ] ! = null )
{
UUID uuid ;
if ( UUID . TryParse ( hash [ key ] . ToString ( ) , out uuid ) )
online . Add ( uuid ) ;
}
}
}
2011-07-16 00:53:25 +00:00
catch
2011-05-24 02:45:39 +00:00
{
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response." ) ;
2011-07-16 00:53:25 +00:00
// reason = "Exception: " + e.Message;
2011-05-24 02:45:39 +00:00
}
return online ;
}
2010-01-29 03:19:42 +00:00
2012-01-01 19:57:13 +00:00
public Dictionary < string , object > GetUserInfo ( UUID userID )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "userID" ] = userID . ToString ( ) ;
2014-02-13 23:55:38 +00:00
hash = CallServer ( "get_user_info" , hash ) ;
2012-01-01 19:57:13 +00:00
Dictionary < string , object > info = new Dictionary < string , object > ( ) ;
2014-02-13 23:55:38 +00:00
foreach ( object key in hash . Keys )
2012-01-01 19:57:13 +00:00
{
2014-02-13 23:55:38 +00:00
if ( hash [ key ] ! = null )
2012-01-01 19:57:13 +00:00
{
2014-02-13 23:55:38 +00:00
info . Add ( key . ToString ( ) , hash [ key ] ) ;
2012-01-01 19:57:13 +00:00
}
}
return info ;
}
2011-05-24 16:38:03 +00:00
public Dictionary < string , object > GetServerURLs ( UUID userID )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "userID" ] = userID . ToString ( ) ;
2014-02-13 23:55:38 +00:00
hash = CallServer ( "get_server_urls" , hash ) ;
Dictionary < string , object > serverURLs = new Dictionary < string , object > ( ) ;
foreach ( object key in hash . Keys )
2011-05-24 16:38:03 +00:00
{
2014-02-13 23:55:38 +00:00
if ( key is string & & ( ( string ) key ) . StartsWith ( "SRV_" ) & & hash [ key ] ! = null )
2011-05-24 16:38:03 +00:00
{
2014-02-13 23:55:38 +00:00
string serverType = key . ToString ( ) . Substring ( 4 ) ; // remove "SRV_"
serverURLs . Add ( serverType , hash [ key ] . ToString ( ) ) ;
2011-05-24 16:38:03 +00:00
}
}
return serverURLs ;
}
2011-05-25 19:32:21 +00:00
public string LocateUser ( UUID userID )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "userID" ] = userID . ToString ( ) ;
2014-02-13 23:55:38 +00:00
hash = CallServer ( "locate_user" , hash ) ;
2011-05-25 19:32:21 +00:00
string url = string . Empty ;
2014-02-13 23:55:38 +00:00
// Here's the actual response
if ( hash . ContainsKey ( "URL" ) )
url = hash [ "URL" ] . ToString ( ) ;
2011-05-25 19:32:21 +00:00
return url ;
}
2011-05-26 17:04:48 +00:00
public string GetUUI ( UUID userID , UUID targetUserID )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "userID" ] = userID . ToString ( ) ;
hash [ "targetUserID" ] = targetUserID . ToString ( ) ;
2014-02-13 23:55:38 +00:00
hash = CallServer ( "get_uui" , hash ) ;
2011-05-26 17:04:48 +00:00
string uui = string . Empty ;
2014-02-13 23:55:38 +00:00
// Here's the actual response
if ( hash . ContainsKey ( "UUI" ) )
uui = hash [ "UUI" ] . ToString ( ) ;
2011-05-26 17:04:48 +00:00
return uui ;
}
2012-03-18 04:27:28 +00:00
public UUID GetUUID ( String first , String last )
{
Hashtable hash = new Hashtable ( ) ;
hash [ "first" ] = first ;
hash [ "last" ] = last ;
2014-02-13 23:55:38 +00:00
hash = CallServer ( "get_uuid" , hash ) ;
2012-03-18 04:27:28 +00:00
2014-02-13 23:55:38 +00:00
if ( ! hash . ContainsKey ( "UUID" ) )
2012-03-18 04:27:28 +00:00
{
2014-03-24 12:20:19 +00:00
throw new Exception ( string . Format ( "[USER AGENT CONNECTOR]: get_uuid call to {0} didn't return a UUID" , m_ServerURLHost ) ) ;
2012-03-18 04:27:28 +00:00
}
2014-02-13 23:55:38 +00:00
UUID uuid ;
if ( ! UUID . TryParse ( hash [ "UUID" ] . ToString ( ) , out uuid ) )
2012-03-18 04:27:28 +00:00
{
2014-03-24 12:20:19 +00:00
throw new Exception ( string . Format ( "[USER AGENT CONNECTOR]: get_uuid call to {0} returned an invalid UUID: {1}" , m_ServerURLHost , hash [ "UUID" ] . ToString ( ) ) ) ;
2012-03-18 04:27:28 +00:00
}
return uuid ;
}
2010-01-29 03:19:42 +00:00
private bool GetBoolResponse ( XmlRpcRequest request , out string reason )
{
2014-03-24 12:20:19 +00:00
//m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURLHost);
2010-01-29 03:19:42 +00:00
XmlRpcResponse response = null ;
try
{
response = request . Send ( m_ServerURL , 10000 ) ;
}
catch ( Exception e )
{
2014-03-24 12:20:19 +00:00
m_log . DebugFormat ( "[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse" , m_ServerURLHost ) ;
2010-01-29 03:19:42 +00:00
reason = "Exception: " + e . Message ;
return false ;
}
if ( response . IsFault )
{
2014-03-24 12:20:19 +00:00
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}" , m_ServerURLHost , response . FaultString ) ;
2010-01-29 03:19:42 +00:00
reason = "XMLRPC Fault" ;
return false ;
}
Hashtable hash = ( Hashtable ) response . Value ;
//foreach (Object o in hash)
// m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
try
{
2010-08-04 18:18:33 +00:00
if ( hash = = null )
{
2014-03-24 12:20:19 +00:00
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD" , m_ServerURLHost ) ;
2010-08-04 18:18:33 +00:00
reason = "Internal error 1" ;
return false ;
}
2010-01-29 03:19:42 +00:00
bool success = false ;
reason = string . Empty ;
2010-08-04 18:18:33 +00:00
if ( hash . ContainsKey ( "result" ) )
Boolean . TryParse ( ( string ) hash [ "result" ] , out success ) ;
else
{
reason = "Internal error 2" ;
2014-03-24 12:20:19 +00:00
m_log . WarnFormat ( "[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'" , m_ServerURLHost ) ;
2010-08-04 18:18:33 +00:00
}
2010-01-29 03:19:42 +00:00
return success ;
}
catch ( Exception e )
{
2010-08-16 21:36:20 +00:00
m_log . ErrorFormat ( "[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response." ) ;
2010-08-04 18:18:33 +00:00
if ( hash . ContainsKey ( "result" ) & & hash [ "result" ] ! = null )
m_log . ErrorFormat ( "Reply was " , ( string ) hash [ "result" ] ) ;
2010-01-29 03:19:42 +00:00
reason = "Exception: " + e . Message ;
return false ;
}
}
}
}