Merge branch 'master' of git://opensimulator.org/git/opensim
commit
5485e3da46
|
@ -70,7 +70,7 @@ namespace OpenSim
|
|||
/// <param name="networkInfo"></param>
|
||||
/// <returns>A configuration that gets passed to modules</returns>
|
||||
public OpenSimConfigSource LoadConfigSettings(
|
||||
IConfigSource argvSource, out ConfigSettings configSettings,
|
||||
IConfigSource argvSource, EnvConfigSource envConfigSource, out ConfigSettings configSettings,
|
||||
out NetworkServersInfo networkInfo)
|
||||
{
|
||||
m_configSettings = configSettings = new ConfigSettings();
|
||||
|
@ -195,6 +195,24 @@ namespace OpenSim
|
|||
// Make sure command line options take precedence
|
||||
m_config.Source.Merge(argvSource);
|
||||
|
||||
|
||||
IConfig enVars = m_config.Source.Configs["Environment"];
|
||||
|
||||
if( enVars != null )
|
||||
{
|
||||
string[] env_keys = enVars.GetKeys();
|
||||
|
||||
foreach ( string key in env_keys )
|
||||
{
|
||||
envConfigSource.AddEnv(key, string.Empty);
|
||||
}
|
||||
|
||||
envConfigSource.LoadEnv();
|
||||
m_config.Source.Merge(envConfigSource);
|
||||
m_config.Source.ExpandKeyValues();
|
||||
}
|
||||
|
||||
|
||||
ReadConfigSettings();
|
||||
|
||||
return m_config;
|
||||
|
|
|
@ -108,6 +108,13 @@ namespace OpenSim
|
|||
get { return m_clientServers; }
|
||||
}
|
||||
|
||||
protected EnvConfigSource m_EnvConfigSource = new EnvConfigSource();
|
||||
|
||||
public EnvConfigSource envConfigSource
|
||||
{
|
||||
get { return m_EnvConfigSource; }
|
||||
}
|
||||
|
||||
protected List<IClientNetworkServer> m_clientServers = new List<IClientNetworkServer>();
|
||||
|
||||
public uint HttpServerPort
|
||||
|
@ -142,7 +149,7 @@ namespace OpenSim
|
|||
protected virtual void LoadConfigSettings(IConfigSource configSource)
|
||||
{
|
||||
m_configLoader = new ConfigurationLoader();
|
||||
m_config = m_configLoader.LoadConfigSettings(configSource, out m_configSettings, out m_networkServersInfo);
|
||||
m_config = m_configLoader.LoadConfigSettings(configSource, envConfigSource, out m_configSettings, out m_networkServersInfo);
|
||||
ReadExtraConfigSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -109,11 +109,13 @@ namespace OpenSim.Tests
|
|||
// Prepare call to ConfigurationLoader.LoadConfigSettings()
|
||||
ConfigurationLoader cl = new ConfigurationLoader();
|
||||
IConfigSource argvSource = new IniConfigSource();
|
||||
EnvConfigSource envConfigSource = new EnvConfigSource();
|
||||
argvSource.AddConfig("Startup").Set("inifile", mainIniFile);
|
||||
ConfigSettings configSettings;
|
||||
NetworkServersInfo networkInfo;
|
||||
|
||||
OpenSimConfigSource source = cl.LoadConfigSettings(argvSource, out configSettings, out networkInfo);
|
||||
OpenSimConfigSource source = cl.LoadConfigSettings(argvSource, envConfigSource,
|
||||
out configSettings, out networkInfo);
|
||||
|
||||
// Remove default config
|
||||
config = source.Source.Configs["Startup"];
|
||||
|
|
|
@ -41,6 +41,8 @@ namespace pCampBot
|
|||
/// </remarks>
|
||||
public class GrabbingBehaviour : IBehaviour
|
||||
{
|
||||
public string Name { get { return "Grabbing"; } }
|
||||
|
||||
public void Action(Bot bot)
|
||||
{
|
||||
Dictionary<UUID, Primitive> objects = bot.Objects;
|
||||
|
|
|
@ -42,6 +42,8 @@ namespace pCampBot
|
|||
/// </remarks>
|
||||
public class PhysicsBehaviour : IBehaviour
|
||||
{
|
||||
public string Name { get { return "Physics"; } }
|
||||
|
||||
private string[] talkarray;
|
||||
|
||||
public PhysicsBehaviour()
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using OpenMetaverse;
|
||||
using pCampBot.Interfaces;
|
||||
|
||||
namespace pCampBot
|
||||
{
|
||||
/// <summary>
|
||||
/// Teleport to a random region on the grid.
|
||||
/// </summary>
|
||||
public class TeleportBehaviour : IBehaviour
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public string Name { get { return "Teleport"; } }
|
||||
|
||||
public void Action(Bot bot)
|
||||
{
|
||||
Random rng = bot.Manager.Rng;
|
||||
GridRegion[] knownRegions;
|
||||
|
||||
lock (bot.Manager.RegionsKnown)
|
||||
{
|
||||
if (bot.Manager.RegionsKnown.Count == 0)
|
||||
{
|
||||
m_log.DebugFormat(
|
||||
"[TELEPORT BEHAVIOUR]: Ignoring teleport action for {0} since no regions are known yet", bot.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
knownRegions = bot.Manager.RegionsKnown.Values.ToArray();
|
||||
}
|
||||
|
||||
Simulator sourceRegion = bot.Client.Network.CurrentSim;
|
||||
GridRegion destRegion = knownRegions[rng.Next(knownRegions.Length)];
|
||||
Vector3 destPosition = new Vector3(rng.Next(255), rng.Next(255), 50);
|
||||
|
||||
m_log.DebugFormat(
|
||||
"[TELEPORT BEHAVIOUR]: Teleporting {0} from {1} {2} to {3} {4}",
|
||||
bot.Name, sourceRegion.Name, bot.Client.Self.SimPosition, destRegion.Name, destPosition);
|
||||
|
||||
bot.Client.Self.Teleport(destRegion.RegionHandle, destPosition);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,8 +49,15 @@ namespace pCampBot
|
|||
|
||||
public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events
|
||||
|
||||
public BotManager BotManager { get; private set; }
|
||||
private IConfig startupConfig; // bot config, passed from BotManager
|
||||
/// <summary>
|
||||
/// Bot manager.
|
||||
/// </summary>
|
||||
public BotManager Manager { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Bot config, passed from BotManager.
|
||||
/// </summary>
|
||||
private IConfig startupConfig;
|
||||
|
||||
/// <summary>
|
||||
/// Behaviours implemented by this bot.
|
||||
|
@ -132,7 +139,7 @@ namespace pCampBot
|
|||
Password = password;
|
||||
LoginUri = loginUri;
|
||||
|
||||
BotManager = bm;
|
||||
Manager = bm;
|
||||
startupConfig = bm.Config;
|
||||
readconfig();
|
||||
|
||||
|
@ -218,7 +225,19 @@ namespace pCampBot
|
|||
{
|
||||
MakeDefaultAppearance(wear);
|
||||
}
|
||||
|
||||
Client.Self.Jump(true);
|
||||
|
||||
// Extract nearby region information.
|
||||
Client.Grid.GridRegion += Manager.Grid_GridRegion;
|
||||
uint xUint, yUint;
|
||||
Utils.LongToUInts(Client.Network.CurrentSim.Handle, out xUint, out yUint);
|
||||
ushort minX, minY, maxX, maxY;
|
||||
minX = (ushort)Math.Min(0, xUint - 5);
|
||||
minY = (ushort)Math.Min(0, yUint - 5);
|
||||
maxX = (ushort)(xUint + 5);
|
||||
maxY = (ushort)(yUint + 5);
|
||||
Client.Grid.RequestMapBlocks(GridLayerType.Terrain, minX, minY, maxX, maxY, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -472,13 +491,13 @@ namespace pCampBot
|
|||
|
||||
private void GetTexture(UUID textureID)
|
||||
{
|
||||
lock (BotManager.AssetsReceived)
|
||||
lock (Manager.AssetsReceived)
|
||||
{
|
||||
// Don't request assets more than once.
|
||||
if (BotManager.AssetsReceived.ContainsKey(textureID))
|
||||
if (Manager.AssetsReceived.ContainsKey(textureID))
|
||||
return;
|
||||
|
||||
BotManager.AssetsReceived[textureID] = false;
|
||||
Manager.AssetsReceived[textureID] = false;
|
||||
Client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture);
|
||||
}
|
||||
}
|
||||
|
@ -490,8 +509,8 @@ namespace pCampBot
|
|||
|
||||
public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset)
|
||||
{
|
||||
lock (BotManager.AssetsReceived)
|
||||
BotManager.AssetsReceived[asset.AssetID] = true;
|
||||
lock (Manager.AssetsReceived)
|
||||
Manager.AssetsReceived[asset.AssetID] = true;
|
||||
|
||||
// if (wear == "save")
|
||||
// {
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using OpenMetaverse;
|
||||
|
@ -48,9 +49,24 @@ namespace pCampBot
|
|||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// Command console
|
||||
/// </summary>
|
||||
protected CommandConsole m_console;
|
||||
|
||||
/// <summary>
|
||||
/// Created bots, whether active or inactive.
|
||||
/// </summary>
|
||||
protected List<Bot> m_lBot;
|
||||
protected Random somthing = new Random(Environment.TickCount);
|
||||
|
||||
/// <summary>
|
||||
/// Random number generator.
|
||||
/// </summary>
|
||||
public Random Rng { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Overall configuration.
|
||||
/// </summary>
|
||||
public IConfig Config { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -58,12 +74,19 @@ namespace pCampBot
|
|||
/// </summary>
|
||||
public Dictionary<UUID, bool> AssetsReceived { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The regions that we know about.
|
||||
/// </summary>
|
||||
public Dictionary<ulong, GridRegion> RegionsKnown { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
|
||||
/// </summary>
|
||||
public BotManager()
|
||||
{
|
||||
Rng = new Random(Environment.TickCount);
|
||||
AssetsReceived = new Dictionary<UUID, bool>();
|
||||
RegionsKnown = new Dictionary<ulong, GridRegion>();
|
||||
|
||||
m_console = CreateConsole();
|
||||
MainConsole.Instance = m_console;
|
||||
|
@ -93,8 +116,13 @@ namespace pCampBot
|
|||
"Shutdown bots and exit",
|
||||
HandleShutdown);
|
||||
|
||||
m_console.Commands.AddCommand("bot", false, "show status",
|
||||
"show status",
|
||||
m_console.Commands.AddCommand("bot", false, "show regions",
|
||||
"show regions",
|
||||
"Show regions known to bots",
|
||||
HandleShowRegions);
|
||||
|
||||
m_console.Commands.AddCommand("bot", false, "show bots",
|
||||
"show bots",
|
||||
"Shows the status of all bots",
|
||||
HandleShowStatus);
|
||||
|
||||
|
@ -123,19 +151,26 @@ namespace pCampBot
|
|||
Array.ForEach<string>(
|
||||
cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
|
||||
|
||||
List<IBehaviour> behaviours = new List<IBehaviour>();
|
||||
|
||||
// Hard-coded for now
|
||||
if (behaviourSwitches.Contains("p"))
|
||||
behaviours.Add(new PhysicsBehaviour());
|
||||
|
||||
if (behaviourSwitches.Contains("g"))
|
||||
behaviours.Add(new GrabbingBehaviour());
|
||||
|
||||
if (behaviourSwitches.Contains("t"))
|
||||
behaviours.Add(new TeleportBehaviour());
|
||||
|
||||
MainConsole.Instance.OutputFormat(
|
||||
"[BOT MANAGER]: Bots configured for behaviours {0}",
|
||||
string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
|
||||
|
||||
for (int i = 0; i < botcount; i++)
|
||||
{
|
||||
string lastName = string.Format("{0}_{1}", lastNameStem, i);
|
||||
|
||||
List<IBehaviour> behaviours = new List<IBehaviour>();
|
||||
|
||||
// Hard-coded for now
|
||||
if (behaviourSwitches.Contains("p"))
|
||||
behaviours.Add(new PhysicsBehaviour());
|
||||
|
||||
if (behaviourSwitches.Contains("g"))
|
||||
behaviours.Add(new GrabbingBehaviour());
|
||||
|
||||
StartBot(this, behaviours, firstName, lastName, password, loginUri);
|
||||
}
|
||||
}
|
||||
|
@ -240,17 +275,33 @@ namespace pCampBot
|
|||
});
|
||||
}
|
||||
|
||||
private void HandleShowRegions(string module, string[] cmd)
|
||||
{
|
||||
string outputFormat = "{0,-30} {1, -20} {2, -5} {3, -5}";
|
||||
MainConsole.Instance.OutputFormat(outputFormat, "Name", "Handle", "X", "Y");
|
||||
|
||||
lock (RegionsKnown)
|
||||
{
|
||||
foreach (GridRegion region in RegionsKnown.Values)
|
||||
{
|
||||
MainConsole.Instance.OutputFormat(
|
||||
outputFormat, region.Name, region.RegionHandle, region.X, region.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleShowStatus(string module, string[] cmd)
|
||||
{
|
||||
string outputFormat = "{0,-30} {1,-14}";
|
||||
MainConsole.Instance.OutputFormat(outputFormat, "Name", "Status");
|
||||
string outputFormat = "{0,-30} {1, -30} {2,-14}";
|
||||
MainConsole.Instance.OutputFormat(outputFormat, "Name", "Region", "Status");
|
||||
|
||||
lock (m_lBot)
|
||||
{
|
||||
foreach (Bot pb in m_lBot)
|
||||
{
|
||||
MainConsole.Instance.OutputFormat(
|
||||
outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected"));
|
||||
outputFormat,
|
||||
pb.Name, pb.Client.Network.CurrentSim.Name, pb.IsConnected ? "Connected" : "Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,5 +325,24 @@ namespace pCampBot
|
|||
// if (newbots > 0)
|
||||
// addbots(newbots);
|
||||
// }
|
||||
|
||||
internal void Grid_GridRegion(object o, GridRegionEventArgs args)
|
||||
{
|
||||
lock (RegionsKnown)
|
||||
{
|
||||
GridRegion newRegion = args.Region;
|
||||
|
||||
if (RegionsKnown.ContainsKey(newRegion.RegionHandle))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.DebugFormat(
|
||||
"[BOT MANAGER]: Adding {0} {1} to known regions", newRegion.Name, newRegion.RegionHandle);
|
||||
RegionsKnown[newRegion.RegionHandle] = newRegion;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,15 @@ namespace pCampBot.Interfaces
|
|||
{
|
||||
public interface IBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of this behaviour.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Action to take when this behaviour is invoked.
|
||||
/// </summary>
|
||||
/// <param name="bot"></param>
|
||||
void Action(Bot bot);
|
||||
}
|
||||
}
|
|
@ -111,7 +111,7 @@ namespace pCampBot
|
|||
" -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" +
|
||||
" -password password for the bots\n" +
|
||||
" -b, behaviours behaviours for bots. Current options p (physics), g (grab). Comma separated, e.g. p,g. Default is p",
|
||||
" -b, behaviours behaviours for bots. Current options p (physics), g (grab), t (teleport). Comma separated, e.g. p,g. Default is p",
|
||||
" -wear set appearance folder to load from (default: no)\n" +
|
||||
" -h, -help show this message"
|
||||
);
|
||||
|
|
BIN
bin/Nini.dll
BIN
bin/Nini.dll
Binary file not shown.
Loading…
Reference in New Issue