Streamline banning code using existing methods.

avinationmerge
Melanie 2012-02-02 16:51:39 +01:00
parent 857d4e60cc
commit fd7e82ee72
2 changed files with 41 additions and 185 deletions

View File

@ -1752,191 +1752,37 @@ namespace OpenSim.Region.CoreModules.World.Land
public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target) public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
{ {
ScenePresence targetAvatar = null; ScenePresence targetAvatar = null;
((Scene)client.Scene).TryGetScenePresence(target, out targetAvatar);
ScenePresence parcelManager = null; ScenePresence parcelManager = null;
((Scene)client.Scene).TryGetScenePresence(client.AgentId, out parcelManager);
//Just eject // Must have presences
if (flags == 0) if (!m_scene.TryGetScenePresence(target, out targetAvatar) ||
{ !m_scene.TryGetScenePresence(client.AgentId, out parcelManager))
if (targetAvatar.UserLevel == 0)
{
ILandObject land = ((Scene)client.Scene).LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
if (!((Scene)client.Scene).Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze))
return; return;
Vector3 position = new Vector3(0, 0, 0); // Cannot eject estate managers or gods
List<ILandObject> allParcels = new List<ILandObject>(); if (m_scene.Permissions.IsAdministrator(target))
allParcels = AllParcels();
if (allParcels.Count != 1)
{
foreach (ILandObject parcel in allParcels)
{
if (parcel.LandData.GlobalID != land.LandData.GlobalID)
{
if (parcel.IsEitherBannedOrRestricted(targetAvatar.UUID) != true)
{
for (int x = 1; x <= Constants.RegionSize; x += 2)
{
for (int y = 1; y <= Constants.RegionSize; y += 2)
{
if (parcel.ContainsPoint(x, y))
{
position = new Vector3(x, y, targetAvatar.AbsolutePosition.Z);
targetAvatar.TeleportWithMomentum(position);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
return;
}
}
}
}
}
}
}
Vector3 targetVector;
if (targetAvatar.AbsolutePosition.X > targetAvatar.AbsolutePosition.Y)
{
if (targetAvatar.AbsolutePosition.X > .5 * Constants.RegionSize)
{
targetVector = new Vector3(Constants.RegionSize, targetAvatar.AbsolutePosition.Y, targetAvatar.AbsolutePosition.Z); ;
targetAvatar.TeleportWithMomentum(targetVector);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
return;
}
else
{
targetVector = new Vector3(0, targetAvatar.AbsolutePosition.Y, targetAvatar.AbsolutePosition.Z); ;
targetAvatar.TeleportWithMomentum(targetVector);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
return;
}
}
else
{
if (targetAvatar.AbsolutePosition.Y > .5 * Constants.RegionSize)
{
targetVector = new Vector3(targetAvatar.AbsolutePosition.X, Constants.RegionSize, targetAvatar.AbsolutePosition.Z); ;
targetAvatar.TeleportWithMomentum(targetVector);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
return;
}
else
{
targetVector = new Vector3(targetAvatar.AbsolutePosition.X, 0, targetAvatar.AbsolutePosition.Z); ;
targetAvatar.TeleportWithMomentum(targetVector);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
return;
}
}
}
}
//Eject and ban
if (flags == 1)
{
if (targetAvatar.UserLevel == 0)
{
ILandObject land = ((Scene)client.Scene).LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
if (!((Scene)client.Scene).Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze))
return; return;
Vector3 position = new Vector3(0, 0, 0); // Check if you even have permission to do this
List<ILandObject> allParcels = new List<ILandObject>(); ILandObject land = m_scene.LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
allParcels = AllParcels(); if (!m_scene.Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze) &&
if (allParcels.Count != 1) !m_scene.Permissions.IsAdministrator(client.AgentId))
return;
Vector3 pos = m_scene.GetNearestAllowedPosition(targetAvatar, land);
targetAvatar.TeleportWithMomentum(pos);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
if ((flags & 1) != 0) // Ban TODO: Remove magic number
{ {
foreach (ILandObject parcel in allParcels)
{
if (parcel.LandData.GlobalID != land.LandData.GlobalID)
{
if (parcel.IsEitherBannedOrRestricted(targetAvatar.UUID) != true)
{
for (int x = 1; x <= Constants.RegionSize; x += 2)
{
for (int y = 1; y <= Constants.RegionSize; y += 2)
{
if (parcel.ContainsPoint(x, y))
{
position = new Vector3(x, y, targetAvatar.AbsolutePosition.Z);
targetAvatar.TeleportWithMomentum(position);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected and banned by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected and Banned.");
ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry(); ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
entry.AgentID = targetAvatar.UUID; entry.AgentID = targetAvatar.UUID;
entry.Flags = AccessList.Ban; entry.Flags = AccessList.Ban;
entry.Time = new DateTime(); entry.Time = new DateTime();
land.LandData.ParcelAccessList.Add(entry); land.LandData.ParcelAccessList.Add(entry);
return;
}
}
}
}
}
}
}
Vector3 targetVector;
if (targetAvatar.AbsolutePosition.X > targetAvatar.AbsolutePosition.Y)
{
if (targetAvatar.AbsolutePosition.X > .5 * Constants.RegionSize)
{
targetVector = new Vector3(Constants.RegionSize, targetAvatar.AbsolutePosition.Y, targetAvatar.AbsolutePosition.Z); ;
targetAvatar.TeleportWithMomentum(targetVector);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected and banned by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected and Banned.");
ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
entry.AgentID = targetAvatar.UUID;
entry.Flags = AccessList.Ban;
entry.Time = new DateTime();
land.LandData.ParcelAccessList.Add(entry);
return;
}
else
{
targetVector = new Vector3(0, targetAvatar.AbsolutePosition.Y, targetAvatar.AbsolutePosition.Z); ;
targetAvatar.TeleportWithMomentum(targetVector);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected and banned by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected and Banned.");
ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
entry.AgentID = targetAvatar.UUID;
entry.Flags = AccessList.Ban;
entry.Time = new DateTime();
land.LandData.ParcelAccessList.Add(entry);
return;
}
}
else
{
if (targetAvatar.AbsolutePosition.Y > .5 * Constants.RegionSize)
{
targetVector = new Vector3(targetAvatar.AbsolutePosition.X, Constants.RegionSize, targetAvatar.AbsolutePosition.Z); ;
targetAvatar.TeleportWithMomentum(targetVector);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected and banned by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected and Banned.");
ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
entry.AgentID = targetAvatar.UUID;
entry.Flags = AccessList.Ban;
entry.Time = new DateTime();
land.LandData.ParcelAccessList.Add(entry);
return;
}
else
{
targetVector = new Vector3(targetAvatar.AbsolutePosition.X, 0, targetAvatar.AbsolutePosition.Z); ;
targetAvatar.TeleportWithMomentum(targetVector);
targetAvatar.ControllingClient.SendAlertMessage("You have been ejected and banned by " + parcelManager.Firstname + " " + parcelManager.Lastname);
parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected and Banned.");
ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
entry.AgentID = targetAvatar.UUID;
entry.Flags = AccessList.Ban;
entry.Time = new DateTime();
land.LandData.ParcelAccessList.Add(entry);
return;
}
}
}
} }
} }

View File

@ -4855,9 +4855,14 @@ Environment.Exit(1);
get { return m_allowScriptCrossings; } get { return m_allowScriptCrossings; }
} }
public Vector3? GetNearestAllowedPosition(ScenePresence avatar) public Vector3 GetNearestAllowedPosition(ScenePresence avatar)
{ {
ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); return GetNearestAllowedPosition(avatar, null);
}
public Vector3 GetNearestAllowedPosition(ScenePresence avatar, ILandObject excludeParcel)
{
ILandObject nearestParcel = GetNearestAllowedParcel(avatar.UUID, avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, excludeParcel);
if (nearestParcel != null) if (nearestParcel != null)
{ {
@ -4915,6 +4920,11 @@ Environment.Exit(1);
} }
public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y) public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y)
{
return GetNearestAllowedParcel(avatarId, x, y, null);
}
public ILandObject GetNearestAllowedParcel(UUID avatarId, float x, float y, ILandObject excludeParcel)
{ {
List<ILandObject> all = AllParcels(); List<ILandObject> all = AllParcels();
float minParcelDistance = float.MaxValue; float minParcelDistance = float.MaxValue;
@ -4922,7 +4932,7 @@ Environment.Exit(1);
foreach (var parcel in all) foreach (var parcel in all)
{ {
if (!parcel.IsEitherBannedOrRestricted(avatarId)) if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel)
{ {
float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); float parcelDistance = GetParcelDistancefromPoint(parcel, x, y);
if (parcelDistance < minParcelDistance) if (parcelDistance < minParcelDistance)