aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/BotManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tools/pCampBot/BotManager.cs')
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs100
1 files changed, 85 insertions, 15 deletions
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index f5dd5e0..29cb1ba 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Linq;
30using System.Reflection; 31using System.Reflection;
31using System.Threading; 32using System.Threading;
32using OpenMetaverse; 33using OpenMetaverse;
@@ -48,9 +49,24 @@ namespace pCampBot
48 { 49 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 51
52 /// <summary>
53 /// Command console
54 /// </summary>
51 protected CommandConsole m_console; 55 protected CommandConsole m_console;
56
57 /// <summary>
58 /// Created bots, whether active or inactive.
59 /// </summary>
52 protected List<Bot> m_lBot; 60 protected List<Bot> m_lBot;
53 protected Random somthing = new Random(Environment.TickCount); 61
62 /// <summary>
63 /// Random number generator.
64 /// </summary>
65 public Random Rng { get; private set; }
66
67 /// <summary>
68 /// Overall configuration.
69 /// </summary>
54 public IConfig Config { get; private set; } 70 public IConfig Config { get; private set; }
55 71
56 /// <summary> 72 /// <summary>
@@ -59,11 +75,18 @@ namespace pCampBot
59 public Dictionary<UUID, bool> AssetsReceived { get; private set; } 75 public Dictionary<UUID, bool> AssetsReceived { get; private set; }
60 76
61 /// <summary> 77 /// <summary>
78 /// The regions that we know about.
79 /// </summary>
80 public Dictionary<ulong, GridRegion> RegionsKnown { get; private set; }
81
82 /// <summary>
62 /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data 83 /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
63 /// </summary> 84 /// </summary>
64 public BotManager() 85 public BotManager()
65 { 86 {
87 Rng = new Random(Environment.TickCount);
66 AssetsReceived = new Dictionary<UUID, bool>(); 88 AssetsReceived = new Dictionary<UUID, bool>();
89 RegionsKnown = new Dictionary<ulong, GridRegion>();
67 90
68 m_console = CreateConsole(); 91 m_console = CreateConsole();
69 MainConsole.Instance = m_console; 92 MainConsole.Instance = m_console;
@@ -93,8 +116,13 @@ namespace pCampBot
93 "Shutdown bots and exit", 116 "Shutdown bots and exit",
94 HandleShutdown); 117 HandleShutdown);
95 118
96 m_console.Commands.AddCommand("bot", false, "show status", 119 m_console.Commands.AddCommand("bot", false, "show regions",
97 "show status", 120 "show regions",
121 "Show regions known to bots",
122 HandleShowRegions);
123
124 m_console.Commands.AddCommand("bot", false, "show bots",
125 "show bots",
98 "Shows the status of all bots", 126 "Shows the status of all bots",
99 HandleShowStatus); 127 HandleShowStatus);
100 128
@@ -123,19 +151,26 @@ namespace pCampBot
123 Array.ForEach<string>( 151 Array.ForEach<string>(
124 cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); 152 cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
125 153
154 List<IBehaviour> behaviours = new List<IBehaviour>();
155
156 // Hard-coded for now
157 if (behaviourSwitches.Contains("p"))
158 behaviours.Add(new PhysicsBehaviour());
159
160 if (behaviourSwitches.Contains("g"))
161 behaviours.Add(new GrabbingBehaviour());
162
163 if (behaviourSwitches.Contains("t"))
164 behaviours.Add(new TeleportBehaviour());
165
166 MainConsole.Instance.OutputFormat(
167 "[BOT MANAGER]: Bots configured for behaviours {0}",
168 string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
169
126 for (int i = 0; i < botcount; i++) 170 for (int i = 0; i < botcount; i++)
127 { 171 {
128 string lastName = string.Format("{0}_{1}", lastNameStem, i); 172 string lastName = string.Format("{0}_{1}", lastNameStem, i);
129 173
130 List<IBehaviour> behaviours = new List<IBehaviour>();
131
132 // Hard-coded for now
133 if (behaviourSwitches.Contains("p"))
134 behaviours.Add(new PhysicsBehaviour());
135
136 if (behaviourSwitches.Contains("g"))
137 behaviours.Add(new GrabbingBehaviour());
138
139 StartBot(this, behaviours, firstName, lastName, password, loginUri); 174 StartBot(this, behaviours, firstName, lastName, password, loginUri);
140 } 175 }
141 } 176 }
@@ -240,17 +275,33 @@ namespace pCampBot
240 }); 275 });
241 } 276 }
242 277
278 private void HandleShowRegions(string module, string[] cmd)
279 {
280 string outputFormat = "{0,-30} {1, -20} {2, -5} {3, -5}";
281 MainConsole.Instance.OutputFormat(outputFormat, "Name", "Handle", "X", "Y");
282
283 lock (RegionsKnown)
284 {
285 foreach (GridRegion region in RegionsKnown.Values)
286 {
287 MainConsole.Instance.OutputFormat(
288 outputFormat, region.Name, region.RegionHandle, region.X, region.Y);
289 }
290 }
291 }
292
243 private void HandleShowStatus(string module, string[] cmd) 293 private void HandleShowStatus(string module, string[] cmd)
244 { 294 {
245 string outputFormat = "{0,-30} {1,-14}"; 295 string outputFormat = "{0,-30} {1, -30} {2,-14}";
246 MainConsole.Instance.OutputFormat(outputFormat, "Name", "Status"); 296 MainConsole.Instance.OutputFormat(outputFormat, "Name", "Region", "Status");
247 297
248 lock (m_lBot) 298 lock (m_lBot)
249 { 299 {
250 foreach (Bot pb in m_lBot) 300 foreach (Bot pb in m_lBot)
251 { 301 {
252 MainConsole.Instance.OutputFormat( 302 MainConsole.Instance.OutputFormat(
253 outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected")); 303 outputFormat,
304 pb.Name, pb.Client.Network.CurrentSim.Name, pb.IsConnected ? "Connected" : "Disconnected");
254 } 305 }
255 } 306 }
256 } 307 }
@@ -274,5 +325,24 @@ namespace pCampBot
274// if (newbots > 0) 325// if (newbots > 0)
275// addbots(newbots); 326// addbots(newbots);
276// } 327// }
328
329 internal void Grid_GridRegion(object o, GridRegionEventArgs args)
330 {
331 lock (RegionsKnown)
332 {
333 GridRegion newRegion = args.Region;
334
335 if (RegionsKnown.ContainsKey(newRegion.RegionHandle))
336 {
337 return;
338 }
339 else
340 {
341 m_log.DebugFormat(
342 "[BOT MANAGER]: Adding {0} {1} to known regions", newRegion.Name, newRegion.RegionHandle);
343 RegionsKnown[newRegion.RegionHandle] = newRegion;
344 }
345 }
346 }
277 } 347 }
278} 348}