aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/BotManager.cs
diff options
context:
space:
mode:
authorMelanie2013-08-14 21:25:22 +0100
committerMelanie2013-08-14 21:25:22 +0100
commitdf7a1e68f6b3f8d136c7f8fe2c973e1fa5b6701b (patch)
treed6e2983a501d41c2793fe30b7a87beb717d298f7 /OpenSim/Tools/pCampBot/BotManager.cs
parentMerge branch 'master' into careminster (diff)
parentIf pCampbot has been asked to shutdown, don't carry on logging in queued bots (diff)
downloadopensim-SC-df7a1e68f6b3f8d136c7f8fe2c973e1fa5b6701b.zip
opensim-SC-df7a1e68f6b3f8d136c7f8fe2c973e1fa5b6701b.tar.gz
opensim-SC-df7a1e68f6b3f8d136c7f8fe2c973e1fa5b6701b.tar.bz2
opensim-SC-df7a1e68f6b3f8d136c7f8fe2c973e1fa5b6701b.tar.xz
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Tools/pCampBot/BotManager.cs')
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs103
1 files changed, 85 insertions, 18 deletions
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 74bd36a..397a98e 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -52,6 +52,11 @@ namespace pCampBot
52 public const int DefaultLoginDelay = 5000; 52 public const int DefaultLoginDelay = 5000;
53 53
54 /// <summary> 54 /// <summary>
55 /// True if pCampbot is in the process of shutting down.
56 /// </summary>
57 public bool ShuttingDown { get; private set; }
58
59 /// <summary>
55 /// Delay between logins of multiple bots. 60 /// Delay between logins of multiple bots.
56 /// </summary> 61 /// </summary>
57 /// <remarks>TODO: This value needs to be configurable by a command line argument.</remarks> 62 /// <remarks>TODO: This value needs to be configurable by a command line argument.</remarks>
@@ -63,6 +68,16 @@ namespace pCampBot
63 protected CommandConsole m_console; 68 protected CommandConsole m_console;
64 69
65 /// <summary> 70 /// <summary>
71 /// Controls whether bots start out sending agent updates on connection.
72 /// </summary>
73 public bool InitBotSendAgentUpdates { get; set; }
74
75 /// <summary>
76 /// Controls whether bots request textures for the object information they receive
77 /// </summary>
78 public bool InitBotRequestObjectTextures { get; set; }
79
80 /// <summary>
66 /// Created bots, whether active or inactive. 81 /// Created bots, whether active or inactive.
67 /// </summary> 82 /// </summary>
68 protected List<Bot> m_lBot; 83 protected List<Bot> m_lBot;
@@ -73,11 +88,6 @@ namespace pCampBot
73 public Random Rng { get; private set; } 88 public Random Rng { get; private set; }
74 89
75 /// <summary> 90 /// <summary>
76 /// Overall configuration.
77 /// </summary>
78 public IConfig Config { get; private set; }
79
80 /// <summary>
81 /// Track the assets we have and have not received so we don't endlessly repeat requests. 91 /// Track the assets we have and have not received so we don't endlessly repeat requests.
82 /// </summary> 92 /// </summary>
83 public Dictionary<UUID, bool> AssetsReceived { get; private set; } 93 public Dictionary<UUID, bool> AssetsReceived { get; private set; }
@@ -92,6 +102,9 @@ namespace pCampBot
92 /// </summary> 102 /// </summary>
93 public BotManager() 103 public BotManager()
94 { 104 {
105 InitBotSendAgentUpdates = true;
106 InitBotRequestObjectTextures = true;
107
95 LoginDelay = DefaultLoginDelay; 108 LoginDelay = DefaultLoginDelay;
96 109
97 Rng = new Random(Environment.TickCount); 110 Rng = new Random(Environment.TickCount);
@@ -148,31 +161,40 @@ namespace pCampBot
148 /// </summary> 161 /// </summary>
149 /// <param name="botcount">How many bots to start up</param> 162 /// <param name="botcount">How many bots to start up</param>
150 /// <param name="cs">The configuration for the bots to use</param> 163 /// <param name="cs">The configuration for the bots to use</param>
151 public void dobotStartup(int botcount, IConfig cs) 164 public void dobotStartup(int botcount, IConfig startupConfig)
152 { 165 {
153 Config = cs; 166 string firstName = startupConfig.GetString("firstname");
167 string lastNameStem = startupConfig.GetString("lastname");
168 string password = startupConfig.GetString("password");
169 string loginUri = startupConfig.GetString("loginuri");
170 string startLocation = startupConfig.GetString("start", "last");
171 int fromBotNumber = startupConfig.GetInt("from", 0);
172 string wearSetting = startupConfig.GetString("wear", "no");
154 173
155 string firstName = cs.GetString("firstname"); 174 string startUri = ParseInputStartLocationToUri(startLocation);
156 string lastNameStem = cs.GetString("lastname");
157 string password = cs.GetString("password");
158 string loginUri = cs.GetString("loginuri");
159 175
160 HashSet<string> behaviourSwitches = new HashSet<string>(); 176 HashSet<string> behaviourSwitches = new HashSet<string>();
161 Array.ForEach<string>( 177 Array.ForEach<string>(
162 cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); 178 startupConfig.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
163 179
164 MainConsole.Instance.OutputFormat( 180 MainConsole.Instance.OutputFormat(
165 "[BOT MANAGER]: Starting {0} bots connecting to {1}, named {2} {3}_<n>", 181 "[BOT MANAGER]: Starting {0} bots connecting to {1}, location {2}, named {3} {4}_<n>",
166 botcount, 182 botcount,
167 loginUri, 183 loginUri,
184 startUri,
168 firstName, 185 firstName,
169 lastNameStem); 186 lastNameStem);
170 187
171 MainConsole.Instance.OutputFormat("[BOT MANAGER]: Delay between logins is {0}ms", LoginDelay); 188 MainConsole.Instance.OutputFormat("[BOT MANAGER]: Delay between logins is {0}ms", LoginDelay);
189 MainConsole.Instance.OutputFormat("[BOT MANAGER]: BotsSendAgentUpdates is {0}", InitBotSendAgentUpdates);
190 MainConsole.Instance.OutputFormat("[BOT MANAGER]: InitBotRequestObjectTextures is {0}", InitBotRequestObjectTextures);
172 191
173 for (int i = 0; i < botcount; i++) 192 for (int i = 0; i < botcount; i++)
174 { 193 {
175 string lastName = string.Format("{0}_{1}", lastNameStem, i); 194 if (ShuttingDown)
195 break;
196
197 string lastName = string.Format("{0}_{1}", lastNameStem, i + fromBotNumber);
176 198
177 // We must give each bot its own list of instantiated behaviours since they store state. 199 // We must give each bot its own list of instantiated behaviours since they store state.
178 List<IBehaviour> behaviours = new List<IBehaviour>(); 200 List<IBehaviour> behaviours = new List<IBehaviour>();
@@ -193,10 +215,49 @@ namespace pCampBot
193 if (behaviourSwitches.Contains("t")) 215 if (behaviourSwitches.Contains("t"))
194 behaviours.Add(new TeleportBehaviour()); 216 behaviours.Add(new TeleportBehaviour());
195 217
196 StartBot(this, behaviours, firstName, lastName, password, loginUri); 218 StartBot(this, behaviours, firstName, lastName, password, loginUri, startUri, wearSetting);
197 } 219 }
198 } 220 }
199 221
222 /// <summary>
223 /// Parses the command line start location to a start string/uri that the login mechanism will recognize.
224 /// </summary>
225 /// <returns>
226 /// The input start location to URI.
227 /// </returns>
228 /// <param name='startLocation'>
229 /// Start location.
230 /// </param>
231 private string ParseInputStartLocationToUri(string startLocation)
232 {
233 if (startLocation == "home" || startLocation == "last")
234 return startLocation;
235
236 string regionName;
237
238 // Just a region name or only one (!) extra component. Like a viewer, we will stick 128/128/0 on the end
239 Vector3 startPos = new Vector3(128, 128, 0);
240
241 string[] startLocationComponents = startLocation.Split('/');
242
243 regionName = startLocationComponents[0];
244
245 if (startLocationComponents.Length >= 2)
246 {
247 float.TryParse(startLocationComponents[1], out startPos.X);
248
249 if (startLocationComponents.Length >= 3)
250 {
251 float.TryParse(startLocationComponents[2], out startPos.Y);
252
253 if (startLocationComponents.Length >= 4)
254 float.TryParse(startLocationComponents[3], out startPos.Z);
255 }
256 }
257
258 return string.Format("uri:{0}&{1}&{2}&{3}", regionName, startPos.X, startPos.Y, startPos.Z);
259 }
260
200// /// <summary> 261// /// <summary>
201// /// Add additional bots (and threads) to our bot pool 262// /// Add additional bots (and threads) to our bot pool
202// /// </summary> 263// /// </summary>
@@ -226,15 +287,19 @@ namespace pCampBot
226 /// <param name="lastName">Last name</param> 287 /// <param name="lastName">Last name</param>
227 /// <param name="password">Password</param> 288 /// <param name="password">Password</param>
228 /// <param name="loginUri">Login URI</param> 289 /// <param name="loginUri">Login URI</param>
290 /// <param name="startLocation">Location to start the bot. Can be "last", "home" or a specific sim name.</param>
291 /// <param name="wearSetting"></param>
229 public void StartBot( 292 public void StartBot(
230 BotManager bm, List<IBehaviour> behaviours, 293 BotManager bm, List<IBehaviour> behaviours,
231 string firstName, string lastName, string password, string loginUri) 294 string firstName, string lastName, string password, string loginUri, string startLocation, string wearSetting)
232 { 295 {
233 MainConsole.Instance.OutputFormat( 296 MainConsole.Instance.OutputFormat(
234 "[BOT MANAGER]: Starting bot {0} {1}, behaviours are {2}", 297 "[BOT MANAGER]: Starting bot {0} {1}, behaviours are {2}",
235 firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray())); 298 firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
236 299
237 Bot pb = new Bot(bm, behaviours, firstName, lastName, password, loginUri); 300 Bot pb = new Bot(bm, behaviours, firstName, lastName, password, startLocation, loginUri);
301 pb.wear = wearSetting;
302 pb.Client.Settings.SEND_AGENT_UPDATES = InitBotSendAgentUpdates;
238 303
239 pb.OnConnected += handlebotEvent; 304 pb.OnConnected += handlebotEvent;
240 pb.OnDisconnected += handlebotEvent; 305 pb.OnDisconnected += handlebotEvent;
@@ -306,7 +371,9 @@ namespace pCampBot
306 371
307 private void HandleShutdown(string module, string[] cmd) 372 private void HandleShutdown(string module, string[] cmd)
308 { 373 {
309 m_log.Info("[BOTMANAGER]: Shutting down bots"); 374 MainConsole.Instance.Output("Shutting down");
375
376 ShuttingDown = true;
310 doBotShutdown(); 377 doBotShutdown();
311 } 378 }
312 379