aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Console/ConsoleUtil.cs29
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs101
2 files changed, 82 insertions, 48 deletions
diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs
index c0ff454..794bfaf 100644
--- a/OpenSim/Framework/Console/ConsoleUtil.cs
+++ b/OpenSim/Framework/Console/ConsoleUtil.cs
@@ -179,8 +179,8 @@ namespace OpenSim.Framework.Console
179 /// Convert a console integer to an int, automatically complaining if a console is given. 179 /// Convert a console integer to an int, automatically complaining if a console is given.
180 /// </summary> 180 /// </summary>
181 /// <param name='console'>Can be null if no console is available.</param> 181 /// <param name='console'>Can be null if no console is available.</param>
182 /// <param name='rawConsoleVector'>/param> 182 /// <param name='rawConsoleInt'>/param>
183 /// <param name='vector'></param> 183 /// <param name='i'></param>
184 /// <returns></returns> 184 /// <returns></returns>
185 public static bool TryParseConsoleInt(ICommandConsole console, string rawConsoleInt, out int i) 185 public static bool TryParseConsoleInt(ICommandConsole console, string rawConsoleInt, out int i)
186 { 186 {
@@ -194,6 +194,31 @@ namespace OpenSim.Framework.Console
194 194
195 return true; 195 return true;
196 } 196 }
197
198 /// <summary>
199 /// Convert a console integer to a natural int, automatically complaining if a console is given.
200 /// </summary>
201 /// <param name='console'>Can be null if no console is available.</param>
202 /// <param name='rawConsoleInt'>/param>
203 /// <param name='i'></param>
204 /// <returns></returns>
205 public static bool TryParseConsoleNaturalInt(ICommandConsole console, string rawConsoleInt, out int i)
206 {
207 if (TryParseConsoleInt(console, rawConsoleInt, out i))
208 {
209 if (i < 0)
210 {
211 if (console != null)
212 console.OutputFormat("ERROR: {0} is not a positive integer", rawConsoleInt);
213
214 return false;
215 }
216
217 return true;
218 }
219
220 return false;
221 }
197 222
198 /// <summary> 223 /// <summary>
199 /// Convert a minimum vector input from the console to an OpenMetaverse.Vector3 224 /// Convert a minimum vector input from the console to an OpenMetaverse.Vector3
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 5c0dc81..157c69c 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -80,7 +80,7 @@ namespace pCampBot
80 /// <summary> 80 /// <summary>
81 /// Created bots, whether active or inactive. 81 /// Created bots, whether active or inactive.
82 /// </summary> 82 /// </summary>
83 protected List<Bot> m_lBot; 83 protected List<Bot> m_bots;
84 84
85 /// <summary> 85 /// <summary>
86 /// Random number generator. 86 /// Random number generator.
@@ -130,35 +130,30 @@ namespace pCampBot
130 } 130 }
131 } 131 }
132 132
133 m_console.Commands.AddCommand("bot", false, "shutdown", 133 m_console.Commands.AddCommand(
134 "shutdown", 134 "bot", false, "shutdown", "shutdown", "Shutdown bots and exit", HandleShutdown);
135 "Shutdown bots and exit", HandleShutdown);
136 135
137 m_console.Commands.AddCommand("bot", false, "quit", 136 m_console.Commands.AddCommand(
138 "quit", 137 "bot", false, "quit", "quit", "Shutdown bots and exit", HandleShutdown);
139 "Shutdown bots and exit",
140 HandleShutdown);
141 138
142 m_console.Commands.AddCommand("bot", false, "disconnect", 139 m_console.Commands.AddCommand(
143 "disconnect", 140 "bot", false, "disconnect", "disconnect [<n>]", "Disconnect bots",
144 "Disconnect all bots", 141 "Disconnecting bots will interupt any bot connection process, including connection on startup.\n"
145 HandleDisconnect); 142 + "If an <n> is given, then the last <n> connected bots by postfix number are disconnected.\n"
143 + "If no <n> is given, then all currently connected bots are disconnected.",
144 HandleDisconnect);
146 145
147 m_console.Commands.AddCommand("bot", false, "show regions", 146 m_console.Commands.AddCommand(
148 "show regions", 147 "bot", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions);
149 "Show regions known to bots",
150 HandleShowRegions);
151 148
152 m_console.Commands.AddCommand("bot", false, "show bots", 149 m_console.Commands.AddCommand(
153 "show bots", 150 "bot", false, "show bots", "show bots", "Shows the status of all bots", HandleShowStatus);
154 "Shows the status of all bots",
155 HandleShowStatus);
156 151
157// m_console.Commands.AddCommand("bot", false, "add bots", 152// m_console.Commands.AddCommand("bot", false, "add bots",
158// "add bots <number>", 153// "add bots <number>",
159// "Add more bots", HandleAddBots); 154// "Add more bots", HandleAddBots);
160 155
161 m_lBot = new List<Bot>(); 156 m_bots = new List<Bot>();
162 } 157 }
163 158
164 /// <summary> 159 /// <summary>
@@ -196,7 +191,7 @@ namespace pCampBot
196 191
197 for (int i = 0; i < botcount; i++) 192 for (int i = 0; i < botcount; i++)
198 { 193 {
199 lock (m_lBot) 194 lock (m_bots)
200 { 195 {
201 if (DisconnectingBots) 196 if (DisconnectingBots)
202 break; 197 break;
@@ -316,7 +311,7 @@ namespace pCampBot
316 pb.OnConnected += handlebotEvent; 311 pb.OnConnected += handlebotEvent;
317 pb.OnDisconnected += handlebotEvent; 312 pb.OnDisconnected += handlebotEvent;
318 313
319 m_lBot.Add(pb); 314 m_bots.Add(pb);
320 315
321 Thread pbThread = new Thread(pb.startup); 316 Thread pbThread = new Thread(pb.startup);
322 pbThread.Name = pb.Name; 317 pbThread.Name = pb.Name;
@@ -349,21 +344,6 @@ namespace pCampBot
349 } 344 }
350 345
351 /// <summary> 346 /// <summary>
352 /// Shut down all bots
353 /// </summary>
354 /// <remarks>
355 /// We launch each shutdown on its own thread so that a slow shutting down bot doesn't hold up all the others.
356 /// </remarks>
357 private void ShutdownBots()
358 {
359 foreach (Bot bot in m_lBot)
360 {
361 Bot thisBot = bot;
362 Util.FireAndForget(o => thisBot.shutdown());
363 }
364 }
365
366 /// <summary>
367 /// Standard CreateConsole routine 347 /// Standard CreateConsole routine
368 /// </summary> 348 /// </summary>
369 /// <returns></returns> 349 /// <returns></returns>
@@ -374,21 +354,50 @@ namespace pCampBot
374 354
375 private void HandleDisconnect(string module, string[] cmd) 355 private void HandleDisconnect(string module, string[] cmd)
376 { 356 {
377 MainConsole.Instance.Output("Disconnecting bots"); 357 lock (m_bots)
378
379 lock (m_lBot)
380 { 358 {
359 int botsToDisconnect;
360 int connectedBots = m_bots.Count(b => b.ConnectionState == ConnectionState.Connected);
361
362 if (cmd.Length == 1)
363 {
364 botsToDisconnect = connectedBots;
365 }
366 else
367 {
368 if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[1], out botsToDisconnect))
369 return;
370
371 botsToDisconnect = Math.Min(botsToDisconnect, connectedBots);
372 }
373
381 DisconnectingBots = true; 374 DisconnectingBots = true;
382 375
383 ShutdownBots(); 376 MainConsole.Instance.OutputFormat("Disconnecting {0} bots", botsToDisconnect);
377
378 int disconnectedBots = 0;
379
380 for (int i = m_bots.Count - 1; i >= 0; i--)
381 {
382 if (disconnectedBots >= botsToDisconnect)
383 break;
384
385 Bot thisBot = m_bots[i];
386
387 if (thisBot.ConnectionState == ConnectionState.Connected)
388 {
389 Util.FireAndForget(o => thisBot.shutdown());
390 disconnectedBots++;
391 }
392 }
384 } 393 }
385 } 394 }
386 395
387 private void HandleShutdown(string module, string[] cmd) 396 private void HandleShutdown(string module, string[] cmd)
388 { 397 {
389 lock (m_lBot) 398 lock (m_bots)
390 { 399 {
391 int connectedBots = m_lBot.Count(b => b.ConnectionState == ConnectionState.Connected); 400 int connectedBots = m_bots.Count(b => b.ConnectionState == ConnectionState.Connected);
392 401
393 if (connectedBots > 0) 402 if (connectedBots > 0)
394 { 403 {
@@ -429,9 +438,9 @@ namespace pCampBot
429 foreach (object o in Enum.GetValues(typeof(ConnectionState))) 438 foreach (object o in Enum.GetValues(typeof(ConnectionState)))
430 totals[(ConnectionState)o] = 0; 439 totals[(ConnectionState)o] = 0;
431 440
432 lock (m_lBot) 441 lock (m_bots)
433 { 442 {
434 foreach (Bot pb in m_lBot) 443 foreach (Bot pb in m_bots)
435 { 444 {
436 Simulator currentSim = pb.Client.Network.CurrentSim; 445 Simulator currentSim = pb.Client.Network.CurrentSim;
437 totals[pb.ConnectionState]++; 446 totals[pb.ConnectionState]++;