aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Tools/pCampBot/PhysicsBot.cs196
-rw-r--r--OpenSim/Tools/pCampBot/pCampBot.cs6
2 files changed, 190 insertions, 12 deletions
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs
index 004cd30..8548aed 100644
--- a/OpenSim/Tools/pCampBot/PhysicsBot.cs
+++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Text;
30using System.IO; 31using System.IO;
31using System.Threading; 32using System.Threading;
32using System.Timers; 33using System.Timers;
@@ -47,6 +48,8 @@ namespace pCampBot
47 public string lastname; 48 public string lastname;
48 public string password; 49 public string password;
49 public string loginURI; 50 public string loginURI;
51 public string saveDir;
52 public string wear;
50 53
51 public event AnEvent OnConnected; 54 public event AnEvent OnConnected;
52 public event AnEvent OnDisconnected; 55 public event AnEvent OnDisconnected;
@@ -54,7 +57,6 @@ namespace pCampBot
54 protected Timer m_action; // Action Timer 57 protected Timer m_action; // Action Timer
55 protected List<uint> objectIDs = new List<uint>(); 58 protected List<uint> objectIDs = new List<uint>();
56 59
57
58 protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here 60 protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here
59 61
60 //New instance of a SecondLife client 62 //New instance of a SecondLife client
@@ -79,9 +81,6 @@ namespace pCampBot
79 { 81 {
80 while (true) 82 while (true)
81 { 83 {
82 //client.Appearance.ForceRebakeAvatarTextures();
83 //client.Appearance.SetPreviousAppearance();
84
85 int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number, 84 int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number,
86 // the greater the bot's chances to walk instead of run. 85 // the greater the bot's chances to walk instead of run.
87 client.Self.Jump(false); 86 client.Self.Jump(false);
@@ -98,14 +97,6 @@ namespace pCampBot
98 Vector3 newpos = new Vector3(somthing.Next(255), somthing.Next(255), somthing.Next(255)); 97 Vector3 newpos = new Vector3(somthing.Next(255), somthing.Next(255), somthing.Next(255));
99 client.Self.Movement.TurnToward(newpos); 98 client.Self.Movement.TurnToward(newpos);
100 99
101 /*
102 // Why does it need to keep setting it true? Changing to just let it walk =)
103 for (int i = 0; i < 2000; i++)
104 {
105 client.Self.Movement.AtPos = true;
106 Thread.Sleep(somthing.Next(25, 75)); // Makes sure the bots keep walking for this time.
107 }
108 */
109 client.Self.Movement.AtPos = true; 100 client.Self.Movement.AtPos = true;
110 Thread.Sleep(somthing.Next(3000,13000)); 101 Thread.Sleep(somthing.Next(3000,13000));
111 client.Self.Movement.AtPos = false; 102 client.Self.Movement.AtPos = false;
@@ -128,6 +119,7 @@ namespace pCampBot
128 lastname = startupConfig.GetString("lastname", "random"); 119 lastname = startupConfig.GetString("lastname", "random");
129 password = startupConfig.GetString("password", "12345"); 120 password = startupConfig.GetString("password", "12345");
130 loginURI = startupConfig.GetString("loginuri"); 121 loginURI = startupConfig.GetString("loginuri");
122 wear = startupConfig.GetString("wear","no");
131 } 123 }
132 124
133 /// <summary> 125 /// <summary>
@@ -163,6 +155,7 @@ namespace pCampBot
163 client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(this.Network_OnDisconnected); 155 client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(this.Network_OnDisconnected);
164 client.Objects.OnNewPrim += Objects_NewPrim; 156 client.Objects.OnNewPrim += Objects_NewPrim;
165 client.Assets.OnImageReceived += Asset_TextureCallback; 157 client.Assets.OnImageReceived += Asset_TextureCallback;
158 client.Assets.OnAssetReceived += Asset_ReceivedCallback;
166 if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name")) 159 if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name"))
167 { 160 {
168 if (OnConnected != null) 161 if (OnConnected != null)
@@ -173,6 +166,15 @@ namespace pCampBot
173 m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed); 166 m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed);
174 m_action.Start(); 167 m_action.Start();
175 OnConnected(this, EventType.CONNECTED); 168 OnConnected(this, EventType.CONNECTED);
169 if (wear == "save")
170 {
171 client.Appearance.SetPreviousAppearance();
172 SaveDefaultAppearance();
173 }
174 else if (wear != "no")
175 {
176 MakeDefaultAppearance(wear);
177 }
176 client.Self.Jump(true); 178 client.Self.Jump(true);
177 } 179 }
178 } 180 }
@@ -186,6 +188,167 @@ namespace pCampBot
186 } 188 }
187 } 189 }
188 190
191 public void SaveDefaultAppearance()
192 {
193 saveDir = "MyAppearance/" + firstname + "_" + lastname;
194 if (!Directory.Exists(saveDir))
195 {
196 Directory.CreateDirectory(saveDir);
197 }
198
199 Array wtypes = Enum.GetValues(typeof(WearableType));
200 foreach (WearableType wtype in wtypes)
201 {
202 UUID wearable = client.Appearance.GetWearableAsset(wtype);
203 if (wearable != UUID.Zero)
204 {
205 client.Assets.RequestAsset(wearable, AssetType.Clothing, false);
206 client.Assets.RequestAsset(wearable, AssetType.Bodypart, false);
207 }
208 }
209 }
210
211 public void SaveAsset(AssetWearable asset)
212 {
213 if (asset != null)
214 {
215 try
216 {
217 if (asset.Decode())
218 {
219 File.WriteAllBytes(Path.Combine(saveDir, String.Format("{1}.{0}",
220 asset.AssetType.ToString().ToLower(),
221 asset.WearableType)), asset.AssetData);
222 }
223 else
224 {
225 MainConsole.Instance.Error(String.Format("Failed to decode {0} asset {1}", asset.AssetType, asset.AssetID));
226 }
227 }
228 catch (Exception e)
229 {
230 MainConsole.Instance.Error(String.Format("Exception: {0}",e.ToString()));
231 }
232 }
233 }
234
235 public WearableType GetWearableType(string path)
236 {
237 string type = ((((path.Split('/'))[2]).Split('.'))[0]).Trim();
238 switch(type)
239 {
240 case "Eyes":
241 return WearableType.Eyes;
242 case "Hair":
243 return WearableType.Hair;
244 case "Pants":
245 return WearableType.Pants;
246 case "Shape":
247 return WearableType.Shape;
248 case "Shirt":
249 return WearableType.Shirt;
250 case "Skin":
251 return WearableType.Skin;
252 default:
253 return WearableType.Shape;
254 }
255 }
256
257 public void MakeDefaultAppearance(string wear)
258 {
259 try
260 {
261 if (wear == "yes")
262 {
263 //TODO: Implement random outfit picking
264 MainConsole.Instance.Notice("Picks a random outfit. Not yet implemented.");
265 }
266 else if (wear != "save")
267 saveDir = "MyAppearance/" + wear;
268 saveDir = saveDir + "/";
269
270 string[] clothing = Directory.GetFiles(saveDir, "*.clothing", SearchOption.TopDirectoryOnly);
271 string[] bodyparts = Directory.GetFiles(saveDir, "*.bodypart", SearchOption.TopDirectoryOnly);
272 InventoryFolder clothfolder = FindClothingFolder();
273 UUID transid = UUID.Random();
274 List<InventoryBase> listwearables = new List<InventoryBase>();
275
276 for (int i = 0; i < clothing.Length; i++)
277 {
278 UUID assetID = UUID.Random();
279 AssetClothing asset = new AssetClothing(assetID, File.ReadAllBytes(clothing[i]));
280 asset.Decode();
281 asset.Owner = client.Self.AgentID;
282 asset.WearableType = GetWearableType(clothing[i]);
283 asset.Encode();
284 transid = client.Assets.RequestUpload(asset,true);
285 client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing,
286 transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item)
287 {
288 if (success)
289 {
290 listwearables.Add(item);
291 }
292 else
293 MainConsole.Instance.Error(String.Format("Failed to create item {0}",item.Name));
294 }
295 );
296 }
297
298 for (int i = 0; i < bodyparts.Length; i++)
299 {
300 UUID assetID = UUID.Random();
301 AssetBodypart asset = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i]));
302 asset.Decode();
303 asset.Owner = client.Self.AgentID;
304 asset.WearableType = GetWearableType(bodyparts[i]);
305 asset.Encode();
306 transid = client.Assets.RequestUpload(asset,true);
307 client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart,
308 transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item)
309 {
310 if (success)
311 {
312 listwearables.Add(item);
313 }
314 else
315 MainConsole.Instance.Error(String.Format("Failed to create item {0}",item.Name));
316 }
317 );
318 }
319
320 Thread.Sleep(1000);
321
322 if (listwearables == null || listwearables.Count == 0)
323 MainConsole.Instance.Notice("Nothing to send on this folder!");
324 else
325 {
326 MainConsole.Instance.Notice(String.Format("Sending {0} wearables...",listwearables.Count));
327 client.Appearance.WearOutfit(listwearables, false);
328 }
329 }
330 catch (Exception ex)
331 {
332 Console.WriteLine(ex.ToString());
333 }
334 }
335
336 public InventoryFolder FindClothingFolder()
337 {
338 UUID rootfolder = client.Inventory.Store.RootFolder.UUID;
339 List<InventoryBase> listfolders = client.Inventory.Store.GetContents(rootfolder);
340 InventoryFolder clothfolder = new InventoryFolder(UUID.Random());
341 foreach (InventoryBase folder in listfolders)
342 {
343 if (folder.Name == "Clothing")
344 {
345 clothfolder = (InventoryFolder)folder;
346 break;
347 }
348 }
349 return clothfolder;
350 }
351
189 public void Network_OnConnected(object sender) 352 public void Network_OnConnected(object sender)
190 { 353 {
191 if (OnConnected != null) 354 if (OnConnected != null)
@@ -237,6 +400,15 @@ namespace pCampBot
237 } 400 }
238 public void Asset_TextureCallback(ImageDownload image, AssetTexture asset) 401 public void Asset_TextureCallback(ImageDownload image, AssetTexture asset)
239 { 402 {
403 //TODO: Implement texture saving and applying
404 }
405
406 public void Asset_ReceivedCallback(AssetDownload transfer,Asset asset)
407 {
408 if (wear == "save")
409 {
410 SaveAsset((AssetWearable) asset);
411 }
240 } 412 }
241 413
242 public string[] readexcuses() 414 public string[] readexcuses()
diff --git a/OpenSim/Tools/pCampBot/pCampBot.cs b/OpenSim/Tools/pCampBot/pCampBot.cs
index 9cde451..098a8ca 100644
--- a/OpenSim/Tools/pCampBot/pCampBot.cs
+++ b/OpenSim/Tools/pCampBot/pCampBot.cs
@@ -77,6 +77,7 @@ namespace pCampBot
77 cs.AddSwitch("Startup", "lastname"); 77 cs.AddSwitch("Startup", "lastname");
78 cs.AddSwitch("Startup", "password"); 78 cs.AddSwitch("Startup", "password");
79 cs.AddSwitch("Startup", "help","h"); 79 cs.AddSwitch("Startup", "help","h");
80 cs.AddSwitch("Startup", "wear");
80 81
81 IConfig ol = cs.Configs["Startup"]; 82 IConfig ol = cs.Configs["Startup"];
82 return ol; 83 return ol;
@@ -84,6 +85,10 @@ namespace pCampBot
84 85
85 private static void Help() 86 private static void Help()
86 { 87 {
88 // Added the wear command. This allows the bot to wear real clothes instead of default locked ones.
89 // You can either say no, to not load anything, yes, to load one of the default wearables, a folder
90 // name, to load an specific folder, or save, to save an avatar with some already existing wearables
91 // worn to the folder MyAppearance/FirstName_LastName, and the load it.
87 Console.WriteLine( 92 Console.WriteLine(
88 "usage: pCampBot <-loginuri loginuri> [OPTIONS]\n" + 93 "usage: pCampBot <-loginuri loginuri> [OPTIONS]\n" +
89 "Spawns a set of bots to test an OpenSim region\n\n" + 94 "Spawns a set of bots to test an OpenSim region\n\n" +
@@ -92,6 +97,7 @@ namespace pCampBot
92 " -firstname first name for the bot(s) (default: random string)\n" + 97 " -firstname first name for the bot(s) (default: random string)\n" +
93 " -lastname lastname for the bot(s) (default: random string)\n" + 98 " -lastname lastname for the bot(s) (default: random string)\n" +
94 " -password password for the bots(s) (default: random string)\n" + 99 " -password password for the bots(s) (default: random string)\n" +
100 " -wear set appearance folder to load from (default: no)\n" +
95 " -h, -help show this message" 101 " -h, -help show this message"
96 ); 102 );
97 } 103 }