<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-15"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
while testing the ban list stuff as well as public/private regions, i
noticed that the way we were handling bans/private was causing <br>
<ul>
  <li>the client to take forever and a day to report back to the user
that he/she didn't have access to the target region</li>
  <li>and also causing OpenSim pain in the form of several exceptions
due to the client object being destroyed while it was already "in
circulation"</li>
</ul>
looking at the code in Scene.cs it seemed a better idea to place the
access control code in NewUserConnection() instead (right after
checking avatar name and password). the only problem with that was that
NewUserConnection() returns just True or False. so r9427 adds reason
reporting. <br>
<br>
i've tested this in standalone and in grid mode and it works there ---
if someone could test this with HG that would be appreciated. also, if
we don't get a success message from the remote region the code should
behave as before (that is, just report region not available if the ACL
code bars the avatar).<br>
<br>
so, it SHOULD NOT  break teleporting, but you never now. <br>
<br>
    DrS/dirk<br>
<br>
<a class="moz-txt-link-abbreviated" href="mailto:drscofield@opensimulator.org">drscofield@opensimulator.org</a> wrote:
<blockquote cite="mid:20090505161752.A6C4D20304@opensimulator.org"
 type="cite">
  <pre wrap="">Author: drscofield
Date: 2009-05-05 09:17:52 -0700 (Tue, 05 May 2009)
New Revision: 9427

Modified:
   trunk/OpenSim/Client/Linden/LLProxyLoginModule.cs
   trunk/OpenSim/Client/Linden/LLStandaloneLoginModule.cs
   trunk/OpenSim/Client/Linden/LLStandaloneLoginService.cs
   trunk/OpenSim/Client/MXP/PacketHandler/MXPPacketServer.cs
   trunk/OpenSim/Framework/Communications/Clients/RegionClient.cs
   trunk/OpenSim/Framework/Communications/Services/LoginResponse.cs
   trunk/OpenSim/Framework/Communications/Services/LoginService.cs
   trunk/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
   trunk/OpenSim/Framework/ILoginServiceToRegionsConnector.cs
   trunk/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs
   trunk/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs
   trunk/OpenSim/Region/CoreModules/ServiceConnectors/Interregion/LocalInterregionComms.cs
   trunk/OpenSim/Region/CoreModules/ServiceConnectors/Interregion/RESTInterregionComms.cs
   trunk/OpenSim/Region/Framework/Interfaces/IInterregionComms.cs
   trunk/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
   trunk/OpenSim/Region/Framework/Scenes/Scene.cs
   trunk/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
   trunk/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
   trunk/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs
Log:
- moving banned check and public/private check to
  Scene.NewUserConnection()
- adding reason reporting

this enforces estate bans very early on and prevents us from
circulating client objects that we'd then have to retract once we
realize that the client is not allowed into the region

Modified: trunk/OpenSim/Client/Linden/LLProxyLoginModule.cs
===================================================================
--- trunk/OpenSim/Client/Linden/LLProxyLoginModule.cs   2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Client/Linden/LLProxyLoginModule.cs   2009-05-05 16:17:52 UTC (rev 9427)
@@ -208,21 +208,22 @@
                     {
                         denyMess = "User is banned from this region";
                         m_log.InfoFormat(
-               "[CLIENT]: Denying access for user {0} {1} because user is banned",
-               agentData.firstname, agentData.lastname);
+                            "[CLIENT]: Denying access for user {0} {1} because user is banned",
+                            agentData.firstname, agentData.lastname);
                     }
                     else
                     {
-                        if (scene.NewUserConnection(agentData))
+                        string reason;
+                        if (scene.NewUserConnection(agentData, out reason))
                         {
                             success = true;
                         }
                         else
                         {
-                            denyMess = "Login refused by region";
+                            denyMess = String.Format("Login refused by region: {0}", reason);
                             m_log.InfoFormat(
-                   "[CLIENT]: Denying access for user {0} {1} because user connection was refused by the region",
-                   agentData.firstname, agentData.lastname);
+                                "[CLIENT]: Denying access for user {0} {1} because user connection was refused by the region",
+                                agentData.firstname, agentData.lastname);
                         }
                     }
                     

Modified: trunk/OpenSim/Client/Linden/LLStandaloneLoginModule.cs
===================================================================
--- trunk/OpenSim/Client/Linden/LLStandaloneLoginModule.cs      2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Client/Linden/LLStandaloneLoginModule.cs      2009-05-05 16:17:52 UTC (rev 9427)
@@ -154,13 +154,14 @@
             }
         }
 
-        public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent)
+        public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent, out string reason)
         {
             Scene scene;
             if (TryGetRegion(regionHandle, out scene))
             {
-                return scene.NewUserConnection(agent);
+                return scene.NewUserConnection(agent, out reason);
             }
+            reason = "Region not found.";
             return false;
         }
 

Modified: trunk/OpenSim/Client/Linden/LLStandaloneLoginService.cs
===================================================================
--- trunk/OpenSim/Client/Linden/LLStandaloneLoginService.cs     2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Client/Linden/LLStandaloneLoginService.cs     2009-05-05 16:17:52 UTC (rev 9427)
@@ -201,7 +201,15 @@
 
             if (m_regionsConnector.RegionLoginsEnabled)
             {
-                return m_regionsConnector.NewUserConnection(regionInfo.RegionHandle, agent);
+                string reason;
+                bool success = m_regionsConnector.NewUserConnection(regionInfo.RegionHandle, agent, out reason);
+                if (!success)
+                {
+                    response.ErrorReason = "key";
+                    response.ErrorMessage = reason;
+                }
+                return success;
+                // return m_regionsConnector.NewUserConnection(regionInfo.RegionHandle, agent, out reason);
             }
 
             return false;

Modified: trunk/OpenSim/Client/MXP/PacketHandler/MXPPacketServer.cs
===================================================================
--- trunk/OpenSim/Client/MXP/PacketHandler/MXPPacketServer.cs   2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Client/MXP/PacketHandler/MXPPacketServer.cs   2009-05-05 16:17:52 UTC (rev 9427)
@@ -312,6 +312,8 @@
                             {
                                 Scene scene = m_scenes[sceneId];
                                 UUID mxpSessionID = UUID.Random();
+                                
+                                string reason;
 
                                 m_log.Debug("[MXP ClientStack]: Session join request success: " + session.SessionId + " (" +
                                    (session.IsIncoming ? "from" : "to") + " " + session.RemoteEndPoint.Address + ":" +
@@ -321,7 +323,13 @@
                                 AttachUserAgentToUserProfile(session, mxpSessionID, sceneId, user);
                                 m_log.Debug("[MXP ClientStack]: Attached UserAgent to UserProfile.");
                                 m_log.Debug("[MXP ClientStack]: Preparing Scene to Connection...");
-                                PrepareSceneForConnection(mxpSessionID, sceneId, user);
+                                if (!PrepareSceneForConnection(mxpSessionID, sceneId, user, out reason))
+                                {
+                                    m_log.DebugFormat("[MXP ClientStack]: Scene refused connection: {0}", reason);
+                                    DeclineConnection(session, joinRequestMessage);
+                                    tmpRemove.Add(session);
+                                    continue;
+                                }
                                 m_log.Debug("[MXP ClientStack]: Prepared Scene to Connection.");
                                 m_log.Debug("[MXP ClientStack]: Accepting connection...");
                                 AcceptConnection(session, joinRequestMessage, mxpSessionID, userId);
@@ -579,7 +587,7 @@
             //userService.CommitAgent(ref userProfile);
         }
 
-        private void PrepareSceneForConnection(UUID sessionId, UUID sceneId, UserProfileData userProfile)
+        private bool PrepareSceneForConnection(UUID sessionId, UUID sceneId, UserProfileData userProfile, out string reason)
         {
             Scene scene = m_scenes[sceneId];
             CommunicationsManager commsManager = m_scenes[sceneId].CommsManager;
@@ -603,9 +611,8 @@
                 m_log.WarnFormat("[INTER]: Appearance not found for {0} {1}. Creating default.", agent.firstname, agent.lastname);
                 agent.Appearance = new AvatarAppearance();
             }
-
-            scene.NewUserConnection(agent);
-
+            
+            return scene.NewUserConnection(agent, out reason);
         }
 
         public void PrintDebugInformation()

Modified: trunk/OpenSim/Framework/Communications/Clients/RegionClient.cs
===================================================================
--- trunk/OpenSim/Framework/Communications/Clients/RegionClient.cs      2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Framework/Communications/Clients/RegionClient.cs      2009-05-05 16:17:52 UTC (rev 9427)
@@ -43,7 +43,7 @@
     {
         private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
-        public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit, string authKey)
+        public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit, string authKey, out string reason)
         {
             // Eventually, we want to use a caps url instead of the agentID
             string uri = <a class="moz-txt-link-rfc2396E" href="http://">"http://"</a> + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/<a class="moz-txt-link-rfc2396E" href="mailto:;@@-56,6+56,8@@//AgentCreateRequest.KeepAlive=false;AgentCreateRequest.Headers.Add(">";
@@ -56,6 +56,8 @@
             //AgentCreateRequest.KeepAlive = false;
             AgentCreateRequest.Headers.Add("</a>Authorization", authKey);
 
+            reason = String.Empty;
+
             // Fill it in
             OSDMap args = null;
             try
@@ -98,7 +100,7 @@
             catch
             {
                 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
-
+                reason = "cannot contact remote region";
                 return false;
             }
 
@@ -112,13 +114,24 @@
                 {
                     m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
                 }
+                else
+                {
 
-                StreamReader sr = new StreamReader(webResponse.GetResponseStream());
-                //reply = sr.ReadToEnd().Trim();
-                sr.ReadToEnd().Trim();
-                sr.Close();
-                //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
-
+                    StreamReader sr = new StreamReader(webResponse.GetResponseStream());
+                    string response = sr.ReadToEnd().Trim();
+                    sr.Close();
+                    m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
+                
+                    if (!String.IsNullOrEmpty(response))
+                    {
+                        // we assume we got an OSDMap back
+                        OSDMap r = GetOSDMap(response);
+                        bool success = r["success"].AsBoolean();
+                        reason = r["reason"].AsString();
+                        
+                        return success;
+                    }
+                }
             }
             catch (WebException ex)
             {

Modified: trunk/OpenSim/Framework/Communications/Services/LoginResponse.cs
===================================================================
--- trunk/OpenSim/Framework/Communications/Services/LoginResponse.cs    2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Framework/Communications/Services/LoginResponse.cs    2009-05-05 16:17:52 UTC (rev 9427)
@@ -320,7 +320,7 @@
         {
             return GenerateFailureResponseLLSD(
                 "key",
-                "Error connecting to grid. Could not percieve credentials from login XML.",
+                "Error connecting to grid. Could not perceive credentials from login XML.",
                 "false");
         }
 

Modified: trunk/OpenSim/Framework/Communications/Services/LoginService.cs
===================================================================
--- trunk/OpenSim/Framework/Communications/Services/LoginService.cs     2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Framework/Communications/Services/LoginService.cs     2009-05-05 16:17:52 UTC (rev 9427)
@@ -946,13 +946,15 @@
             {
                 regionInfo = homeInfo;
                 theUser.CurrentAgent.Position = theUser.HomeLocation;
-                response.LookAt = "[r" + theUser.HomeLookAt.X.ToString() + ",r" + theUser.HomeLookAt.Y.ToString() + ",r" + theUser.HomeLookAt.Z.ToString() + "]";
+                response.LookAt = String.Format("[r{0},r{1},r{2}]", theUser.HomeLookAt.X.ToString(), 
+                                                theUser.HomeLookAt.Y.ToString(), theUser.HomeLookAt.Z.ToString());
             }
             else if (startLocationRequest == "last")
             {
                 UUID lastRegion = theUser.CurrentAgent.Region;
                 regionInfo = GetRegionInfo(lastRegion);
-                response.LookAt = "[r" + theUser.CurrentAgent.LookAt.X.ToString() + ",r" + theUser.CurrentAgent.LookAt.Y.ToString() + ",r" + theUser.CurrentAgent.LookAt.Z.ToString() + "]";
+                response.LookAt = String.Format("[r{0},r{1},r{2}]", theUser.CurrentAgent.LookAt.X.ToString(),
+                                                theUser.CurrentAgent.LookAt.Y.ToString(), theUser.CurrentAgent.LookAt.Z.ToString());
             }
             else
             {

Modified: trunk/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
===================================================================
--- trunk/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs   2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs   2009-05-05 16:17:52 UTC (rev 9427)
@@ -345,8 +345,9 @@
             {
             }
 
-            public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent)
+            public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent, out string reason)
             {
+                reason = String.Empty;
                 lock (m_regionsList)
                 {
                     foreach (RegionInfo regInfo in m_regionsList)
@@ -355,6 +356,7 @@
                             return true;
                     }
                 }
+                reason = "Region not found";
                 return false;
             }
 

Modified: trunk/OpenSim/Framework/ILoginServiceToRegionsConnector.cs
===================================================================
--- trunk/OpenSim/Framework/ILoginServiceToRegionsConnector.cs  2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Framework/ILoginServiceToRegionsConnector.cs  2009-05-05 16:17:52 UTC (rev 9427)
@@ -34,7 +34,7 @@
     {
         bool RegionLoginsEnabled { get; }
         void LogOffUserFromGrid(ulong regionHandle, UUID AvatarID, UUID RegionSecret, string message);
-        bool NewUserConnection(ulong regionHandle, AgentCircuitData agent);
+        bool NewUserConnection(ulong regionHandle, AgentCircuitData agent, out string reason);
         RegionInfo RequestClosestRegion(string region);
         RegionInfo RequestNeighbourInfo(UUID regionID);
         RegionInfo RequestNeighbourInfo(ulong regionhandle);

Modified: trunk/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs
===================================================================
--- trunk/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs       2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs       2009-05-05 16:17:52 UTC (rev 9427)
@@ -160,8 +160,9 @@
             }
         }
 
-        public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent)
+        public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent, out string reason)
         {
+            reason = String.Empty;
             return true;
         }
 

Modified: trunk/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs
===================================================================
--- trunk/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs        2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs        2009-05-05 16:17:52 UTC (rev 9427)
@@ -545,8 +545,16 @@
             homeScene.CommsManager.UserProfileCacheService.PreloadUserCache(userProfile);
 
             // Call 'new user' event handler
-            homeScene.NewUserConnection(agentData);
+            string reason;
+            if (!homeScene.NewUserConnection(agentData, out reason))
+            {
+                responseMap["connect"] = OSD.FromBoolean(false);
+                responseMap["message"] = OSD.FromString(String.Format("Connection refused: {0}", reason));
+                m_log.ErrorFormat("[OGP]: rez_avatar/request failed: {0}", reason);
+                return responseMap;
+            }
 
+
             //string raCap = string.Empty;
 
             UUID AvatarRezCapUUID = LocalAgentID;

Modified: trunk/OpenSim/Region/CoreModules/ServiceConnectors/Interregion/LocalInterregionComms.cs
===================================================================
--- trunk/OpenSim/Region/CoreModules/ServiceConnectors/Interregion/LocalInterregionComms.cs     2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/CoreModules/ServiceConnectors/Interregion/LocalInterregionComms.cs     2009-05-05 16:17:52 UTC (rev 9427)
@@ -24,6 +24,7 @@
  * (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;
 using System.Collections.Generic;
 using System.Reflection;
 using log4net;
@@ -112,19 +113,19 @@
          * Agent-related communications 
          */
 
-        public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit)
+        public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit, out string reason)
         {            
             foreach (Scene s in m_sceneList)
             {                
                 if (s.RegionInfo.RegionHandle == regionHandle)
                 {
 //                    m_log.DebugFormat("[LOCAL COMMS]: Found region {0} to send SendCreateChildAgent", regionHandle);
-                    s.NewUserConnection(aCircuit);
-                    return true;
+                    return s.NewUserConnection(aCircuit, out reason);
                 }
             }
             
 //            m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for SendCreateChildAgent", regionHandle);
+            reason = "Did not find region.";
             return false;
         }
 

Modified: trunk/OpenSim/Region/CoreModules/ServiceConnectors/Interregion/RESTInterregionComms.cs
===================================================================
--- trunk/OpenSim/Region/CoreModules/ServiceConnectors/Interregion/RESTInterregionComms.cs      2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/CoreModules/ServiceConnectors/Interregion/RESTInterregionComms.cs      2009-05-05 16:17:52 UTC (rev 9427)
@@ -140,10 +140,10 @@
          * Agent-related communications 
          */
 
-        public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit)
+        public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit, out string reason)
         {
             // Try local first
-            if (m_localBackend.SendCreateChildAgent(regionHandle, aCircuit))
+            if (m_localBackend.SendCreateChildAgent(regionHandle, aCircuit, out reason))
                 return true;
 
             // else do the remote thing
@@ -154,7 +154,7 @@
                 {
                     m_regionClient.SendUserInformation(regInfo, aCircuit);
 
-                    return m_regionClient.DoCreateChildAgentCall(regInfo, aCircuit, "None");
+                    return m_regionClient.DoCreateChildAgentCall(regInfo, aCircuit, "None", out reason);
                 }
                 //else
                 //    m_log.Warn("[REST COMMS]: Region not found " + regionHandle);
@@ -431,12 +431,19 @@
                 return;
             }
 
+            OSDMap resp = new OSDMap(2);
+            string reason = String.Empty;
+
             // This is the meaning of POST agent
             m_regionClient.AdjustUserInformation(aCircuit);
-            bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit);
+            bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit, out reason);
 
+            resp["reason"] = OSD.FromString(reason);
+            resp["success"] = OSD.FromBoolean(result);
+
+            // TODO: add reason if not String.Empty?
             responsedata["int_response_code"] = 200;
-            responsedata["str_response_string"] = result.ToString();
+            responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
         }
 
         protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata)

Modified: trunk/OpenSim/Region/Framework/Interfaces/IInterregionComms.cs
===================================================================
--- trunk/OpenSim/Region/Framework/Interfaces/IInterregionComms.cs      2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/Framework/Interfaces/IInterregionComms.cs      2009-05-05 16:17:52 UTC (rev 9427)
@@ -38,7 +38,7 @@
 
         #region Agents
 
-        bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit);
+        bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit, out string reason);
 
         /// <summary>
         /// Full child agent update.

Modified: trunk/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
===================================================================
--- trunk/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs      2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs      2009-05-05 16:17:52 UTC (rev 9427)
@@ -180,10 +180,13 @@
                             agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
                         }
 
+                        string reason = String.Empty;
+
                         //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit))
-                        if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit))
+                        if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit, out reason))
                         {
-                            avatar.ControllingClient.SendTeleportFailed("Destination is not accepting teleports.");
+                            avatar.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}",
+                                                                                      reason));
                             return;
                         }
 

Modified: trunk/OpenSim/Region/Framework/Scenes/Scene.cs
===================================================================
--- trunk/OpenSim/Region/Framework/Scenes/Scene.cs      2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/Framework/Scenes/Scene.cs      2009-05-05 16:17:52 UTC (rev 9427)
@@ -1859,87 +1859,46 @@
 
         public override void AddNewClient(IClientAPI client)
         {
-            bool welcome  = true;
+            SubscribeToClientEvents(client);
+            ScenePresence presence;
 
-            if (m_regInfo.EstateSettings.IsBanned(client.AgentId) && (!Permissions.IsGod(client.AgentId)))
+            if (m_restorePresences.ContainsKey(client.AgentId))
             {
-                m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
-                                client.AgentId, client.FirstName, client.LastName, RegionInfo.RegionName);
-                client.SendAlertMessage("Denied access to region " + RegionInfo.RegionName + ". You have been banned from that region.");
-                welcome = false;
-            }
-            else if (!m_regInfo.EstateSettings.PublicAccess && !m_regInfo.EstateSettings.HasAccess(client.AgentId) && !Permissions.IsGod(client.AgentId))
-            {
-                m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access",
-                                client.AgentId, client.FirstName, client.LastName, RegionInfo.RegionName);
-                client.SendAlertMessage("Denied access to private region " + RegionInfo.RegionName + ". You do not have access to this region.");
-                welcome = false;
-            }
-
-            if (!welcome)
-            {
-                try
+                m_log.DebugFormat("[SCENE]: Restoring agent {0} {1} in {2}", client.Name, client.AgentId, RegionInfo.RegionName);
+                
+                presence = m_restorePresences[client.AgentId];
+                m_restorePresences.Remove(client.AgentId);
+                
+                // This is one of two paths to create avatars that are
+                // used.  This tends to get called more in standalone
+                // than grid, not really sure why, but as such needs
+                // an explicity appearance lookup here.
+                AvatarAppearance appearance = null;
+                GetAvatarAppearance(client, out appearance);
+                presence.Appearance = appearance;
+                
+                presence.initializeScenePresence(client, RegionInfo, this);
+                
+                m_sceneGraph.AddScenePresence(presence);
+                
+                lock (m_restorePresences)
                 {
-                    IEventQueue eq = RequestModuleInterface<IEventQueue>();
-                    if (eq != null)
-                    {
-                        eq.DisableSimulator(RegionInfo.RegionHandle, client.AgentId);
-                    }
-                    else
-                        client.SendShutdownConnectionNotice();
-
-                    client.Close(false);
-                    CapsModule.RemoveCapsHandler(client.AgentId);
-                    m_authenticateHandler.RemoveCircuit(client.CircuitCode);
+                    Monitor.PulseAll(m_restorePresences);
                 }
-                catch (Exception e)
-                {
-                    m_log.DebugFormat("[SCENE]: Exception while closing unwelcome client {0} {1}: {2}", client.FirstName, client.LastName, e.Message);
-                }
             }
             else
             {
-                SubscribeToClientEvents(client);
-                ScenePresence presence;
-
-                if (m_restorePresences.ContainsKey(client.AgentId))
-                {
-                    m_log.DebugFormat("[SCENE]: Restoring agent {0} {1} in {2}", client.Name, client.AgentId, RegionInfo.RegionName);
-
-                    presence = m_restorePresences[client.AgentId];
-                    m_restorePresences.Remove(client.AgentId);
-
-                    // This is one of two paths to create avatars that are
-                    // used.  This tends to get called more in standalone
-                    // than grid, not really sure why, but as such needs
-                    // an explicity appearance lookup here.
-                    AvatarAppearance appearance = null;
-                    GetAvatarAppearance(client, out appearance);
-                    presence.Appearance = appearance;
-
-                    presence.initializeScenePresence(client, RegionInfo, this);
-
-                    m_sceneGraph.AddScenePresence(presence);
-
-                    lock (m_restorePresences)
-                    {
-                        Monitor.PulseAll(m_restorePresences);
-                    }
-                }
-                else
-                {
-                    m_log.DebugFormat(
-                        "[SCENE]: Adding new child agent for {0} in {1}",
-                        client.Name, RegionInfo.RegionName);
-
-                    CommsManager.UserProfileCacheService.AddNewUser(client.AgentId);
-
-                    CreateAndAddScenePresence(client);
-                }
-
-                m_LastLogin = Environment.TickCount;
-                EventManager.TriggerOnNewClient(client);
+                m_log.DebugFormat(
+                    "[SCENE]: Adding new child agent for {0} in {1}",
+                    client.Name, RegionInfo.RegionName);
+                
+                CommsManager.UserProfileCacheService.AddNewUser(client.AgentId);
+                
+                CreateAndAddScenePresence(client);
             }
+
+            m_LastLogin = Environment.TickCount;
+            EventManager.TriggerOnNewClient(client);
         }
 
         protected virtual void SubscribeToClientEvents(IClientAPI client)
@@ -2404,7 +2363,8 @@
         /// <param name="agent"></param>
         public void HandleNewUserConnection(AgentCircuitData agent)
         {
-            NewUserConnection(agent);
+            string reason;
+            NewUserConnection(agent, out reason);
         }
 
         /// <summary>
@@ -2415,10 +2375,36 @@
         /// </summary>
         /// <param name="regionHandle"></param>
         /// <param name="agent"></param>
-        public bool NewUserConnection(AgentCircuitData agent)
+        /// <param name="reason"></param>
+        public bool NewUserConnection(AgentCircuitData agent, out string reason)
         {
             bool goodUserConnection = AuthenticateUser(agent);
 
+            reason = String.Empty;
+
+            if (goodUserConnection && 
+                m_regInfo.EstateSettings.IsBanned(agent.AgentID) && 
+                (!Permissions.IsGod(agent.AgentID)))
+            {
+                m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user is on the banlist",
+                                agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
+                reason = String.Format("Denied access to region {0}: You have been banned from that region.",
+                                       RegionInfo.RegionName);
+                goodUserConnection = false;
+            }
+            else if (goodUserConnection && 
+                     !m_regInfo.EstateSettings.PublicAccess && 
+                     !m_regInfo.EstateSettings.HasAccess(agent.AgentID) && 
+                     !Permissions.IsGod(agent.AgentID))
+            {
+                m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because the user does not have access",
+                                agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName);
+                reason = String.Format("Denied access to private region {0}: You are not on the access list for that region.", 
+                                       RegionInfo.RegionName);
+                goodUserConnection = false;
+            }
+
+
             if (goodUserConnection)
             {
                 CapsModule.NewUserConnection(agent);
@@ -2431,7 +2417,7 @@
                         agent.AgentID, RegionInfo.RegionName);
 
                     sp.AdjustKnownSeeds();
-
+                    
                     return true;
                 }
 
@@ -2440,13 +2426,13 @@
                     "[CONNECTION BEGIN]: Region {0} told of incoming client {1} {2} {3} (circuit code {4})",
                     RegionInfo.RegionName, agent.firstname, agent.lastname, agent.AgentID, agent.circuitcode);
 
-                if (m_regInfo.EstateSettings.IsBanned(agent.AgentID))
-                {
-                    m_log.WarnFormat(
-                   "[CONNECTION BEGIN]: Incoming user {0} at {1} is on the region banlist",
-                   agent.AgentID, RegionInfo.RegionName);
-                    //return false;
-                }
+                // if (m_regInfo.EstateSettings.IsBanned(agent.AgentID))
+                // {
+                //     m_log.WarnFormat(
+                //    "[CONNECTION BEGIN]: Incoming user {0} at {1} is on the region banlist",
+                //    agent.AgentID, RegionInfo.RegionName);
+                //     //return false;
+                // }
 
                 CapsModule.AddCapsHandler(agent.AgentID);
 
@@ -2481,7 +2467,12 @@
             }
             else
             {
-                m_log.WarnFormat("[CONNECTION BEGIN]: failed to authenticate user {0} {1}. Denying connection.", agent.firstname, agent.lastname);
+                m_log.WarnFormat("[CONNECTION BEGIN]: failed to authenticate user {0} {1}: {2}. Denying connection.", 
+                                 agent.firstname, agent.lastname, reason);
+                if (String.IsNullOrEmpty(reason))
+                {
+                    reason = String.Format("Failed to authenticate user {0} {1}, access denied.", agent.firstname, agent.lastname);
+                }
                 return false;
             }
         }

Modified: trunk/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
===================================================================
--- trunk/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs  2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs  2009-05-05 16:17:52 UTC (rev 9427)
@@ -296,8 +296,10 @@
             string capsPath = <a class="moz-txt-link-rfc2396E" href="http://">"http://"</a> + reg.ExternalHostName + ":" + reg.HttpPort
                   + "/CAPS/" + a.CapsPath + "0000/";
 
+            string reason = String.Empty;
+
             //bool regionAccepted = m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, a);
-            bool regionAccepted = m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, a);
+            bool regionAccepted = m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, a, out reason);
 
             if (regionAccepted && newAgent)
             {
@@ -785,11 +787,14 @@
                             agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
                         }
 
+                        string reason = String.Empty;
+
                         // Let's create an agent there if one doesn't exist yet. 
                         //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit))
-                        if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit))
+                        if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit, out reason))
                         {
-                            avatar.ControllingClient.SendTeleportFailed("Destination is not accepting teleports.");
+                            avatar.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}",
+                                                                                      reason));
                             return;
                         }
 

Modified: trunk/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
===================================================================
--- trunk/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs   2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs   2009-05-05 16:17:52 UTC (rev 9427)
@@ -115,7 +115,8 @@
             agent.startpos = Vector3.Zero;
             agent.CapsPath = GetRandomCapsObjectPath();
 
-            scene.NewUserConnection(agent);
+            string reason;
+            scene.NewUserConnection(agent, out reason);
             testclient = new TestClient(agent, scene);
             scene.AddNewClient(testclient);
 
@@ -146,7 +147,8 @@
         {
             Console.WriteLine("Beginning test {0}", MethodBase.GetCurrentMethod());
 
-            scene.NewUserConnection(acd1);
+            string reason;
+            scene.NewUserConnection(acd1, out reason);
             scene.AddNewClient(testclient);
 
             ScenePresence presence = scene.GetScenePresence(agent1);
@@ -203,7 +205,8 @@
             Console.WriteLine("Beginning test {0}", MethodBase.GetCurrentMethod());
 
             // Adding child agent to region 1001
-            scene2.NewUserConnection(acd1);
+            string reason;
+            scene2.NewUserConnection(acd1, out reason);
             scene2.AddNewClient(testclient);
 
             ScenePresence presence = scene.GetScenePresence(agent1);

Modified: trunk/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs
===================================================================
--- trunk/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs       2009-05-05 15:23:44 UTC (rev 9426)
+++ trunk/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs       2009-05-05 16:17:52 UTC (rev 9427)
@@ -245,9 +245,11 @@
         /// <returns></returns>
         public static TestClient AddRootAgent(Scene scene, AgentCircuitData agentData)
         {
+            string reason;
+
             // We emulate the proper login sequence here by doing things in three stages
             // Stage 1: simulate login by telling the scene to expect a new user connection
-            scene.NewUserConnection(agentData);
+            scene.NewUserConnection(agentData, out reason);
 
             // Stage 2: add the new client as a child agent to the scene
             TestClient client = new TestClient(agentData, scene);

_______________________________________________
Opensim-commits mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Opensim-commits@lists.berlios.de">Opensim-commits@lists.berlios.de</a>
<a class="moz-txt-link-freetext" href="https://lists.berlios.de/mailman/listinfo/opensim-commits">https://lists.berlios.de/mailman/listinfo/opensim-commits</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="80">-- 
dr dirk husemann ---- virtual worlds research ---- ibm zurich research lab
SL: dr scofield ---- <a class="moz-txt-link-abbreviated" href="mailto:drscofield@xyzzyxyzzy.net">drscofield@xyzzyxyzzy.net</a> ---- <a class="moz-txt-link-freetext" href="http://xyzzyxyzzy.net/">http://xyzzyxyzzy.net/</a>
RL: <a class="moz-txt-link-abbreviated" href="mailto:hud@zurich.ibm.com">hud@zurich.ibm.com</a> - +41 44 724 8573 - <a class="moz-txt-link-freetext" href="http://www.zurich.ibm.com/~hud/">http://www.zurich.ibm.com/~hud/</a>
</pre>
</body>
</html>