From c73b02d5832ea5dd4fc238dfaf610e4103bab205 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Mon, 22 Sep 2014 23:13:19 +0100
Subject: Replace two connecting bots state booleans in pCampbot with a single
state machine.
Also adds "show status" command to pCampbot that currently just shows bot connecting state
---
OpenSim/Tools/pCampBot/BotManager.cs | 78 +++++++++++++++++++++++++-----------
1 file changed, 55 insertions(+), 23 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 29739dc..c7d8f05 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -43,6 +43,14 @@ using pCampBot.Interfaces;
namespace pCampBot
{
+ public enum BotManagerBotConnectingState
+ {
+ Initializing,
+ Ready,
+ Connecting,
+ Disconnecting
+ }
+
///
/// Thread/Bot manager for the application
///
@@ -53,14 +61,14 @@ namespace pCampBot
public const int DefaultLoginDelay = 5000;
///
- /// Is pCampbot in the process of connecting bots?
+ /// Is pCampbot ready to connect or currently in the process of connecting or disconnecting bots?
///
- public bool ConnectingBots { get; private set; }
+ public BotManagerBotConnectingState BotConnectingState { get; private set; }
///
- /// Is pCampbot in the process of disconnecting bots?
+ /// Used to control locking as we can't lock an enum.
///
- public bool DisconnectingBots { get; private set; }
+ private object BotConnectingStateChangeObject = new object();
///
/// Delay between logins of multiple bots.
@@ -239,12 +247,15 @@ namespace pCampBot
"Bots", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions);
m_console.Commands.AddCommand(
- "Bots", false, "show bots", "show bots", "Shows the status of all bots", HandleShowBotsStatus);
+ "Bots", false, "show bots", "show bots", "Shows the status of all bots.", HandleShowBotsStatus);
m_console.Commands.AddCommand(
"Bots", false, "show bot", "show bot ",
"Shows the detailed status and settings of a particular bot.", HandleShowBotStatus);
+ m_console.Commands.AddCommand(
+ "Bots", false, "show status", "show status", "Shows pCampbot status.", HandleShowStatus);
+
m_bots = new List();
Watchdog.Enabled = true;
@@ -254,6 +265,8 @@ namespace pCampBot
m_serverStatsCollector.Initialise(null);
m_serverStatsCollector.Enabled = true;
m_serverStatsCollector.Start();
+
+ BotConnectingState = BotManagerBotConnectingState.Ready;
}
///
@@ -335,7 +348,17 @@ namespace pCampBot
public void ConnectBots(int botcount)
{
- ConnectingBots = true;
+ lock (BotConnectingStateChangeObject)
+ {
+ if (BotConnectingState != BotManagerBotConnectingState.Ready)
+ {
+ MainConsole.Instance.OutputFormat(
+ "Bot connecting status is {0}. Please wait for previous process to complete.", BotConnectingState);
+ return;
+ }
+
+ BotConnectingState = BotManagerBotConnectingState.Connecting;
+ }
Thread connectBotThread = new Thread(o => ConnectBotsInternal(botcount));
@@ -373,11 +396,14 @@ namespace pCampBot
foreach (Bot bot in botsToConnect)
{
- if (!ConnectingBots)
+ lock (BotConnectingStateChangeObject)
{
- MainConsole.Instance.Output(
- "[BOT MANAGER]: Aborting bot connection due to user-initiated disconnection");
- break;
+ if (BotConnectingState != BotManagerBotConnectingState.Connecting)
+ {
+ MainConsole.Instance.Output(
+ "[BOT MANAGER]: Aborting bot connection due to user-initiated disconnection");
+ return;
+ }
}
bot.Connect();
@@ -386,7 +412,11 @@ namespace pCampBot
Thread.Sleep(LoginDelay);
}
- ConnectingBots = false;
+ lock (BotConnectingStateChangeObject)
+ {
+ if (BotConnectingState == BotManagerBotConnectingState.Connecting)
+ BotConnectingState = BotManagerBotConnectingState.Ready;
+ }
}
///
@@ -491,13 +521,7 @@ namespace pCampBot
}
private void HandleConnect(string module, string[] cmd)
- {
- if (ConnectingBots)
- {
- MainConsole.Instance.Output("Still connecting bots. Please wait for previous process to complete.");
- return;
- }
-
+ {
lock (m_bots)
{
int botsToConnect;
@@ -653,7 +677,8 @@ namespace pCampBot
botsToDisconnectCount = Math.Min(botsToDisconnectCount, connectedBots.Count);
}
- DisconnectingBots = true;
+ lock (BotConnectingStateChangeObject)
+ BotConnectingState = BotManagerBotConnectingState.Disconnecting;
Thread disconnectBotThread = new Thread(o => DisconnectBotsInternal(connectedBots, botsToDisconnectCount));
@@ -662,9 +687,7 @@ namespace pCampBot
}
private void DisconnectBotsInternal(List connectedBots, int disconnectCount)
- {
- ConnectingBots = false;
-
+ {
MainConsole.Instance.OutputFormat("Disconnecting {0} bots", disconnectCount);
int disconnectedBots = 0;
@@ -683,7 +706,8 @@ namespace pCampBot
}
}
- DisconnectingBots = false;
+ lock (BotConnectingStateChangeObject)
+ BotConnectingState = BotManagerBotConnectingState.Ready;
}
private void HandleSit(string module, string[] cmd)
@@ -775,6 +799,14 @@ namespace pCampBot
}
}
+ private void HandleShowStatus(string module, string[] cmd)
+ {
+ ConsoleDisplayList cdl = new ConsoleDisplayList();
+ cdl.AddRow("Bot connecting state", BotConnectingState);
+
+ MainConsole.Instance.Output(cdl.ToString());
+ }
+
private void HandleShowBotsStatus(string module, string[] cmd)
{
ConsoleDisplayTable cdt = new ConsoleDisplayTable();
--
cgit v1.1