From a1643c78beddf6e96d6bf124cdee8ef8c96cab51 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 4 Mar 2010 22:43:30 +0000 Subject: [PATCH] remove test presence from NullPresenceData since this appears to stop existing sessions with home locations from being picked up only tested for a single user so this may still fail for multiple users this may well be all academic anyway since standalone need to persistently store home location in presence data in some way --- OpenSim/Data/MySQL/MySQLPresenceData.cs | 4 +- OpenSim/Data/Null/NullPresenceData.cs | 51 +++++++++++++++---- .../Services/LLLoginService/LLLoginService.cs | 31 +++++++++-- 3 files changed, 72 insertions(+), 14 deletions(-) diff --git a/OpenSim/Data/MySQL/MySQLPresenceData.cs b/OpenSim/Data/MySQL/MySQLPresenceData.cs index fcbe3d669e..68a68af3c8 100644 --- a/OpenSim/Data/MySQL/MySQLPresenceData.cs +++ b/OpenSim/Data/MySQL/MySQLPresenceData.cs @@ -122,7 +122,7 @@ namespace OpenSim.Data.MySQL cmd.CommandText = String.Format("select * from {0} where UserID=?UserID", m_Realm); cmd.Parameters.AddWithValue("?UserID", userID); -; + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) { dbcon.Open(); @@ -131,7 +131,6 @@ namespace OpenSim.Data.MySQL using (IDataReader reader = cmd.ExecuteReader()) { - List deleteSessions = new List(); int online = 0; @@ -143,6 +142,7 @@ namespace OpenSim.Data.MySQL deleteSessions.Add(new UUID(reader["SessionID"].ToString())); } + // Leave one session behind so that we can pick up details such as home location if (online == 0 && deleteSessions.Count > 0) deleteSessions.RemoveAt(0); diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs index 5f786910c3..555c92f950 100644 --- a/OpenSim/Data/Null/NullPresenceData.cs +++ b/OpenSim/Data/Null/NullPresenceData.cs @@ -28,6 +28,8 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Reflection; +using log4net; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Data; @@ -36,6 +38,8 @@ namespace OpenSim.Data.Null { public class NullPresenceData : IPresenceData { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static NullPresenceData Instance; Dictionary m_presenceData = new Dictionary(); @@ -48,20 +52,25 @@ namespace OpenSim.Data.Null //Console.WriteLine("[XXX] NullRegionData constructor"); // Let's stick in a test presence + /* PresenceData p = new PresenceData(); p.SessionID = UUID.Zero; p.UserID = UUID.Zero.ToString(); p.Data = new Dictionary(); p.Data["Online"] = true.ToString(); m_presenceData.Add(UUID.Zero, p); + */ } } public bool Store(PresenceData data) - { + { if (Instance != this) return Instance.Store(data); +// m_log.DebugFormat("[NULL PRESENCE DATA]: Storing presence {0}", data.UserID); +// Console.WriteLine("HOME for " + data.UserID + " is " + (data.Data.ContainsKey("HomeRegionID") ? data.Data["HomeRegionID"] : "Not found")); + m_presenceData[data.SessionID] = data; return true; } @@ -100,6 +109,7 @@ namespace OpenSim.Data.Null { if (Instance != this) return Instance.ReportAgent(sessionID, regionID, position, lookAt); + if (m_presenceData.ContainsKey(sessionID)) { m_presenceData[sessionID].RegionID = regionID; @@ -112,7 +122,7 @@ namespace OpenSim.Data.Null } public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) - { + { if (Instance != this) return Instance.SetHomeLocation(userID, regionID, position, lookAt); @@ -121,27 +131,40 @@ namespace OpenSim.Data.Null { if (p.UserID == userID) { +// m_log.DebugFormat( +// "[NULL PRESENCE DATA]: Setting home location {0} {1} {2} for {3}", +// regionID, position, lookAt, p.UserID); + p.Data["HomeRegionID"] = regionID.ToString(); p.Data["HomePosition"] = position.ToString(); p.Data["HomeLookAt"] = lookAt.ToString(); foundone = true; - } + } } return foundone; } public PresenceData[] Get(string field, string data) - { + { if (Instance != this) return Instance.Get(field, data); +// m_log.DebugFormat( +// "[NULL PRESENCE DATA]: Getting presence data for field {0} with parameter {1}", field, data); + List presences = new List(); if (field == "UserID") { foreach (PresenceData p in m_presenceData.Values) - if (p.UserID == data) - presences.Add(p); + { + if (p.UserID == data) + { + presences.Add(p); +// Console.WriteLine("HOME for " + p.UserID + " is " + (p.Data.ContainsKey("HomeRegionID") ? p.Data["HomeRegionID"] : "Not found")); + } + } + return presences.ToArray(); } else if (field == "SessionID") @@ -180,36 +203,46 @@ namespace OpenSim.Data.Null } public void Prune(string userID) - { + { if (Instance != this) { Instance.Prune(userID); return; } +// m_log.DebugFormat("[NULL PRESENCE DATA]: Prune called for {0}", userID); + List deleteSessions = new List(); int online = 0; foreach (KeyValuePair kvp in m_presenceData) { + m_log.DebugFormat("Online: {0}", kvp.Value.Data["Online"]); + bool on = false; if (bool.TryParse(kvp.Value.Data["Online"], out on) && on) online++; else deleteSessions.Add(kvp.Key); } + +// m_log.DebugFormat("[NULL PRESENCE DATA]: online [{0}], deleteSession.Count [{1}]", online, deleteSessions.Count); + + // Leave one session behind so that we can pick up details such as home location if (online == 0 && deleteSessions.Count > 0) deleteSessions.RemoveAt(0); foreach (UUID s in deleteSessions) m_presenceData.Remove(s); - } public bool Delete(string field, string data) { +// m_log.DebugFormat( +// "[NULL PRESENCE DATA]: Deleting presence data for field {0} with parameter {1}", field, data); + if (Instance != this) - return Delete(field, data); + return Instance.Delete(field, data); List presences = new List(); if (field == "UserID") diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs index ee93f73cde..ae729f8ca4 100644 --- a/OpenSim/Services/LLLoginService/LLLoginService.cs +++ b/OpenSim/Services/LLLoginService/LLLoginService.cs @@ -279,7 +279,31 @@ namespace OpenSim.Services.LLLoginService GridRegion region = null; - if (pinfo.HomeRegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.HomeRegionID)) == null) + bool tryDefaults = false; + + if (pinfo.HomeRegionID.Equals(UUID.Zero)) + { + m_log.WarnFormat( + "[LLOGIN SERVICE]: User {0} {1} tried to login to a 'home' start location but they have none set", + account.FirstName, account.LastName); + + tryDefaults = true; + } + else + { + region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.HomeRegionID); + + if (null == region) + { + m_log.WarnFormat( + "[LLOGIN SERVICE]: User {0} {1} has a recorded home region of {2} but this cannot be found by the grid service", + account.FirstName, account.LastName, pinfo.HomeRegionID); + + tryDefaults = true; + } + } + + if (tryDefaults) { List defaults = m_GridService.GetDefaultRegions(account.ScopeID); if (defaults != null && defaults.Count > 0) @@ -288,7 +312,8 @@ namespace OpenSim.Services.LLLoginService where = "safe"; } else - m_log.WarnFormat("[LLOGIN SERVICE]: User {0} {1} does not have a home set and this grid does not have default locations.", + m_log.WarnFormat( + "[LLOGIN SERVICE]: User {0} {1} does not have a valid home and this grid does not have default locations.", account.FirstName, account.LastName); } @@ -318,8 +343,8 @@ namespace OpenSim.Services.LLLoginService position = pinfo.Position; lookAt = pinfo.LookAt; } + return region; - } else {