diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Tools/pCampBot/Bot.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Tools/pCampBot/Bot.cs | 348 |
1 files changed, 274 insertions, 74 deletions
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index daaa3c0..4f28733 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs | |||
@@ -35,11 +35,13 @@ using System.Timers; | |||
35 | using log4net; | 35 | using log4net; |
36 | using OpenMetaverse; | 36 | using OpenMetaverse; |
37 | using OpenMetaverse.Assets; | 37 | using OpenMetaverse.Assets; |
38 | using OpenMetaverse.Packets; | ||
38 | using Nini.Config; | 39 | using Nini.Config; |
39 | using OpenSim.Framework; | 40 | using OpenSim.Framework; |
40 | using OpenSim.Framework.Console; | 41 | using OpenSim.Framework.Console; |
41 | using pCampBot.Interfaces; | 42 | using pCampBot.Interfaces; |
42 | using Timer = System.Timers.Timer; | 43 | using Timer = System.Timers.Timer; |
44 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
43 | 45 | ||
44 | namespace pCampBot | 46 | namespace pCampBot |
45 | { | 47 | { |
@@ -55,25 +57,47 @@ namespace pCampBot | |||
55 | { | 57 | { |
56 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 58 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
57 | 59 | ||
60 | public int PacketDebugLevel | ||
61 | { | ||
62 | get { return m_packetDebugLevel; } | ||
63 | set | ||
64 | { | ||
65 | if (value == m_packetDebugLevel) | ||
66 | return; | ||
67 | |||
68 | m_packetDebugLevel = value; | ||
69 | |||
70 | if (Client != null) | ||
71 | { | ||
72 | if (m_packetDebugLevel <= 0) | ||
73 | Client.Network.UnregisterCallback(PacketType.Default, PacketReceivedDebugHandler); | ||
74 | else | ||
75 | Client.Network.RegisterCallback(PacketType.Default, PacketReceivedDebugHandler, false); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | private int m_packetDebugLevel; | ||
80 | |||
58 | public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events | 81 | public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events |
59 | 82 | ||
60 | /// <summary> | 83 | /// <summary> |
61 | /// Bot manager. | 84 | /// Controls whether bots request textures for the object information they receive |
62 | /// </summary> | 85 | /// </summary> |
63 | public BotManager Manager { get; private set; } | 86 | public bool RequestObjectTextures { get; set; } |
64 | 87 | ||
65 | /// <summary> | 88 | /// <summary> |
66 | /// Bot config, passed from BotManager. | 89 | /// Bot manager. |
67 | /// </summary> | 90 | /// </summary> |
68 | private IConfig startupConfig; | 91 | public BotManager Manager { get; private set; } |
69 | 92 | ||
70 | /// <summary> | 93 | /// <summary> |
71 | /// Behaviours implemented by this bot. | 94 | /// Behaviours implemented by this bot. |
72 | /// </summary> | 95 | /// </summary> |
73 | /// <remarks> | 96 | /// <remarks> |
74 | /// Lock this list before manipulating it. | 97 | /// Indexed by abbreviated name. There can only be one instance of a particular behaviour. |
98 | /// Lock this structure before manipulating it. | ||
75 | /// </remarks> | 99 | /// </remarks> |
76 | public List<IBehaviour> Behaviours { get; private set; } | 100 | public Dictionary<string, IBehaviour> Behaviours { get; private set; } |
77 | 101 | ||
78 | /// <summary> | 102 | /// <summary> |
79 | /// Objects that the bot has discovered. | 103 | /// Objects that the bot has discovered. |
@@ -96,11 +120,35 @@ namespace pCampBot | |||
96 | /// </summary> | 120 | /// </summary> |
97 | public ConnectionState ConnectionState { get; private set; } | 121 | public ConnectionState ConnectionState { get; private set; } |
98 | 122 | ||
123 | public List<Simulator> Simulators | ||
124 | { | ||
125 | get | ||
126 | { | ||
127 | lock (Client.Network.Simulators) | ||
128 | return new List<Simulator>(Client.Network.Simulators); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | /// <summary> | ||
133 | /// The number of connections that this bot has to different simulators. | ||
134 | /// </summary> | ||
135 | /// <value>Includes both root and child connections.</value> | ||
136 | public int SimulatorsCount | ||
137 | { | ||
138 | get | ||
139 | { | ||
140 | lock (Client.Network.Simulators) | ||
141 | return Client.Network.Simulators.Count; | ||
142 | } | ||
143 | } | ||
144 | |||
99 | public string FirstName { get; private set; } | 145 | public string FirstName { get; private set; } |
100 | public string LastName { get; private set; } | 146 | public string LastName { get; private set; } |
101 | public string Name { get; private set; } | 147 | public string Name { get; private set; } |
102 | public string Password { get; private set; } | 148 | public string Password { get; private set; } |
103 | public string LoginUri { get; private set; } | 149 | public string LoginUri { get; private set; } |
150 | public string StartLocation { get; private set; } | ||
151 | |||
104 | public string saveDir; | 152 | public string saveDir; |
105 | public string wear; | 153 | public string wear; |
106 | 154 | ||
@@ -136,94 +184,180 @@ namespace pCampBot | |||
136 | /// <param name="behaviours"></param> | 184 | /// <param name="behaviours"></param> |
137 | public Bot( | 185 | public Bot( |
138 | BotManager bm, List<IBehaviour> behaviours, | 186 | BotManager bm, List<IBehaviour> behaviours, |
139 | string firstName, string lastName, string password, string loginUri) | 187 | string firstName, string lastName, string password, string startLocation, string loginUri) |
140 | { | 188 | { |
141 | ConnectionState = ConnectionState.Disconnected; | 189 | ConnectionState = ConnectionState.Disconnected; |
142 | 190 | ||
143 | behaviours.ForEach(b => b.Initialize(this)); | 191 | Random = new Random(bm.Rng.Next()); |
144 | |||
145 | Client = new GridClient(); | ||
146 | |||
147 | Random = new Random(Environment.TickCount);// We do stuff randomly here | ||
148 | FirstName = firstName; | 192 | FirstName = firstName; |
149 | LastName = lastName; | 193 | LastName = lastName; |
150 | Name = string.Format("{0} {1}", FirstName, LastName); | 194 | Name = string.Format("{0} {1}", FirstName, LastName); |
151 | Password = password; | 195 | Password = password; |
152 | LoginUri = loginUri; | 196 | LoginUri = loginUri; |
197 | StartLocation = startLocation; | ||
153 | 198 | ||
154 | Manager = bm; | 199 | Manager = bm; |
155 | startupConfig = bm.Config; | ||
156 | readconfig(); | ||
157 | 200 | ||
158 | Behaviours = behaviours; | 201 | Behaviours = new Dictionary<string, IBehaviour>(); |
202 | foreach (IBehaviour behaviour in behaviours) | ||
203 | AddBehaviour(behaviour); | ||
204 | |||
205 | // Only calling for use as a template. | ||
206 | CreateLibOmvClient(); | ||
207 | } | ||
208 | |||
209 | public bool TryGetBehaviour(string abbreviatedName, out IBehaviour behaviour) | ||
210 | { | ||
211 | lock (Behaviours) | ||
212 | return Behaviours.TryGetValue(abbreviatedName, out behaviour); | ||
213 | } | ||
214 | |||
215 | public bool AddBehaviour(IBehaviour behaviour) | ||
216 | { | ||
217 | Dictionary<string, IBehaviour> updatedBehaviours = new Dictionary<string, IBehaviour>(Behaviours); | ||
218 | |||
219 | if (!updatedBehaviours.ContainsKey(behaviour.AbbreviatedName)) | ||
220 | { | ||
221 | behaviour.Initialize(this); | ||
222 | updatedBehaviours.Add(behaviour.AbbreviatedName, behaviour); | ||
223 | Behaviours = updatedBehaviours; | ||
224 | |||
225 | return true; | ||
226 | } | ||
227 | |||
228 | return false; | ||
229 | } | ||
230 | |||
231 | public bool RemoveBehaviour(string abbreviatedName) | ||
232 | { | ||
233 | if (Behaviours.Count <= 0) | ||
234 | return false; | ||
235 | |||
236 | Dictionary<string, IBehaviour> updatedBehaviours = new Dictionary<string, IBehaviour>(Behaviours); | ||
237 | IBehaviour behaviour; | ||
238 | |||
239 | if (!updatedBehaviours.TryGetValue(abbreviatedName, out behaviour)) | ||
240 | return false; | ||
241 | |||
242 | updatedBehaviours.Remove(abbreviatedName); | ||
243 | Behaviours = updatedBehaviours; | ||
244 | |||
245 | behaviour.Close(); | ||
246 | |||
247 | return true; | ||
248 | } | ||
249 | |||
250 | private void CreateLibOmvClient() | ||
251 | { | ||
252 | GridClient newClient = new GridClient(); | ||
253 | |||
254 | if (Client != null) | ||
255 | { | ||
256 | // Remove any registered debug handlers | ||
257 | Client.Network.UnregisterCallback(PacketType.Default, PacketReceivedDebugHandler); | ||
258 | |||
259 | newClient.Settings.LOGIN_SERVER = Client.Settings.LOGIN_SERVER; | ||
260 | newClient.Settings.ALWAYS_DECODE_OBJECTS = Client.Settings.ALWAYS_DECODE_OBJECTS; | ||
261 | newClient.Settings.AVATAR_TRACKING = Client.Settings.AVATAR_TRACKING; | ||
262 | newClient.Settings.OBJECT_TRACKING = Client.Settings.OBJECT_TRACKING; | ||
263 | newClient.Settings.SEND_AGENT_THROTTLE = Client.Settings.SEND_AGENT_THROTTLE; | ||
264 | newClient.Settings.SEND_AGENT_UPDATES = Client.Settings.SEND_AGENT_UPDATES; | ||
265 | newClient.Settings.SEND_PINGS = Client.Settings.SEND_PINGS; | ||
266 | newClient.Settings.STORE_LAND_PATCHES = Client.Settings.STORE_LAND_PATCHES; | ||
267 | newClient.Settings.USE_ASSET_CACHE = Client.Settings.USE_ASSET_CACHE; | ||
268 | newClient.Settings.MULTIPLE_SIMS = Client.Settings.MULTIPLE_SIMS; | ||
269 | newClient.Throttle.Asset = Client.Throttle.Asset; | ||
270 | newClient.Throttle.Land = Client.Throttle.Land; | ||
271 | newClient.Throttle.Task = Client.Throttle.Task; | ||
272 | newClient.Throttle.Texture = Client.Throttle.Texture; | ||
273 | newClient.Throttle.Wind = Client.Throttle.Wind; | ||
274 | newClient.Throttle.Total = Client.Throttle.Total; | ||
275 | } | ||
276 | else | ||
277 | { | ||
278 | newClient.Settings.LOGIN_SERVER = LoginUri; | ||
279 | newClient.Settings.ALWAYS_DECODE_OBJECTS = false; | ||
280 | newClient.Settings.AVATAR_TRACKING = false; | ||
281 | newClient.Settings.OBJECT_TRACKING = false; | ||
282 | newClient.Settings.SEND_AGENT_THROTTLE = true; | ||
283 | newClient.Settings.SEND_PINGS = true; | ||
284 | newClient.Settings.STORE_LAND_PATCHES = false; | ||
285 | newClient.Settings.USE_ASSET_CACHE = false; | ||
286 | newClient.Settings.MULTIPLE_SIMS = true; | ||
287 | newClient.Throttle.Asset = 100000; | ||
288 | newClient.Throttle.Land = 100000; | ||
289 | newClient.Throttle.Task = 100000; | ||
290 | newClient.Throttle.Texture = 100000; | ||
291 | newClient.Throttle.Wind = 100000; | ||
292 | newClient.Throttle.Total = 400000; | ||
293 | } | ||
294 | |||
295 | newClient.Network.LoginProgress += Network_LoginProgress; | ||
296 | newClient.Network.SimConnected += Network_SimConnected; | ||
297 | newClient.Network.SimDisconnected += Network_SimDisconnected; | ||
298 | newClient.Network.Disconnected += Network_OnDisconnected; | ||
299 | newClient.Objects.ObjectUpdate += Objects_NewPrim; | ||
300 | |||
301 | if (m_packetDebugLevel > 0) | ||
302 | newClient.Network.RegisterCallback(PacketType.Default, PacketReceivedDebugHandler); | ||
303 | |||
304 | Client = newClient; | ||
159 | } | 305 | } |
160 | 306 | ||
161 | //We do our actions here. This is where one would | 307 | //We do our actions here. This is where one would |
162 | //add additional steps and/or things the bot should do | 308 | //add additional steps and/or things the bot should do |
163 | private void Action() | 309 | private void Action() |
164 | { | 310 | { |
165 | while (true) | 311 | while (ConnectionState == ConnectionState.Connected) |
166 | lock (Behaviours) | 312 | { |
167 | Behaviours.ForEach( | 313 | foreach (IBehaviour behaviour in Behaviours.Values) |
168 | b => | 314 | { |
169 | { | 315 | // Thread.Sleep(Random.Next(3000, 10000)); |
170 | Thread.Sleep(Random.Next(3000, 10000)); | 316 | |
171 | 317 | // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); | |
172 | // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); | 318 | behaviour.Action(); |
173 | b.Action(); | 319 | } |
174 | } | 320 | } |
175 | ); | ||
176 | } | ||
177 | 321 | ||
178 | /// <summary> | 322 | foreach (IBehaviour b in Behaviours.Values) |
179 | /// Read the Nini config and initialize | 323 | b.Close(); |
180 | /// </summary> | ||
181 | public void readconfig() | ||
182 | { | ||
183 | wear = startupConfig.GetString("wear", "no"); | ||
184 | } | 324 | } |
185 | 325 | ||
186 | /// <summary> | 326 | /// <summary> |
187 | /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. | 327 | /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. |
188 | /// </summary> | 328 | /// </summary> |
189 | public void shutdown() | 329 | public void Disconnect() |
190 | { | 330 | { |
191 | ConnectionState = ConnectionState.Disconnecting; | 331 | ConnectionState = ConnectionState.Disconnecting; |
192 | 332 | ||
193 | if (m_actionThread != null) | 333 | foreach (IBehaviour behaviour in Behaviours.Values) |
194 | m_actionThread.Abort(); | 334 | behaviour.Close(); |
195 | 335 | ||
196 | Client.Network.Logout(); | 336 | Client.Network.Logout(); |
197 | } | 337 | } |
198 | 338 | ||
339 | public void Connect() | ||
340 | { | ||
341 | Thread connectThread = new Thread(ConnectInternal); | ||
342 | connectThread.Name = Name; | ||
343 | connectThread.IsBackground = true; | ||
344 | |||
345 | connectThread.Start(); | ||
346 | } | ||
347 | |||
199 | /// <summary> | 348 | /// <summary> |
200 | /// This is the bot startup loop. | 349 | /// This is the bot startup loop. |
201 | /// </summary> | 350 | /// </summary> |
202 | public void startup() | 351 | private void ConnectInternal() |
203 | { | 352 | { |
204 | Client.Settings.LOGIN_SERVER = LoginUri; | ||
205 | Client.Settings.ALWAYS_DECODE_OBJECTS = false; | ||
206 | Client.Settings.AVATAR_TRACKING = false; | ||
207 | Client.Settings.OBJECT_TRACKING = false; | ||
208 | Client.Settings.SEND_AGENT_THROTTLE = true; | ||
209 | Client.Settings.SEND_PINGS = true; | ||
210 | Client.Settings.STORE_LAND_PATCHES = false; | ||
211 | Client.Settings.USE_ASSET_CACHE = false; | ||
212 | Client.Settings.MULTIPLE_SIMS = true; | ||
213 | Client.Throttle.Asset = 100000; | ||
214 | Client.Throttle.Land = 100000; | ||
215 | Client.Throttle.Task = 100000; | ||
216 | Client.Throttle.Texture = 100000; | ||
217 | Client.Throttle.Wind = 100000; | ||
218 | Client.Throttle.Total = 400000; | ||
219 | Client.Network.LoginProgress += this.Network_LoginProgress; | ||
220 | Client.Network.SimConnected += this.Network_SimConnected; | ||
221 | Client.Network.Disconnected += this.Network_OnDisconnected; | ||
222 | Client.Objects.ObjectUpdate += Objects_NewPrim; | ||
223 | |||
224 | ConnectionState = ConnectionState.Connecting; | 353 | ConnectionState = ConnectionState.Connecting; |
225 | 354 | ||
226 | if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) | 355 | // Current create a new client on each connect. libomv doesn't seem to process new sim |
356 | // information (e.g. EstablishAgentCommunication events) if connecting after a disceonnect with the same | ||
357 | // client | ||
358 | CreateLibOmvClient(); | ||
359 | |||
360 | if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", StartLocation, "pCampBot")) | ||
227 | { | 361 | { |
228 | ConnectionState = ConnectionState.Connected; | 362 | ConnectionState = ConnectionState.Connected; |
229 | 363 | ||
@@ -234,7 +368,6 @@ namespace pCampBot | |||
234 | // OnConnected(this, EventType.CONNECTED); | 368 | // OnConnected(this, EventType.CONNECTED); |
235 | if (wear == "save") | 369 | if (wear == "save") |
236 | { | 370 | { |
237 | Client.Appearance.SetPreviousAppearance(); | ||
238 | SaveDefaultAppearance(); | 371 | SaveDefaultAppearance(); |
239 | } | 372 | } |
240 | else if (wear != "no") | 373 | else if (wear != "no") |
@@ -267,6 +400,30 @@ namespace pCampBot | |||
267 | } | 400 | } |
268 | } | 401 | } |
269 | 402 | ||
403 | /// <summary> | ||
404 | /// Sit this bot on the ground. | ||
405 | /// </summary> | ||
406 | public void SitOnGround() | ||
407 | { | ||
408 | if (ConnectionState == ConnectionState.Connected) | ||
409 | Client.Self.SitOnGround(); | ||
410 | } | ||
411 | |||
412 | /// <summary> | ||
413 | /// Stand this bot | ||
414 | /// </summary> | ||
415 | public void Stand() | ||
416 | { | ||
417 | if (ConnectionState == ConnectionState.Connected) | ||
418 | { | ||
419 | // Unlike sit on ground, here libomv checks whether we have SEND_AGENT_UPDATES enabled. | ||
420 | bool prevUpdatesSetting = Client.Settings.SEND_AGENT_UPDATES; | ||
421 | Client.Settings.SEND_AGENT_UPDATES = true; | ||
422 | Client.Self.Stand(); | ||
423 | Client.Settings.SEND_AGENT_UPDATES = prevUpdatesSetting; | ||
424 | } | ||
425 | } | ||
426 | |||
270 | public void SaveDefaultAppearance() | 427 | public void SaveDefaultAppearance() |
271 | { | 428 | { |
272 | saveDir = "MyAppearance/" + FirstName + "_" + LastName; | 429 | saveDir = "MyAppearance/" + FirstName + "_" + LastName; |
@@ -362,7 +519,7 @@ namespace pCampBot | |||
362 | asset.Encode(); | 519 | asset.Encode(); |
363 | transid = Client.Assets.RequestUpload(asset,true); | 520 | transid = Client.Assets.RequestUpload(asset,true); |
364 | Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing, | 521 | Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyClothing" + i.ToString(), "MyClothing", AssetType.Clothing, |
365 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) | 522 | transid, InventoryType.Wearable, asset.WearableType, (OpenMetaverse.PermissionMask)PermissionMask.All, delegate(bool success, InventoryItem item) |
366 | { | 523 | { |
367 | if (success) | 524 | if (success) |
368 | { | 525 | { |
@@ -386,7 +543,7 @@ namespace pCampBot | |||
386 | asset.Encode(); | 543 | asset.Encode(); |
387 | transid = Client.Assets.RequestUpload(asset,true); | 544 | transid = Client.Assets.RequestUpload(asset,true); |
388 | Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart, | 545 | Client.Inventory.RequestCreateItem(clothfolder.UUID, "MyBodyPart" + i.ToString(), "MyBodyPart", AssetType.Bodypart, |
389 | transid, InventoryType.Wearable, asset.WearableType, PermissionMask.All, delegate(bool success, InventoryItem item) | 546 | transid, InventoryType.Wearable, asset.WearableType, (OpenMetaverse.PermissionMask)PermissionMask.All, delegate(bool success, InventoryItem item) |
390 | { | 547 | { |
391 | if (success) | 548 | if (success) |
392 | { | 549 | { |
@@ -450,7 +607,13 @@ namespace pCampBot | |||
450 | public void Network_SimConnected(object sender, SimConnectedEventArgs args) | 607 | public void Network_SimConnected(object sender, SimConnectedEventArgs args) |
451 | { | 608 | { |
452 | m_log.DebugFormat( | 609 | m_log.DebugFormat( |
453 | "[BOT]: Bot {0} connected to {1} at {2}", Name, args.Simulator.Name, args.Simulator.IPEndPoint); | 610 | "[BOT]: Bot {0} connected to region {1} at {2}", Name, args.Simulator.Name, args.Simulator.IPEndPoint); |
611 | } | ||
612 | |||
613 | public void Network_SimDisconnected(object sender, SimDisconnectedEventArgs args) | ||
614 | { | ||
615 | m_log.DebugFormat( | ||
616 | "[BOT]: Bot {0} disconnected from region {1} at {2}", Name, args.Simulator.Name, args.Simulator.IPEndPoint); | ||
454 | } | 617 | } |
455 | 618 | ||
456 | public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) | 619 | public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) |
@@ -458,7 +621,7 @@ namespace pCampBot | |||
458 | ConnectionState = ConnectionState.Disconnected; | 621 | ConnectionState = ConnectionState.Disconnected; |
459 | 622 | ||
460 | m_log.DebugFormat( | 623 | m_log.DebugFormat( |
461 | "[BOT]: Bot {0} disconnected reason {1}, message {2}", Name, args.Reason, args.Message); | 624 | "[BOT]: Bot {0} disconnected from grid, reason {1}, message {2}", Name, args.Reason, args.Message); |
462 | 625 | ||
463 | // m_log.ErrorFormat("Fired Network_OnDisconnected"); | 626 | // m_log.ErrorFormat("Fired Network_OnDisconnected"); |
464 | 627 | ||
@@ -467,6 +630,8 @@ namespace pCampBot | |||
467 | // || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) | 630 | // || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) |
468 | // && OnDisconnected != null) | 631 | // && OnDisconnected != null) |
469 | 632 | ||
633 | |||
634 | |||
470 | if ( | 635 | if ( |
471 | (args.Reason == NetworkManager.DisconnectType.ClientInitiated | 636 | (args.Reason == NetworkManager.DisconnectType.ClientInitiated |
472 | || args.Reason == NetworkManager.DisconnectType.ServerInitiated | 637 | || args.Reason == NetworkManager.DisconnectType.ServerInitiated |
@@ -480,8 +645,8 @@ namespace pCampBot | |||
480 | 645 | ||
481 | public void Objects_NewPrim(object sender, PrimEventArgs args) | 646 | public void Objects_NewPrim(object sender, PrimEventArgs args) |
482 | { | 647 | { |
483 | // if (Name.EndsWith("4")) | 648 | if (!RequestObjectTextures) |
484 | // throw new Exception("Aaargh"); | 649 | return; |
485 | 650 | ||
486 | Primitive prim = args.Prim; | 651 | Primitive prim = args.Prim; |
487 | 652 | ||
@@ -494,7 +659,7 @@ namespace pCampBot | |||
494 | { | 659 | { |
495 | if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) | 660 | if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) |
496 | { | 661 | { |
497 | GetTexture(prim.Textures.DefaultTexture.TextureID); | 662 | GetTextureOrMesh(prim.Textures.DefaultTexture.TextureID, true); |
498 | } | 663 | } |
499 | 664 | ||
500 | for (int i = 0; i < prim.Textures.FaceTextures.Length; i++) | 665 | for (int i = 0; i < prim.Textures.FaceTextures.Length; i++) |
@@ -506,32 +671,56 @@ namespace pCampBot | |||
506 | UUID textureID = prim.Textures.FaceTextures[i].TextureID; | 671 | UUID textureID = prim.Textures.FaceTextures[i].TextureID; |
507 | 672 | ||
508 | if (textureID != UUID.Zero) | 673 | if (textureID != UUID.Zero) |
509 | GetTexture(textureID); | 674 | GetTextureOrMesh(textureID, true); |
510 | } | 675 | } |
511 | } | 676 | } |
512 | } | 677 | } |
513 | 678 | ||
514 | if (prim.Sculpt != null && prim.Sculpt.SculptTexture != UUID.Zero) | 679 | if (prim.Sculpt != null && prim.Sculpt.SculptTexture != UUID.Zero) |
515 | GetTexture(prim.Sculpt.SculptTexture); | 680 | { |
681 | bool mesh = (prim.Sculpt.Type == SculptType.Mesh); | ||
682 | GetTextureOrMesh(prim.Sculpt.SculptTexture, !mesh); | ||
683 | } | ||
516 | } | 684 | } |
517 | } | 685 | } |
518 | 686 | ||
519 | private void GetTexture(UUID textureID) | 687 | private void GetTextureOrMesh(UUID assetID, bool texture) |
520 | { | 688 | { |
521 | lock (Manager.AssetsReceived) | 689 | lock (Manager.AssetsReceived) |
522 | { | 690 | { |
523 | // Don't request assets more than once. | 691 | // Don't request assets more than once. |
524 | if (Manager.AssetsReceived.ContainsKey(textureID)) | 692 | if (Manager.AssetsReceived.ContainsKey(assetID)) |
525 | return; | 693 | return; |
526 | 694 | ||
527 | Manager.AssetsReceived[textureID] = false; | 695 | Manager.AssetsReceived[assetID] = false; |
528 | Client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); | 696 | } |
697 | |||
698 | try | ||
699 | { | ||
700 | if (texture) | ||
701 | Client.Assets.RequestImage(assetID, ImageType.Normal, Asset_TextureCallback_Texture); | ||
702 | else | ||
703 | Client.Assets.RequestMesh(assetID, Asset_MeshCallback); | ||
704 | } | ||
705 | catch (Exception e) | ||
706 | { | ||
707 | m_log.Warn(string.Format("Error requesting {0} {1}", texture ? "texture" : "mesh", assetID), e); | ||
529 | } | 708 | } |
530 | } | 709 | } |
531 | 710 | ||
532 | public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) | 711 | public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) |
533 | { | 712 | { |
534 | //TODO: Implement texture saving and applying | 713 | if (state == TextureRequestState.Finished) |
714 | { | ||
715 | lock (Manager.AssetsReceived) | ||
716 | Manager.AssetsReceived[assetTexture.AssetID] = true; | ||
717 | } | ||
718 | } | ||
719 | |||
720 | private void Asset_MeshCallback(bool success, AssetMesh assetMesh) | ||
721 | { | ||
722 | lock (Manager.AssetsReceived) | ||
723 | Manager.AssetsReceived[assetMesh.AssetID] = success; | ||
535 | } | 724 | } |
536 | 725 | ||
537 | public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset) | 726 | public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset) |
@@ -544,5 +733,16 @@ namespace pCampBot | |||
544 | // SaveAsset((AssetWearable) asset); | 733 | // SaveAsset((AssetWearable) asset); |
545 | // } | 734 | // } |
546 | } | 735 | } |
736 | |||
737 | private void PacketReceivedDebugHandler(object o, PacketReceivedEventArgs args) | ||
738 | { | ||
739 | Packet p = args.Packet; | ||
740 | Header h = p.Header; | ||
741 | Simulator s = args.Simulator; | ||
742 | |||
743 | m_log.DebugFormat( | ||
744 | "[BOT]: Bot {0} received from {1} packet {2} #{3}, rel {4}, res {5}", | ||
745 | Name, s.Name, p.Type, h.Sequence, h.Reliable, h.Resent); | ||
746 | } | ||
547 | } | 747 | } |
548 | } | 748 | } |