Console command to rename Estate

0.8.0.3
Dev Random 2014-04-01 08:56:05 -04:00 committed by Justin Clark-Casey (justincc)
parent 444737c830
commit 43eab5e163
3 changed files with 340 additions and 232 deletions

View File

@ -54,14 +54,9 @@ namespace OpenSim.Region.CoreModules.World.Estate
protected Commander m_commander = new Commander("estate");
// variable used in processing "estate set owner"
private static string[] m_ownerCmd = null;
// variable used in processing "estate set owner"
private static UserAccount m_ownerAccount;
// variable used in processing "estate set owner"
private static List<uint> m_ownerEstates;
// used to prevent multiple processing of commands when called from root region
private static string[] m_currentCmd = null;
private static EstateSettings m_estateSettings = null;
public EstateManagementCommands(EstateManagementModule module)
{
@ -92,18 +87,22 @@ namespace OpenSim.Region.CoreModules.World.Estate
"Specify -1 in <x> or <y> to wildcard that coordinate.",
consoleSetWaterHeight);
m_module.Scene.AddCommand(
"Estates", m_module, "estate show", "estate show", "Shows all estates on the simulator.", ShowEstatesCommand);
m_module.Scene.AddCommand(
"Estates", m_module, "estate set owner", "estate set owner [ <UUID> | <Firstname> <Lastname> ]",
"Sets the owner of the current region's estate to the specified UUID or user. " +
"If called from root region, all estates will be prompted for change.", SetEstateOwnerCommand);
"Estates", m_module, "estate set owner", "estate set owner <estate-id>[ <UUID> | <Firstname> <Lastname> ]",
"Sets the owner of the specified estate to the specified UUID or user. ", SetEstateOwnerCommand);
m_module.Scene.AddCommand(
"Estates", m_module, "estate set name", "estate set name <estate-id> <new name>",
"Sets the name of the specified estate to the specified value. " +
"New name must be unique.", SetEstateNameCommand);
}
public void Close() {}
#region CommandHandlers
protected void consoleSetTerrainTexture(string module, string[] args)
{
string num = args[3];
@ -248,112 +247,170 @@ namespace OpenSim.Region.CoreModules.World.Estate
EstateSettings es = m_module.Scene.RegionInfo.EstateSettings;
if(args != m_ownerCmd)
if (args == m_currentCmd)
{
// new command... clear out the old values
m_ownerCmd = args;
m_ownerEstates = new List<uint>();
m_ownerAccount = null;
}
// HACK to propagate new estate info to Scene Regions
if (m_estateSettings != null && es.EstateID == m_estateSettings.EstateID)
es.EstateOwner = m_estateSettings.EstateOwner;
if (MainConsole.Instance.ConsoleScene == null)
{
if(m_ownerEstates.Contains(es.EstateID))
{
// already checked this one
return;
}
else if(m_ownerEstates.Count > 0 && m_ownerAccount == null)
{
// lookup will have been tried and not found.
return;
}
// flag this estate, so it is not tried multiple times
m_ownerEstates.Add(es.EstateID);
}
else if(MainConsole.Instance.ConsoleScene != m_module.Scene)
{
// trying to process a single region, and this isn't it
return;
}
UserAccount account = null;
if(m_ownerAccount == null)
// new command... clear out the old value
m_currentCmd = args;
if (args.Length == 3)
{
if(args.Length == 3)
response = "No estate specified.";
}
else
{
int estateId;
if (!int.TryParse(args[3], out estateId))
{
response = "No user specified.";
response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
}
else
{
// TODO: Is there a better choice here?
UUID scopeID = UUID.Zero;
string s1 = args[3];
if(args.Length == 4)
if (args.Length == 4)
{
// attempt to get account by UUID
UUID u;
if(UUID.TryParse(s1, out u))
response = "No user specified.";
}
else
{
UserAccount account = null;
// TODO: Is there a better choice here?
UUID scopeID = UUID.Zero;
string s1 = args[4];
if (args.Length == 5)
{
account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, u);
if(account == null)
// attempt to get account by UUID
UUID u;
if (UUID.TryParse(s1, out u))
{
response = String.Format("Could not find user {0}", s1);
account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, u);
if (account == null)
response = String.Format("Could not find user {0}", s1);
}
else
{
response = String.Format("Invalid UUID {0}", s1);
}
}
else
{
response = String.Format("Invalid UUID {0}", s1);
account = null;
// attempt to get account by Firstname, Lastname
string s2 = args[5];
account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, s1, s2);
if (account == null)
response = String.Format("Could not find user {0} {1}", s1, s2);
}
}
else
{
// attempt to get account by Firstname, Lastname
string s2 = args[4];
account = m_module.Scene.UserAccountService.GetUserAccount(scopeID, s1, s2);
if(account == null)
// If it's valid, send it off for processing.
if (account != null)
response = m_module.SetEstateOwner(estateId, account);
if (response == String.Empty)
{
response = String.Format("Could not find user {0} {1}", s1, s2);
response = String.Format("Estate owner changed to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName);
// save data for propagation to other Scene Regions
m_estateSettings = new EstateSettings();
m_estateSettings.EstateID = (uint)estateId;
m_estateSettings.EstateOwner = account.PrincipalID;
// update current Scene Region if appropriate
if (es.EstateID == estateId)
es.EstateOwner = account.PrincipalID;
}
else
{
m_estateSettings = null;
}
}
}
}
else
{
account = m_ownerAccount;
}
if(account != null)
{
if (MainConsole.Instance.ConsoleScene == null)
m_ownerAccount = account;
string choice;
do
{
// Get user confirmation, in case there are multiple estates involved (from root)
choice = MainConsole.Instance.CmdPrompt(
string.Format("Change owner of Estate {0} ({1}) [y/n]? ",es.EstateID, es.EstateName),
"Y");
if("y".Equals(choice, StringComparison.OrdinalIgnoreCase))
{
response = m_module.setEstateOwner((int)es.EstateID, account);
}
else if(!"n".Equals(choice, StringComparison.OrdinalIgnoreCase))
{
MainConsole.Instance.Output("Invalid response. Please select y or n.");
choice = null;
}
}
while(choice == null);
}
// Give the user some feedback
if(response != null)
// give the user some feedback
if (response != null)
MainConsole.Instance.Output(response);
}
protected void SetEstateNameCommand(string module, string[] args)
{
string response = null;
EstateSettings es = m_module.Scene.RegionInfo.EstateSettings;
if (args == m_currentCmd)
{
// HACK to propagate new estate info to Scene Regions
if (m_estateSettings != null && es.EstateID == m_estateSettings.EstateID)
es.EstateName = m_estateSettings.EstateName;
return;
}
// new command... clear out the old value
m_currentCmd = args;
if (args.Length == 3)
{
response = "No estate specified.";
}
else
{
int estateId;
if (!int.TryParse(args[3], out estateId))
{
response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
}
else
{
if (args.Length == 4)
{
response = "No name specified.";
}
else
{
// everything after the estate ID is "name"
StringBuilder sb = new StringBuilder(args[4]);
for (int i = 5; i < args.Length; i++)
sb.Append (" " + args[i]);
string estateName = sb.ToString();
// send it off for processing.
response = m_module.SetEstateName(estateId, estateName);
if (response == String.Empty)
{
response = String.Format("Estate {0} renamed from \"{1}\" to \"{2}\"", estateId, es.EstateName, estateName);
// save data for propagation to other Scene Regions
m_estateSettings = new EstateSettings();
m_estateSettings.EstateID = (uint)estateId;
m_estateSettings.EstateName = estateName;
// update current Scene Region if appropriate
if (es.EstateID == estateId)
es.EstateName = estateName;
}
else
{
m_estateSettings = null;
}
}
}
}
// give the user some feedback
if (response != null)
MainConsole.Instance.Output(response);
}
#endregion
}
}

View File

@ -68,8 +68,6 @@ namespace OpenSim.Region.CoreModules.World.Estate
public event ChangeDelegate OnEstateInfoChange;
public event MessageDelegate OnEstateMessage;
private int m_delayCount = 0;
#region Region Module interface
public string Name { get { return "EstateManagementModule"; } }
@ -117,6 +115,189 @@ namespace OpenSim.Region.CoreModules.World.Estate
#endregion
#region IEstateModule Functions
public uint GetRegionFlags()
{
RegionFlags flags = RegionFlags.None;
// Fully implemented
//
if (Scene.RegionInfo.RegionSettings.AllowDamage)
flags |= RegionFlags.AllowDamage;
if (Scene.RegionInfo.RegionSettings.BlockTerraform)
flags |= RegionFlags.BlockTerraform;
if (!Scene.RegionInfo.RegionSettings.AllowLandResell)
flags |= RegionFlags.BlockLandResell;
if (Scene.RegionInfo.RegionSettings.DisableCollisions)
flags |= RegionFlags.SkipCollisions;
if (Scene.RegionInfo.RegionSettings.DisableScripts)
flags |= RegionFlags.SkipScripts;
if (Scene.RegionInfo.RegionSettings.DisablePhysics)
flags |= RegionFlags.SkipPhysics;
if (Scene.RegionInfo.RegionSettings.BlockFly)
flags |= RegionFlags.NoFly;
if (Scene.RegionInfo.RegionSettings.RestrictPushing)
flags |= RegionFlags.RestrictPushObject;
if (Scene.RegionInfo.RegionSettings.AllowLandJoinDivide)
flags |= RegionFlags.AllowParcelChanges;
if (Scene.RegionInfo.RegionSettings.BlockShowInSearch)
flags |= RegionFlags.BlockParcelSearch;
if (Scene.RegionInfo.RegionSettings.FixedSun)
flags |= RegionFlags.SunFixed;
if (Scene.RegionInfo.RegionSettings.Sandbox)
flags |= RegionFlags.Sandbox;
if (Scene.RegionInfo.EstateSettings.AllowVoice)
flags |= RegionFlags.AllowVoice;
if (Scene.RegionInfo.EstateSettings.AllowLandmark)
flags |= RegionFlags.AllowLandmark;
if (Scene.RegionInfo.EstateSettings.AllowSetHome)
flags |= RegionFlags.AllowSetHome;
if (Scene.RegionInfo.EstateSettings.BlockDwell)
flags |= RegionFlags.BlockDwell;
if (Scene.RegionInfo.EstateSettings.ResetHomeOnTeleport)
flags |= RegionFlags.ResetHomeOnTeleport;
// TODO: SkipUpdateInterestList
// Omitted
//
// Omitted: NullLayer (what is that?)
// Omitted: SkipAgentAction (what does it do?)
return (uint)flags;
}
public bool IsManager(UUID avatarID)
{
if (avatarID == Scene.RegionInfo.EstateSettings.EstateOwner)
return true;
List<UUID> ems = new List<UUID>(Scene.RegionInfo.EstateSettings.EstateManagers);
if (ems.Contains(avatarID))
return true;
return false;
}
public void sendRegionHandshakeToAll()
{
Scene.ForEachClient(sendRegionHandshake);
}
public void TriggerEstateInfoChange()
{
ChangeDelegate change = OnEstateInfoChange;
if (change != null)
change(Scene.RegionInfo.RegionID);
}
public void TriggerRegionInfoChange()
{
m_regionChangeTimer.Stop();
m_regionChangeTimer.Start();
ChangeDelegate change = OnRegionInfoChange;
if (change != null)
change(Scene.RegionInfo.RegionID);
}
public void setEstateTerrainBaseTexture(int level, UUID texture)
{
setEstateTerrainBaseTexture(null, level, texture);
sendRegionHandshakeToAll();
}
public void setEstateTerrainTextureHeights(int corner, float lowValue, float highValue)
{
setEstateTerrainTextureHeights(null, corner, lowValue, highValue);
}
public bool IsTerrainXfer(ulong xferID)
{
lock (this)
{
if (TerrainUploader == null)
return false;
else
return TerrainUploader.XferID == xferID;
}
}
public string SetEstateOwner(int estateID, UserAccount account)
{
string response;
// get the current settings from DB
EstateSettings dbSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
if (dbSettings.EstateID == 0)
{
response = String.Format("No estate found with ID {0}", estateID);
}
else if (account.PrincipalID == dbSettings.EstateOwner)
{
response = String.Format("Estate already belongs to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName);
}
else
{
dbSettings.EstateOwner = account.PrincipalID;
dbSettings.Save();
response = String.Empty;
// make sure there's a log entry to document the change
m_log.InfoFormat("[ESTATE]: Estate Owner for {0} changed to {1} ({2} {3})", dbSettings.EstateName,
account.PrincipalID, account.FirstName, account.LastName);
TriggerEstateInfoChange();
sendRegionHandshakeToAll();
}
return response;
}
public string SetEstateName(int estateID, string newName)
{
string response;
// get the current settings from DB
EstateSettings dbSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
if (dbSettings.EstateID == 0)
{
response = String.Format("No estate found with ID {0}", estateID);
}
else if (newName == dbSettings.EstateName)
{
response = String.Format("Estate {0} is already named \"{1}\"", estateID, newName);
}
else
{
List<int> estates = Scene.EstateDataService.GetEstates(newName);
if (estates.Count() > 0)
{
response = String.Format("An estate named \"{0}\" already exists.", newName);
}
else
{
string oldName = dbSettings.EstateName;
dbSettings.EstateName = newName;
dbSettings.Save();
response = String.Empty;
// make sure there's a log entry to document the change
m_log.InfoFormat("[ESTATE]: Estate {0} renamed from \"{1}\" to \"{2}\"", estateID, oldName, newName);
TriggerEstateInfoChange();
sendRegionHandshakeToAll();
}
}
return response;
}
#endregion
#region Packet Data Responders
private void clientSendDetailedEstateData(IClientAPI remote_client, UUID invoice)
@ -224,12 +405,6 @@ namespace OpenSim.Region.CoreModules.World.Estate
sendRegionInfoPacketToAll();
}
public void setEstateTerrainBaseTexture(int level, UUID texture)
{
setEstateTerrainBaseTexture(null, level, texture);
sendRegionHandshakeToAll();
}
public void setEstateTerrainBaseTexture(IClientAPI remoteClient, int level, UUID texture)
{
if (texture == UUID.Zero)
@ -256,11 +431,6 @@ namespace OpenSim.Region.CoreModules.World.Estate
sendRegionInfoPacketToAll();
}
public void setEstateTerrainTextureHeights(int corner, float lowValue, float highValue)
{
setEstateTerrainTextureHeights(null, corner, lowValue, highValue);
}
public void setEstateTerrainTextureHeights(IClientAPI client, int corner, float lowValue, float highValue)
{
switch (corner)
@ -925,17 +1095,6 @@ namespace OpenSim.Region.CoreModules.World.Estate
}
}
public bool IsTerrainXfer(ulong xferID)
{
lock (this)
{
if (TerrainUploader == null)
return false;
else
return TerrainUploader.XferID == xferID;
}
}
private void handleTerrainRequest(IClientAPI remote_client, string clientFileName)
{
// Save terrain here
@ -1117,11 +1276,6 @@ namespace OpenSim.Region.CoreModules.World.Estate
remoteClient.SendRegionHandshake(Scene.RegionInfo,args);
}
public void sendRegionHandshakeToAll()
{
Scene.ForEachClient(sendRegionHandshake);
}
public void handleEstateChangeInfo(IClientAPI remoteClient, UUID invoice, UUID senderID, UInt32 parms1, UInt32 parms2)
{
if (parms2 == 0)
@ -1203,31 +1357,8 @@ namespace OpenSim.Region.CoreModules.World.Estate
sendRegionInfoPacketToAll();
}
public string setEstateOwner(int estateID, UserAccount account)
{
string response;
// get the current settings from DB
EstateSettings dbSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
if(account.PrincipalID != dbSettings.EstateOwner) {
dbSettings.EstateOwner = account.PrincipalID;
dbSettings.Save();
response = String.Format("Estate owner changed to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName);
// make sure there's a log entry to document the change
m_log.InfoFormat("[ESTATE]: Estate Owner for {0} changed to {1} ({2} {3})", dbSettings.EstateName,
account.PrincipalID, account.FirstName, account.LastName);
TriggerEstateInfoChange();
}
else
{
response = String.Format("Estate already belongs to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName);
}
return response;
}
#endregion
#endregion
private void EventManager_OnNewClient(IClientAPI client)
{
@ -1257,60 +1388,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
sendRegionHandshake(client);
}
public uint GetRegionFlags()
{
RegionFlags flags = RegionFlags.None;
// Fully implemented
//
if (Scene.RegionInfo.RegionSettings.AllowDamage)
flags |= RegionFlags.AllowDamage;
if (Scene.RegionInfo.RegionSettings.BlockTerraform)
flags |= RegionFlags.BlockTerraform;
if (!Scene.RegionInfo.RegionSettings.AllowLandResell)
flags |= RegionFlags.BlockLandResell;
if (Scene.RegionInfo.RegionSettings.DisableCollisions)
flags |= RegionFlags.SkipCollisions;
if (Scene.RegionInfo.RegionSettings.DisableScripts)
flags |= RegionFlags.SkipScripts;
if (Scene.RegionInfo.RegionSettings.DisablePhysics)
flags |= RegionFlags.SkipPhysics;
if (Scene.RegionInfo.RegionSettings.BlockFly)
flags |= RegionFlags.NoFly;
if (Scene.RegionInfo.RegionSettings.RestrictPushing)
flags |= RegionFlags.RestrictPushObject;
if (Scene.RegionInfo.RegionSettings.AllowLandJoinDivide)
flags |= RegionFlags.AllowParcelChanges;
if (Scene.RegionInfo.RegionSettings.BlockShowInSearch)
flags |= RegionFlags.BlockParcelSearch;
if (Scene.RegionInfo.RegionSettings.FixedSun)
flags |= RegionFlags.SunFixed;
if (Scene.RegionInfo.RegionSettings.Sandbox)
flags |= RegionFlags.Sandbox;
if (Scene.RegionInfo.EstateSettings.AllowVoice)
flags |= RegionFlags.AllowVoice;
if (Scene.RegionInfo.EstateSettings.AllowLandmark)
flags |= RegionFlags.AllowLandmark;
if (Scene.RegionInfo.EstateSettings.AllowSetHome)
flags |= RegionFlags.AllowSetHome;
if (Scene.RegionInfo.EstateSettings.BlockDwell)
flags |= RegionFlags.BlockDwell;
if (Scene.RegionInfo.EstateSettings.ResetHomeOnTeleport)
flags |= RegionFlags.ResetHomeOnTeleport;
// TODO: SkipUpdateInterestList
// Omitted
//
// Omitted: NullLayer (what is that?)
// Omitted: SkipAgentAction (what does it do?)
return (uint)flags;
}
public uint GetEstateFlags()
private uint GetEstateFlags()
{
RegionFlags flags = RegionFlags.None;
@ -1351,37 +1429,6 @@ namespace OpenSim.Region.CoreModules.World.Estate
return (uint)flags;
}
public bool IsManager(UUID avatarID)
{
if (avatarID == Scene.RegionInfo.EstateSettings.EstateOwner)
return true;
List<UUID> ems = new List<UUID>(Scene.RegionInfo.EstateSettings.EstateManagers);
if (ems.Contains(avatarID))
return true;
return false;
}
public void TriggerRegionInfoChange()
{
m_regionChangeTimer.Stop();
m_regionChangeTimer.Start();
ChangeDelegate change = OnRegionInfoChange;
if (change != null)
change(Scene.RegionInfo.RegionID);
}
public void TriggerEstateInfoChange()
{
ChangeDelegate change = OnEstateInfoChange;
if (change != null)
change(Scene.RegionInfo.RegionID);
}
public void TriggerEstateMessage(UUID fromID, string fromName, string message)
{
MessageDelegate onmessage = OnEstateMessage;

View File

@ -26,6 +26,7 @@
*/
using OpenMetaverse;
using OpenSim.Services.Interfaces;
namespace OpenSim.Region.Framework.Interfaces
{
@ -41,6 +42,9 @@ namespace OpenSim.Region.Framework.Interfaces
uint GetRegionFlags();
bool IsManager(UUID avatarID);
string SetEstateOwner(int estateID, UserAccount account);
string SetEstateName(int estateID, string newName);
/// <summary>
/// Tell all clients about the current state of the region (terrain textures, water height, etc.).
/// </summary>