From 6f83b0ee4625ae6b94a7ca0525f7d8369da7e126 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 20 Aug 2010 09:02:05 -0700 Subject: [PATCH] Cleaned up a few more things related to incoming agents. --- OpenSim/Region/Framework/Scenes/Scene.cs | 91 ++++++++++++------------ 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 2f862ea290..a14762841d 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2502,18 +2502,25 @@ namespace OpenSim.Region.Framework.Scenes /// public override void AddNewClient(IClientAPI client) { + AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode); bool vialogin = false; - m_clientManager.Add(client); + if (aCircuit == null) // no good, didn't pass NewUserConnection successfully + return; + + vialogin = (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 || + (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0; CheckHeartbeat(); - 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); + m_clientManager.Add(client); + SubscribeToClientEvents(client); + presence = m_restorePresences[client.AgentId]; m_restorePresences.Remove(client.AgentId); @@ -2536,49 +2543,35 @@ namespace OpenSim.Region.Framework.Scenes } else { - AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode); - - //// Do the verification here -- No, really don't do this here. This is UDP address, let it go. - //System.Net.IPEndPoint ep = (System.Net.IPEndPoint)client.GetClientEP(); - //if (aCircuit != null) - //{ - // if (!VerifyClient(aCircuit, ep, out vialogin)) - // { - // // uh-oh, this is fishy - // m_log.WarnFormat("[SCENE]: Agent {0} with session {1} connecting with unidentified end point {2}. Refusing service.", - // client.AgentId, client.SessionId, ep.ToString()); - // try - // { - // client.Close(); - // } - // catch (Exception e) - // { - // m_log.DebugFormat("[SCENE]: Exception while closing aborted client: {0}", e.StackTrace); - // } - // return; - // } - //} - - m_log.Debug("[SCENE]: Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName); - - ScenePresence sp = CreateAndAddScenePresence(client); - if (aCircuit != null) - sp.Appearance = aCircuit.Appearance; - - // HERE!!! Do the initial attachments right here - // first agent upon login is a root agent by design. - // All other AddNewClient calls find aCircuit.child to be true - if (aCircuit == null || (aCircuit != null && aCircuit.child == false)) + if (GetScenePresence(client.AgentId) == null) // ensure there is no SP here { - sp.IsChildAgent = false; - Util.FireAndForget(delegate(object o) { sp.RezAttachments(); }); + m_log.Debug("[SCENE]: Adding new agent " + client.Name + " to scene " + RegionInfo.RegionName); + + m_clientManager.Add(client); + SubscribeToClientEvents(client); + + ScenePresence sp = CreateAndAddScenePresence(client); + if (aCircuit != null) + sp.Appearance = aCircuit.Appearance; + + // HERE!!! Do the initial attachments right here + // first agent upon login is a root agent by design. + // All other AddNewClient calls find aCircuit.child to be true + if (aCircuit == null || (aCircuit != null && aCircuit.child == false)) + { + sp.IsChildAgent = false; + Util.FireAndForget(delegate(object o) { sp.RezAttachments(); }); + } } } - m_LastLogin = Util.EnvironmentTickCount(); - EventManager.TriggerOnNewClient(client); - if (vialogin) - EventManager.TriggerOnClientLogin(client); + if (GetScenePresence(client.AgentId) != null) + { + m_LastLogin = Util.EnvironmentTickCount(); + EventManager.TriggerOnNewClient(client); + if (vialogin) + EventManager.TriggerOnClientLogin(client); + } } private bool VerifyClient(AgentCircuitData aCircuit, System.Net.IPEndPoint ep, out bool vialogin) @@ -2605,8 +2598,11 @@ namespace OpenSim.Region.Framework.Scenes } else if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0) - m_log.DebugFormat("[SCENE]: Incoming client {0} {1} in region {2} via regular login. Client IP verification not performed.", + { + m_log.DebugFormat("[SCENE]: Incoming client {0} {1} in region {2} via regular login. Client IP verification not performed.", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); + vialogin = true; + } return true; } @@ -3245,7 +3241,8 @@ namespace OpenSim.Region.Framework.Scenes /// also return a reason. public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason) { - TeleportFlags tp = (TeleportFlags)teleportFlags; + bool vialogin = ((teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0 || + (teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0); reason = String.Empty; //Teleport flags: @@ -3282,7 +3279,7 @@ namespace OpenSim.Region.Framework.Scenes ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); //On login test land permisions - if (tp == TeleportFlags.ViaLogin) + if (vialogin) { if (land != null && !TestLandRestrictions(agent, land, out reason)) { @@ -3341,7 +3338,7 @@ namespace OpenSim.Region.Framework.Scenes agent.teleportFlags = teleportFlags; m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); - if (tp == TeleportFlags.ViaLogin) + if (vialogin) { if (TestBorderCross(agent.startpos, Cardinals.E)) { @@ -3459,7 +3456,7 @@ namespace OpenSim.Region.Framework.Scenes IPresenceService presence = RequestModuleInterface(); if (presence == null) { - reason = String.Format("Failed to verify user {0} {1} in region {2}. Presence service does not exist.", agent.firstname, agent.lastname, RegionInfo.RegionName); + reason = String.Format("Failed to verify user presence in the grid for {0} {1} in region {2}. Presence service does not exist.", agent.firstname, agent.lastname, RegionInfo.RegionName); return false; } @@ -3467,7 +3464,7 @@ namespace OpenSim.Region.Framework.Scenes if (pinfo == null) { - reason = String.Format("Failed to verify user {0} {1}, access denied to region {2}.", agent.firstname, agent.lastname, RegionInfo.RegionName); + reason = String.Format("Failed to verify user presence in the grid for {0} {1}, access denied to region {2}.", agent.firstname, agent.lastname, RegionInfo.RegionName); return false; }