refactoring Scene.NewUserConnection() to be simpler and clearer.

0.6.5-rc1
Dr Scofield 2009-05-06 20:02:49 +00:00
parent 1afdf2ee1f
commit 1352a19838
2 changed files with 88 additions and 93 deletions

View File

@ -2378,35 +2378,19 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="reason"></param>
public bool NewUserConnection(AgentCircuitData agent, out string reason)
{
bool goodUserConnection = AuthenticateUser(agent);
// Don't disable this log message - it's too helpful
m_log.InfoFormat(
"[CONNECTION BEGIN]: Region {0} told of incoming {1} agent {2} {3} {4} (circuit code {5})",
RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
agent.AgentID, agent.circuitcode);
reason = String.Empty;
if (!AuthenticateUser(agent, out reason))
return false;
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 (!AuthorizeUser(agent, out reason))
return false;
if (goodUserConnection)
{
CapsModule.NewUserConnection(agent);
ScenePresence sp = m_sceneGraph.GetScenePresence(agent.AgentID);
@ -2421,19 +2405,6 @@ namespace OpenSim.Region.Framework.Scenes
return true;
}
// Don't disable this log message - it's too helpful
m_log.InfoFormat(
"[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;
// }
CapsModule.AddCapsHandler(agent.AgentID);
if (!agent.child)
@ -2465,25 +2436,47 @@ namespace OpenSim.Region.Framework.Scenes
return true;
}
else
{
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;
}
}
public virtual bool AuthenticateUser(AgentCircuitData agent)
public virtual bool AuthenticateUser(AgentCircuitData agent, out string reason)
{
reason = String.Empty;
bool result = CommsManager.UserService.VerifySession(agent.AgentID, agent.SessionID);
m_log.Debug("[CONNECTION BEGIN]: User authentication returned " + result);
if (!result)
reason = String.Format("Failed to authenticate user {0} {1}, access denied.", agent.firstname, agent.lastname);
return result;
}
protected virtual bool AuthorizeUser(AgentCircuitData agent, out string reason)
{
reason = String.Empty;
if (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);
return false;
}
if (!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);
return false;
}
return true;
}
public void UpdateCircuitData(AgentCircuitData data)
{
m_authenticateHandler.UpdateAgentData(data);

View File

@ -25,6 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
@ -55,8 +56,9 @@ namespace OpenSim.Tests.Common.Mock
///
/// <param name="agent"></param>
/// <returns></returns>
public override bool AuthenticateUser(AgentCircuitData agent)
public override bool AuthenticateUser(AgentCircuitData agent, out string reason)
{
reason = String.Empty;
return true;
}