From c93f7188c758571283c017aa3d33a6ba55cf2cd5 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 9 Nov 2007 01:59:18 +0000 Subject: * Added a mutex to the LoginService allowing only a single login simultaneously. (queues) * This is a temporary fix to prevent an issue with adjohn reported when attempting to login large numbers of users in a short period of time. * A rewritten login service is on the cards. --- OpenSim/Framework/Communications/LoginService.cs | 175 ++++++++++++----------- 1 file changed, 93 insertions(+), 82 deletions(-) (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs index 497cc5d..e24d858 100644 --- a/OpenSim/Framework/Communications/LoginService.cs +++ b/OpenSim/Framework/Communications/LoginService.cs @@ -28,6 +28,7 @@ using System; using System.Collections; +using System.Threading; using libsecondlife; using Nwc.XmlRpc; using OpenSim.Framework.Console; @@ -38,6 +39,7 @@ namespace OpenSim.Framework.UserManagement { protected string m_welcomeMessage = "Welcome to OpenSim"; protected UserManagerBase m_userManager = null; + protected Mutex m_loginMutex = new Mutex(false); public LoginService(UserManagerBase userManager, string welcomeMess) { @@ -55,104 +57,113 @@ namespace OpenSim.Framework.UserManagement /// The response to send public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) { - MainLog.Instance.Verbose("LOGIN", "Attempting login now..."); - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable requestData = (Hashtable) request.Params[0]; - - bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && - requestData.Contains("passwd")); - bool GoodLogin = false; + // Temporary fix + m_loginMutex.WaitOne(); + try + { + MainLog.Instance.Verbose("LOGIN", "Attempting login now..."); + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; - UserProfileData userProfile; - LoginResponse logResponse = new LoginResponse(); + bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && + requestData.Contains("passwd")); + bool GoodLogin = false; - if (GoodXML) - { - string firstname = (string) requestData["first"]; - string lastname = (string) requestData["last"]; - string passwd = (string) requestData["passwd"]; + UserProfileData userProfile; + LoginResponse logResponse = new LoginResponse(); - userProfile = GetTheUser(firstname, lastname); - if (userProfile == null) - return logResponse.CreateLoginFailedResponse(); + if (GoodXML) + { + string firstname = (string)requestData["first"]; + string lastname = (string)requestData["last"]; + string passwd = (string)requestData["passwd"]; - GoodLogin = AuthenticateUser(userProfile, passwd); - } - else - { - return logResponse.CreateGridErrorResponse(); - } + userProfile = GetTheUser(firstname, lastname); + if (userProfile == null) + return logResponse.CreateLoginFailedResponse(); - if (!GoodLogin) - { - return logResponse.CreateLoginFailedResponse(); - } - else - { - // If we already have a session... - if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline) + GoodLogin = AuthenticateUser(userProfile, passwd); + } + else { - // Reject the login - return logResponse.CreateAlreadyLoggedInResponse(); + return logResponse.CreateGridErrorResponse(); } - // Otherwise... - // Create a new agent session - CreateAgent(userProfile, request); - try + if (!GoodLogin) { - LLUUID agentID = userProfile.UUID; - - // Inventory Library Section - InventoryData inventData = CreateInventoryData(agentID); - ArrayList AgentInventoryArray = inventData.InventoryArray; - - Hashtable InventoryRootHash = new Hashtable(); - InventoryRootHash["folder_id"] = inventData.RootFolderID.ToStringHyphenated(); - ArrayList InventoryRoot = new ArrayList(); - InventoryRoot.Add(InventoryRootHash); - userProfile.rootInventoryFolderID = inventData.RootFolderID; - - // Circuit Code - uint circode = (uint) (Util.RandomClass.Next()); - - logResponse.Lastname = userProfile.surname; - logResponse.Firstname = userProfile.username; - logResponse.AgentID = agentID.ToStringHyphenated(); - logResponse.SessionID = userProfile.currentAgent.sessionID.ToStringHyphenated(); - logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToStringHyphenated(); - logResponse.InventoryRoot = InventoryRoot; - logResponse.InventorySkeleton = AgentInventoryArray; - logResponse.InventoryLibrary = GetInventoryLibrary(); - logResponse.InventoryLibraryOwner = GetLibraryOwner(); - logResponse.CircuitCode = (Int32) circode; - //logResponse.RegionX = 0; //overwritten - //logResponse.RegionY = 0; //overwritten - logResponse.Home = "!!null temporary value {home}!!"; // Overwritten - //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n"; - //logResponse.SimAddress = "127.0.0.1"; //overwritten - //logResponse.SimPort = 0; //overwritten - logResponse.Message = GetMessage(); + return logResponse.CreateLoginFailedResponse(); + } + else + { + // If we already have a session... + if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline) + { + // Reject the login + return logResponse.CreateAlreadyLoggedInResponse(); + } + // Otherwise... + // Create a new agent session + CreateAgent(userProfile, request); try { - CustomiseResponse(logResponse, userProfile); + LLUUID agentID = userProfile.UUID; + + // Inventory Library Section + InventoryData inventData = CreateInventoryData(agentID); + ArrayList AgentInventoryArray = inventData.InventoryArray; + + Hashtable InventoryRootHash = new Hashtable(); + InventoryRootHash["folder_id"] = inventData.RootFolderID.ToStringHyphenated(); + ArrayList InventoryRoot = new ArrayList(); + InventoryRoot.Add(InventoryRootHash); + userProfile.rootInventoryFolderID = inventData.RootFolderID; + + // Circuit Code + uint circode = (uint)(Util.RandomClass.Next()); + + logResponse.Lastname = userProfile.surname; + logResponse.Firstname = userProfile.username; + logResponse.AgentID = agentID.ToStringHyphenated(); + logResponse.SessionID = userProfile.currentAgent.sessionID.ToStringHyphenated(); + logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToStringHyphenated(); + logResponse.InventoryRoot = InventoryRoot; + logResponse.InventorySkeleton = AgentInventoryArray; + logResponse.InventoryLibrary = GetInventoryLibrary(); + logResponse.InventoryLibraryOwner = GetLibraryOwner(); + logResponse.CircuitCode = (Int32)circode; + //logResponse.RegionX = 0; //overwritten + //logResponse.RegionY = 0; //overwritten + logResponse.Home = "!!null temporary value {home}!!"; // Overwritten + //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n"; + //logResponse.SimAddress = "127.0.0.1"; //overwritten + //logResponse.SimPort = 0; //overwritten + logResponse.Message = GetMessage(); + + try + { + CustomiseResponse(logResponse, userProfile); + } + catch (Exception e) + { + MainLog.Instance.Verbose(e.ToString()); + return logResponse.CreateDeadRegionResponse(); + //return logResponse.ToXmlRpcResponse(); + } + CommitAgent(ref userProfile); + return logResponse.ToXmlRpcResponse(); } - catch (Exception e) + + catch (Exception E) { - MainLog.Instance.Verbose(e.ToString()); - return logResponse.CreateDeadRegionResponse(); - //return logResponse.ToXmlRpcResponse(); + MainLog.Instance.Verbose(E.ToString()); } - CommitAgent(ref userProfile); - return logResponse.ToXmlRpcResponse(); + //} } - - catch (Exception E) - { - MainLog.Instance.Verbose(E.ToString()); - } - //} + } + finally + { + m_loginMutex.ReleaseMutex(); } return response; } -- cgit v1.1