From 952029380a6a038e382dd3b2c312b3e16ff08625 Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Fri, 4 Jun 2010 10:59:59 -0700
Subject: Fixed a couple of buglets in Friendship offers / acceptance / decline
 when avies are in different sims.

---
 .../CoreModules/Avatar/Friends/FriendsModule.cs    | 56 +++++++++++++---------
 .../Avatar/Friends/FriendsRequestHandler.cs        | 13 +++--
 .../UserAccounts/UserAccountCache.cs               |  4 +-
 .../Handlers/Inventory/XInventoryInConnector.cs    |  2 +-
 OpenSim/Server/Handlers/Login/LLLoginHandlers.cs   |  2 +-
 .../Connectors/Friends/FriendsServiceConnector.cs  |  2 +-
 .../Connectors/Friends/FriendsSimConnector.cs      |  9 +++-
 OpenSim/Services/LLLoginService/LLLoginService.cs  |  2 +
 .../Services/PresenceService/PresenceService.cs    |  2 +-
 9 files changed, 58 insertions(+), 34 deletions(-)

(limited to 'OpenSim')

diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index 0c81f44..0050653 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -111,10 +111,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
 
         protected IGridService GridService
         {
-            get
-            {
-                return m_Scenes[0].GridService;
-            }
+            get { return m_Scenes[0].GridService; }
+        }
+
+        public IUserAccountService UserAccountService
+        {
+            get { return m_Scenes[0].UserAccountService; }
         }
 
         public IScene Scene
@@ -220,33 +222,37 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
 
             client.OnLogout += OnLogout;
 
-            if (m_Friends.ContainsKey(client.AgentId))
+            lock (m_Friends)
             {
-                m_Friends[client.AgentId].Refcount++;
-                return;
-            }
+                if (m_Friends.ContainsKey(client.AgentId))
+                {
+                    m_Friends[client.AgentId].Refcount++;
+                    return;
+                }
 
-            UserFriendData newFriends = new UserFriendData();
+                UserFriendData newFriends = new UserFriendData();
 
-            newFriends.PrincipalID = client.AgentId;
-            newFriends.Friends = m_FriendsService.GetFriends(client.AgentId);
-            newFriends.Refcount = 1;
-            newFriends.RegionID = UUID.Zero;
+                newFriends.PrincipalID = client.AgentId;
+                newFriends.Friends = m_FriendsService.GetFriends(client.AgentId);
+                newFriends.Refcount = 1;
+                newFriends.RegionID = UUID.Zero;
 
-            m_Friends.Add(client.AgentId, newFriends);
+                m_Friends.Add(client.AgentId, newFriends);
+            }
             
             //StatusChange(client.AgentId, true);
         }
 
         private void OnClientClosed(UUID agentID, Scene scene)
         {
-            if (m_Friends.ContainsKey(agentID))
-            {
-                if (m_Friends[agentID].Refcount == 1)
-                    m_Friends.Remove(agentID);
-                else
-                    m_Friends[agentID].Refcount--;
-            }
+            lock (m_Friends)
+                if (m_Friends.ContainsKey(agentID))
+                {
+                    if (m_Friends[agentID].Refcount == 1)
+                        m_Friends.Remove(agentID);
+                    else
+                        m_Friends[agentID].Refcount--;
+                }
         }
 
         private void OnLogout(IClientAPI client)
@@ -518,12 +524,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
 
         private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders)
         {
+            m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID);
+            
             FriendsService.StoreFriend(agentID, friendID.ToString(), 1);
             FriendsService.StoreFriend(friendID, agentID.ToString(), 1);
             // update the local cache
             m_Friends[agentID].Friends = FriendsService.GetFriends(agentID);
 
-            m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID);
 
             //
             // Notify the friend
@@ -572,7 +579,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
                 if (friendSession != null)
                 {
                     GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
-                    m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID);
+                    if (region != null)
+                        m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID);
+                    else
+                        m_log.WarnFormat("[FRIENDS]: Could not find region {0} in locating {1}", friendSession.RegionID, friendID);
                 }
             }
         }
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs
index 0883c5b..496f2ab 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs
@@ -35,6 +35,7 @@ using OpenSim.Framework;
 using OpenSim.Server.Base;
 using OpenSim.Framework.Servers.HttpServer;
 using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
+using OpenSim.Services.Interfaces;
 
 using OpenMetaverse;
 using log4net;
@@ -61,7 +62,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
             sr.Close();
             body = body.Trim();
 
-            m_log.DebugFormat("[XXX]: query String: {0}", body);
+            //m_log.DebugFormat("[XXX]: query String: {0}", body);
 
             try
             {
@@ -115,9 +116,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
             if (!UUID.TryParse(request["ToID"].ToString(), out toID))
                 return FailureResult();
 
-            GridInstantMessage im = new GridInstantMessage(m_FriendsModule.Scene, fromID, "", toID, 
+            UserAccount account = m_FriendsModule.UserAccountService.GetUserAccount(m_FriendsModule.Scene.RegionInfo.ScopeID, fromID);
+            string name = (account == null) ? "Unknown" : account.FirstName + " " + account.LastName;
+
+            GridInstantMessage im = new GridInstantMessage(m_FriendsModule.Scene, fromID, name, toID, 
                 (byte)InstantMessageDialog.FriendshipOffered, message, false, Vector3.Zero);
-            
+
+            // !! HACK
+            im.imSessionID = im.fromAgentID;
+
             if (m_FriendsModule.LocalFriendshipOffered(toID, im))
                 return SuccessResult();
 
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
index a355661..e1bc243 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
@@ -44,10 +44,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
 
         public UserAccountCache()
         {
-            // Warning: the size values are a bit fuzzy. What matters
-            // most for this cache is the count value (128 entries).
             m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
-            m_NameCache = new ExpiringCache<string, UUID>(); // this one is unbound
+            m_NameCache = new ExpiringCache<string, UUID>(); 
         }
 
         public void Cache(UUID userID, UserAccount account)
diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
index b0fee6d..6e580f1 100644
--- a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
+++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
@@ -149,7 +149,7 @@ namespace OpenSim.Server.Handlers.Asset
             }
             catch (Exception e)
             {
-                m_log.Debug("[XINVENTORY HANDLER]: Exception {0}" + e);
+                m_log.Debug("[XINVENTORY HANDLER]: Exception {0}", e);
             }
 
             return FailureResult();
diff --git a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
index c9bf996..5bb529c 100644
--- a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
+++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
@@ -83,7 +83,7 @@ namespace OpenSim.Server.Handlers.Login
                         clientVersion = requestData["version"].ToString();
                     // We should do something interesting with the client version...
 
-                    m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
+                    //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
 
                     LoginResponse reply = null;
                     reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, remoteClient);
diff --git a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs
index baefebd..d7a5731 100644
--- a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs
@@ -196,7 +196,7 @@ namespace OpenSim.Services.Connectors
         {
             Dictionary<string, object> sendData = new Dictionary<string, object>();
             sendData["PRINCIPALID"] = PrincipalID.ToString();
-            sendData["FRIENDS"] = Friend;
+            sendData["FRIEND"] = Friend;
             sendData["METHOD"] = "deletefriend";
 
             string reqString = ServerUtils.BuildQueryString(sendData);
diff --git a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
index d7cb015..0a7b277 100644
--- a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
+++ b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
@@ -74,6 +74,9 @@ namespace OpenSim.Services.Connectors.Friends
 
         public bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID)
         {
+            if (region == null)
+                return false;
+
             Dictionary<string, object> sendData = new Dictionary<string, object>();
             //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
             //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
@@ -131,7 +134,11 @@ namespace OpenSim.Services.Connectors.Friends
         private bool Call(GridRegion region, Dictionary<string, object> sendData)
         {
             string reqString = ServerUtils.BuildQueryString(sendData);
-            // m_log.DebugFormat("[FRIENDS CONNECTOR]: queryString = {0}", reqString);
+            //m_log.DebugFormat("[FRIENDS CONNECTOR]: queryString = {0}", reqString);
+            if (region == null)
+                return false;
+
+            m_log.DebugFormat("[FRIENDS CONNECTOR]: region: {0}", region.ExternalHostName + ":" + region.HttpPort);
             try
             {
                 string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
index 6319cc4..00fffff 100644
--- a/OpenSim/Services/LLLoginService/LLLoginService.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -209,6 +209,8 @@ namespace OpenSim.Services.LLLoginService
             bool success = false;
             UUID session = UUID.Random();
 
+            m_log.InfoFormat("[LLOGIN SERVICE]: Login request for {0} {1} from {2} with user agent {3} starting in {4}", 
+                firstName, lastName, clientIP.Address.ToString(), clientVersion, startLocation);
             try
             {
                 //
diff --git a/OpenSim/Services/PresenceService/PresenceService.cs b/OpenSim/Services/PresenceService/PresenceService.cs
index 601a69f..976153f 100644
--- a/OpenSim/Services/PresenceService/PresenceService.cs
+++ b/OpenSim/Services/PresenceService/PresenceService.cs
@@ -55,7 +55,7 @@ namespace OpenSim.Services.PresenceService
                 UUID secureSessionID)
         {
             //PresenceData[] d = m_Database.Get("UserID", userID);
-            m_Database.Get("UserID", userID);
+            //m_Database.Get("UserID", userID);
 
             PresenceData data = new PresenceData();
 
-- 
cgit v1.1