aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/PhysicsBot.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tools/pCampBot/PhysicsBot.cs')
-rw-r--r--OpenSim/Tools/pCampBot/PhysicsBot.cs152
1 files changed, 62 insertions, 90 deletions
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs
index a8b2426..c1bd49f 100644
--- a/OpenSim/Tools/pCampBot/PhysicsBot.cs
+++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs
@@ -36,6 +36,7 @@ using log4net;
36using OpenMetaverse; 36using OpenMetaverse;
37using OpenMetaverse.Assets; 37using OpenMetaverse.Assets;
38using Nini.Config; 38using Nini.Config;
39using pCampBot.Interfaces;
39using OpenSim.Framework; 40using OpenSim.Framework;
40using OpenSim.Framework.Console; 41using OpenSim.Framework.Console;
41using Timer = System.Timers.Timer; 42using Timer = System.Timers.Timer;
@@ -52,6 +53,11 @@ namespace pCampBot
52 private IConfig startupConfig; // bot config, passed from BotManager 53 private IConfig startupConfig; // bot config, passed from BotManager
53 54
54 /// <summary> 55 /// <summary>
56 /// Behaviours implemented by this bot.
57 /// </summary>
58 public List<IBehaviour> Behaviours { get; private set; }
59
60 /// <summary>
55 /// Is this bot connected to the grid? 61 /// Is this bot connected to the grid?
56 /// </summary> 62 /// </summary>
57 public bool IsConnected { get; private set; } 63 public bool IsConnected { get; private set; }
@@ -74,25 +80,33 @@ namespace pCampBot
74 80
75 protected List<uint> objectIDs = new List<uint>(); 81 protected List<uint> objectIDs = new List<uint>();
76 82
77 protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here 83 /// <summary>
84 /// Random number generator.
85 /// </summary>
86 public Random Random { get; private set; }
78 87
79 /// <summary> 88 /// <summary>
80 /// New instance of a SecondLife client 89 /// New instance of a SecondLife client
81 /// </summary> 90 /// </summary>
82 public GridClient client = new GridClient(); 91 public GridClient Client { get; private set; }
83
84 protected string[] talkarray;
85 92
86 /// <summary> 93 /// <summary>
87 /// Constructor 94 /// Constructor
88 /// </summary> 95 /// </summary>
89 /// <param name="bm"></param> 96 /// <param name="bm"></param>
97 /// <param name="behaviours">Behaviours for this bot to perform</param>
90 /// <param name="firstName"></param> 98 /// <param name="firstName"></param>
91 /// <param name="lastName"></param> 99 /// <param name="lastName"></param>
92 /// <param name="password"></param> 100 /// <param name="password"></param>
93 /// <param name="loginUri"></param> 101 /// <param name="loginUri"></param>
94 public PhysicsBot(BotManager bm, string firstName, string lastName, string password, string loginUri) 102 /// <param name="behaviours"></param>
103 public PhysicsBot(
104 BotManager bm, List<IBehaviour> behaviours,
105 string firstName, string lastName, string password, string loginUri)
95 { 106 {
107 Client = new GridClient();
108
109 Random = new Random(Environment.TickCount);// We do stuff randomly here
96 FirstName = firstName; 110 FirstName = firstName;
97 LastName = lastName; 111 LastName = lastName;
98 Name = string.Format("{0} {1}", FirstName, LastName); 112 Name = string.Format("{0} {1}", FirstName, LastName);
@@ -102,7 +116,8 @@ namespace pCampBot
102 BotManager = bm; 116 BotManager = bm;
103 startupConfig = bm.Config; 117 startupConfig = bm.Config;
104 readconfig(); 118 readconfig();
105 talkarray = readexcuses(); 119
120 Behaviours = behaviours;
106 } 121 }
107 122
108 //We do our actions here. This is where one would 123 //We do our actions here. This is where one would
@@ -110,34 +125,7 @@ namespace pCampBot
110 private void Action() 125 private void Action()
111 { 126 {
112 while (true) 127 while (true)
113 { 128 Behaviours.ForEach(b => b.Action(this));
114 int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number,
115 // the greater the bot's chances to walk instead of run.
116 client.Self.Jump(false);
117 if (walkorrun == 0)
118 {
119 client.Self.Movement.AlwaysRun = true;
120 }
121 else
122 {
123 client.Self.Movement.AlwaysRun = false;
124 }
125
126 // TODO: unused: Vector3 pos = client.Self.SimPosition;
127 Vector3 newpos = new Vector3(somthing.Next(1, 254), somthing.Next(1, 254), somthing.Next(1, 254));
128 client.Self.Movement.TurnToward(newpos);
129
130 client.Self.Movement.AtPos = true;
131 Thread.Sleep(somthing.Next(3000, 13000));
132 client.Self.Movement.AtPos = false;
133 client.Self.Jump(true);
134
135 string randomf = talkarray[somthing.Next(talkarray.Length)];
136 if (talkarray.Length > 1 && randomf.Length > 1)
137 client.Self.Chat(randomf, 0, ChatType.Normal);
138
139 Thread.Sleep(somthing.Next(1000, 10000));
140 }
141 } 129 }
142 130
143 /// <summary> 131 /// <summary>
@@ -145,7 +133,7 @@ namespace pCampBot
145 /// </summary> 133 /// </summary>
146 public void readconfig() 134 public void readconfig()
147 { 135 {
148 wear = startupConfig.GetString("wear","no"); 136 wear = startupConfig.GetString("wear", "no");
149 } 137 }
150 138
151 /// <summary> 139 /// <summary>
@@ -156,7 +144,7 @@ namespace pCampBot
156 if (m_actionThread != null) 144 if (m_actionThread != null)
157 m_actionThread.Abort(); 145 m_actionThread.Abort();
158 146
159 client.Network.Logout(); 147 Client.Network.Logout();
160 } 148 }
161 149
162 /// <summary> 150 /// <summary>
@@ -164,50 +152,50 @@ namespace pCampBot
164 /// </summary> 152 /// </summary>
165 public void startup() 153 public void startup()
166 { 154 {
167 client.Settings.LOGIN_SERVER = LoginUri; 155 Client.Settings.LOGIN_SERVER = LoginUri;
168 client.Settings.ALWAYS_DECODE_OBJECTS = false; 156 Client.Settings.ALWAYS_DECODE_OBJECTS = false;
169 client.Settings.AVATAR_TRACKING = false; 157 Client.Settings.AVATAR_TRACKING = false;
170 client.Settings.OBJECT_TRACKING = false; 158 Client.Settings.OBJECT_TRACKING = false;
171 client.Settings.SEND_AGENT_THROTTLE = true; 159 Client.Settings.SEND_AGENT_THROTTLE = true;
172 client.Settings.SEND_PINGS = true; 160 Client.Settings.SEND_PINGS = true;
173 client.Settings.STORE_LAND_PATCHES = false; 161 Client.Settings.STORE_LAND_PATCHES = false;
174 client.Settings.USE_ASSET_CACHE = false; 162 Client.Settings.USE_ASSET_CACHE = false;
175 client.Settings.MULTIPLE_SIMS = true; 163 Client.Settings.MULTIPLE_SIMS = true;
176 client.Throttle.Asset = 100000; 164 Client.Throttle.Asset = 100000;
177 client.Throttle.Land = 100000; 165 Client.Throttle.Land = 100000;
178 client.Throttle.Task = 100000; 166 Client.Throttle.Task = 100000;
179 client.Throttle.Texture = 100000; 167 Client.Throttle.Texture = 100000;
180 client.Throttle.Wind = 100000; 168 Client.Throttle.Wind = 100000;
181 client.Throttle.Total = 400000; 169 Client.Throttle.Total = 400000;
182 client.Network.LoginProgress += this.Network_LoginProgress; 170 Client.Network.LoginProgress += this.Network_LoginProgress;
183 client.Network.SimConnected += this.Network_SimConnected; 171 Client.Network.SimConnected += this.Network_SimConnected;
184 client.Network.Disconnected += this.Network_OnDisconnected; 172 Client.Network.Disconnected += this.Network_OnDisconnected;
185 client.Objects.ObjectUpdate += Objects_NewPrim; 173 Client.Objects.ObjectUpdate += Objects_NewPrim;
186 174
187 if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) 175 if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name"))
188 { 176 {
189 IsConnected = true; 177 IsConnected = true;
190 178
191 Thread.Sleep(somthing.Next(1000, 10000)); 179 Thread.Sleep(Random.Next(1000, 10000));
192 m_actionThread = new Thread(Action); 180 m_actionThread = new Thread(Action);
193 m_actionThread.Start(); 181 m_actionThread.Start();
194 182
195// OnConnected(this, EventType.CONNECTED); 183// OnConnected(this, EventType.CONNECTED);
196 if (wear == "save") 184 if (wear == "save")
197 { 185 {
198 client.Appearance.SetPreviousAppearance(); 186 Client.Appearance.SetPreviousAppearance();
199 SaveDefaultAppearance(); 187 SaveDefaultAppearance();
200 } 188 }
201 else if (wear != "no") 189 else if (wear != "no")
202 { 190 {
203 MakeDefaultAppearance(wear); 191 MakeDefaultAppearance(wear);
204 } 192 }
205 client.Self.Jump(true); 193 Client.Self.Jump(true);
206 } 194 }
207 else 195 else
208 { 196 {
209 MainConsole.Instance.OutputFormat( 197 MainConsole.Instance.OutputFormat(
210 "{0} {1} cannot login: {2}", FirstName, LastName, client.Network.LoginMessage); 198 "{0} {1} cannot login: {2}", FirstName, LastName, Client.Network.LoginMessage);
211 199
212 if (OnDisconnected != null) 200 if (OnDisconnected != null)
213 { 201 {
@@ -227,11 +215,11 @@ namespace pCampBot
227 Array wtypes = Enum.GetValues(typeof(WearableType)); 215 Array wtypes = Enum.GetValues(typeof(WearableType));
228 foreach (WearableType wtype in wtypes) 216 foreach (WearableType wtype in wtypes)
229 { 217 {
230 UUID wearable = client.Appearance.GetWearableAsset(wtype); 218 UUID wearable = Client.Appearance.GetWearableAsset(wtype);
231 if (wearable != UUID.Zero) 219 if (wearable != UUID.Zero)
232 { 220 {
233 client.Assets.RequestAsset(wearable, AssetType.Clothing, false, Asset_ReceivedCallback); 221 Client.Assets.RequestAsset(wearable, AssetType.Clothing, false, Asset_ReceivedCallback);
234 client.Assets.RequestAsset(wearable, AssetType.Bodypart, false, Asset_ReceivedCallback); 222 Client.Assets.RequestAsset(wearable, AssetType.Bodypart, false, Asset_ReceivedCallback);
235 } 223 }
236 } 224 }
237 } 225 }
@@ -306,11 +294,11 @@ namespace pCampBot
306 UUID assetID = UUID.Random(); 294 UUID assetID = UUID.Random();
307 AssetClothing asset = new AssetClothing(assetID, File.ReadAllBytes(clothing[i])); 295 AssetClothing asset = new AssetClothing(assetID, File.ReadAllBytes(clothing[i]));
308 asset.Decode(); 296 asset.Decode();
309 asset.Owner = client.Self.AgentID; 297 asset.Owner = Client.Self.AgentID;
310 asset.WearableType = GetWearableType(clothing[i]); 298 asset.WearableType = GetWearableType(clothing[i]);
311 asset.Encode(); 299 asset.Encode();
312 transid = client.Assets.RequestUpload(asset,true); 300 transid = Client.Assets.RequestUpload(asset,true);
313 client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing, 301 Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing,
314 transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) 302 transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item)
315 { 303 {
316 if (success) 304 if (success)
@@ -328,11 +316,11 @@ namespace pCampBot
328 UUID assetID = UUID.Random(); 316 UUID assetID = UUID.Random();
329 AssetBodypart asset = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i])); 317 AssetBodypart asset = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i]));
330 asset.Decode(); 318 asset.Decode();
331 asset.Owner = client.Self.AgentID; 319 asset.Owner = Client.Self.AgentID;
332 asset.WearableType = GetWearableType(bodyparts[i]); 320 asset.WearableType = GetWearableType(bodyparts[i]);
333 asset.Encode(); 321 asset.Encode();
334 transid = client.Assets.RequestUpload(asset,true); 322 transid = Client.Assets.RequestUpload(asset,true);
335 client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart, 323 Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart,
336 transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) 324 transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item)
337 { 325 {
338 if (success) 326 if (success)
@@ -352,7 +340,7 @@ namespace pCampBot
352 else 340 else
353 { 341 {
354 MainConsole.Instance.Output(String.Format("Sending {0} wearables...",listwearables.Count)); 342 MainConsole.Instance.Output(String.Format("Sending {0} wearables...",listwearables.Count));
355 client.Appearance.WearOutfit(listwearables, false); 343 Client.Appearance.WearOutfit(listwearables, false);
356 } 344 }
357 } 345 }
358 catch (Exception ex) 346 catch (Exception ex)
@@ -363,8 +351,8 @@ namespace pCampBot
363 351
364 public InventoryFolder FindClothingFolder() 352 public InventoryFolder FindClothingFolder()
365 { 353 {
366 UUID rootfolder = client.Inventory.Store.RootFolder.UUID; 354 UUID rootfolder = Client.Inventory.Store.RootFolder.UUID;
367 List<InventoryBase> listfolders = client.Inventory.Store.GetContents(rootfolder); 355 List<InventoryBase> listfolders = Client.Inventory.Store.GetContents(rootfolder);
368 InventoryFolder clothfolder = new InventoryFolder(UUID.Random()); 356 InventoryFolder clothfolder = new InventoryFolder(UUID.Random());
369 foreach (InventoryBase folder in listfolders) 357 foreach (InventoryBase folder in listfolders)
370 { 358 {
@@ -453,10 +441,9 @@ namespace pCampBot
453 return; 441 return;
454 442
455 BotManager.AssetsReceived[textureID] = false; 443 BotManager.AssetsReceived[textureID] = false;
456 client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); 444 Client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture);
457 } 445 }
458 } 446 }
459
460 447
461 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) 448 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
462 { 449 {
@@ -473,20 +460,5 @@ namespace pCampBot
473// SaveAsset((AssetWearable) asset); 460// SaveAsset((AssetWearable) asset);
474// } 461// }
475 } 462 }
476
477 public string[] readexcuses()
478 {
479 string allexcuses = "";
480
481 string file = Path.Combine(Util.configDir(), "pCampBotSentences.txt");
482 if (File.Exists(file))
483 {
484 StreamReader csr = File.OpenText(file);
485 allexcuses = csr.ReadToEnd();
486 csr.Close();
487 }
488
489 return allexcuses.Split(Environment.NewLine.ToCharArray());
490 }
491 } 463 }
492} 464}