Merge branch 'master' into careminster

avinationmerge
Melanie 2013-08-14 21:25:22 +01:00
commit df7a1e68f6
7 changed files with 192 additions and 70 deletions

View File

@ -3540,6 +3540,18 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
/// <summary>
/// Remove the given client from the scene.
/// </summary>
/// <remarks>
/// Only clientstack code should call this directly. All other code should call IncomingCloseAgent() instead
/// to properly operate the state machine and avoid race conditions with other close requests (such as directly
/// from viewers).
/// </remarks>
/// <param name='agentID'>ID of agent to close</param>
/// <param name='closeChildAgents'>
/// Close the neighbour child agents associated with this client.
/// </param>
public override void RemoveClient(UUID agentID, bool closeChildAgents) public override void RemoveClient(UUID agentID, bool closeChildAgents)
{ {
AgentCircuitData acd = m_authenticateHandler.GetAgentCircuitData(agentID); AgentCircuitData acd = m_authenticateHandler.GetAgentCircuitData(agentID);

View File

@ -218,6 +218,19 @@ namespace OpenSim.Region.Framework.Scenes
#region Add/Remove Agent/Avatar #region Add/Remove Agent/Avatar
public abstract ISceneAgent AddNewClient(IClientAPI client, PresenceType type); public abstract ISceneAgent AddNewClient(IClientAPI client, PresenceType type);
/// <summary>
/// Remove the given client from the scene.
/// </summary>
/// <remarks>
/// Only clientstack code should call this directly. All other code should call IncomingCloseAgent() instead
/// to properly operate the state machine and avoid race conditions with other close requests (such as directly
/// from viewers).
/// </remarks>
/// <param name='agentID'>ID of agent to close</param>
/// <param name='closeChildAgents'>
/// Close the neighbour child agents associated with this client.
/// </param>
public abstract void RemoveClient(UUID agentID, bool closeChildAgents); public abstract void RemoveClient(UUID agentID, bool closeChildAgents);
public bool TryGetScenePresence(UUID agentID, out object scenePresence) public bool TryGetScenePresence(UUID agentID, out object scenePresence)

View File

@ -89,13 +89,6 @@ public sealed class BSCharacter : BSPhysObject
// set _avatarVolume and _mass based on capsule size, _density and Scale // set _avatarVolume and _mass based on capsule size, _density and Scale
ComputeAvatarVolumeAndMass(); ComputeAvatarVolumeAndMass();
// The avatar's movement is controlled by this motor that speeds up and slows down
// the avatar seeking to reach the motor's target speed.
// This motor runs as a prestep action for the avatar so it will keep the avatar
// standing as well as moving. Destruction of the avatar will destroy the pre-step action.
m_moveActor = new BSActorAvatarMove(PhysScene, this, AvatarMoveActorName);
PhysicalActors.Add(AvatarMoveActorName, m_moveActor);
DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5},pos={6}", DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5},pos={6}",
LocalID, _size, Scale, Density, _avatarVolume, RawMass, pos); LocalID, _size, Scale, Density, _avatarVolume, RawMass, pos);
@ -106,6 +99,13 @@ public sealed class BSCharacter : BSPhysObject
// New body and shape into PhysBody and PhysShape // New body and shape into PhysBody and PhysShape
PhysScene.Shapes.GetBodyAndShape(true, PhysScene.World, this); PhysScene.Shapes.GetBodyAndShape(true, PhysScene.World, this);
// The avatar's movement is controlled by this motor that speeds up and slows down
// the avatar seeking to reach the motor's target speed.
// This motor runs as a prestep action for the avatar so it will keep the avatar
// standing as well as moving. Destruction of the avatar will destroy the pre-step action.
m_moveActor = new BSActorAvatarMove(PhysScene, this, AvatarMoveActorName);
PhysicalActors.Add(AvatarMoveActorName, m_moveActor);
SetPhysicalProperties(); SetPhysicalProperties();
}); });
return; return;

View File

@ -63,11 +63,6 @@ namespace pCampBot
/// </summary> /// </summary>
public BotManager Manager { get; private set; } public BotManager Manager { get; private set; }
/// <summary>
/// Bot config, passed from BotManager.
/// </summary>
private IConfig startupConfig;
/// <summary> /// <summary>
/// Behaviours implemented by this bot. /// Behaviours implemented by this bot.
/// </summary> /// </summary>
@ -102,6 +97,8 @@ namespace pCampBot
public string Name { get; private set; } public string Name { get; private set; }
public string Password { get; private set; } public string Password { get; private set; }
public string LoginUri { get; private set; } public string LoginUri { get; private set; }
public string StartLocation { get; private set; }
public string saveDir; public string saveDir;
public string wear; public string wear;
@ -137,7 +134,7 @@ namespace pCampBot
/// <param name="behaviours"></param> /// <param name="behaviours"></param>
public Bot( public Bot(
BotManager bm, List<IBehaviour> behaviours, BotManager bm, List<IBehaviour> behaviours,
string firstName, string lastName, string password, string loginUri) string firstName, string lastName, string password, string startLocation, string loginUri)
{ {
ConnectionState = ConnectionState.Disconnected; ConnectionState = ConnectionState.Disconnected;
@ -151,11 +148,9 @@ namespace pCampBot
Name = string.Format("{0} {1}", FirstName, LastName); Name = string.Format("{0} {1}", FirstName, LastName);
Password = password; Password = password;
LoginUri = loginUri; LoginUri = loginUri;
StartLocation = startLocation;
Manager = bm; Manager = bm;
startupConfig = bm.Config;
readconfig();
Behaviours = behaviours; Behaviours = behaviours;
} }
@ -163,7 +158,7 @@ namespace pCampBot
//add additional steps and/or things the bot should do //add additional steps and/or things the bot should do
private void Action() private void Action()
{ {
while (true) while (ConnectionState != ConnectionState.Disconnecting)
lock (Behaviours) lock (Behaviours)
Behaviours.ForEach( Behaviours.ForEach(
b => b =>
@ -176,14 +171,6 @@ namespace pCampBot
); );
} }
/// <summary>
/// Read the Nini config and initialize
/// </summary>
public void readconfig()
{
wear = startupConfig.GetString("wear", "no");
}
/// <summary> /// <summary>
/// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes.
/// </summary> /// </summary>
@ -191,8 +178,8 @@ namespace pCampBot
{ {
ConnectionState = ConnectionState.Disconnecting; ConnectionState = ConnectionState.Disconnecting;
if (m_actionThread != null) // if (m_actionThread != null)
m_actionThread.Abort(); // m_actionThread.Abort();
Client.Network.Logout(); Client.Network.Logout();
} }
@ -207,6 +194,7 @@ namespace pCampBot
Client.Settings.AVATAR_TRACKING = false; Client.Settings.AVATAR_TRACKING = false;
Client.Settings.OBJECT_TRACKING = false; Client.Settings.OBJECT_TRACKING = false;
Client.Settings.SEND_AGENT_THROTTLE = true; Client.Settings.SEND_AGENT_THROTTLE = true;
Client.Settings.SEND_AGENT_UPDATES = false;
Client.Settings.SEND_PINGS = true; Client.Settings.SEND_PINGS = true;
Client.Settings.STORE_LAND_PATCHES = false; Client.Settings.STORE_LAND_PATCHES = false;
Client.Settings.USE_ASSET_CACHE = false; Client.Settings.USE_ASSET_CACHE = false;
@ -224,7 +212,7 @@ namespace pCampBot
ConnectionState = ConnectionState.Connecting; ConnectionState = ConnectionState.Connecting;
if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", StartLocation, "Your name"))
{ {
ConnectionState = ConnectionState.Connected; ConnectionState = ConnectionState.Connected;
@ -481,9 +469,6 @@ namespace pCampBot
public void Objects_NewPrim(object sender, PrimEventArgs args) public void Objects_NewPrim(object sender, PrimEventArgs args)
{ {
// if (Name.EndsWith("4"))
// throw new Exception("Aaargh");
Primitive prim = args.Prim; Primitive prim = args.Prim;
if (prim != null) if (prim != null)

View File

@ -51,6 +51,11 @@ namespace pCampBot
public const int DefaultLoginDelay = 5000; public const int DefaultLoginDelay = 5000;
/// <summary>
/// True if pCampbot is in the process of shutting down.
/// </summary>
public bool ShuttingDown { get; private set; }
/// <summary> /// <summary>
/// Delay between logins of multiple bots. /// Delay between logins of multiple bots.
/// </summary> /// </summary>
@ -62,6 +67,16 @@ namespace pCampBot
/// </summary> /// </summary>
protected CommandConsole m_console; protected CommandConsole m_console;
/// <summary>
/// Controls whether bots start out sending agent updates on connection.
/// </summary>
public bool InitBotSendAgentUpdates { get; set; }
/// <summary>
/// Controls whether bots request textures for the object information they receive
/// </summary>
public bool InitBotRequestObjectTextures { get; set; }
/// <summary> /// <summary>
/// Created bots, whether active or inactive. /// Created bots, whether active or inactive.
/// </summary> /// </summary>
@ -72,11 +87,6 @@ namespace pCampBot
/// </summary> /// </summary>
public Random Rng { get; private set; } public Random Rng { get; private set; }
/// <summary>
/// Overall configuration.
/// </summary>
public IConfig Config { get; private set; }
/// <summary> /// <summary>
/// Track the assets we have and have not received so we don't endlessly repeat requests. /// Track the assets we have and have not received so we don't endlessly repeat requests.
/// </summary> /// </summary>
@ -92,6 +102,9 @@ namespace pCampBot
/// </summary> /// </summary>
public BotManager() public BotManager()
{ {
InitBotSendAgentUpdates = true;
InitBotRequestObjectTextures = true;
LoginDelay = DefaultLoginDelay; LoginDelay = DefaultLoginDelay;
Rng = new Random(Environment.TickCount); Rng = new Random(Environment.TickCount);
@ -148,31 +161,40 @@ namespace pCampBot
/// </summary> /// </summary>
/// <param name="botcount">How many bots to start up</param> /// <param name="botcount">How many bots to start up</param>
/// <param name="cs">The configuration for the bots to use</param> /// <param name="cs">The configuration for the bots to use</param>
public void dobotStartup(int botcount, IConfig cs) public void dobotStartup(int botcount, IConfig startupConfig)
{ {
Config = cs; string firstName = startupConfig.GetString("firstname");
string lastNameStem = startupConfig.GetString("lastname");
string password = startupConfig.GetString("password");
string loginUri = startupConfig.GetString("loginuri");
string startLocation = startupConfig.GetString("start", "last");
int fromBotNumber = startupConfig.GetInt("from", 0);
string wearSetting = startupConfig.GetString("wear", "no");
string firstName = cs.GetString("firstname"); string startUri = ParseInputStartLocationToUri(startLocation);
string lastNameStem = cs.GetString("lastname");
string password = cs.GetString("password");
string loginUri = cs.GetString("loginuri");
HashSet<string> behaviourSwitches = new HashSet<string>(); HashSet<string> behaviourSwitches = new HashSet<string>();
Array.ForEach<string>( Array.ForEach<string>(
cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); startupConfig.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
MainConsole.Instance.OutputFormat( MainConsole.Instance.OutputFormat(
"[BOT MANAGER]: Starting {0} bots connecting to {1}, named {2} {3}_<n>", "[BOT MANAGER]: Starting {0} bots connecting to {1}, location {2}, named {3} {4}_<n>",
botcount, botcount,
loginUri, loginUri,
startUri,
firstName, firstName,
lastNameStem); lastNameStem);
MainConsole.Instance.OutputFormat("[BOT MANAGER]: Delay between logins is {0}ms", LoginDelay); MainConsole.Instance.OutputFormat("[BOT MANAGER]: Delay between logins is {0}ms", LoginDelay);
MainConsole.Instance.OutputFormat("[BOT MANAGER]: BotsSendAgentUpdates is {0}", InitBotSendAgentUpdates);
MainConsole.Instance.OutputFormat("[BOT MANAGER]: InitBotRequestObjectTextures is {0}", InitBotRequestObjectTextures);
for (int i = 0; i < botcount; i++) for (int i = 0; i < botcount; i++)
{ {
string lastName = string.Format("{0}_{1}", lastNameStem, i); if (ShuttingDown)
break;
string lastName = string.Format("{0}_{1}", lastNameStem, i + fromBotNumber);
// We must give each bot its own list of instantiated behaviours since they store state. // We must give each bot its own list of instantiated behaviours since they store state.
List<IBehaviour> behaviours = new List<IBehaviour>(); List<IBehaviour> behaviours = new List<IBehaviour>();
@ -193,10 +215,49 @@ namespace pCampBot
if (behaviourSwitches.Contains("t")) if (behaviourSwitches.Contains("t"))
behaviours.Add(new TeleportBehaviour()); behaviours.Add(new TeleportBehaviour());
StartBot(this, behaviours, firstName, lastName, password, loginUri); StartBot(this, behaviours, firstName, lastName, password, loginUri, startUri, wearSetting);
} }
} }
/// <summary>
/// Parses the command line start location to a start string/uri that the login mechanism will recognize.
/// </summary>
/// <returns>
/// The input start location to URI.
/// </returns>
/// <param name='startLocation'>
/// Start location.
/// </param>
private string ParseInputStartLocationToUri(string startLocation)
{
if (startLocation == "home" || startLocation == "last")
return startLocation;
string regionName;
// Just a region name or only one (!) extra component. Like a viewer, we will stick 128/128/0 on the end
Vector3 startPos = new Vector3(128, 128, 0);
string[] startLocationComponents = startLocation.Split('/');
regionName = startLocationComponents[0];
if (startLocationComponents.Length >= 2)
{
float.TryParse(startLocationComponents[1], out startPos.X);
if (startLocationComponents.Length >= 3)
{
float.TryParse(startLocationComponents[2], out startPos.Y);
if (startLocationComponents.Length >= 4)
float.TryParse(startLocationComponents[3], out startPos.Z);
}
}
return string.Format("uri:{0}&{1}&{2}&{3}", regionName, startPos.X, startPos.Y, startPos.Z);
}
// /// <summary> // /// <summary>
// /// Add additional bots (and threads) to our bot pool // /// Add additional bots (and threads) to our bot pool
// /// </summary> // /// </summary>
@ -226,15 +287,19 @@ namespace pCampBot
/// <param name="lastName">Last name</param> /// <param name="lastName">Last name</param>
/// <param name="password">Password</param> /// <param name="password">Password</param>
/// <param name="loginUri">Login URI</param> /// <param name="loginUri">Login URI</param>
/// <param name="startLocation">Location to start the bot. Can be "last", "home" or a specific sim name.</param>
/// <param name="wearSetting"></param>
public void StartBot( public void StartBot(
BotManager bm, List<IBehaviour> behaviours, BotManager bm, List<IBehaviour> behaviours,
string firstName, string lastName, string password, string loginUri) string firstName, string lastName, string password, string loginUri, string startLocation, string wearSetting)
{ {
MainConsole.Instance.OutputFormat( MainConsole.Instance.OutputFormat(
"[BOT MANAGER]: Starting bot {0} {1}, behaviours are {2}", "[BOT MANAGER]: Starting bot {0} {1}, behaviours are {2}",
firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray())); firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
Bot pb = new Bot(bm, behaviours, firstName, lastName, password, loginUri); Bot pb = new Bot(bm, behaviours, firstName, lastName, password, startLocation, loginUri);
pb.wear = wearSetting;
pb.Client.Settings.SEND_AGENT_UPDATES = InitBotSendAgentUpdates;
pb.OnConnected += handlebotEvent; pb.OnConnected += handlebotEvent;
pb.OnDisconnected += handlebotEvent; pb.OnDisconnected += handlebotEvent;
@ -306,7 +371,9 @@ namespace pCampBot
private void HandleShutdown(string module, string[] cmd) private void HandleShutdown(string module, string[] cmd)
{ {
m_log.Info("[BOTMANAGER]: Shutting down bots"); MainConsole.Instance.Output("Shutting down");
ShuttingDown = true;
doBotShutdown(); doBotShutdown();
} }

View File

@ -26,6 +26,7 @@
*/ */
using System; using System;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using log4net; using log4net;
@ -50,28 +51,52 @@ namespace pCampBot
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public const string ConfigFileName = "pCampbot.ini";
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
XmlConfigurator.Configure(); XmlConfigurator.Configure();
IConfig config = ParseConfig(args); IConfig commandLineConfig = ParseConfig(args);
if (config.Get("help") != null || config.Get("loginuri") == null) if (commandLineConfig.Get("help") != null || commandLineConfig.Get("loginuri") == null)
{ {
Help(); Help();
} }
else if (config.Get("firstname") == null || config.Get("lastname") == null || config.Get("password") == null) else if (
commandLineConfig.Get("firstname") == null
|| commandLineConfig.Get("lastname") == null
|| commandLineConfig.Get("password") == null)
{ {
Console.WriteLine("ERROR: You must supply a firstname, lastname and password for the bots."); Console.WriteLine("ERROR: You must supply a firstname, lastname and password for the bots.");
} }
else else
{ {
int botcount = config.GetInt("botcount", 1);
BotManager bm = new BotManager(); BotManager bm = new BotManager();
string iniFilePath = Path.GetFullPath(Path.Combine(Util.configDir(), ConfigFileName));
if (File.Exists(iniFilePath))
{
m_log.InfoFormat("[PCAMPBOT]: Reading configuration settings from {0}", iniFilePath);
IConfigSource configSource = new IniConfigSource(iniFilePath);
IConfig botConfig = configSource.Configs["Bot"];
if (botConfig != null)
{
bm.InitBotSendAgentUpdates
= botConfig.GetBoolean("SendAgentUpdates", bm.InitBotSendAgentUpdates);
bm.InitBotRequestObjectTextures
= botConfig.GetBoolean("RequestObjectTextures", bm.InitBotRequestObjectTextures);
}
}
int botcount = commandLineConfig.GetInt("botcount", 1);
//startup specified number of bots. 1 is the default //startup specified number of bots. 1 is the default
Thread startBotThread = new Thread(o => bm.dobotStartup(botcount, config)); Thread startBotThread = new Thread(o => bm.dobotStartup(botcount, commandLineConfig));
startBotThread.Name = "Initial start bots thread"; startBotThread.Name = "Initial start bots thread";
startBotThread.Start(); startBotThread.Start();
@ -95,7 +120,9 @@ namespace pCampBot
ArgvConfigSource cs = new ArgvConfigSource(args); ArgvConfigSource cs = new ArgvConfigSource(args);
cs.AddSwitch("Startup", "botcount", "n"); cs.AddSwitch("Startup", "botcount", "n");
cs.AddSwitch("Startup", "from", "f");
cs.AddSwitch("Startup", "loginuri", "l"); cs.AddSwitch("Startup", "loginuri", "l");
cs.AddSwitch("Startup", "start", "s");
cs.AddSwitch("Startup", "firstname"); cs.AddSwitch("Startup", "firstname");
cs.AddSwitch("Startup", "lastname"); cs.AddSwitch("Startup", "lastname");
cs.AddSwitch("Startup", "password"); cs.AddSwitch("Startup", "password");
@ -113,23 +140,26 @@ namespace pCampBot
// You can either say no, to not load anything, yes, to load one of the default wearables, a folder // You can either say no, to not load anything, yes, to load one of the default wearables, a folder
// name, to load an specific folder, or save, to save an avatar with some already existing wearables // name, to load an specific folder, or save, to save an avatar with some already existing wearables
// worn to the folder MyAppearance/FirstName_LastName, and the load it. // worn to the folder MyAppearance/FirstName_LastName, and the load it.
Console.WriteLine( Console.WriteLine(
"usage: pCampBot <-loginuri loginuri> [OPTIONS]\n" + "usage: pCampBot <-loginuri loginuri> [OPTIONS]\n"
"Spawns a set of bots to test an OpenSim region\n\n" + + "Spawns a set of bots to test an OpenSim region\n\n"
" -l, -loginuri loginuri for sim to log into (required)\n" + + " -l, -loginuri loginuri for grid/standalone (required)\n"
" -n, -botcount number of bots to start (default: 1)\n" + + " -s, -start optional start location for bots. Can be \"last\", \"home\" or a specific location with or without co-ords (e.g. \"region1\" or \"region2/50/30/90\"\n"
" -firstname first name for the bots\n" + + " -firstname first name for the bots\n"
" -lastname lastname for the bots. Each lastname will have _<bot-number> appended, e.g. Ima Bot_0\n" + + " -lastname lastname for the bots. Each lastname will have _<bot-number> appended, e.g. Ima Bot_0\n"
" -password password for the bots\n" + + " -password password for the bots\n"
" -b, behaviours behaviours for bots. Comma separated, e.g. p,g. Default is p\n" + + " -n, -botcount optional number of bots to start (default: 1)\n"
" current options are:\n" + + " -f, -from optional starting number for login bot names, e.g. 25 will login Ima Bot_25, Ima Bot_26, etc. (default: 0)"
" p (physics - bots constantly move and jump around)\n" + + " -b, behaviours behaviours for bots. Comma separated, e.g. p,g. Default is p\n"
" g (grab - bots randomly click prims whether set clickable or not)\n" + + " current options are:\n"
" n (none - bots do nothing)\n" + + " p (physics - bots constantly move and jump around)\n"
" t (teleport - bots regularly teleport between regions on the grid)\n" + + " g (grab - bots randomly click prims whether set clickable or not)\n"
+ " n (none - bots do nothing)\n"
+ " t (teleport - bots regularly teleport between regions on the grid)\n"
// " c (cross)" + // " c (cross)" +
" -wear set appearance folder to load from (default: no)\n" + + " -wear optional folder from which to load appearance data, \"no\" if there is no such folder (default: no)\n"
" -h, -help show this message"); + " -h, -help show this message.\n");
} }
} }
} }

15
bin/pCampbot.ini.example Normal file
View File

@ -0,0 +1,15 @@
; This is the example config file for pCampbot
; To use it, copy this file to pCampbot.ini and change settings if required
[Bot]
; Control whether bots should regularly send agent updates
; Not doing this will reduce CPU requirements for pCampbot but greatly
; reduce the realism compared to viewers which are constantly sending AgentUpdates UDP packets.
; Defaults to true.
SendAgentUpdates = true
; Control whether bots will requests textures when receiving object information
; Not doing this will reduce CPU requirements for pCampbot but greatly
; reduce the realism compared to viewers which requests such texture data if not already cached.
; Defaults to true.
RequestObjectTextures = true