diff options
author | Melanie | 2011-11-04 01:18:37 +0000 |
---|---|---|
committer | Melanie | 2011-11-04 01:18:37 +0000 |
commit | 24235006f473cec56213705ce70df781cf9bcbc1 (patch) | |
tree | 7d0e75978d48272827c3f03f087bf79658dd16cf /OpenSim/Tools/pCampBot/Bot.cs | |
parent | Merge branch 'master' into bigmerge (diff) | |
parent | Rename ForEachAvatar back to ForEachScenePresence. The other changes (diff) | |
download | opensim-SC-24235006f473cec56213705ce70df781cf9bcbc1.zip opensim-SC-24235006f473cec56213705ce70df781cf9bcbc1.tar.gz opensim-SC-24235006f473cec56213705ce70df781cf9bcbc1.tar.bz2 opensim-SC-24235006f473cec56213705ce70df781cf9bcbc1.tar.xz |
Merge branch 'master' into bigmerge
Conflicts:
OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
OpenSim/Region/CoreModules/Avatar/Gods/GodsModule.cs
OpenSim/Region/CoreModules/LightShare/LightShareModule.cs
OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Tools/pCampBot/Bot.cs (renamed from OpenSim/Tools/pCampBot/PhysicsBot.cs) | 189 |
1 files changed, 95 insertions, 94 deletions
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/Bot.cs index a8b2426..1b30766 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs | |||
@@ -38,20 +38,45 @@ using OpenMetaverse.Assets; | |||
38 | using Nini.Config; | 38 | using Nini.Config; |
39 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
40 | using OpenSim.Framework.Console; | 40 | using OpenSim.Framework.Console; |
41 | using pCampBot.Interfaces; | ||
41 | using Timer = System.Timers.Timer; | 42 | using Timer = System.Timers.Timer; |
42 | 43 | ||
43 | namespace pCampBot | 44 | namespace pCampBot |
44 | { | 45 | { |
45 | public class PhysicsBot | 46 | public class Bot |
46 | { | 47 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 49 | ||
49 | public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events | 50 | public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events |
50 | 51 | ||
51 | public BotManager BotManager { get; private set; } | 52 | public BotManager BotManager { get; private set; } |
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 | /// <remarks> | ||
59 | /// Lock this list before manipulating it. | ||
60 | /// </remarks> | ||
61 | public List<IBehaviour> Behaviours { get; private set; } | ||
62 | |||
63 | /// <summary> | ||
64 | /// Objects that the bot has discovered. | ||
65 | /// </summary> | ||
66 | /// <remarks> | ||
67 | /// Returns a list copy. Inserting new objects manually will have no effect. | ||
68 | /// </remarks> | ||
69 | public Dictionary<UUID, Primitive> Objects | ||
70 | { | ||
71 | get | ||
72 | { | ||
73 | lock (m_objects) | ||
74 | return new Dictionary<UUID, Primitive>(m_objects); | ||
75 | } | ||
76 | } | ||
77 | private Dictionary<UUID, Primitive> m_objects = new Dictionary<UUID, Primitive>(); | ||
78 | |||
79 | /// <summary> | ||
55 | /// Is this bot connected to the grid? | 80 | /// Is this bot connected to the grid? |
56 | /// </summary> | 81 | /// </summary> |
57 | public bool IsConnected { get; private set; } | 82 | public bool IsConnected { get; private set; } |
@@ -74,25 +99,33 @@ namespace pCampBot | |||
74 | 99 | ||
75 | protected List<uint> objectIDs = new List<uint>(); | 100 | protected List<uint> objectIDs = new List<uint>(); |
76 | 101 | ||
77 | protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here | 102 | /// <summary> |
103 | /// Random number generator. | ||
104 | /// </summary> | ||
105 | public Random Random { get; private set; } | ||
78 | 106 | ||
79 | /// <summary> | 107 | /// <summary> |
80 | /// New instance of a SecondLife client | 108 | /// New instance of a SecondLife client |
81 | /// </summary> | 109 | /// </summary> |
82 | public GridClient client = new GridClient(); | 110 | public GridClient Client { get; private set; } |
83 | |||
84 | protected string[] talkarray; | ||
85 | 111 | ||
86 | /// <summary> | 112 | /// <summary> |
87 | /// Constructor | 113 | /// Constructor |
88 | /// </summary> | 114 | /// </summary> |
89 | /// <param name="bm"></param> | 115 | /// <param name="bm"></param> |
116 | /// <param name="behaviours">Behaviours for this bot to perform</param> | ||
90 | /// <param name="firstName"></param> | 117 | /// <param name="firstName"></param> |
91 | /// <param name="lastName"></param> | 118 | /// <param name="lastName"></param> |
92 | /// <param name="password"></param> | 119 | /// <param name="password"></param> |
93 | /// <param name="loginUri"></param> | 120 | /// <param name="loginUri"></param> |
94 | public PhysicsBot(BotManager bm, string firstName, string lastName, string password, string loginUri) | 121 | /// <param name="behaviours"></param> |
122 | public Bot( | ||
123 | BotManager bm, List<IBehaviour> behaviours, | ||
124 | string firstName, string lastName, string password, string loginUri) | ||
95 | { | 125 | { |
126 | Client = new GridClient(); | ||
127 | |||
128 | Random = new Random(Environment.TickCount);// We do stuff randomly here | ||
96 | FirstName = firstName; | 129 | FirstName = firstName; |
97 | LastName = lastName; | 130 | LastName = lastName; |
98 | Name = string.Format("{0} {1}", FirstName, LastName); | 131 | Name = string.Format("{0} {1}", FirstName, LastName); |
@@ -102,7 +135,8 @@ namespace pCampBot | |||
102 | BotManager = bm; | 135 | BotManager = bm; |
103 | startupConfig = bm.Config; | 136 | startupConfig = bm.Config; |
104 | readconfig(); | 137 | readconfig(); |
105 | talkarray = readexcuses(); | 138 | |
139 | Behaviours = behaviours; | ||
106 | } | 140 | } |
107 | 141 | ||
108 | //We do our actions here. This is where one would | 142 | //We do our actions here. This is where one would |
@@ -110,34 +144,16 @@ namespace pCampBot | |||
110 | private void Action() | 144 | private void Action() |
111 | { | 145 | { |
112 | while (true) | 146 | while (true) |
113 | { | 147 | lock (Behaviours) |
114 | int walkorrun = somthing.Next(4); // Randomize between walking and running. The greater this number, | 148 | Behaviours.ForEach( |
115 | // the greater the bot's chances to walk instead of run. | 149 | b => |
116 | client.Self.Jump(false); | 150 | { |
117 | if (walkorrun == 0) | 151 | // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); |
118 | { | 152 | b.Action(this); |
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 | 153 | ||
139 | Thread.Sleep(somthing.Next(1000, 10000)); | 154 | Thread.Sleep(Random.Next(1000, 10000)); |
140 | } | 155 | } |
156 | ); | ||
141 | } | 157 | } |
142 | 158 | ||
143 | /// <summary> | 159 | /// <summary> |
@@ -145,7 +161,7 @@ namespace pCampBot | |||
145 | /// </summary> | 161 | /// </summary> |
146 | public void readconfig() | 162 | public void readconfig() |
147 | { | 163 | { |
148 | wear = startupConfig.GetString("wear","no"); | 164 | wear = startupConfig.GetString("wear", "no"); |
149 | } | 165 | } |
150 | 166 | ||
151 | /// <summary> | 167 | /// <summary> |
@@ -156,7 +172,7 @@ namespace pCampBot | |||
156 | if (m_actionThread != null) | 172 | if (m_actionThread != null) |
157 | m_actionThread.Abort(); | 173 | m_actionThread.Abort(); |
158 | 174 | ||
159 | client.Network.Logout(); | 175 | Client.Network.Logout(); |
160 | } | 176 | } |
161 | 177 | ||
162 | /// <summary> | 178 | /// <summary> |
@@ -164,50 +180,50 @@ namespace pCampBot | |||
164 | /// </summary> | 180 | /// </summary> |
165 | public void startup() | 181 | public void startup() |
166 | { | 182 | { |
167 | client.Settings.LOGIN_SERVER = LoginUri; | 183 | Client.Settings.LOGIN_SERVER = LoginUri; |
168 | client.Settings.ALWAYS_DECODE_OBJECTS = false; | 184 | Client.Settings.ALWAYS_DECODE_OBJECTS = false; |
169 | client.Settings.AVATAR_TRACKING = false; | 185 | Client.Settings.AVATAR_TRACKING = false; |
170 | client.Settings.OBJECT_TRACKING = false; | 186 | Client.Settings.OBJECT_TRACKING = false; |
171 | client.Settings.SEND_AGENT_THROTTLE = true; | 187 | Client.Settings.SEND_AGENT_THROTTLE = true; |
172 | client.Settings.SEND_PINGS = true; | 188 | Client.Settings.SEND_PINGS = true; |
173 | client.Settings.STORE_LAND_PATCHES = false; | 189 | Client.Settings.STORE_LAND_PATCHES = false; |
174 | client.Settings.USE_ASSET_CACHE = false; | 190 | Client.Settings.USE_ASSET_CACHE = false; |
175 | client.Settings.MULTIPLE_SIMS = true; | 191 | Client.Settings.MULTIPLE_SIMS = true; |
176 | client.Throttle.Asset = 100000; | 192 | Client.Throttle.Asset = 100000; |
177 | client.Throttle.Land = 100000; | 193 | Client.Throttle.Land = 100000; |
178 | client.Throttle.Task = 100000; | 194 | Client.Throttle.Task = 100000; |
179 | client.Throttle.Texture = 100000; | 195 | Client.Throttle.Texture = 100000; |
180 | client.Throttle.Wind = 100000; | 196 | Client.Throttle.Wind = 100000; |
181 | client.Throttle.Total = 400000; | 197 | Client.Throttle.Total = 400000; |
182 | client.Network.LoginProgress += this.Network_LoginProgress; | 198 | Client.Network.LoginProgress += this.Network_LoginProgress; |
183 | client.Network.SimConnected += this.Network_SimConnected; | 199 | Client.Network.SimConnected += this.Network_SimConnected; |
184 | client.Network.Disconnected += this.Network_OnDisconnected; | 200 | Client.Network.Disconnected += this.Network_OnDisconnected; |
185 | client.Objects.ObjectUpdate += Objects_NewPrim; | 201 | Client.Objects.ObjectUpdate += Objects_NewPrim; |
186 | 202 | ||
187 | if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) | 203 | if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) |
188 | { | 204 | { |
189 | IsConnected = true; | 205 | IsConnected = true; |
190 | 206 | ||
191 | Thread.Sleep(somthing.Next(1000, 10000)); | 207 | Thread.Sleep(Random.Next(1000, 10000)); |
192 | m_actionThread = new Thread(Action); | 208 | m_actionThread = new Thread(Action); |
193 | m_actionThread.Start(); | 209 | m_actionThread.Start(); |
194 | 210 | ||
195 | // OnConnected(this, EventType.CONNECTED); | 211 | // OnConnected(this, EventType.CONNECTED); |
196 | if (wear == "save") | 212 | if (wear == "save") |
197 | { | 213 | { |
198 | client.Appearance.SetPreviousAppearance(); | 214 | Client.Appearance.SetPreviousAppearance(); |
199 | SaveDefaultAppearance(); | 215 | SaveDefaultAppearance(); |
200 | } | 216 | } |
201 | else if (wear != "no") | 217 | else if (wear != "no") |
202 | { | 218 | { |
203 | MakeDefaultAppearance(wear); | 219 | MakeDefaultAppearance(wear); |
204 | } | 220 | } |
205 | client.Self.Jump(true); | 221 | Client.Self.Jump(true); |
206 | } | 222 | } |
207 | else | 223 | else |
208 | { | 224 | { |
209 | MainConsole.Instance.OutputFormat( | 225 | MainConsole.Instance.OutputFormat( |
210 | "{0} {1} cannot login: {2}", FirstName, LastName, client.Network.LoginMessage); | 226 | "{0} {1} cannot login: {2}", FirstName, LastName, Client.Network.LoginMessage); |
211 | 227 | ||
212 | if (OnDisconnected != null) | 228 | if (OnDisconnected != null) |
213 | { | 229 | { |
@@ -227,11 +243,11 @@ namespace pCampBot | |||
227 | Array wtypes = Enum.GetValues(typeof(WearableType)); | 243 | Array wtypes = Enum.GetValues(typeof(WearableType)); |
228 | foreach (WearableType wtype in wtypes) | 244 | foreach (WearableType wtype in wtypes) |
229 | { | 245 | { |
230 | UUID wearable = client.Appearance.GetWearableAsset(wtype); | 246 | UUID wearable = Client.Appearance.GetWearableAsset(wtype); |
231 | if (wearable != UUID.Zero) | 247 | if (wearable != UUID.Zero) |
232 | { | 248 | { |
233 | client.Assets.RequestAsset(wearable, AssetType.Clothing, false, Asset_ReceivedCallback); | 249 | Client.Assets.RequestAsset(wearable, AssetType.Clothing, false, Asset_ReceivedCallback); |
234 | client.Assets.RequestAsset(wearable, AssetType.Bodypart, false, Asset_ReceivedCallback); | 250 | Client.Assets.RequestAsset(wearable, AssetType.Bodypart, false, Asset_ReceivedCallback); |
235 | } | 251 | } |
236 | } | 252 | } |
237 | } | 253 | } |
@@ -306,11 +322,11 @@ namespace pCampBot | |||
306 | UUID assetID = UUID.Random(); | 322 | UUID assetID = UUID.Random(); |
307 | AssetClothing asset = new AssetClothing(assetID, File.ReadAllBytes(clothing[i])); | 323 | AssetClothing asset = new AssetClothing(assetID, File.ReadAllBytes(clothing[i])); |
308 | asset.Decode(); | 324 | asset.Decode(); |
309 | asset.Owner = client.Self.AgentID; | 325 | asset.Owner = Client.Self.AgentID; |
310 | asset.WearableType = GetWearableType(clothing[i]); | 326 | asset.WearableType = GetWearableType(clothing[i]); |
311 | asset.Encode(); | 327 | asset.Encode(); |
312 | transid = client.Assets.RequestUpload(asset,true); | 328 | transid = Client.Assets.RequestUpload(asset,true); |
313 | client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing, | 329 | Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing, |
314 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) | 330 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) |
315 | { | 331 | { |
316 | if (success) | 332 | if (success) |
@@ -328,11 +344,11 @@ namespace pCampBot | |||
328 | UUID assetID = UUID.Random(); | 344 | UUID assetID = UUID.Random(); |
329 | AssetBodypart asset = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i])); | 345 | AssetBodypart asset = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i])); |
330 | asset.Decode(); | 346 | asset.Decode(); |
331 | asset.Owner = client.Self.AgentID; | 347 | asset.Owner = Client.Self.AgentID; |
332 | asset.WearableType = GetWearableType(bodyparts[i]); | 348 | asset.WearableType = GetWearableType(bodyparts[i]); |
333 | asset.Encode(); | 349 | asset.Encode(); |
334 | transid = client.Assets.RequestUpload(asset,true); | 350 | transid = Client.Assets.RequestUpload(asset,true); |
335 | client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart, | 351 | Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart, |
336 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) | 352 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) |
337 | { | 353 | { |
338 | if (success) | 354 | if (success) |
@@ -352,7 +368,7 @@ namespace pCampBot | |||
352 | else | 368 | else |
353 | { | 369 | { |
354 | MainConsole.Instance.Output(String.Format("Sending {0} wearables...",listwearables.Count)); | 370 | MainConsole.Instance.Output(String.Format("Sending {0} wearables...",listwearables.Count)); |
355 | client.Appearance.WearOutfit(listwearables, false); | 371 | Client.Appearance.WearOutfit(listwearables, false); |
356 | } | 372 | } |
357 | } | 373 | } |
358 | catch (Exception ex) | 374 | catch (Exception ex) |
@@ -363,8 +379,8 @@ namespace pCampBot | |||
363 | 379 | ||
364 | public InventoryFolder FindClothingFolder() | 380 | public InventoryFolder FindClothingFolder() |
365 | { | 381 | { |
366 | UUID rootfolder = client.Inventory.Store.RootFolder.UUID; | 382 | UUID rootfolder = Client.Inventory.Store.RootFolder.UUID; |
367 | List<InventoryBase> listfolders = client.Inventory.Store.GetContents(rootfolder); | 383 | List<InventoryBase> listfolders = Client.Inventory.Store.GetContents(rootfolder); |
368 | InventoryFolder clothfolder = new InventoryFolder(UUID.Random()); | 384 | InventoryFolder clothfolder = new InventoryFolder(UUID.Random()); |
369 | foreach (InventoryBase folder in listfolders) | 385 | foreach (InventoryBase folder in listfolders) |
370 | { | 386 | { |
@@ -419,6 +435,9 @@ namespace pCampBot | |||
419 | 435 | ||
420 | if (prim != null) | 436 | if (prim != null) |
421 | { | 437 | { |
438 | lock (m_objects) | ||
439 | m_objects[prim.ID] = prim; | ||
440 | |||
422 | if (prim.Textures != null) | 441 | if (prim.Textures != null) |
423 | { | 442 | { |
424 | if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) | 443 | if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) |
@@ -430,10 +449,8 @@ namespace pCampBot | |||
430 | { | 449 | { |
431 | UUID textureID = prim.Textures.FaceTextures[i].TextureID; | 450 | UUID textureID = prim.Textures.FaceTextures[i].TextureID; |
432 | 451 | ||
433 | if (textureID != null && textureID != UUID.Zero) | 452 | if (textureID != UUID.Zero) |
434 | { | ||
435 | GetTexture(textureID); | 453 | GetTexture(textureID); |
436 | } | ||
437 | } | 454 | } |
438 | } | 455 | } |
439 | 456 | ||
@@ -453,10 +470,9 @@ namespace pCampBot | |||
453 | return; | 470 | return; |
454 | 471 | ||
455 | BotManager.AssetsReceived[textureID] = false; | 472 | BotManager.AssetsReceived[textureID] = false; |
456 | client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); | 473 | Client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); |
457 | } | 474 | } |
458 | } | 475 | } |
459 | |||
460 | 476 | ||
461 | public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) | 477 | public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) |
462 | { | 478 | { |
@@ -473,20 +489,5 @@ namespace pCampBot | |||
473 | // SaveAsset((AssetWearable) asset); | 489 | // SaveAsset((AssetWearable) asset); |
474 | // } | 490 | // } |
475 | } | 491 | } |
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 | } | 492 | } |
492 | } | 493 | } |