aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/BotManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tools/pCampBot/BotManager.cs')
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs169
1 files changed, 94 insertions, 75 deletions
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 614b350..b05bd6d 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -49,17 +49,22 @@ namespace pCampBot
49 49
50 protected CommandConsole m_console; 50 protected CommandConsole m_console;
51 protected List<PhysicsBot> m_lBot; 51 protected List<PhysicsBot> m_lBot;
52 protected Thread[] m_td;
53 protected bool m_verbose = true;
54 protected Random somthing = new Random(Environment.TickCount); 52 protected Random somthing = new Random(Environment.TickCount);
55 protected int numbots = 0; 53 protected int numbots = 0;
56 protected IConfig Previous_config; 54 public IConfig Config { get; private set; }
55
56 /// <summary>
57 /// Track the assets we have and have not received so we don't endlessly repeat requests.
58 /// </summary>
59 public Dictionary<UUID, bool> AssetsReceived { get; private set; }
57 60
58 /// <summary> 61 /// <summary>
59 /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data 62 /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
60 /// </summary> 63 /// </summary>
61 public BotManager() 64 public BotManager()
62 { 65 {
66 AssetsReceived = new Dictionary<UUID, bool>();
67
63 m_console = CreateConsole(); 68 m_console = CreateConsole();
64 MainConsole.Instance = m_console; 69 MainConsole.Instance = m_console;
65 70
@@ -81,16 +86,21 @@ namespace pCampBot
81 86
82 m_console.Commands.AddCommand("bot", false, "shutdown", 87 m_console.Commands.AddCommand("bot", false, "shutdown",
83 "shutdown", 88 "shutdown",
84 "Gracefully shut down bots", HandleShutdown); 89 "Shutdown bots and exit", HandleShutdown);
85 90
86 m_console.Commands.AddCommand("bot", false, "quit", 91 m_console.Commands.AddCommand("bot", false, "quit",
87 "quit", 92 "quit",
88 "Force quit (DANGEROUS, try shutdown first)", 93 "Shutdown bots and exit",
89 HandleShutdown); 94 HandleShutdown);
90 95
91 m_console.Commands.AddCommand("bot", false, "add bots", 96 m_console.Commands.AddCommand("bot", false, "show status",
92 "add bots <number>", 97 "show status",
93 "Add more bots", HandleAddBots); 98 "Shows the status of all bots",
99 HandleShowStatus);
100
101// m_console.Commands.AddCommand("bot", false, "add bots",
102// "add bots <number>",
103// "Add more bots", HandleAddBots);
94 104
95 m_lBot = new List<PhysicsBot>(); 105 m_lBot = new List<PhysicsBot>();
96 } 106 }
@@ -102,69 +112,63 @@ namespace pCampBot
102 /// <param name="cs">The configuration for the bots to use</param> 112 /// <param name="cs">The configuration for the bots to use</param>
103 public void dobotStartup(int botcount, IConfig cs) 113 public void dobotStartup(int botcount, IConfig cs)
104 { 114 {
105 Previous_config = cs; 115 Config = cs;
106 m_td = new Thread[botcount]; 116
117 string firstName = cs.GetString("firstname");
118 string lastNameStem = cs.GetString("lastname");
119 string password = cs.GetString("password");
120 string loginUri = cs.GetString("loginuri");
121
107 for (int i = 0; i < botcount; i++) 122 for (int i = 0; i < botcount; i++)
108 { 123 {
109 startupBot(i, cs); 124 string lastName = string.Format("{0}_{1}", lastNameStem, i);
125 startupBot(i, this, firstName, lastName, password, loginUri);
110 } 126 }
111 } 127 }
112 128
113 /// <summary> 129// /// <summary>
114 /// Add additional bots (and threads) to our bot pool 130// /// Add additional bots (and threads) to our bot pool
115 /// </summary> 131// /// </summary>
116 /// <param name="botcount">How Many of them to add</param> 132// /// <param name="botcount">How Many of them to add</param>
117 public void addbots(int botcount) 133// public void addbots(int botcount)
118 { 134// {
119 int len = m_td.Length; 135// int len = m_td.Length;
120 Thread[] m_td2 = new Thread[len + botcount]; 136// Thread[] m_td2 = new Thread[len + botcount];
121 for (int i = 0; i < len; i++) 137// for (int i = 0; i < len; i++)
122 { 138// {
123 m_td2[i] = m_td[i]; 139// m_td2[i] = m_td[i];
124 } 140// }
125 m_td = m_td2; 141// m_td = m_td2;
126 int newlen = len + botcount; 142// int newlen = len + botcount;
127 for (int i = len; i < newlen; i++) 143// for (int i = len; i < newlen; i++)
128 { 144// {
129 startupBot(i, Previous_config); 145// startupBot(i, Config);
130 } 146// }
131 } 147// }
132 148
133 /// <summary> 149 /// <summary>
134 /// This starts up the bot and stores the thread for the bot in the thread array 150 /// This starts up the bot and stores the thread for the bot in the thread array
135 /// </summary> 151 /// </summary>
136 /// <param name="pos">The position in the thread array to stick the bot's thread</param> 152 /// <param name="pos">The position in the thread array to stick the bot's thread</param>
137 /// <param name="cs">Configuration of the bot</param> 153 /// <param name="cs">Configuration of the bot</param>
138 public void startupBot(int pos, IConfig cs) 154 /// <param name="firstName">First name</param>
155 /// <param name="lastName">Last name</param>
156 /// <param name="password">Password</param>
157 /// <param name="loginUri">Login URI</param>
158 public void startupBot(int pos, BotManager bm, string firstName, string lastName, string password, string loginUri)
139 { 159 {
140 PhysicsBot pb = new PhysicsBot(cs); 160 PhysicsBot pb = new PhysicsBot(bm, firstName, lastName, password, loginUri);
141 161
142 pb.OnConnected += handlebotEvent; 162 pb.OnConnected += handlebotEvent;
143 pb.OnDisconnected += handlebotEvent; 163 pb.OnDisconnected += handlebotEvent;
144 if (cs.GetString("firstname", "random") == "random") pb.firstname = CreateRandomName();
145 if (cs.GetString("lastname", "random") == "random") pb.lastname = CreateRandomName();
146
147 m_td[pos] = new Thread(pb.startup);
148 m_td[pos].Name = "CampBot_" + pos;
149 m_td[pos].IsBackground = true;
150 m_td[pos].Start();
151 m_lBot.Add(pb);
152 }
153 164
154 /// <summary> 165 lock (m_lBot)
155 /// Creates a random name for the bot 166 m_lBot.Add(pb);
156 /// </summary>
157 /// <returns></returns>
158 private string CreateRandomName()
159 {
160 string returnstring = "";
161 string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
162 167
163 for (int i = 0; i < 7; i++) 168 Thread pbThread = new Thread(pb.startup);
164 { 169 pbThread.Name = pb.Name;
165 returnstring += chars.Substring(somthing.Next(chars.Length),1); 170 pbThread.IsBackground = true;
166 } 171 pbThread.Start();
167 return returnstring;
168 } 172 }
169 173
170 /// <summary> 174 /// <summary>
@@ -172,19 +176,20 @@ namespace pCampBot
172 /// </summary> 176 /// </summary>
173 /// <param name="callbot"></param> 177 /// <param name="callbot"></param>
174 /// <param name="eventt"></param> 178 /// <param name="eventt"></param>
175 public void handlebotEvent(PhysicsBot callbot, EventType eventt) 179 private void handlebotEvent(PhysicsBot callbot, EventType eventt)
176 { 180 {
177 switch (eventt) 181 switch (eventt)
178 { 182 {
179 case EventType.CONNECTED: 183 case EventType.CONNECTED:
180 m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Connected"); 184 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected");
181 numbots++; 185 numbots++;
186// m_log.InfoFormat("NUMBOTS {0}", numbots);
182 break; 187 break;
183 case EventType.DISCONNECTED: 188 case EventType.DISCONNECTED:
184 m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Disconnected"); 189 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected");
185 m_td[m_lBot.IndexOf(callbot)].Abort();
186 numbots--; 190 numbots--;
187 if (numbots >1) 191// m_log.InfoFormat("NUMBOTS {0}", numbots);
192 if (numbots <= 0)
188 Environment.Exit(0); 193 Environment.Exit(0);
189 break; 194 break;
190 } 195 }
@@ -195,10 +200,9 @@ namespace pCampBot
195 /// </summary> 200 /// </summary>
196 public void doBotShutdown() 201 public void doBotShutdown()
197 { 202 {
198 foreach (PhysicsBot pb in m_lBot) 203 lock (m_lBot)
199 { 204 foreach (PhysicsBot pb in m_lBot)
200 pb.shutdown(); 205 pb.shutdown();
201 }
202 } 206 }
203 207
204 /// <summary> 208 /// <summary>
@@ -216,6 +220,21 @@ namespace pCampBot
216 doBotShutdown(); 220 doBotShutdown();
217 } 221 }
218 222
223 private void HandleShowStatus(string module, string[] cmd)
224 {
225 string outputFormat = "{0,-30} {1,-14}";
226 MainConsole.Instance.OutputFormat(outputFormat, "Name", "Status");
227
228 lock (m_lBot)
229 {
230 foreach (PhysicsBot pb in m_lBot)
231 {
232 MainConsole.Instance.OutputFormat(
233 outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected"));
234 }
235 }
236 }
237
219 /* 238 /*
220 private void HandleQuit(string module, string[] cmd) 239 private void HandleQuit(string module, string[] cmd)
221 { 240 {
@@ -223,17 +242,17 @@ namespace pCampBot
223 Environment.Exit(0); 242 Environment.Exit(0);
224 } 243 }
225 */ 244 */
226 245//
227 private void HandleAddBots(string module, string[] cmd) 246// private void HandleAddBots(string module, string[] cmd)
228 { 247// {
229 int newbots = 0; 248// int newbots = 0;
230 249//
231 if (cmd.Length > 2) 250// if (cmd.Length > 2)
232 { 251// {
233 Int32.TryParse(cmd[2], out newbots); 252// Int32.TryParse(cmd[2], out newbots);
234 } 253// }
235 if (newbots > 0) 254// if (newbots > 0)
236 addbots(newbots); 255// addbots(newbots);
237 } 256// }
238 } 257 }
239} 258}