Add --regex options to "sit user name" and "stand user name" console commands to sit/stand many avatars at once.

Currently, first name and last name are input separate but are concatenated with a space in the middle to form a regex.
So to sit all bots with the first name "ima", for instance, the command is "sit user name --regex ima .*"
0.7.6-extended
Justin Clark-Casey (justincc) 2013-08-20 18:13:40 +01:00
parent e384ff604e
commit 43940f6562
1 changed files with 88 additions and 57 deletions

View File

@ -30,18 +30,16 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using log4net; using log4net;
using Mono.Addins; using Mono.Addins;
using NDesk.Options;
using Nini.Config; using Nini.Config;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Framework.Monitoring;
using OpenSim.Region.ClientStack.LindenUDP;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Scenes.Animation;
using OpenSim.Services.Interfaces;
namespace OpenSim.Region.OptionalModules.Avatar.SitStand namespace OpenSim.Region.OptionalModules.Avatar.SitStand
{ {
@ -92,37 +90,35 @@ namespace OpenSim.Region.OptionalModules.Avatar.SitStand
scene.AddCommand( scene.AddCommand(
"Users", this, "sit user name", "Users", this, "sit user name",
"sit user name <first-name> <last-name>", "sit user name [--regex] <first-name> <last-name>",
"Sit the named user on an unoccupied object with a sit target.\n" "Sit the named user on an unoccupied object with a sit target.",
+ "If there are no such objects then nothing happens", "If there are no such objects then nothing happens.\n"
+ "If --regex is specified then the names are treated as regular expressions.",
HandleSitUserNameCommand); HandleSitUserNameCommand);
scene.AddCommand( scene.AddCommand(
"Users", this, "stand user name", "Users", this, "stand user name",
"stand user name <first-name> <last-name>", "stand user name [--regex] <first-name> <last-name>",
"Stand the named user.", "Stand the named user.",
"If --regex is specified then the names are treated as regular expressions.",
HandleStandUserNameCommand); HandleStandUserNameCommand);
} }
protected void HandleSitUserNameCommand(string module, string[] cmd) private void HandleSitUserNameCommand(string module, string[] cmd)
{ {
if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null) if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
return; return;
if (cmd.Length != 5) if (cmd.Length < 5)
{ {
MainConsole.Instance.Output("Usage: sit user name <first-name> <last-name>"); MainConsole.Instance.Output("Usage: sit user name [--regex] <first-name> <last-name>");
return; return;
} }
string firstName = cmd[3]; List<ScenePresence> scenePresences = GetScenePresences(cmd);
string lastName = cmd[4];
ScenePresence sp = m_scene.GetScenePresence(firstName, lastName);
if (sp == null || sp.IsChildAgent)
return;
foreach (ScenePresence sp in scenePresences)
{
SceneObjectPart sitPart = null; SceneObjectPart sitPart = null;
List<SceneObjectGroup> sceneObjects = m_scene.GetSceneObjectGroups(); List<SceneObjectGroup> sceneObjects = m_scene.GetSceneObjectGroups();
@ -150,31 +146,66 @@ namespace OpenSim.Region.OptionalModules.Avatar.SitStand
else else
{ {
MainConsole.Instance.OutputFormat( MainConsole.Instance.OutputFormat(
"Could not find any unoccupied set seat on which to sit {0} in {1}", "Could not find any unoccupied set seat on which to sit {0} in {1}. Aborting",
sp.Name, m_scene.Name); sp.Name, m_scene.Name);
break;
}
} }
} }
protected void HandleStandUserNameCommand(string module, string[] cmd) private void HandleStandUserNameCommand(string module, string[] cmd)
{ {
if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null) if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
return; return;
if (cmd.Length != 5) if (cmd.Length < 5)
{ {
MainConsole.Instance.Output("Usage: stand user name <first-name> <last-name>"); MainConsole.Instance.Output("Usage: stand user name [--regex] <first-name> <last-name>");
return; return;
} }
string firstName = cmd[3]; List<ScenePresence> scenePresences = GetScenePresences(cmd);
string lastName = cmd[4];
ScenePresence sp = m_scene.GetScenePresence(firstName, lastName);
if (sp == null || sp.IsChildAgent)
return;
foreach (ScenePresence sp in scenePresences)
{
MainConsole.Instance.OutputFormat("Standing {0} in {1}", sp.Name, m_scene.Name);
sp.StandUp(); sp.StandUp();
} }
} }
private List<ScenePresence> GetScenePresences(string[] cmdParams)
{
bool useRegex = false;
OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null );
List<string> mainParams = options.Parse(cmdParams);
string firstName = mainParams[3];
string lastName = mainParams[4];
List<ScenePresence> scenePresencesMatched = new List<ScenePresence>();
if (useRegex)
{
Regex nameRegex = new Regex(string.Format("{0} {1}", firstName, lastName));
List<ScenePresence> scenePresences = m_scene.GetScenePresences();
foreach (ScenePresence sp in scenePresences)
{
if (!sp.IsChildAgent && nameRegex.IsMatch(sp.Name))
scenePresencesMatched.Add(sp);
}
}
else
{
ScenePresence sp = m_scene.GetScenePresence(firstName, lastName);
if (sp != null && !sp.IsChildAgent)
scenePresencesMatched.Add(sp);
}
return scenePresencesMatched;
}
}
} }