From 49b7cbda72cdaae8b5a7a89c94915851997b0b13 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 19 Aug 2013 20:29:17 +0100 Subject: Create a separate pCampbot "disconnect" console command which disconnects connected bots. "quit" console command now requires bots to be separate disconnected first before quitting. This is to prepare the way for disconnecting/reconnecting different numbers of bots in a pCampbot session. And hopefully resolves bug where console appears not to be reset if Environment.Exit(0) is called on a different thread --- OpenSim/Tools/pCampBot/BotManager.cs | 110 +++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 43 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index 8f31bdf..5c0dc81 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -52,9 +52,9 @@ namespace pCampBot public const int DefaultLoginDelay = 5000; /// - /// True if pCampbot is in the process of shutting down. + /// Is pCampbot in the process of disconnecting bots? /// - public bool ShuttingDown { get; private set; } + public bool DisconnectingBots { get; private set; } /// /// Delay between logins of multiple bots. @@ -139,6 +139,11 @@ namespace pCampBot "Shutdown bots and exit", HandleShutdown); + m_console.Commands.AddCommand("bot", false, "disconnect", + "disconnect", + "Disconnect all bots", + HandleDisconnect); + m_console.Commands.AddCommand("bot", false, "show regions", "show regions", "Show regions known to bots", @@ -191,31 +196,37 @@ namespace pCampBot for (int i = 0; i < botcount; i++) { - if (ShuttingDown) - break; + lock (m_lBot) + { + if (DisconnectingBots) + break; + + string lastName = string.Format("{0}_{1}", lastNameStem, i + fromBotNumber); - string lastName = string.Format("{0}_{1}", lastNameStem, i + fromBotNumber); + // We must give each bot its own list of instantiated behaviours since they store state. + List behaviours = new List(); + + // Hard-coded for now + if (behaviourSwitches.Contains("c")) + behaviours.Add(new CrossBehaviour()); - // We must give each bot its own list of instantiated behaviours since they store state. - List behaviours = new List(); - - // Hard-coded for now - if (behaviourSwitches.Contains("c")) - behaviours.Add(new CrossBehaviour()); + if (behaviourSwitches.Contains("g")) + behaviours.Add(new GrabbingBehaviour()); - if (behaviourSwitches.Contains("g")) - behaviours.Add(new GrabbingBehaviour()); + if (behaviourSwitches.Contains("n")) + behaviours.Add(new NoneBehaviour()); - if (behaviourSwitches.Contains("n")) - behaviours.Add(new NoneBehaviour()); + if (behaviourSwitches.Contains("p")) + behaviours.Add(new PhysicsBehaviour()); + + if (behaviourSwitches.Contains("t")) + behaviours.Add(new TeleportBehaviour()); - if (behaviourSwitches.Contains("p")) - behaviours.Add(new PhysicsBehaviour()); - - if (behaviourSwitches.Contains("t")) - behaviours.Add(new TeleportBehaviour()); + StartBot(this, behaviours, firstName, lastName, password, loginUri, startUri, wearSetting); + } - StartBot(this, behaviours, firstName, lastName, password, loginUri, startUri, wearSetting); + // Stagger logins + Thread.Sleep(LoginDelay); } } @@ -305,17 +316,13 @@ namespace pCampBot pb.OnConnected += handlebotEvent; pb.OnDisconnected += handlebotEvent; - lock (m_lBot) - m_lBot.Add(pb); + m_lBot.Add(pb); Thread pbThread = new Thread(pb.startup); pbThread.Name = pb.Name; pbThread.IsBackground = true; pbThread.Start(); - - // Stagger logins - Thread.Sleep(LoginDelay); } /// @@ -328,18 +335,16 @@ namespace pCampBot switch (eventt) { case EventType.CONNECTED: + { m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected"); break; + } + case EventType.DISCONNECTED: + { m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected"); - - lock (m_lBot) - { - if (m_lBot.TrueForAll(b => b.ConnectionState == ConnectionState.Disconnected)) - Environment.Exit(0); - - break; - } + break; + } } } @@ -349,15 +354,12 @@ namespace pCampBot /// /// We launch each shutdown on its own thread so that a slow shutting down bot doesn't hold up all the others. /// - public void doBotShutdown() + private void ShutdownBots() { - lock (m_lBot) + foreach (Bot bot in m_lBot) { - foreach (Bot bot in m_lBot) - { - Bot thisBot = bot; - Util.FireAndForget(o => thisBot.shutdown()); - } + Bot thisBot = bot; + Util.FireAndForget(o => thisBot.shutdown()); } } @@ -370,12 +372,34 @@ namespace pCampBot return new LocalConsole("pCampbot"); } + private void HandleDisconnect(string module, string[] cmd) + { + MainConsole.Instance.Output("Disconnecting bots"); + + lock (m_lBot) + { + DisconnectingBots = true; + + ShutdownBots(); + } + } + private void HandleShutdown(string module, string[] cmd) { + lock (m_lBot) + { + int connectedBots = m_lBot.Count(b => b.ConnectionState == ConnectionState.Connected); + + if (connectedBots > 0) + { + MainConsole.Instance.OutputFormat("Please disconnect {0} connected bots first", connectedBots); + return; + } + } + MainConsole.Instance.Output("Shutting down"); - ShuttingDown = true; - doBotShutdown(); + Environment.Exit(0); } private void HandleShowRegions(string module, string[] cmd) -- cgit v1.1