diff options
Diffstat (limited to 'OpenSim/Tools/pCampBot/PhysicsBot.cs')
-rw-r--r-- | OpenSim/Tools/pCampBot/PhysicsBot.cs | 171 |
1 files changed, 114 insertions, 57 deletions
diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 5d4af31..a8b2426 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs | |||
@@ -29,56 +29,85 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Text; | 30 | using System.Text; |
31 | using System.IO; | 31 | using System.IO; |
32 | using System.Reflection; | ||
32 | using System.Threading; | 33 | using System.Threading; |
33 | using System.Timers; | 34 | using System.Timers; |
35 | using log4net; | ||
34 | using OpenMetaverse; | 36 | using OpenMetaverse; |
35 | using OpenMetaverse.Assets; | 37 | using OpenMetaverse.Assets; |
36 | using Nini.Config; | 38 | using Nini.Config; |
37 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Console; | 40 | using OpenSim.Framework.Console; |
39 | using Timer=System.Timers.Timer; | 41 | using Timer = System.Timers.Timer; |
40 | 42 | ||
41 | namespace pCampBot | 43 | namespace pCampBot |
42 | { | 44 | { |
43 | public class PhysicsBot | 45 | public class PhysicsBot |
44 | { | 46 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
45 | public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events | 49 | public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events |
46 | public IConfig startupConfig; // bot config, passed from BotManager | ||
47 | 50 | ||
48 | public string firstname; | 51 | public BotManager BotManager { get; private set; } |
49 | public string lastname; | 52 | private IConfig startupConfig; // bot config, passed from BotManager |
50 | public string password; | 53 | |
51 | public string loginURI; | 54 | /// <summary> |
55 | /// Is this bot connected to the grid? | ||
56 | /// </summary> | ||
57 | public bool IsConnected { get; private set; } | ||
58 | |||
59 | public string FirstName { get; private set; } | ||
60 | public string LastName { get; private set; } | ||
61 | public string Name { get; private set; } | ||
62 | public string Password { get; private set; } | ||
63 | public string LoginUri { get; private set; } | ||
52 | public string saveDir; | 64 | public string saveDir; |
53 | public string wear; | 65 | public string wear; |
54 | 66 | ||
55 | public event AnEvent OnConnected; | 67 | public event AnEvent OnConnected; |
56 | public event AnEvent OnDisconnected; | 68 | public event AnEvent OnDisconnected; |
57 | 69 | ||
58 | protected Timer m_action; // Action Timer | 70 | /// <summary> |
71 | /// Keep a track of the continuously acting thread so that we can abort it. | ||
72 | /// </summary> | ||
73 | private Thread m_actionThread; | ||
74 | |||
59 | protected List<uint> objectIDs = new List<uint>(); | 75 | protected List<uint> objectIDs = new List<uint>(); |
60 | 76 | ||
61 | protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here | 77 | protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here |
62 | 78 | ||
63 | //New instance of a SecondLife client | 79 | /// <summary> |
80 | /// New instance of a SecondLife client | ||
81 | /// </summary> | ||
64 | public GridClient client = new GridClient(); | 82 | public GridClient client = new GridClient(); |
65 | 83 | ||
66 | protected string[] talkarray; | 84 | protected string[] talkarray; |
85 | |||
67 | /// <summary> | 86 | /// <summary> |
68 | /// | 87 | /// Constructor |
69 | /// </summary> | 88 | /// </summary> |
70 | /// <param name="bsconfig">nini config for the bot</param> | 89 | /// <param name="bm"></param> |
71 | public PhysicsBot(IConfig bsconfig) | 90 | /// <param name="firstName"></param> |
91 | /// <param name="lastName"></param> | ||
92 | /// <param name="password"></param> | ||
93 | /// <param name="loginUri"></param> | ||
94 | public PhysicsBot(BotManager bm, string firstName, string lastName, string password, string loginUri) | ||
72 | { | 95 | { |
73 | startupConfig = bsconfig; | 96 | FirstName = firstName; |
97 | LastName = lastName; | ||
98 | Name = string.Format("{0} {1}", FirstName, LastName); | ||
99 | Password = password; | ||
100 | LoginUri = loginUri; | ||
101 | |||
102 | BotManager = bm; | ||
103 | startupConfig = bm.Config; | ||
74 | readconfig(); | 104 | readconfig(); |
75 | talkarray = readexcuses(); | 105 | talkarray = readexcuses(); |
76 | } | 106 | } |
77 | 107 | ||
78 | //We do our actions here. This is where one would | 108 | //We do our actions here. This is where one would |
79 | //add additional steps and/or things the bot should do | 109 | //add additional steps and/or things the bot should do |
80 | 110 | private void Action() | |
81 | void m_action_Elapsed(object sender, ElapsedEventArgs e) | ||
82 | { | 111 | { |
83 | while (true) | 112 | while (true) |
84 | { | 113 | { |
@@ -95,11 +124,11 @@ namespace pCampBot | |||
95 | } | 124 | } |
96 | 125 | ||
97 | // TODO: unused: Vector3 pos = client.Self.SimPosition; | 126 | // TODO: unused: Vector3 pos = client.Self.SimPosition; |
98 | Vector3 newpos = new Vector3(somthing.Next(255), somthing.Next(255), somthing.Next(255)); | 127 | Vector3 newpos = new Vector3(somthing.Next(1, 254), somthing.Next(1, 254), somthing.Next(1, 254)); |
99 | client.Self.Movement.TurnToward(newpos); | 128 | client.Self.Movement.TurnToward(newpos); |
100 | 129 | ||
101 | client.Self.Movement.AtPos = true; | 130 | client.Self.Movement.AtPos = true; |
102 | Thread.Sleep(somthing.Next(3000,13000)); | 131 | Thread.Sleep(somthing.Next(3000, 13000)); |
103 | client.Self.Movement.AtPos = false; | 132 | client.Self.Movement.AtPos = false; |
104 | client.Self.Jump(true); | 133 | client.Self.Jump(true); |
105 | 134 | ||
@@ -116,10 +145,6 @@ namespace pCampBot | |||
116 | /// </summary> | 145 | /// </summary> |
117 | public void readconfig() | 146 | public void readconfig() |
118 | { | 147 | { |
119 | firstname = startupConfig.GetString("firstname", "random"); | ||
120 | lastname = startupConfig.GetString("lastname", "random"); | ||
121 | password = startupConfig.GetString("password", "12345"); | ||
122 | loginURI = startupConfig.GetString("loginuri"); | ||
123 | wear = startupConfig.GetString("wear","no"); | 148 | wear = startupConfig.GetString("wear","no"); |
124 | } | 149 | } |
125 | 150 | ||
@@ -128,6 +153,9 @@ namespace pCampBot | |||
128 | /// </summary> | 153 | /// </summary> |
129 | public void shutdown() | 154 | public void shutdown() |
130 | { | 155 | { |
156 | if (m_actionThread != null) | ||
157 | m_actionThread.Abort(); | ||
158 | |||
131 | client.Network.Logout(); | 159 | client.Network.Logout(); |
132 | } | 160 | } |
133 | 161 | ||
@@ -136,7 +164,7 @@ namespace pCampBot | |||
136 | /// </summary> | 164 | /// </summary> |
137 | public void startup() | 165 | public void startup() |
138 | { | 166 | { |
139 | client.Settings.LOGIN_SERVER = loginURI; | 167 | client.Settings.LOGIN_SERVER = LoginUri; |
140 | client.Settings.ALWAYS_DECODE_OBJECTS = false; | 168 | client.Settings.ALWAYS_DECODE_OBJECTS = false; |
141 | client.Settings.AVATAR_TRACKING = false; | 169 | client.Settings.AVATAR_TRACKING = false; |
142 | client.Settings.OBJECT_TRACKING = false; | 170 | client.Settings.OBJECT_TRACKING = false; |
@@ -155,32 +183,32 @@ namespace pCampBot | |||
155 | client.Network.SimConnected += this.Network_SimConnected; | 183 | client.Network.SimConnected += this.Network_SimConnected; |
156 | client.Network.Disconnected += this.Network_OnDisconnected; | 184 | client.Network.Disconnected += this.Network_OnDisconnected; |
157 | client.Objects.ObjectUpdate += Objects_NewPrim; | 185 | client.Objects.ObjectUpdate += Objects_NewPrim; |
158 | //client.Assets.OnAssetReceived += Asset_ReceivedCallback; | 186 | |
159 | if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name")) | 187 | if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) |
160 | { | 188 | { |
161 | if (OnConnected != null) | 189 | IsConnected = true; |
190 | |||
191 | Thread.Sleep(somthing.Next(1000, 10000)); | ||
192 | m_actionThread = new Thread(Action); | ||
193 | m_actionThread.Start(); | ||
194 | |||
195 | // OnConnected(this, EventType.CONNECTED); | ||
196 | if (wear == "save") | ||
162 | { | 197 | { |
163 | m_action = new Timer(somthing.Next(1000, 10000)); | 198 | client.Appearance.SetPreviousAppearance(); |
164 | m_action.Enabled = true; | 199 | SaveDefaultAppearance(); |
165 | m_action.AutoReset = false; | 200 | } |
166 | m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed); | 201 | else if (wear != "no") |
167 | m_action.Start(); | 202 | { |
168 | OnConnected(this, EventType.CONNECTED); | 203 | MakeDefaultAppearance(wear); |
169 | if (wear == "save") | ||
170 | { | ||
171 | client.Appearance.SetPreviousAppearance(); | ||
172 | SaveDefaultAppearance(); | ||
173 | } | ||
174 | else if (wear != "no") | ||
175 | { | ||
176 | MakeDefaultAppearance(wear); | ||
177 | } | ||
178 | client.Self.Jump(true); | ||
179 | } | 204 | } |
205 | client.Self.Jump(true); | ||
180 | } | 206 | } |
181 | else | 207 | else |
182 | { | 208 | { |
183 | MainConsole.Instance.Output(firstname + " " + lastname + " Can't login: " + client.Network.LoginMessage); | 209 | MainConsole.Instance.OutputFormat( |
210 | "{0} {1} cannot login: {2}", FirstName, LastName, client.Network.LoginMessage); | ||
211 | |||
184 | if (OnDisconnected != null) | 212 | if (OnDisconnected != null) |
185 | { | 213 | { |
186 | OnDisconnected(this, EventType.DISCONNECTED); | 214 | OnDisconnected(this, EventType.DISCONNECTED); |
@@ -190,7 +218,7 @@ namespace pCampBot | |||
190 | 218 | ||
191 | public void SaveDefaultAppearance() | 219 | public void SaveDefaultAppearance() |
192 | { | 220 | { |
193 | saveDir = "MyAppearance/" + firstname + "_" + lastname; | 221 | saveDir = "MyAppearance/" + FirstName + "_" + LastName; |
194 | if (!Directory.Exists(saveDir)) | 222 | if (!Directory.Exists(saveDir)) |
195 | { | 223 | { |
196 | Directory.CreateDirectory(saveDir); | 224 | Directory.CreateDirectory(saveDir); |
@@ -216,7 +244,7 @@ namespace pCampBot | |||
216 | { | 244 | { |
217 | if (asset.Decode()) | 245 | if (asset.Decode()) |
218 | { | 246 | { |
219 | File.WriteAllBytes(Path.Combine(saveDir, String.Format("{1}.{0}", | 247 | File.WriteAllBytes(Path.Combine(saveDir, String.Format("{1}.{0}", |
220 | asset.AssetType.ToString().ToLower(), | 248 | asset.AssetType.ToString().ToLower(), |
221 | asset.WearableType)), asset.AssetData); | 249 | asset.WearableType)), asset.AssetData); |
222 | } | 250 | } |
@@ -366,8 +394,21 @@ namespace pCampBot | |||
366 | 394 | ||
367 | public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) | 395 | public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) |
368 | { | 396 | { |
369 | if (OnDisconnected != null) | 397 | // m_log.ErrorFormat("Fired Network_OnDisconnected"); |
398 | |||
399 | // if ( | ||
400 | // (args.Reason == NetworkManager.DisconnectType.SimShutdown | ||
401 | // || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) | ||
402 | // && OnDisconnected != null) | ||
403 | |||
404 | if ( | ||
405 | (args.Reason == NetworkManager.DisconnectType.ClientInitiated | ||
406 | || args.Reason == NetworkManager.DisconnectType.ServerInitiated | ||
407 | || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) | ||
408 | && OnDisconnected != null) | ||
409 | // if (OnDisconnected != null) | ||
370 | { | 410 | { |
411 | IsConnected = false; | ||
371 | OnDisconnected(this, EventType.DISCONNECTED); | 412 | OnDisconnected(this, EventType.DISCONNECTED); |
372 | } | 413 | } |
373 | } | 414 | } |
@@ -382,39 +423,55 @@ namespace pCampBot | |||
382 | { | 423 | { |
383 | if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) | 424 | if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) |
384 | { | 425 | { |
385 | client.Assets.RequestImage(prim.Textures.DefaultTexture.TextureID, ImageType.Normal, Asset_TextureCallback_Texture); | 426 | GetTexture(prim.Textures.DefaultTexture.TextureID); |
386 | } | 427 | } |
428 | |||
387 | for (int i = 0; i < prim.Textures.FaceTextures.Length; i++) | 429 | for (int i = 0; i < prim.Textures.FaceTextures.Length; i++) |
388 | { | 430 | { |
389 | if (prim.Textures.FaceTextures[i] != null) | 431 | UUID textureID = prim.Textures.FaceTextures[i].TextureID; |
390 | { | ||
391 | if (prim.Textures.FaceTextures[i].TextureID != UUID.Zero) | ||
392 | { | ||
393 | client.Assets.RequestImage(prim.Textures.FaceTextures[i].TextureID, ImageType.Normal, Asset_TextureCallback_Texture); | ||
394 | } | ||
395 | 432 | ||
433 | if (textureID != null && textureID != UUID.Zero) | ||
434 | { | ||
435 | GetTexture(textureID); | ||
396 | } | 436 | } |
397 | } | 437 | } |
398 | } | 438 | } |
439 | |||
399 | if (prim.Sculpt.SculptTexture != UUID.Zero) | 440 | if (prim.Sculpt.SculptTexture != UUID.Zero) |
400 | { | 441 | { |
401 | client.Assets.RequestImage(prim.Sculpt.SculptTexture, ImageType.Normal, Asset_TextureCallback_Texture); | 442 | GetTexture(prim.Sculpt.SculptTexture); |
402 | } | 443 | } |
403 | } | 444 | } |
404 | } | 445 | } |
405 | 446 | ||
447 | private void GetTexture(UUID textureID) | ||
448 | { | ||
449 | lock (BotManager.AssetsReceived) | ||
450 | { | ||
451 | // Don't request assets more than once. | ||
452 | if (BotManager.AssetsReceived.ContainsKey(textureID)) | ||
453 | return; | ||
454 | |||
455 | BotManager.AssetsReceived[textureID] = false; | ||
456 | client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); | ||
457 | } | ||
458 | } | ||
459 | |||
406 | 460 | ||
407 | public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) | 461 | public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) |
408 | { | 462 | { |
409 | //TODO: Implement texture saving and applying | 463 | //TODO: Implement texture saving and applying |
410 | } | 464 | } |
411 | 465 | ||
412 | public void Asset_ReceivedCallback(AssetDownload transfer,Asset asset) | 466 | public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset) |
413 | { | 467 | { |
414 | if (wear == "save") | 468 | lock (BotManager.AssetsReceived) |
415 | { | 469 | BotManager.AssetsReceived[asset.AssetID] = true; |
416 | SaveAsset((AssetWearable) asset); | 470 | |
417 | } | 471 | // if (wear == "save") |
472 | // { | ||
473 | // SaveAsset((AssetWearable) asset); | ||
474 | // } | ||
418 | } | 475 | } |
419 | 476 | ||
420 | public string[] readexcuses() | 477 | public string[] readexcuses() |