From fd7e82ee7237617a8e19b1eede3cf5164a587a67 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 2 Feb 2012 16:51:39 +0100 Subject: Streamline banning code using existing methods. --- .../CoreModules/World/Land/LandManagementModule.cs | 212 +++------------------ OpenSim/Region/Framework/Scenes/Scene.cs | 16 +- 2 files changed, 42 insertions(+), 186 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs index 400e453..5db56b0 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs @@ -1752,191 +1752,37 @@ namespace OpenSim.Region.CoreModules.World.Land public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target) { ScenePresence targetAvatar = null; - ((Scene)client.Scene).TryGetScenePresence(target, out targetAvatar); ScenePresence parcelManager = null; - ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out parcelManager); - //Just eject - if (flags == 0) - { - 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; - - Vector3 position = new Vector3(0, 0, 0); - List allParcels = new List(); - 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) + + // Must have presences + if (!m_scene.TryGetScenePresence(target, out targetAvatar) || + !m_scene.TryGetScenePresence(client.AgentId, out parcelManager)) + return; + + // Cannot eject estate managers or gods + if (m_scene.Permissions.IsAdministrator(target)) + return; + + // Check if you even have permission to do this + ILandObject land = m_scene.LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y); + if (!m_scene.Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze) && + !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 { - 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; - - Vector3 position = new Vector3(0, 0, 0); - List allParcels = new List(); - 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 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; - } - } - } - } - } - } - } - 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; - } - } - } + ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry(); + entry.AgentID = targetAvatar.UUID; + entry.Flags = AccessList.Ban; + entry.Time = new DateTime(); + + land.LandData.ParcelAccessList.Add(entry); } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index b37df82..128954f 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4855,9 +4855,14 @@ Environment.Exit(1); 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) { @@ -4916,13 +4921,18 @@ Environment.Exit(1); 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 all = AllParcels(); float minParcelDistance = float.MaxValue; ILandObject nearestParcel = null; foreach (var parcel in all) { - if (!parcel.IsEitherBannedOrRestricted(avatarId)) + if (!parcel.IsEitherBannedOrRestricted(avatarId) && parcel != excludeParcel) { float parcelDistance = GetParcelDistancefromPoint(parcel, x, y); if (parcelDistance < minParcelDistance) -- cgit v1.1