aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-05-11 00:53:21 +0100
committerJustin Clark-Casey (justincc)2012-05-11 00:53:21 +0100
commitdc39ec82fa8343657ad9b45a7d9cfeb27bf26e79 (patch)
treec1e8bde99dbb20e83202c4f405b717967c5d65c6 /OpenSim/Tools
parentIf a bot is not connected, show region name "(none)" instead of throwing an e... (diff)
downloadopensim-SC_OLD-dc39ec82fa8343657ad9b45a7d9cfeb27bf26e79.zip
opensim-SC_OLD-dc39ec82fa8343657ad9b45a7d9cfeb27bf26e79.tar.gz
opensim-SC_OLD-dc39ec82fa8343657ad9b45a7d9cfeb27bf26e79.tar.bz2
opensim-SC_OLD-dc39ec82fa8343657ad9b45a7d9cfeb27bf26e79.tar.xz
Change bot.IsConnected to be ConnectionState with Disconnected, Connecting, Connnected and Disconnecting states
Diffstat (limited to 'OpenSim/Tools')
-rw-r--r--OpenSim/Tools/pCampBot/Bot.cs23
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs4
2 files changed, 22 insertions, 5 deletions
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;
43 43
44namespace pCampBot 44namespace pCampBot
45{ 45{
46 public enum ConnectionState
47 {
48 Disconnected,
49 Connecting,
50 Connected,
51 Disconnecting
52 }
53
46 public class Bot 54 public class Bot
47 { 55 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 56 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -86,7 +94,7 @@ namespace pCampBot
86 /// <summary> 94 /// <summary>
87 /// Is this bot connected to the grid? 95 /// Is this bot connected to the grid?
88 /// </summary> 96 /// </summary>
89 public bool IsConnected { get; private set; } 97 public ConnectionState ConnectionState { get; private set; }
90 98
91 public string FirstName { get; private set; } 99 public string FirstName { get; private set; }
92 public string LastName { get; private set; } 100 public string LastName { get; private set; }
@@ -130,6 +138,8 @@ namespace pCampBot
130 BotManager bm, List<IBehaviour> behaviours, 138 BotManager bm, List<IBehaviour> behaviours,
131 string firstName, string lastName, string password, string loginUri) 139 string firstName, string lastName, string password, string loginUri)
132 { 140 {
141 ConnectionState = ConnectionState.Disconnected;
142
133 behaviours.ForEach(b => b.Initialize(this)); 143 behaviours.ForEach(b => b.Initialize(this));
134 144
135 Client = new GridClient(); 145 Client = new GridClient();
@@ -178,6 +188,8 @@ namespace pCampBot
178 /// </summary> 188 /// </summary>
179 public void shutdown() 189 public void shutdown()
180 { 190 {
191 ConnectionState = ConnectionState.Disconnecting;
192
181 if (m_actionThread != null) 193 if (m_actionThread != null)
182 m_actionThread.Abort(); 194 m_actionThread.Abort();
183 195
@@ -209,9 +221,11 @@ namespace pCampBot
209 Client.Network.Disconnected += this.Network_OnDisconnected; 221 Client.Network.Disconnected += this.Network_OnDisconnected;
210 Client.Objects.ObjectUpdate += Objects_NewPrim; 222 Client.Objects.ObjectUpdate += Objects_NewPrim;
211 223
224 ConnectionState = ConnectionState.Connecting;
225
212 if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) 226 if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name"))
213 { 227 {
214 IsConnected = true; 228 ConnectionState = ConnectionState.Connected;
215 229
216 Thread.Sleep(Random.Next(1000, 10000)); 230 Thread.Sleep(Random.Next(1000, 10000));
217 m_actionThread = new Thread(Action); 231 m_actionThread = new Thread(Action);
@@ -241,6 +255,8 @@ namespace pCampBot
241 } 255 }
242 else 256 else
243 { 257 {
258 ConnectionState = ConnectionState.Disconnected;
259
244 m_log.ErrorFormat( 260 m_log.ErrorFormat(
245 "{0} {1} cannot login: {2}", FirstName, LastName, Client.Network.LoginMessage); 261 "{0} {1} cannot login: {2}", FirstName, LastName, Client.Network.LoginMessage);
246 262
@@ -439,6 +455,8 @@ namespace pCampBot
439 455
440 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) 456 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args)
441 { 457 {
458 ConnectionState = ConnectionState.Disconnected;
459
442 m_log.DebugFormat( 460 m_log.DebugFormat(
443 "[BOT]: Bot {0} disconnected reason {1}, message {2}", Name, args.Reason, args.Message); 461 "[BOT]: Bot {0} disconnected reason {1}, message {2}", Name, args.Reason, args.Message);
444 462
@@ -456,7 +474,6 @@ namespace pCampBot
456 && OnDisconnected != null) 474 && OnDisconnected != null)
457// if (OnDisconnected != null) 475// if (OnDisconnected != null)
458 { 476 {
459 IsConnected = false;
460 OnDisconnected(this, EventType.DISCONNECTED); 477 OnDisconnected(this, EventType.DISCONNECTED);
461 } 478 }
462 } 479 }
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
242 242
243 lock (m_lBot) 243 lock (m_lBot)
244 { 244 {
245 if (m_lBot.TrueForAll(b => !b.IsConnected)) 245 if (m_lBot.TrueForAll(b => b.ConnectionState == ConnectionState.Disconnected))
246 Environment.Exit(0); 246 Environment.Exit(0);
247 247
248 break; 248 break;
@@ -306,7 +306,7 @@ namespace pCampBot
306 306
307 MainConsole.Instance.OutputFormat( 307 MainConsole.Instance.OutputFormat(
308 outputFormat, 308 outputFormat,
309 pb.Name, currentSim != null ? currentSim.Name : "(none)", pb.IsConnected ? "Connected" : "Disconnected"); 309 pb.Name, currentSim != null ? currentSim.Name : "(none)", pb.ConnectionState);
310 } 310 }
311 } 311 }
312 } 312 }