public bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, out string reason, bool requirePresenceLookup)
{
bool vialogin = ((teleportFlags & (uint)Constants.TeleportFlags.ViaLogin) != 0 ||
(teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0);
reason = String.Empty;
//Teleport flags:
//
// TeleportFlags.ViaGodlikeLure - Border Crossing
// TeleportFlags.ViaLogin - Login
// TeleportFlags.TeleportFlags.ViaLure - Teleport request sent by another user
// TeleportFlags.ViaLandmark | TeleportFlags.ViaLocation | TeleportFlags.ViaLandmark | TeleportFlags.Default - Regular Teleport
// 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}, teleportflags {6})",
RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
agent.AgentID, agent.circuitcode, teleportFlags);
if (LoginsDisabled)
{
reason = "Logins Disabled";
return false;
}
ScenePresence sp = GetScenePresence(agent.AgentID);
if (sp != null && !sp.IsChildAgent)
{
// We have a zombie from a crashed session.
// Or the same user is trying to be root twice here, won't work.
// Kill it.
m_log.DebugFormat("[SCENE]: Zombie scene presence detected for {0} in {1}", agent.AgentID, RegionInfo.RegionName);
sp.ControllingClient.Close();
sp = null;
}
ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
//On login test land permisions
if (vialogin)
{
if (land != null && !TestLandRestrictions(agent, land, out reason))
{
return false;
}
}
if (sp == null) // We don't have an [child] agent here already
{
if (requirePresenceLookup)
{
try
{
if (!VerifyUserPresence(agent, out reason))
return false;
}
catch (Exception e)
{
m_log.ErrorFormat("[CONNECTION BEGIN]: Exception verifying presence " + e.ToString());
return false;
}
}
try
{
if (!AuthorizeUser(agent, out reason))
return false;
}
catch (Exception e)
{
m_log.ErrorFormat("[CONNECTION BEGIN]: Exception authorizing user " + e.ToString());
return false;
}
m_log.InfoFormat(
"[CONNECTION BEGIN]: Region {0} authenticated and authorized incoming {1} agent {2} {3} {4} (circuit code {5})",
RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
agent.AgentID, agent.circuitcode);
CapsModule.NewUserConnection(agent);
CapsModule.AddCapsHandler(agent.AgentID);
}
else
{
if (sp.IsChildAgent)
{
m_log.DebugFormat(
"[SCENE]: Adjusting known seeds for existing agent {0} in {1}",
agent.AgentID, RegionInfo.RegionName);
sp.AdjustKnownSeeds();
CapsModule.NewUserConnection(agent);
}
}
// In all cases, add or update the circuit data with the new agent circuit data and teleport flags
agent.teleportFlags = teleportFlags;
m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
if (vialogin)
{
CleanDroppedAttachments();
if (TestBorderCross(agent.startpos, Cardinals.E))
{
Border crossedBorder = GetCrossedBorder(agent.startpos, Cardinals.E);
agent.startpos.X = crossedBorder.BorderLine.Z - 1;
}
if (TestBorderCross(agent.startpos, Cardinals.N))
{
Border crossedBorder = GetCrossedBorder(agent.startpos, Cardinals.N);
agent.startpos.Y = crossedBorder.BorderLine.Z - 1;
}
//Mitigate http://opensimulator.org/mantis/view.php?id=3522
// Check if start position is outside of region
// If it is, check the Z start position also.. if not, leave it alone.
if (BordersLocked)
{
lock (EastBorders)
{
if (agent.startpos.X > EastBorders[0].BorderLine.Z)
{
m_log.Warn("FIX AGENT POSITION");
agent.startpos.X = EastBorders[0].BorderLine.Z * 0.5f;
if (agent.startpos.Z > 720)
agent.startpos.Z = 720;
}
}
lock (NorthBorders)
{
if (agent.startpos.Y > NorthBorders[0].BorderLine.Z)
{
m_log.Warn("FIX Agent POSITION");
agent.startpos.Y = NorthBorders[0].BorderLine.Z * 0.5f;
if (agent.startpos.Z > 720)
agent.startpos.Z = 720;
}
}
}
else
{
if (agent.startpos.X > EastBorders[0].BorderLine.Z)
{
m_log.Warn("FIX AGENT POSITION");
agent.startpos.X = EastBorders[0].BorderLine.Z * 0.5f;
if (agent.startpos.Z > 720)
agent.startpos.Z = 720;
}
if (agent.startpos.Y > NorthBorders[0].BorderLine.Z)
{
m_log.Warn("FIX Agent POSITION");
agent.startpos.Y = NorthBorders[0].BorderLine.Z * 0.5f;
if (agent.startpos.Z > 720)
agent.startpos.Z = 720;
}
}
// Honor parcel landing type and position.
if (land != null)
{
if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero)
{
agent.startpos = land.LandData.UserLocation;
}
}
}
return true;
}