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-05-05 21:06:36 +00:00
using System.Collections ;
2009-12-31 05:00:16 +00:00
using System.Collections.Generic ;
2010-11-02 19:00:14 +00:00
using System.Linq ;
2010-01-01 01:18:55 +00:00
using System.Net ;
2009-12-31 05:00:16 +00:00
using System.Reflection ;
2009-12-31 19:42:33 +00:00
using System.Text.RegularExpressions ;
2009-12-31 05:00:16 +00:00
using log4net ;
using Nini.Config ;
using OpenMetaverse ;
using OpenSim.Framework ;
2010-01-11 04:17:37 +00:00
using OpenSim.Framework.Console ;
2009-12-31 05:00:16 +00:00
using OpenSim.Server.Base ;
using OpenSim.Services.Interfaces ;
2009-12-31 19:42:33 +00:00
using GridRegion = OpenSim . Services . Interfaces . GridRegion ;
2010-02-26 00:11:04 +00:00
using FriendInfo = OpenSim . Services . Interfaces . FriendInfo ;
2010-01-29 03:19:42 +00:00
using OpenSim.Services.Connectors.Hypergrid ;
2009-12-31 05:00:16 +00:00
namespace OpenSim.Services.LLLoginService
{
public class LLLoginService : ILoginService
{
2009-12-31 19:42:33 +00:00
private static readonly ILog m_log = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2013-11-02 22:42:26 +00:00
private static readonly string LogHeader = "[LLOGIN SERVICE]" ;
2010-01-11 04:17:37 +00:00
private static bool Initialized = false ;
2009-12-31 19:42:33 +00:00
2010-03-10 12:44:53 +00:00
protected IUserAccountService m_UserAccountService ;
2010-05-08 04:29:56 +00:00
protected IGridUserService m_GridUserService ;
2010-03-10 12:44:53 +00:00
protected IAuthenticationService m_AuthenticationService ;
protected IInventoryService m_InventoryService ;
2014-03-24 16:00:59 +00:00
protected IInventoryService m_HGInventoryService ;
2010-03-10 12:44:53 +00:00
protected IGridService m_GridService ;
protected IPresenceService m_PresenceService ;
2010-05-13 14:59:30 +00:00
protected ISimulationService m_LocalSimulationService ;
protected ISimulationService m_RemoteSimulationService ;
2010-03-10 12:44:53 +00:00
protected ILibraryService m_LibraryService ;
protected IFriendsService m_FriendsService ;
protected IAvatarService m_AvatarService ;
2010-05-13 14:59:30 +00:00
protected IUserAgentService m_UserAgentService ;
2010-01-29 03:19:42 +00:00
2010-05-13 14:59:30 +00:00
protected GatekeeperServiceConnector m_GatekeeperConnector ;
2009-12-31 05:00:16 +00:00
2010-05-13 14:59:30 +00:00
protected string m_DefaultRegionName ;
2010-03-10 12:44:53 +00:00
protected string m_WelcomeMessage ;
2010-05-13 14:59:30 +00:00
protected bool m_RequireInventory ;
2010-03-10 12:44:53 +00:00
protected int m_MinLoginLevel ;
2010-05-13 14:59:30 +00:00
protected string m_GatekeeperURL ;
protected bool m_AllowRemoteSetLoginLevel ;
2010-07-02 03:03:35 +00:00
protected string m_MapTileURL ;
2015-09-02 18:54:53 +00:00
protected string m_ProfileURL ;
protected string m_OpenIDURL ;
2010-08-07 21:24:17 +00:00
protected string m_SearchURL ;
2011-08-14 16:20:20 +00:00
protected string m_Currency ;
2013-06-13 13:18:27 +00:00
protected string m_ClassifiedFee ;
2017-01-04 19:13:59 +00:00
protected int m_MaxAgentGroups = 42 ;
2013-05-09 14:46:37 +00:00
protected string m_DestinationGuide ;
protected string m_AvatarPicker ;
2011-04-27 14:02:37 +00:00
protected string m_AllowedClients ;
protected string m_DeniedClients ;
2015-06-23 17:15:22 +00:00
protected string m_MessageUrl ;
2012-05-04 18:21:43 +00:00
protected string m_DSTZone ;
2010-01-17 19:33:47 +00:00
IConfig m_LoginServerConfig ;
2011-11-24 22:11:54 +00:00
// IConfig m_ClientsConfig;
2010-01-17 19:33:47 +00:00
2010-01-02 05:12:46 +00:00
public LLLoginService ( IConfigSource config , ISimulationService simService , ILibraryService libraryService )
2009-12-31 05:00:16 +00:00
{
2010-01-17 19:33:47 +00:00
m_LoginServerConfig = config . Configs [ "LoginService" ] ;
if ( m_LoginServerConfig = = null )
2009-12-31 05:00:16 +00:00
throw new Exception ( String . Format ( "No section LoginService in config file" ) ) ;
2010-01-17 19:33:47 +00:00
string accountService = m_LoginServerConfig . GetString ( "UserAccountService" , String . Empty ) ;
2010-05-08 04:29:56 +00:00
string gridUserService = m_LoginServerConfig . GetString ( "GridUserService" , String . Empty ) ;
2010-01-29 03:19:42 +00:00
string agentService = m_LoginServerConfig . GetString ( "UserAgentService" , String . Empty ) ;
2010-01-17 19:33:47 +00:00
string authService = m_LoginServerConfig . GetString ( "AuthenticationService" , String . Empty ) ;
string invService = m_LoginServerConfig . GetString ( "InventoryService" , String . Empty ) ;
string gridService = m_LoginServerConfig . GetString ( "GridService" , String . Empty ) ;
string presenceService = m_LoginServerConfig . GetString ( "PresenceService" , String . Empty ) ;
string libService = m_LoginServerConfig . GetString ( "LibraryService" , String . Empty ) ;
2010-02-26 00:11:04 +00:00
string friendsService = m_LoginServerConfig . GetString ( "FriendsService" , String . Empty ) ;
2010-01-17 19:33:47 +00:00
string avatarService = m_LoginServerConfig . GetString ( "AvatarService" , String . Empty ) ;
string simulationService = m_LoginServerConfig . GetString ( "SimulationService" , String . Empty ) ;
2009-12-31 05:00:16 +00:00
2010-01-17 19:33:47 +00:00
m_DefaultRegionName = m_LoginServerConfig . GetString ( "DefaultRegion" , String . Empty ) ;
m_WelcomeMessage = m_LoginServerConfig . GetString ( "WelcomeMessage" , "Welcome to OpenSim!" ) ;
m_RequireInventory = m_LoginServerConfig . GetBoolean ( "RequireInventory" , true ) ;
2010-05-05 21:06:36 +00:00
m_AllowRemoteSetLoginLevel = m_LoginServerConfig . GetBoolean ( "AllowRemoteSetLoginLevel" , false ) ;
m_MinLoginLevel = m_LoginServerConfig . GetInt ( "MinLoginLevel" , 0 ) ;
2013-02-28 04:59:16 +00:00
m_GatekeeperURL = Util . GetConfigVarFromSections < string > ( config , "GatekeeperURI" ,
new string [ ] { "Startup" , "Hypergrid" , "LoginService" } , String . Empty ) ;
2010-07-02 03:03:35 +00:00
m_MapTileURL = m_LoginServerConfig . GetString ( "MapTileURL" , string . Empty ) ;
2015-09-02 18:54:53 +00:00
m_ProfileURL = m_LoginServerConfig . GetString ( "ProfileServerURL" , string . Empty ) ;
m_OpenIDURL = m_LoginServerConfig . GetString ( "OpenIDServerURL" , String . Empty ) ;
2010-08-07 21:24:17 +00:00
m_SearchURL = m_LoginServerConfig . GetString ( "SearchURL" , string . Empty ) ;
2011-08-14 16:20:20 +00:00
m_Currency = m_LoginServerConfig . GetString ( "Currency" , string . Empty ) ;
2013-06-13 13:18:27 +00:00
m_ClassifiedFee = m_LoginServerConfig . GetString ( "ClassifiedFee" , string . Empty ) ;
2013-05-09 14:46:37 +00:00
m_DestinationGuide = m_LoginServerConfig . GetString ( "DestinationGuide" , string . Empty ) ;
m_AvatarPicker = m_LoginServerConfig . GetString ( "AvatarPicker" , string . Empty ) ;
2011-04-27 14:02:37 +00:00
2015-09-06 17:00:20 +00:00
string [ ] possibleAccessControlConfigSections = new string [ ] { "AccessControl" , "LoginService" } ;
m_AllowedClients = Util . GetConfigVarFromSections < string > (
config , "AllowedClients" , possibleAccessControlConfigSections , string . Empty ) ;
m_DeniedClients = Util . GetConfigVarFromSections < string > (
config , "DeniedClients" , possibleAccessControlConfigSections , string . Empty ) ;
2015-06-23 17:15:22 +00:00
m_MessageUrl = m_LoginServerConfig . GetString ( "MessageUrl" , string . Empty ) ;
2012-05-04 18:21:43 +00:00
m_DSTZone = m_LoginServerConfig . GetString ( "DSTZone" , "America/Los_Angeles;Pacific Standard Time" ) ;
2015-08-06 23:32:58 +00:00
IConfig groupConfig = config . Configs [ "Groups" ] ;
if ( groupConfig ! = null )
m_MaxAgentGroups = groupConfig . GetInt ( "MaxAgentGroups" , 42 ) ;
2011-06-13 05:10:16 +00:00
// Clean up some of these vars
if ( m_MapTileURL ! = String . Empty )
{
m_MapTileURL = m_MapTileURL . Trim ( ) ;
if ( ! m_MapTileURL . EndsWith ( "/" ) )
m_MapTileURL = m_MapTileURL + "/" ;
}
2010-01-03 00:26:40 +00:00
// These are required; the others aren't
if ( accountService = = string . Empty | | authService = = string . Empty )
2009-12-31 05:00:16 +00:00
throw new Exception ( "LoginService is missing service specifications" ) ;
2011-11-05 09:42:21 +00:00
// replace newlines in welcome message
m_WelcomeMessage = m_WelcomeMessage . Replace ( "\\n" , "\n" ) ;
2009-12-31 05:00:16 +00:00
Object [ ] args = new Object [ ] { config } ;
m_UserAccountService = ServerUtils . LoadPlugin < IUserAccountService > ( accountService , args ) ;
2010-05-08 04:29:56 +00:00
m_GridUserService = ServerUtils . LoadPlugin < IGridUserService > ( gridUserService , args ) ;
2010-11-25 19:34:55 +00:00
Object [ ] authArgs = new Object [ ] { config , m_UserAccountService } ;
m_AuthenticationService = ServerUtils . LoadPlugin < IAuthenticationService > ( authService , authArgs ) ;
2009-12-31 05:00:16 +00:00
m_InventoryService = ServerUtils . LoadPlugin < IInventoryService > ( invService , args ) ;
2010-05-08 04:29:56 +00:00
2009-12-31 05:00:16 +00:00
if ( gridService ! = string . Empty )
m_GridService = ServerUtils . LoadPlugin < IGridService > ( gridService , args ) ;
if ( presenceService ! = string . Empty )
m_PresenceService = ServerUtils . LoadPlugin < IPresenceService > ( presenceService , args ) ;
2010-01-03 00:26:40 +00:00
if ( avatarService ! = string . Empty )
m_AvatarService = ServerUtils . LoadPlugin < IAvatarService > ( avatarService , args ) ;
2010-02-26 00:11:04 +00:00
if ( friendsService ! = string . Empty )
m_FriendsService = ServerUtils . LoadPlugin < IFriendsService > ( friendsService , args ) ;
2010-01-03 19:44:57 +00:00
if ( simulationService ! = string . Empty )
m_RemoteSimulationService = ServerUtils . LoadPlugin < ISimulationService > ( simulationService , args ) ;
2010-01-29 03:19:42 +00:00
if ( agentService ! = string . Empty )
m_UserAgentService = ServerUtils . LoadPlugin < IUserAgentService > ( agentService , args ) ;
2014-03-24 16:00:59 +00:00
// Get the Hypergrid inventory service (exists only if Hypergrid is enabled)
2014-03-24 16:33:18 +00:00
string hgInvServicePlugin = m_LoginServerConfig . GetString ( "HGInventoryServicePlugin" , String . Empty ) ;
if ( hgInvServicePlugin ! = string . Empty )
2014-03-24 16:00:59 +00:00
{
2017-01-02 17:47:20 +00:00
// TODO: Remove HGInventoryServiceConstructorArg after 0.9 release
2014-03-24 16:33:18 +00:00
string hgInvServiceArg = m_LoginServerConfig . GetString ( "HGInventoryServiceConstructorArg" , String . Empty ) ;
2017-01-02 17:47:20 +00:00
if ( hgInvServiceArg ! = String . Empty )
{
m_log . Warn ( "[LLOGIN SERVICE]: You are using HGInventoryServiceConstructorArg, which is deprecated. See example file for correct syntax." ) ;
hgInvServicePlugin = hgInvServiceArg + "@" + hgInvServicePlugin ;
}
m_HGInventoryService = ServerUtils . LoadPlugin < IInventoryService > ( hgInvServicePlugin , args ) ;
2014-03-24 16:00:59 +00:00
}
2010-01-02 05:12:46 +00:00
/ /
// deal with the services given as argument
/ /
2009-12-31 22:59:26 +00:00
m_LocalSimulationService = simService ;
2010-01-02 05:12:46 +00:00
if ( libraryService ! = null )
{
m_log . DebugFormat ( "[LLOGIN SERVICE]: Using LibraryService given as argument" ) ;
m_LibraryService = libraryService ;
}
else if ( libService ! = string . Empty )
{
m_log . DebugFormat ( "[LLOGIN SERVICE]: Using instantiated LibraryService" ) ;
m_LibraryService = ServerUtils . LoadPlugin < ILibraryService > ( libService , args ) ;
}
2009-12-31 05:00:16 +00:00
2010-01-29 03:19:42 +00:00
m_GatekeeperConnector = new GatekeeperServiceConnector ( ) ;
2010-01-11 04:17:37 +00:00
if ( ! Initialized )
{
Initialized = true ;
RegisterCommands ( ) ;
}
2010-01-01 04:51:35 +00:00
m_log . DebugFormat ( "[LLOGIN SERVICE]: Starting..." ) ;
2009-12-31 05:00:16 +00:00
}
2010-01-02 05:12:46 +00:00
public LLLoginService ( IConfigSource config ) : this ( config , null , null )
2009-12-31 22:59:26 +00:00
{
}
2010-05-05 21:06:36 +00:00
public Hashtable SetLevel ( string firstName , string lastName , string passwd , int level , IPEndPoint clientIP )
{
Hashtable response = new Hashtable ( ) ;
response [ "success" ] = "false" ;
if ( ! m_AllowRemoteSetLoginLevel )
return response ;
try
{
UserAccount account = m_UserAccountService . GetUserAccount ( UUID . Zero , firstName , lastName ) ;
if ( account = = null )
{
m_log . InfoFormat ( "[LLOGIN SERVICE]: Set Level failed, user {0} {1} not found" , firstName , lastName ) ;
return response ;
}
if ( account . UserLevel < 200 )
{
m_log . InfoFormat ( "[LLOGIN SERVICE]: Set Level failed, reason: user level too low" ) ;
return response ;
}
/ /
// Authenticate this user
/ /
// We don't support clear passwords here
/ /
string token = m_AuthenticationService . Authenticate ( account . PrincipalID , passwd , 30 ) ;
UUID secureSession = UUID . Zero ;
if ( ( token = = string . Empty ) | | ( token ! = string . Empty & & ! UUID . TryParse ( token , out secureSession ) ) )
{
m_log . InfoFormat ( "[LLOGIN SERVICE]: SetLevel failed, reason: authentication failed" ) ;
return response ;
}
}
catch ( Exception e )
{
m_log . Error ( "[LLOGIN SERVICE]: SetLevel failed, exception " + e . ToString ( ) ) ;
return response ;
}
m_MinLoginLevel = level ;
m_log . InfoFormat ( "[LLOGIN SERVICE]: Login level set to {0} by {1} {2}" , level , firstName , lastName ) ;
response [ "success" ] = true ;
return response ;
}
2010-10-04 03:01:59 +00:00
public LoginResponse Login ( string firstName , string lastName , string passwd , string startLocation , UUID scopeID ,
2015-11-23 23:10:02 +00:00
string clientVersion , string channel , string mac , string id0 , IPEndPoint clientIP , bool LibOMVclient )
2009-12-31 05:00:16 +00:00
{
2009-12-31 22:59:26 +00:00
bool success = false ;
2010-01-02 00:54:24 +00:00
UUID session = UUID . Random ( ) ;
2015-09-02 18:54:53 +00:00
2015-06-25 22:01:43 +00:00
string processedMessage ;
2015-09-02 18:54:53 +00:00
2015-11-23 23:10:02 +00:00
if ( clientVersion . Contains ( "Radegast" ) )
LibOMVclient = false ;
2014-10-24 01:12:30 +00:00
m_log . InfoFormat ( "[LLOGIN SERVICE]: Login request for {0} {1} at {2} using viewer {3}, channel {4}, IP {5}, Mac {6}, Id0 {7}, Possible LibOMVGridProxy: {8} " ,
2015-11-23 23:10:02 +00:00
firstName , lastName , startLocation , clientVersion , channel , clientIP . Address . ToString ( ) , mac , id0 , LibOMVclient . ToString ( ) ) ;
2012-05-04 18:21:43 +00:00
2010-01-02 00:54:24 +00:00
try
2010-01-01 01:18:55 +00:00
{
2011-04-27 14:02:37 +00:00
/ /
// Check client
/ /
if ( m_AllowedClients ! = string . Empty )
{
Regex arx = new Regex ( m_AllowedClients ) ;
Match am = arx . Match ( clientVersion ) ;
if ( ! am . Success )
{
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed for {0} {1}, reason: client {2} is not allowed" ,
firstName , lastName , clientVersion ) ;
2011-04-27 14:02:37 +00:00
return LLFailedLoginResponse . LoginBlockedProblem ;
}
}
if ( m_DeniedClients ! = string . Empty )
{
Regex drx = new Regex ( m_DeniedClients ) ;
Match dm = drx . Match ( clientVersion ) ;
if ( dm . Success )
{
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed for {0} {1}, reason: client {2} is denied" ,
firstName , lastName , clientVersion ) ;
2011-04-27 14:02:37 +00:00
return LLFailedLoginResponse . LoginBlockedProblem ;
}
}
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
// Get the account and check that it exists
2010-01-14 02:30:33 +00:00
/ /
2010-04-27 02:48:49 +00:00
UserAccount account = m_UserAccountService . GetUserAccount ( scopeID , firstName , lastName ) ;
2010-01-02 00:54:24 +00:00
if ( account = = null )
{
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed for {0} {1}, reason: user not found" , firstName , lastName ) ;
2010-01-02 00:54:24 +00:00
return LLFailedLoginResponse . UserProblem ;
}
2009-12-31 05:00:16 +00:00
2010-01-11 04:17:37 +00:00
if ( account . UserLevel < m_MinLoginLevel )
{
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed for {0} {1}, reason: user level is {2} but minimum login level is {3}" ,
2012-10-01 10:26:11 +00:00
firstName , lastName , account . UserLevel , m_MinLoginLevel ) ;
2010-01-11 04:17:37 +00:00
return LLFailedLoginResponse . LoginBlockedProblem ;
}
2010-04-27 02:48:49 +00:00
// If a scope id is requested, check that the account is in
// that scope, or unscoped.
/ /
if ( scopeID ! = UUID . Zero )
{
if ( account . ScopeID ! = scopeID & & account . ScopeID ! = UUID . Zero )
{
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed, reason: user {0} {1} not found" , firstName , lastName ) ;
2010-04-27 02:48:49 +00:00
return LLFailedLoginResponse . UserProblem ;
}
}
else
{
scopeID = account . ScopeID ;
}
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
// Authenticate this user
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
if ( ! passwd . StartsWith ( "$1$" ) )
passwd = "$1$" + Util . Md5Hash ( passwd ) ;
passwd = passwd . Remove ( 0 , 3 ) ; //remove $1$
2012-08-15 21:31:38 +00:00
UUID realID ;
string token = m_AuthenticationService . Authenticate ( account . PrincipalID , passwd , 30 , out realID ) ;
2010-01-02 00:54:24 +00:00
UUID secureSession = UUID . Zero ;
if ( ( token = = string . Empty ) | | ( token ! = string . Empty & & ! UUID . TryParse ( token , out secureSession ) ) )
{
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed for {0} {1}, reason: authentication failed" ,
firstName , lastName ) ;
2010-01-02 00:54:24 +00:00
return LLFailedLoginResponse . UserProblem ;
}
2009-12-31 05:00:16 +00:00
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
// Get the user's inventory
2010-01-14 02:30:33 +00:00
/ /
2010-01-03 00:26:40 +00:00
if ( m_RequireInventory & & m_InventoryService = = null )
{
2012-07-05 20:30:20 +00:00
m_log . WarnFormat (
"[LLOGIN SERVICE]: Login failed for {0} {1}, reason: inventory service not set up" ,
firstName , lastName ) ;
2010-01-03 00:26:40 +00:00
return LLFailedLoginResponse . InventoryProblem ;
}
2012-07-05 20:30:20 +00:00
2014-03-24 16:00:59 +00:00
if ( m_HGInventoryService ! = null )
{
// Give the Suitcase service a chance to create the suitcase folder.
// (If we're not using the Suitcase inventory service then this won't do anything.)
m_HGInventoryService . GetRootFolder ( account . PrincipalID ) ;
}
2010-01-02 00:54:24 +00:00
List < InventoryFolderBase > inventorySkel = m_InventoryService . GetInventorySkeleton ( account . PrincipalID ) ;
if ( m_RequireInventory & & ( ( inventorySkel = = null ) | | ( inventorySkel ! = null & & inventorySkel . Count = = 0 ) ) )
{
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed, for {0} {1}, reason: unable to retrieve user inventory" ,
firstName , lastName ) ;
2010-01-02 00:54:24 +00:00
return LLFailedLoginResponse . InventoryProblem ;
}
2009-12-31 05:00:16 +00:00
2010-05-16 16:12:40 +00:00
// Get active gestures
List < InventoryItemBase > gestures = m_InventoryService . GetActiveGestures ( account . PrincipalID ) ;
2011-01-18 00:25:24 +00:00
// m_log.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count);
2010-05-16 16:12:40 +00:00
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
// Login the presence
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
if ( m_PresenceService ! = null )
2010-01-01 01:18:55 +00:00
{
2010-01-02 00:54:24 +00:00
success = m_PresenceService . LoginAgent ( account . PrincipalID . ToString ( ) , session , secureSession ) ;
2012-07-05 20:30:20 +00:00
2010-01-02 00:54:24 +00:00
if ( ! success )
{
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed for {0} {1}, reason: could not login presence" ,
firstName , lastName ) ;
2010-01-02 00:54:24 +00:00
return LLFailedLoginResponse . GridProblem ;
}
}
2010-05-08 04:29:56 +00:00
/ /
// Change Online status and get the home region
/ /
GridRegion home = null ;
GridUserInfo guinfo = m_GridUserService . LoggedIn ( account . PrincipalID . ToString ( ) ) ;
2014-01-30 00:40:56 +00:00
// We are only going to complain about no home if the user actually tries to login there, to avoid
// spamming the console.
if ( guinfo ! = null )
2010-05-08 04:29:56 +00:00
{
2014-01-30 00:40:56 +00:00
if ( guinfo . HomeRegionID = = UUID . Zero & & startLocation = = "home" )
{
m_log . WarnFormat (
"[LLOGIN SERVICE]: User {0} tried to login to a 'home' start location but they have none set" ,
account . Name ) ;
}
else if ( m_GridService ! = null )
{
home = m_GridService . GetRegionByUUID ( scopeID , guinfo . HomeRegionID ) ;
if ( home = = null & & startLocation = = "home" )
{
m_log . WarnFormat (
"[LLOGIN SERVICE]: User {0} tried to login to a 'home' start location with ID {1} but this was not found." ,
account . Name , guinfo . HomeRegionID ) ;
}
}
2010-05-08 04:29:56 +00:00
}
2014-01-30 00:40:56 +00:00
else
2010-05-08 04:29:56 +00:00
{
// something went wrong, make something up, so that we don't have to test this anywhere else
2013-11-02 22:42:26 +00:00
m_log . DebugFormat ( "{0} Failed to fetch GridUserInfo. Creating empty GridUserInfo as home" , LogHeader ) ;
2010-05-08 04:29:56 +00:00
guinfo = new GridUserInfo ( ) ;
2010-09-12 17:43:49 +00:00
guinfo . LastPosition = guinfo . HomePosition = new Vector3 ( 128 , 128 , 30 ) ;
2010-05-08 04:29:56 +00:00
}
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
// Find the destination region/grid
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
string where = string . Empty ;
Vector3 position = Vector3 . Zero ;
Vector3 lookAt = Vector3 . Zero ;
2010-01-29 03:19:42 +00:00
GridRegion gatekeeper = null ;
2011-01-27 02:49:32 +00:00
TeleportFlags flags ;
GridRegion destination = FindDestination ( account , scopeID , guinfo , session , startLocation , home , out gatekeeper , out where , out position , out lookAt , out flags ) ;
2010-01-02 00:54:24 +00:00
if ( destination = = null )
{
2010-05-08 04:29:56 +00:00
m_PresenceService . LogoutAgent ( session ) ;
2012-07-05 20:30:20 +00:00
m_log . InfoFormat (
"[LLOGIN SERVICE]: Login failed for {0} {1}, reason: destination not found" ,
firstName , lastName ) ;
2009-12-31 19:42:33 +00:00
return LLFailedLoginResponse . GridProblem ;
2010-01-01 01:18:55 +00:00
}
2012-07-05 20:30:20 +00:00
else
{
m_log . DebugFormat (
"[LLOGIN SERVICE]: Found destination {0}, endpoint {1} for {2} {3}" ,
destination . RegionName , destination . ExternalEndPoint , firstName , lastName ) ;
}
2010-01-01 01:18:55 +00:00
2011-01-27 02:54:41 +00:00
if ( account . UserLevel > = 200 )
flags | = TeleportFlags . Godlike ;
2010-01-14 02:30:33 +00:00
/ /
2010-01-03 00:26:40 +00:00
// Get the avatar
2010-01-14 02:30:33 +00:00
/ /
2010-10-20 23:17:54 +00:00
AvatarAppearance avatar = null ;
2010-01-03 00:26:40 +00:00
if ( m_AvatarService ! = null )
{
2010-10-20 23:17:54 +00:00
avatar = m_AvatarService . GetAppearance ( account . PrincipalID ) ;
2010-01-03 00:26:40 +00:00
}
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
// Instantiate/get the simulation interface and launch an agent at the destination
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
string reason = string . Empty ;
2010-08-09 01:56:47 +00:00
GridRegion dest ;
2010-10-04 03:01:59 +00:00
AgentCircuitData aCircuit = LaunchAgentAtGrid ( gatekeeper , destination , account , avatar , session , secureSession , position , where ,
2011-01-27 02:49:32 +00:00
clientVersion , channel , mac , id0 , clientIP , flags , out where , out reason , out dest ) ;
2010-08-09 01:56:47 +00:00
destination = dest ;
2010-01-02 00:54:24 +00:00
if ( aCircuit = = null )
{
2010-05-08 04:29:56 +00:00
m_PresenceService . LogoutAgent ( session ) ;
2012-07-05 20:30:20 +00:00
m_log . InfoFormat ( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: {2}" , firstName , lastName , reason ) ;
2010-08-08 23:48:08 +00:00
return new LLFailedLoginResponse ( "key" , reason , "false" ) ;
2010-01-14 02:30:33 +00:00
2010-01-01 01:18:55 +00:00
}
2010-02-26 00:11:04 +00:00
// Get Friends list
FriendInfo [ ] friendsList = new FriendInfo [ 0 ] ;
if ( m_FriendsService ! = null )
{
friendsList = m_FriendsService . GetFriends ( account . PrincipalID ) ;
2011-08-30 21:08:43 +00:00
// m_log.DebugFormat("[LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length);
2010-02-26 00:11:04 +00:00
}
2009-12-31 19:42:33 +00:00
2010-01-14 02:30:33 +00:00
/ /
2010-01-02 00:54:24 +00:00
// Finally, fill out the response and return it
2010-01-14 02:30:33 +00:00
/ /
2015-06-23 17:15:22 +00:00
if ( m_MessageUrl ! = String . Empty )
{
2016-08-22 05:06:13 +00:00
using ( WebClient client = new WebClient ( ) )
processedMessage = client . DownloadString ( m_MessageUrl ) ;
2015-06-23 17:15:22 +00:00
}
else
{
2015-06-25 22:01:43 +00:00
processedMessage = m_WelcomeMessage ;
2015-06-23 17:15:22 +00:00
}
2015-06-25 22:01:43 +00:00
processedMessage = processedMessage . Replace ( "\\n" , "\n" ) . Replace ( "<USERNAME>" , firstName + " " + lastName ) ;
2012-05-04 18:21:43 +00:00
LLLoginResponse response
= new LLLoginResponse (
account , aCircuit , guinfo , destination , inventorySkel , friendsList , m_LibraryService ,
2015-09-28 14:21:23 +00:00
where , startLocation , position , lookAt , gestures , processedMessage , home , clientIP ,
2013-05-09 14:46:37 +00:00
m_MapTileURL , m_ProfileURL , m_OpenIDURL , m_SearchURL , m_Currency , m_DSTZone ,
2015-09-02 18:54:53 +00:00
m_DestinationGuide , m_AvatarPicker , realID , m_ClassifiedFee , m_MaxAgentGroups ) ;
2010-01-02 00:54:24 +00:00
2015-06-23 17:15:22 +00:00
m_log . DebugFormat ( "[LLOGIN SERVICE]: All clear. Sending login response to {0} {1}" , firstName , lastName ) ;
2012-07-05 20:30:20 +00:00
2015-06-23 17:15:22 +00:00
return response ;
}
2010-01-02 00:54:24 +00:00
catch ( Exception e )
2009-12-31 22:59:26 +00:00
{
2010-03-03 04:17:25 +00:00
m_log . WarnFormat ( "[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}" , firstName , lastName , e . ToString ( ) , e . StackTrace ) ;
2010-01-02 00:54:24 +00:00
if ( m_PresenceService ! = null )
2010-05-08 04:29:56 +00:00
m_PresenceService . LogoutAgent ( session ) ;
2010-01-02 00:54:24 +00:00
return LLFailedLoginResponse . InternalError ;
2009-12-31 22:59:26 +00:00
}
2009-12-31 05:00:16 +00:00
}
2009-12-31 19:42:33 +00:00
2012-05-04 18:21:43 +00:00
protected GridRegion FindDestination (
UserAccount account , UUID scopeID , GridUserInfo pinfo , UUID sessionID , string startLocation ,
GridRegion home , out GridRegion gatekeeper ,
out string where , out Vector3 position , out Vector3 lookAt , out TeleportFlags flags )
2009-12-31 19:42:33 +00:00
{
2011-01-27 02:49:32 +00:00
flags = TeleportFlags . ViaLogin ;
2012-07-05 20:30:20 +00:00
m_log . DebugFormat (
"[LLOGIN SERVICE]: Finding destination matching start location {0} for {1}" ,
startLocation , account . Name ) ;
2010-01-02 00:54:24 +00:00
2010-01-29 03:19:42 +00:00
gatekeeper = null ;
2009-12-31 19:42:33 +00:00
where = "home" ;
position = new Vector3 ( 128 , 128 , 0 ) ;
lookAt = new Vector3 ( 0 , 1 , 0 ) ;
2010-01-14 02:30:33 +00:00
if ( m_GridService = = null )
return null ;
2009-12-31 19:42:33 +00:00
if ( startLocation . Equals ( "home" ) )
{
// logging into home region
if ( pinfo = = null )
return null ;
2010-01-01 01:18:55 +00:00
GridRegion region = null ;
2010-03-04 22:43:30 +00:00
bool tryDefaults = false ;
2010-05-08 04:29:56 +00:00
if ( home = = null )
2010-03-04 22:43:30 +00:00
{
tryDefaults = true ;
}
else
{
2010-05-08 04:29:56 +00:00
region = home ;
2010-03-04 22:43:30 +00:00
2010-05-08 04:29:56 +00:00
position = pinfo . HomePosition ;
lookAt = pinfo . HomeLookAt ;
2012-02-18 05:32:09 +00:00
flags | = TeleportFlags . ViaHome ;
2010-03-04 22:43:30 +00:00
}
if ( tryDefaults )
2010-01-02 00:54:24 +00:00
{
2010-04-27 02:48:49 +00:00
List < GridRegion > defaults = m_GridService . GetDefaultRegions ( scopeID ) ;
2010-03-26 20:13:33 +00:00
if ( defaults ! = null & & defaults . Count > 0 )
{
2016-09-15 00:56:38 +00:00
flags | = TeleportFlags . ViaRegionID ;
2010-03-26 20:13:33 +00:00
region = defaults [ 0 ] ;
where = "safe" ;
}
else
{
m_log . WarnFormat ( "[LLOGIN SERVICE]: User {0} {1} does not have a valid home and this grid does not have default locations. Attempting to find random region" ,
account . FirstName , account . LastName ) ;
2010-11-02 19:00:14 +00:00
region = FindAlternativeRegion ( scopeID ) ;
if ( region ! = null )
2016-09-15 00:56:38 +00:00
{
flags | = TeleportFlags . ViaRegionID ;
2010-03-26 20:13:33 +00:00
where = "safe" ;
2016-09-15 00:56:38 +00:00
}
2010-01-02 00:54:24 +00:00
}
}
2009-12-31 19:42:33 +00:00
return region ;
}
else if ( startLocation . Equals ( "last" ) )
{
// logging into last visited region
where = "last" ;
if ( pinfo = = null )
return null ;
2010-01-01 01:18:55 +00:00
GridRegion region = null ;
2010-05-08 04:29:56 +00:00
if ( pinfo . LastRegionID . Equals ( UUID . Zero ) | | ( region = m_GridService . GetRegionByUUID ( scopeID , pinfo . LastRegionID ) ) = = null )
2010-01-02 00:54:24 +00:00
{
2010-04-27 02:48:49 +00:00
List < GridRegion > defaults = m_GridService . GetDefaultRegions ( scopeID ) ;
2010-01-13 23:28:46 +00:00
if ( defaults ! = null & & defaults . Count > 0 )
{
2016-09-15 00:56:38 +00:00
flags | = TeleportFlags . ViaRegionID ;
2010-01-13 23:28:46 +00:00
region = defaults [ 0 ] ;
where = "safe" ;
2010-03-26 20:13:33 +00:00
}
else
{
m_log . Info ( "[LLOGIN SERVICE]: Last Region Not Found Attempting to find random region" ) ;
2010-11-02 19:00:14 +00:00
region = FindAlternativeRegion ( scopeID ) ;
if ( region ! = null )
2016-09-15 00:56:38 +00:00
{
flags | = TeleportFlags . ViaRegionID ;
2010-03-26 20:13:33 +00:00
where = "safe" ;
2016-09-15 00:56:38 +00:00
}
2010-01-13 23:28:46 +00:00
}
2010-03-26 19:16:41 +00:00
2010-01-02 00:54:24 +00:00
}
2009-12-31 19:42:33 +00:00
else
{
2010-05-08 04:29:56 +00:00
position = pinfo . LastPosition ;
lookAt = pinfo . LastLookAt ;
2009-12-31 19:42:33 +00:00
}
2010-03-04 22:43:30 +00:00
2009-12-31 19:42:33 +00:00
return region ;
}
else
2010-03-26 20:13:33 +00:00
{
2011-01-27 02:49:32 +00:00
flags | = TeleportFlags . ViaRegionID ;
2009-12-31 19:42:33 +00:00
// free uri form
// e.g. New Moon&135&46 New Moon@osgrid.org:8002&153&34
where = "url" ;
2011-06-01 17:44:20 +00:00
GridRegion region = null ;
2014-11-14 21:55:52 +00:00
Regex reURI = new Regex ( @"^uri:(?<region>[^&]+)&(?<x>\d+[.]?\d*)&(?<y>\d+[.]?\d*)&(?<z>\d+[.]?\d*)$" ) ;
2009-12-31 19:42:33 +00:00
Match uriMatch = reURI . Match ( startLocation ) ;
if ( uriMatch = = null )
{
m_log . InfoFormat ( "[LLLOGIN SERVICE]: Got Custom Login URI {0}, but can't process it" , startLocation ) ;
return null ;
}
else
{
2010-04-22 15:47:47 +00:00
position = new Vector3 ( float . Parse ( uriMatch . Groups [ "x" ] . Value , Culture . NumberFormatInfo ) ,
float . Parse ( uriMatch . Groups [ "y" ] . Value , Culture . NumberFormatInfo ) ,
float . Parse ( uriMatch . Groups [ "z" ] . Value , Culture . NumberFormatInfo ) ) ;
2009-12-31 19:42:33 +00:00
string regionName = uriMatch . Groups [ "region" ] . ToString ( ) ;
if ( regionName ! = null )
{
if ( ! regionName . Contains ( "@" ) )
2010-03-26 20:13:33 +00:00
{
2010-04-27 02:48:49 +00:00
List < GridRegion > regions = m_GridService . GetRegionsByName ( scopeID , regionName , 1 ) ;
2009-12-31 19:42:33 +00:00
if ( ( regions = = null ) | | ( regions ! = null & & regions . Count = = 0 ) )
{
2010-01-13 23:28:46 +00:00
m_log . InfoFormat ( "[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}. Trying defaults." , startLocation , regionName ) ;
2010-04-27 02:48:49 +00:00
regions = m_GridService . GetDefaultRegions ( scopeID ) ;
2010-01-13 23:28:46 +00:00
if ( regions ! = null & & regions . Count > 0 )
{
where = "safe" ;
return regions [ 0 ] ;
}
else
{
2011-06-01 17:44:20 +00:00
m_log . Info ( "[LLOGIN SERVICE]: Last Region Not Found Attempting to find random region" ) ;
region = FindAlternativeRegion ( scopeID ) ;
if ( region ! = null )
{
where = "safe" ;
return region ;
}
else
{
m_log . InfoFormat ( "[LLLOGIN SERVICE]: Got Custom Login URI {0}, Grid does not provide default regions and no alternative found." , startLocation ) ;
return null ;
}
2010-01-13 23:28:46 +00:00
}
2009-12-31 19:42:33 +00:00
}
return regions [ 0 ] ;
}
else
2010-03-26 20:13:33 +00:00
{
2010-01-29 03:19:42 +00:00
if ( m_UserAgentService = = null )
{
m_log . WarnFormat ( "[LLLOGIN SERVICE]: This llogin service is not running a user agent service, as such it can't lauch agents at foreign grids" ) ;
return null ;
}
2009-12-31 19:42:33 +00:00
string [ ] parts = regionName . Split ( new char [ ] { '@' } ) ;
if ( parts . Length < 2 )
{
m_log . InfoFormat ( "[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}" , startLocation , regionName ) ;
return null ;
}
2010-03-26 20:13:33 +00:00
// Valid specification of a remote grid
2010-03-26 19:16:41 +00:00
2009-12-31 19:42:33 +00:00
regionName = parts [ 0 ] ;
string domainLocator = parts [ 1 ] ;
parts = domainLocator . Split ( new char [ ] { ':' } ) ;
string domainName = parts [ 0 ] ;
uint port = 0 ;
if ( parts . Length > 1 )
UInt32 . TryParse ( parts [ 1 ] , out port ) ;
2010-03-26 19:16:41 +00:00
2014-04-06 13:18:40 +00:00
region = FindForeignRegion ( domainName , port , regionName , account , out gatekeeper ) ;
2009-12-31 19:42:33 +00:00
return region ;
}
}
else
{
2010-04-27 02:48:49 +00:00
List < GridRegion > defaults = m_GridService . GetDefaultRegions ( scopeID ) ;
2010-01-13 23:28:46 +00:00
if ( defaults ! = null & & defaults . Count > 0 )
{
where = "safe" ;
return defaults [ 0 ] ;
}
else
return null ;
2009-12-31 19:42:33 +00:00
}
}
//response.LookAt = "[r0,r1,r0]";
//// can be: last, home, safe, url
//response.StartLocation = "url";
}
}
2009-12-31 22:59:26 +00:00
2010-11-02 19:00:14 +00:00
private GridRegion FindAlternativeRegion ( UUID scopeID )
{
List < GridRegion > hyperlinks = null ;
2013-11-09 04:53:37 +00:00
List < GridRegion > regions = m_GridService . GetFallbackRegions ( scopeID , ( int ) Util . RegionToWorldLoc ( 1000 ) , ( int ) Util . RegionToWorldLoc ( 1000 ) ) ;
2010-11-02 19:00:14 +00:00
if ( regions ! = null & & regions . Count > 0 )
{
hyperlinks = m_GridService . GetHyperlinks ( scopeID ) ;
IEnumerable < GridRegion > availableRegions = regions . Except ( hyperlinks ) ;
if ( availableRegions . Count ( ) > 0 )
return availableRegions . ElementAt ( 0 ) ;
}
// No fallbacks, try to find an arbitrary region that is not a hyperlink
// maxNumber is fixed for now; maybe use some search pattern with increasing maxSize here?
regions = m_GridService . GetRegionsByName ( scopeID , "" , 10 ) ;
if ( regions ! = null & & regions . Count > 0 )
{
if ( hyperlinks = = null )
hyperlinks = m_GridService . GetHyperlinks ( scopeID ) ;
IEnumerable < GridRegion > availableRegions = regions . Except ( hyperlinks ) ;
if ( availableRegions . Count ( ) > 0 )
return availableRegions . ElementAt ( 0 ) ;
}
return null ;
}
2014-04-06 13:18:40 +00:00
private GridRegion FindForeignRegion ( string domainName , uint port , string regionName , UserAccount account , out GridRegion gatekeeper )
2010-01-29 03:19:42 +00:00
{
2010-12-06 03:43:24 +00:00
m_log . Debug ( "[LLLOGIN SERVICE]: attempting to findforeignregion " + domainName + ":" + port . ToString ( ) + ":" + regionName ) ;
2010-01-29 03:19:42 +00:00
gatekeeper = new GridRegion ( ) ;
gatekeeper . ExternalHostName = domainName ;
gatekeeper . HttpPort = port ;
gatekeeper . RegionName = regionName ;
2010-01-31 00:09:40 +00:00
gatekeeper . InternalEndPoint = new IPEndPoint ( IPAddress . Parse ( "0.0.0.0" ) , 0 ) ;
2010-01-29 03:19:42 +00:00
UUID regionID ;
ulong handle ;
string imageURL = string . Empty , reason = string . Empty ;
2014-04-03 09:47:20 +00:00
string message ;
2016-11-20 04:22:00 +00:00
int sizeX = ( int ) Constants . RegionSize ;
int sizeY = ( int ) Constants . RegionSize ;
if ( m_GatekeeperConnector . LinkRegion ( gatekeeper , out regionID , out handle , out domainName , out imageURL , out reason , out sizeX , out sizeY ) )
2010-01-29 03:19:42 +00:00
{
2014-04-06 13:18:40 +00:00
string homeURI = null ;
if ( account . ServiceURLs ! = null & & account . ServiceURLs . ContainsKey ( "HomeURI" ) )
homeURI = ( string ) account . ServiceURLs [ "HomeURI" ] ;
GridRegion destination = m_GatekeeperConnector . GetHyperlinkRegion ( gatekeeper , regionID , account . PrincipalID , homeURI , out message ) ;
2010-01-29 03:19:42 +00:00
return destination ;
}
return null ;
}
private string hostName = string . Empty ;
private int port = 0 ;
private void SetHostAndPort ( string url )
{
try
{
Uri uri = new Uri ( url ) ;
hostName = uri . Host ;
port = uri . Port ;
}
catch
{
m_log . WarnFormat ( "[LLLogin SERVICE]: Unable to parse GatekeeperURL {0}" , url ) ;
}
}
2010-10-20 23:17:54 +00:00
protected AgentCircuitData LaunchAgentAtGrid ( GridRegion gatekeeper , GridRegion destination , UserAccount account , AvatarAppearance avatar ,
2010-10-04 03:01:59 +00:00
UUID session , UUID secureSession , Vector3 position , string currentWhere , string viewer , string channel , string mac , string id0 ,
2011-01-27 02:49:32 +00:00
IPEndPoint clientIP , TeleportFlags flags , out string where , out string reason , out GridRegion dest )
2009-12-31 22:59:26 +00:00
{
2010-01-29 03:19:42 +00:00
where = currentWhere ;
ISimulationService simConnector = null ;
2009-12-31 22:59:26 +00:00
reason = string . Empty ;
2010-01-29 03:19:42 +00:00
uint circuitCode = 0 ;
AgentCircuitData aCircuit = null ;
if ( m_UserAgentService = = null )
{
// HG standalones have both a localSimulatonDll and a remoteSimulationDll
// non-HG standalones have just a localSimulationDll
// independent login servers have just a remoteSimulationDll
if ( m_LocalSimulationService ! = null )
simConnector = m_LocalSimulationService ;
else if ( m_RemoteSimulationService ! = null )
simConnector = m_RemoteSimulationService ;
}
else // User Agent Service is on
{
if ( gatekeeper = = null ) // login to local grid
{
if ( hostName = = string . Empty )
SetHostAndPort ( m_GatekeeperURL ) ;
gatekeeper = new GridRegion ( destination ) ;
gatekeeper . ExternalHostName = hostName ;
gatekeeper . HttpPort = ( uint ) port ;
2010-10-23 04:18:19 +00:00
gatekeeper . ServerURI = m_GatekeeperURL ;
2010-01-29 03:19:42 +00:00
}
2010-12-06 03:43:24 +00:00
m_log . Debug ( "[LLLOGIN SERVICE]: no gatekeeper detected..... using " + m_GatekeeperURL ) ;
2010-01-29 03:19:42 +00:00
}
bool success = false ;
if ( m_UserAgentService = = null & & simConnector ! = null )
{
circuitCode = ( uint ) Util . RandomClass . Next ( ) ; ;
2010-10-04 03:01:59 +00:00
aCircuit = MakeAgent ( destination , account , avatar , session , secureSession , circuitCode , position , clientIP . Address . ToString ( ) , viewer , channel , mac , id0 ) ;
2011-01-27 02:49:32 +00:00
success = LaunchAgentDirectly ( simConnector , destination , aCircuit , flags , out reason ) ;
2010-01-29 03:19:42 +00:00
if ( ! success & & m_GridService ! = null )
{
// Try the fallback regions
List < GridRegion > fallbacks = m_GridService . GetFallbackRegions ( account . ScopeID , destination . RegionLocX , destination . RegionLocY ) ;
if ( fallbacks ! = null )
{
foreach ( GridRegion r in fallbacks )
{
2011-01-27 02:49:32 +00:00
success = LaunchAgentDirectly ( simConnector , r , aCircuit , flags | TeleportFlags . ViaRegionID , out reason ) ;
2010-01-29 03:19:42 +00:00
if ( success )
{
where = "safe" ;
destination = r ;
break ;
}
}
}
}
}
if ( m_UserAgentService ! = null )
{
circuitCode = ( uint ) Util . RandomClass . Next ( ) ; ;
2010-10-04 03:01:59 +00:00
aCircuit = MakeAgent ( destination , account , avatar , session , secureSession , circuitCode , position , clientIP . Address . ToString ( ) , viewer , channel , mac , id0 ) ;
2012-02-18 05:32:09 +00:00
aCircuit . teleportFlags | = ( uint ) flags ;
2010-05-16 02:25:14 +00:00
success = LaunchAgentIndirectly ( gatekeeper , destination , aCircuit , clientIP , out reason ) ;
2010-01-29 03:19:42 +00:00
if ( ! success & & m_GridService ! = null )
{
// Try the fallback regions
List < GridRegion > fallbacks = m_GridService . GetFallbackRegions ( account . ScopeID , destination . RegionLocX , destination . RegionLocY ) ;
if ( fallbacks ! = null )
{
foreach ( GridRegion r in fallbacks )
{
2010-05-16 02:25:14 +00:00
success = LaunchAgentIndirectly ( gatekeeper , r , aCircuit , clientIP , out reason ) ;
2010-01-29 03:19:42 +00:00
if ( success )
{
where = "safe" ;
destination = r ;
break ;
}
}
}
}
}
2010-08-09 01:56:47 +00:00
dest = destination ;
2010-01-29 03:19:42 +00:00
if ( success )
return aCircuit ;
else
return null ;
}
private AgentCircuitData MakeAgent ( GridRegion region , UserAccount account ,
2010-10-20 23:17:54 +00:00
AvatarAppearance avatar , UUID session , UUID secureSession , uint circuit , Vector3 position ,
2010-10-04 03:01:59 +00:00
string ipaddress , string viewer , string channel , string mac , string id0 )
2010-01-29 03:19:42 +00:00
{
2009-12-31 22:59:26 +00:00
AgentCircuitData aCircuit = new AgentCircuitData ( ) ;
2010-01-01 01:18:55 +00:00
2009-12-31 22:59:26 +00:00
aCircuit . AgentID = account . PrincipalID ;
2010-01-03 00:26:40 +00:00
if ( avatar ! = null )
2010-10-20 23:17:54 +00:00
aCircuit . Appearance = new AvatarAppearance ( avatar ) ;
2010-01-13 18:20:02 +00:00
else
2011-08-01 23:13:04 +00:00
aCircuit . Appearance = new AvatarAppearance ( ) ;
2010-01-13 18:20:02 +00:00
2009-12-31 22:59:26 +00:00
//aCircuit.BaseFolder = irrelevant
2010-01-01 01:18:55 +00:00
aCircuit . CapsPath = CapsUtil . GetRandomCapsObjectPath ( ) ;
2010-01-03 00:26:40 +00:00
aCircuit . child = false ; // the first login agent is root
2010-01-03 19:44:57 +00:00
aCircuit . ChildrenCapSeeds = new Dictionary < ulong , string > ( ) ;
2010-01-01 01:18:55 +00:00
aCircuit . circuitcode = circuit ;
2009-12-31 22:59:26 +00:00
aCircuit . firstname = account . FirstName ;
//aCircuit.InventoryFolder = irrelevant
aCircuit . lastname = account . LastName ;
2010-01-01 01:18:55 +00:00
aCircuit . SecureSessionID = secureSession ;
2009-12-31 22:59:26 +00:00
aCircuit . SessionID = session ;
2010-01-01 01:18:55 +00:00
aCircuit . startpos = position ;
2010-10-04 03:01:59 +00:00
aCircuit . IPAddress = ipaddress ;
2010-05-05 22:34:49 +00:00
aCircuit . Viewer = viewer ;
2010-10-04 03:01:59 +00:00
aCircuit . Channel = channel ;
aCircuit . Mac = mac ;
aCircuit . Id0 = id0 ;
2010-01-17 19:33:47 +00:00
SetServiceURLs ( aCircuit , account ) ;
2010-01-01 01:18:55 +00:00
2010-01-29 03:19:42 +00:00
return aCircuit ;
2009-12-31 22:59:26 +00:00
}
2010-01-11 04:17:37 +00:00
2010-01-17 19:33:47 +00:00
private void SetServiceURLs ( AgentCircuitData aCircuit , UserAccount account )
{
aCircuit . ServiceURLs = new Dictionary < string , object > ( ) ;
if ( account . ServiceURLs = = null )
return ;
2010-11-25 19:14:16 +00:00
// Old style: get the service keys from the DB
2010-01-17 19:33:47 +00:00
foreach ( KeyValuePair < string , object > kvp in account . ServiceURLs )
{
2011-05-24 16:38:03 +00:00
if ( kvp . Value ! = null )
2010-01-17 19:33:47 +00:00
{
aCircuit . ServiceURLs [ kvp . Key ] = kvp . Value ;
2011-05-24 16:38:03 +00:00
if ( ! aCircuit . ServiceURLs [ kvp . Key ] . ToString ( ) . EndsWith ( "/" ) )
aCircuit . ServiceURLs [ kvp . Key ] = aCircuit . ServiceURLs [ kvp . Key ] + "/" ;
2010-01-17 19:33:47 +00:00
}
}
2010-11-25 19:14:16 +00:00
// New style: service keys start with SRV_; override the previous
string [ ] keys = m_LoginServerConfig . GetKeys ( ) ;
if ( keys . Length > 0 )
{
2011-05-24 16:38:03 +00:00
bool newUrls = false ;
2010-11-25 19:14:16 +00:00
IEnumerable < string > serviceKeys = keys . Where ( value = > value . StartsWith ( "SRV_" ) ) ;
foreach ( string serviceKey in serviceKeys )
{
string keyName = serviceKey . Replace ( "SRV_" , "" ) ;
2011-05-24 16:38:03 +00:00
string keyValue = m_LoginServerConfig . GetString ( serviceKey , string . Empty ) ;
if ( ! keyValue . EndsWith ( "/" ) )
keyValue = keyValue + "/" ;
2014-04-22 17:04:12 +00:00
if ( ! account . ServiceURLs . ContainsKey ( keyName ) | | ( account . ServiceURLs . ContainsKey ( keyName ) & & ( string ) account . ServiceURLs [ keyName ] ! = keyValue ) )
2011-05-24 16:38:03 +00:00
{
account . ServiceURLs [ keyName ] = keyValue ;
newUrls = true ;
}
aCircuit . ServiceURLs [ keyName ] = keyValue ;
2010-12-10 00:52:37 +00:00
2010-11-25 19:14:16 +00:00
m_log . DebugFormat ( "[LLLOGIN SERVICE]: found new key {0} {1}" , keyName , aCircuit . ServiceURLs [ keyName ] ) ;
}
2011-05-24 16:38:03 +00:00
2014-10-27 21:27:42 +00:00
if ( ! account . ServiceURLs . ContainsKey ( "GatekeeperURI" ) & & ! string . IsNullOrEmpty ( m_GatekeeperURL ) )
{
m_log . DebugFormat ( "[LLLOGIN SERVICE]: adding gatekeeper uri {0}" , m_GatekeeperURL ) ;
account . ServiceURLs [ "GatekeeperURI" ] = m_GatekeeperURL ;
newUrls = true ;
}
2011-05-24 16:38:03 +00:00
// The grid operator decided to override the defaults in the
// [LoginService] configuration. Let's store the correct ones.
if ( newUrls )
m_UserAccountService . StoreUserAccount ( account ) ;
2010-11-25 19:14:16 +00:00
}
2010-01-17 19:33:47 +00:00
}
2011-01-27 02:49:32 +00:00
private bool LaunchAgentDirectly ( ISimulationService simConnector , GridRegion region , AgentCircuitData aCircuit , TeleportFlags flags , out string reason )
2010-01-29 03:19:42 +00:00
{
2015-10-31 17:13:02 +00:00
EntityTransferContext ctx = new EntityTransferContext ( ) ;
2014-07-21 22:53:33 +00:00
2015-10-18 23:06:31 +00:00
if ( ! simConnector . QueryAccess (
2015-10-31 17:13:02 +00:00
region , aCircuit . AgentID , null , true , aCircuit . startpos , new List < UUID > ( ) , ctx , out reason ) )
2014-07-21 22:53:33 +00:00
return false ;
2015-11-01 18:11:14 +00:00
return simConnector . CreateAgent ( null , region , aCircuit , ( uint ) flags , ctx , out reason ) ;
2010-01-29 03:19:42 +00:00
}
2010-05-16 02:25:14 +00:00
private bool LaunchAgentIndirectly ( GridRegion gatekeeper , GridRegion destination , AgentCircuitData aCircuit , IPEndPoint clientIP , out string reason )
2010-01-29 03:19:42 +00:00
{
2014-07-21 22:53:33 +00:00
m_log . Debug ( "[LLOGIN SERVICE]: Launching agent at " + destination . RegionName ) ;
2014-07-22 17:01:54 +00:00
2014-04-09 05:03:25 +00:00
if ( m_UserAgentService . LoginAgentToGrid ( null , aCircuit , gatekeeper , destination , true , out reason ) )
2010-05-16 02:25:14 +00:00
return true ;
return false ;
2010-01-29 03:19:42 +00:00
}
2010-01-11 04:17:37 +00:00
#region Console Commands
private void RegisterCommands ( )
{
//MainConsole.Instance.Commands.AddCommand
2012-03-08 01:51:37 +00:00
MainConsole . Instance . Commands . AddCommand ( "Users" , false , "login level" ,
2010-01-11 04:17:37 +00:00
"login level <level>" ,
"Set the minimum user level to log in" , HandleLoginCommand ) ;
2012-03-08 01:51:37 +00:00
MainConsole . Instance . Commands . AddCommand ( "Users" , false , "login reset" ,
2010-01-11 04:17:37 +00:00
"login reset" ,
"Reset the login level to allow all users" ,
HandleLoginCommand ) ;
2012-03-08 01:51:37 +00:00
MainConsole . Instance . Commands . AddCommand ( "Users" , false , "login text" ,
2010-01-11 04:17:37 +00:00
"login text <text>" ,
"Set the text users will see on login" , HandleLoginCommand ) ;
}
private void HandleLoginCommand ( string module , string [ ] cmd )
{
string subcommand = cmd [ 1 ] ;
switch ( subcommand )
{
case "level" :
// Set the minimum level to allow login
// Useful to allow grid update without worrying about users.
// or fixing critical issues
/ /
if ( cmd . Length > 2 )
2013-02-20 00:51:55 +00:00
{
if ( Int32 . TryParse ( cmd [ 2 ] , out m_MinLoginLevel ) )
MainConsole . Instance . OutputFormat ( "Set minimum login level to {0}" , m_MinLoginLevel ) ;
else
MainConsole . Instance . OutputFormat ( "ERROR: {0} is not a valid login level" , cmd [ 2 ] ) ;
}
2010-01-11 04:17:37 +00:00
break ;
2013-02-20 00:51:55 +00:00
case "reset" :
2010-01-11 04:17:37 +00:00
m_MinLoginLevel = 0 ;
2013-02-20 00:51:55 +00:00
MainConsole . Instance . OutputFormat ( "Reset min login level to {0}" , m_MinLoginLevel ) ;
2010-01-11 04:17:37 +00:00
break ;
2013-02-20 00:51:55 +00:00
2010-01-11 04:17:37 +00:00
case "text" :
if ( cmd . Length > 2 )
2013-02-20 00:51:55 +00:00
{
2010-01-11 04:17:37 +00:00
m_WelcomeMessage = cmd [ 2 ] ;
2013-02-20 00:51:55 +00:00
MainConsole . Instance . OutputFormat ( "Login welcome message set to '{0}'" , m_WelcomeMessage ) ;
}
2010-01-11 04:17:37 +00:00
break ;
}
}
2009-12-31 05:00:16 +00:00
}
2010-01-11 04:17:37 +00:00
# endregion
2009-12-31 05:00:16 +00:00
}