From dc39ec82fa8343657ad9b45a7d9cfeb27bf26e79 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 11 May 2012 00:53:21 +0100
Subject: Change bot.IsConnected to be ConnectionState with Disconnected,
Connecting, Connnected and Disconnecting states
---
OpenSim/Tools/pCampBot/Bot.cs | 23 ++++++++++++++++++++---
OpenSim/Tools/pCampBot/BotManager.cs | 4 ++--
2 files changed, 22 insertions(+), 5 deletions(-)
(limited to 'OpenSim/Tools/pCampBot')
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs
index da090dd..2b4a171 100644
--- a/OpenSim/Tools/pCampBot/Bot.cs
+++ b/OpenSim/Tools/pCampBot/Bot.cs
@@ -43,6 +43,14 @@ using Timer = System.Timers.Timer;
namespace pCampBot
{
+ public enum ConnectionState
+ {
+ Disconnected,
+ Connecting,
+ Connected,
+ Disconnecting
+ }
+
public class Bot
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -86,7 +94,7 @@ namespace pCampBot
///
/// Is this bot connected to the grid?
///
- public bool IsConnected { get; private set; }
+ public ConnectionState ConnectionState { get; private set; }
public string FirstName { get; private set; }
public string LastName { get; private set; }
@@ -130,6 +138,8 @@ namespace pCampBot
BotManager bm, List behaviours,
string firstName, string lastName, string password, string loginUri)
{
+ ConnectionState = ConnectionState.Disconnected;
+
behaviours.ForEach(b => b.Initialize(this));
Client = new GridClient();
@@ -178,6 +188,8 @@ namespace pCampBot
///
public void shutdown()
{
+ ConnectionState = ConnectionState.Disconnecting;
+
if (m_actionThread != null)
m_actionThread.Abort();
@@ -209,9 +221,11 @@ namespace pCampBot
Client.Network.Disconnected += this.Network_OnDisconnected;
Client.Objects.ObjectUpdate += Objects_NewPrim;
+ ConnectionState = ConnectionState.Connecting;
+
if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name"))
{
- IsConnected = true;
+ ConnectionState = ConnectionState.Connected;
Thread.Sleep(Random.Next(1000, 10000));
m_actionThread = new Thread(Action);
@@ -241,6 +255,8 @@ namespace pCampBot
}
else
{
+ ConnectionState = ConnectionState.Disconnected;
+
m_log.ErrorFormat(
"{0} {1} cannot login: {2}", FirstName, LastName, Client.Network.LoginMessage);
@@ -439,6 +455,8 @@ namespace pCampBot
public void Network_OnDisconnected(object sender, DisconnectedEventArgs args)
{
+ ConnectionState = ConnectionState.Disconnected;
+
m_log.DebugFormat(
"[BOT]: Bot {0} disconnected reason {1}, message {2}", Name, args.Reason, args.Message);
@@ -456,7 +474,6 @@ namespace pCampBot
&& OnDisconnected != null)
// if (OnDisconnected != null)
{
- IsConnected = false;
OnDisconnected(this, EventType.DISCONNECTED);
}
}
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index fd32a6a..d4bbc2a 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -242,7 +242,7 @@ namespace pCampBot
lock (m_lBot)
{
- if (m_lBot.TrueForAll(b => !b.IsConnected))
+ if (m_lBot.TrueForAll(b => b.ConnectionState == ConnectionState.Disconnected))
Environment.Exit(0);
break;
@@ -306,7 +306,7 @@ namespace pCampBot
MainConsole.Instance.OutputFormat(
outputFormat,
- pb.Name, currentSim != null ? currentSim.Name : "(none)", pb.IsConnected ? "Connected" : "Disconnected");
+ pb.Name, currentSim != null ? currentSim.Name : "(none)", pb.ConnectionState);
}
}
}
--
cgit v1.1