1
0

ChildAgentDataUpdate.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using log4net;
  32. using OpenMetaverse;
  33. using OpenMetaverse.StructuredData;
  34. namespace OpenSim.Framework
  35. {
  36. // Soon to be dismissed
  37. [Serializable]
  38. public class ChildAgentDataUpdate
  39. {
  40. public Guid ActiveGroupID;
  41. public Guid AgentID;
  42. public bool alwaysrun;
  43. public float AVHeight;
  44. public Vector3 cameraPosition;
  45. public float drawdistance;
  46. public float godlevel;
  47. public uint GroupAccess;
  48. public Vector3 Position;
  49. public ulong regionHandle;
  50. public byte[] throttles;
  51. public Vector3 Velocity;
  52. public ChildAgentDataUpdate()
  53. {
  54. }
  55. }
  56. public interface IAgentData
  57. {
  58. UUID AgentID { get; set; }
  59. OSDMap Pack();
  60. void Unpack(OSDMap map, IScene scene);
  61. }
  62. /// <summary>
  63. /// Replacement for ChildAgentDataUpdate. Used over RESTComms and LocalComms.
  64. /// </summary>
  65. public class AgentPosition : IAgentData
  66. {
  67. private UUID m_id;
  68. public UUID AgentID
  69. {
  70. get { return m_id; }
  71. set { m_id = value; }
  72. }
  73. public ulong RegionHandle;
  74. public uint CircuitCode;
  75. public UUID SessionID;
  76. public float Far;
  77. public Vector3 Position;
  78. public Vector3 Velocity;
  79. public Vector3 Center;
  80. public Vector3 Size;
  81. public Vector3 AtAxis;
  82. public Vector3 LeftAxis;
  83. public Vector3 UpAxis;
  84. public bool ChangedGrid;
  85. // This probably shouldn't be here
  86. public byte[] Throttles;
  87. public OSDMap Pack()
  88. {
  89. OSDMap args = new OSDMap();
  90. args["message_type"] = OSD.FromString("AgentPosition");
  91. args["region_handle"] = OSD.FromString(RegionHandle.ToString());
  92. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  93. args["agent_uuid"] = OSD.FromUUID(AgentID);
  94. args["session_uuid"] = OSD.FromUUID(SessionID);
  95. args["position"] = OSD.FromString(Position.ToString());
  96. args["velocity"] = OSD.FromString(Velocity.ToString());
  97. args["center"] = OSD.FromString(Center.ToString());
  98. args["size"] = OSD.FromString(Size.ToString());
  99. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  100. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  101. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  102. args["far"] = OSD.FromReal(Far);
  103. args["changed_grid"] = OSD.FromBoolean(ChangedGrid);
  104. if ((Throttles != null) && (Throttles.Length > 0))
  105. args["throttles"] = OSD.FromBinary(Throttles);
  106. return args;
  107. }
  108. public void Unpack(OSDMap args, IScene scene)
  109. {
  110. if (args.ContainsKey("region_handle"))
  111. UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
  112. if (args["circuit_code"] != null)
  113. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  114. if (args["agent_uuid"] != null)
  115. AgentID = args["agent_uuid"].AsUUID();
  116. if (args["session_uuid"] != null)
  117. SessionID = args["session_uuid"].AsUUID();
  118. if (args["position"] != null)
  119. Vector3.TryParse(args["position"].AsString(), out Position);
  120. if (args["velocity"] != null)
  121. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  122. if (args["center"] != null)
  123. Vector3.TryParse(args["center"].AsString(), out Center);
  124. if (args["size"] != null)
  125. Vector3.TryParse(args["size"].AsString(), out Size);
  126. if (args["at_axis"] != null)
  127. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  128. if (args["left_axis"] != null)
  129. Vector3.TryParse(args["left_axis"].AsString(), out LeftAxis);
  130. if (args["up_axis"] != null)
  131. Vector3.TryParse(args["up_axis"].AsString(), out UpAxis);
  132. if (args["changed_grid"] != null)
  133. ChangedGrid = args["changed_grid"].AsBoolean();
  134. if (args["far"] != null)
  135. Far = (float)(args["far"].AsReal());
  136. if (args["throttles"] != null)
  137. Throttles = args["throttles"].AsBinary();
  138. }
  139. /// <summary>
  140. /// Soon to be decommissioned
  141. /// </summary>
  142. /// <param name="cAgent"></param>
  143. public void CopyFrom(ChildAgentDataUpdate cAgent, UUID sid)
  144. {
  145. AgentID = new UUID(cAgent.AgentID);
  146. SessionID = sid;
  147. // next: ???
  148. Size = new Vector3();
  149. Size.Z = cAgent.AVHeight;
  150. Center = cAgent.cameraPosition;
  151. Far = cAgent.drawdistance;
  152. Position = cAgent.Position;
  153. RegionHandle = cAgent.regionHandle;
  154. Throttles = cAgent.throttles;
  155. Velocity = cAgent.Velocity;
  156. }
  157. }
  158. public class AgentGroupData
  159. {
  160. public UUID GroupID;
  161. public ulong GroupPowers;
  162. public bool AcceptNotices;
  163. public AgentGroupData(UUID id, ulong powers, bool notices)
  164. {
  165. GroupID = id;
  166. GroupPowers = powers;
  167. AcceptNotices = notices;
  168. }
  169. public AgentGroupData(OSDMap args)
  170. {
  171. UnpackUpdateMessage(args);
  172. }
  173. public OSDMap PackUpdateMessage()
  174. {
  175. OSDMap groupdata = new OSDMap();
  176. groupdata["group_id"] = OSD.FromUUID(GroupID);
  177. groupdata["group_powers"] = OSD.FromString(GroupPowers.ToString());
  178. groupdata["accept_notices"] = OSD.FromBoolean(AcceptNotices);
  179. return groupdata;
  180. }
  181. public void UnpackUpdateMessage(OSDMap args)
  182. {
  183. if (args["group_id"] != null)
  184. GroupID = args["group_id"].AsUUID();
  185. if (args["group_powers"] != null)
  186. UInt64.TryParse((string)args["group_powers"].AsString(), out GroupPowers);
  187. if (args["accept_notices"] != null)
  188. AcceptNotices = args["accept_notices"].AsBoolean();
  189. }
  190. }
  191. public class ControllerData
  192. {
  193. public UUID ObjectID;
  194. public UUID ItemID;
  195. public uint IgnoreControls;
  196. public uint EventControls;
  197. public ControllerData(UUID obj, UUID item, uint ignore, uint ev)
  198. {
  199. ObjectID = obj;
  200. ItemID = item;
  201. IgnoreControls = ignore;
  202. EventControls = ev;
  203. }
  204. public ControllerData(OSDMap args)
  205. {
  206. UnpackUpdateMessage(args);
  207. }
  208. public OSDMap PackUpdateMessage()
  209. {
  210. OSDMap controldata = new OSDMap();
  211. controldata["object"] = OSD.FromUUID(ObjectID);
  212. controldata["item"] = OSD.FromUUID(ItemID);
  213. controldata["ignore"] = OSD.FromInteger(IgnoreControls);
  214. controldata["event"] = OSD.FromInteger(EventControls);
  215. return controldata;
  216. }
  217. public void UnpackUpdateMessage(OSDMap args)
  218. {
  219. if (args["object"] != null)
  220. ObjectID = args["object"].AsUUID();
  221. if (args["item"] != null)
  222. ItemID = args["item"].AsUUID();
  223. if (args["ignore"] != null)
  224. IgnoreControls = (uint)args["ignore"].AsInteger();
  225. if (args["event"] != null)
  226. EventControls = (uint)args["event"].AsInteger();
  227. }
  228. }
  229. public class AgentData : IAgentData
  230. {
  231. private UUID m_id;
  232. public UUID AgentID
  233. {
  234. get { return m_id; }
  235. set { m_id = value; }
  236. }
  237. public UUID RegionID;
  238. public uint CircuitCode;
  239. public UUID SessionID;
  240. public Vector3 Position;
  241. public Vector3 Velocity;
  242. public Vector3 Center;
  243. public Vector3 Size;
  244. public Vector3 AtAxis;
  245. public Vector3 LeftAxis;
  246. public Vector3 UpAxis;
  247. /// <summary>
  248. /// Signal on a V2 teleport that Scene.IncomingChildAgentDataUpdate(AgentData ad) should wait for the
  249. /// scene presence to become root (triggered when the viewer sends a CompleteAgentMovement UDP packet after
  250. /// establishing the connection triggered by it's receipt of a TeleportFinish EQ message).
  251. /// </summary>
  252. public bool SenderWantsToWaitForRoot;
  253. public float Far;
  254. public float Aspect;
  255. //public int[] Throttles;
  256. public byte[] Throttles;
  257. public uint LocomotionState;
  258. public Quaternion HeadRotation;
  259. public Quaternion BodyRotation;
  260. public uint ControlFlags;
  261. public float EnergyLevel;
  262. public Byte GodLevel;
  263. public bool AlwaysRun;
  264. public UUID PreyAgent;
  265. public Byte AgentAccess;
  266. public UUID ActiveGroupID;
  267. public AgentGroupData[] Groups;
  268. public Animation[] Anims;
  269. public Animation DefaultAnim = null;
  270. public Animation AnimState = null;
  271. public UUID GranterID;
  272. public UUID ParentPart;
  273. public Vector3 SitOffset;
  274. // Appearance
  275. public AvatarAppearance Appearance;
  276. // DEBUG ON
  277. private static readonly ILog m_log =
  278. LogManager.GetLogger(
  279. MethodBase.GetCurrentMethod().DeclaringType);
  280. // DEBUG OFF
  281. /*
  282. public byte[] AgentTextures;
  283. public byte[] VisualParams;
  284. public UUID[] Wearables;
  285. public AvatarAttachment[] Attachments;
  286. */
  287. // Scripted
  288. public ControllerData[] Controllers;
  289. public string CallbackURI;
  290. // These two must have the same Count
  291. public List<ISceneObject> AttachmentObjects;
  292. public List<string> AttachmentObjectStates;
  293. public virtual OSDMap Pack()
  294. {
  295. // m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Pack data");
  296. OSDMap args = new OSDMap();
  297. args["message_type"] = OSD.FromString("AgentData");
  298. args["region_id"] = OSD.FromString(RegionID.ToString());
  299. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  300. args["agent_uuid"] = OSD.FromUUID(AgentID);
  301. args["session_uuid"] = OSD.FromUUID(SessionID);
  302. args["position"] = OSD.FromString(Position.ToString());
  303. args["velocity"] = OSD.FromString(Velocity.ToString());
  304. args["center"] = OSD.FromString(Center.ToString());
  305. args["size"] = OSD.FromString(Size.ToString());
  306. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  307. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  308. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  309. //backwards compatibility
  310. args["changed_grid"] = OSD.FromBoolean(SenderWantsToWaitForRoot);
  311. args["wait_for_root"] = OSD.FromBoolean(SenderWantsToWaitForRoot);
  312. args["far"] = OSD.FromReal(Far);
  313. args["aspect"] = OSD.FromReal(Aspect);
  314. if ((Throttles != null) && (Throttles.Length > 0))
  315. args["throttles"] = OSD.FromBinary(Throttles);
  316. args["locomotion_state"] = OSD.FromString(LocomotionState.ToString());
  317. args["head_rotation"] = OSD.FromString(HeadRotation.ToString());
  318. args["body_rotation"] = OSD.FromString(BodyRotation.ToString());
  319. args["control_flags"] = OSD.FromString(ControlFlags.ToString());
  320. args["energy_level"] = OSD.FromReal(EnergyLevel);
  321. args["god_level"] = OSD.FromString(GodLevel.ToString());
  322. args["always_run"] = OSD.FromBoolean(AlwaysRun);
  323. args["prey_agent"] = OSD.FromUUID(PreyAgent);
  324. args["agent_access"] = OSD.FromString(AgentAccess.ToString());
  325. args["active_group_id"] = OSD.FromUUID(ActiveGroupID);
  326. if ((Groups != null) && (Groups.Length > 0))
  327. {
  328. OSDArray groups = new OSDArray(Groups.Length);
  329. foreach (AgentGroupData agd in Groups)
  330. groups.Add(agd.PackUpdateMessage());
  331. args["groups"] = groups;
  332. }
  333. if ((Anims != null) && (Anims.Length > 0))
  334. {
  335. OSDArray anims = new OSDArray(Anims.Length);
  336. foreach (Animation aanim in Anims)
  337. anims.Add(aanim.PackUpdateMessage());
  338. args["animations"] = anims;
  339. }
  340. if (DefaultAnim != null)
  341. {
  342. args["default_animation"] = DefaultAnim.PackUpdateMessage();
  343. }
  344. if (AnimState != null)
  345. {
  346. args["animation_state"] = AnimState.PackUpdateMessage();
  347. }
  348. if (Appearance != null)
  349. args["packed_appearance"] = Appearance.Pack();
  350. //if ((AgentTextures != null) && (AgentTextures.Length > 0))
  351. //{
  352. // OSDArray textures = new OSDArray(AgentTextures.Length);
  353. // foreach (UUID uuid in AgentTextures)
  354. // textures.Add(OSD.FromUUID(uuid));
  355. // args["agent_textures"] = textures;
  356. //}
  357. // The code to pack textures, visuals, wearables and attachments
  358. // should be removed; packed appearance contains the full appearance
  359. // This is retained for backward compatibility only
  360. if (Appearance.Texture != null)
  361. {
  362. byte[] rawtextures = Appearance.Texture.GetBytes();
  363. args["texture_entry"] = OSD.FromBinary(rawtextures);
  364. }
  365. if ((Appearance.VisualParams != null) && (Appearance.VisualParams.Length > 0))
  366. args["visual_params"] = OSD.FromBinary(Appearance.VisualParams);
  367. // We might not pass this in all cases...
  368. if ((Appearance.Wearables != null) && (Appearance.Wearables.Length > 0))
  369. {
  370. int wearsCount;
  371. if(Appearance.PackLegacyWearables)
  372. wearsCount = AvatarWearable.LEGACY_VERSION_MAX_WEARABLES;
  373. else
  374. wearsCount = AvatarWearable.MAX_WEARABLES;
  375. if(wearsCount > Appearance.Wearables.Length)
  376. wearsCount = Appearance.Wearables.Length;
  377. OSDArray wears = new OSDArray(wearsCount);
  378. for(int i = 0; i < wearsCount ; i++)
  379. wears.Add(Appearance.Wearables[i].Pack());
  380. args["wearables"] = wears;
  381. }
  382. List<AvatarAttachment> attachments = Appearance.GetAttachments();
  383. if ((attachments != null) && (attachments.Count > 0))
  384. {
  385. OSDArray attachs = new OSDArray(attachments.Count);
  386. foreach (AvatarAttachment att in attachments)
  387. attachs.Add(att.Pack());
  388. args["attachments"] = attachs;
  389. }
  390. // End of code to remove
  391. if ((Controllers != null) && (Controllers.Length > 0))
  392. {
  393. OSDArray controls = new OSDArray(Controllers.Length);
  394. foreach (ControllerData ctl in Controllers)
  395. controls.Add(ctl.PackUpdateMessage());
  396. args["controllers"] = controls;
  397. }
  398. if ((CallbackURI != null) && (!CallbackURI.Equals("")))
  399. args["callback_uri"] = OSD.FromString(CallbackURI);
  400. // Attachment objects for fatpack messages
  401. if (AttachmentObjects != null)
  402. {
  403. int i = 0;
  404. OSDArray attObjs = new OSDArray(AttachmentObjects.Count);
  405. foreach (ISceneObject so in AttachmentObjects)
  406. {
  407. OSDMap info = new OSDMap(4);
  408. info["sog"] = OSD.FromString(so.ToXml2());
  409. info["extra"] = OSD.FromString(so.ExtraToXmlString());
  410. info["modified"] = OSD.FromBoolean(so.HasGroupChanged);
  411. try
  412. {
  413. info["state"] = OSD.FromString(AttachmentObjectStates[i++]);
  414. }
  415. catch (IndexOutOfRangeException)
  416. {
  417. m_log.WarnFormat("[CHILD AGENT DATA]: scripts list is shorter than object list.");
  418. }
  419. attObjs.Add(info);
  420. }
  421. args["attach_objects"] = attObjs;
  422. }
  423. args["parent_part"] = OSD.FromUUID(ParentPart);
  424. args["sit_offset"] = OSD.FromString(SitOffset.ToString());
  425. return args;
  426. }
  427. /// <summary>
  428. /// Deserialization of agent data.
  429. /// Avoiding reflection makes it painful to write, but that's the price!
  430. /// </summary>
  431. /// <param name="hash"></param>
  432. public virtual void Unpack(OSDMap args, IScene scene)
  433. {
  434. //m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");
  435. if (args.ContainsKey("region_id"))
  436. UUID.TryParse(args["region_id"].AsString(), out RegionID);
  437. if (args["circuit_code"] != null)
  438. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  439. if (args["agent_uuid"] != null)
  440. AgentID = args["agent_uuid"].AsUUID();
  441. if (args["session_uuid"] != null)
  442. SessionID = args["session_uuid"].AsUUID();
  443. if (args["position"] != null)
  444. Vector3.TryParse(args["position"].AsString(), out Position);
  445. if (args["velocity"] != null)
  446. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  447. if (args["center"] != null)
  448. Vector3.TryParse(args["center"].AsString(), out Center);
  449. if (args["size"] != null)
  450. Vector3.TryParse(args["size"].AsString(), out Size);
  451. if (args["at_axis"] != null)
  452. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  453. if (args["left_axis"] != null)
  454. Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
  455. if (args["up_axis"] != null)
  456. Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
  457. if (args.ContainsKey("wait_for_root") && args["wait_for_root"] != null)
  458. SenderWantsToWaitForRoot = args["wait_for_root"].AsBoolean();
  459. if (args["far"] != null)
  460. Far = (float)(args["far"].AsReal());
  461. if (args["aspect"] != null)
  462. Aspect = (float)args["aspect"].AsReal();
  463. if (args["throttles"] != null)
  464. Throttles = args["throttles"].AsBinary();
  465. if (args["locomotion_state"] != null)
  466. UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
  467. if (args["head_rotation"] != null)
  468. Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
  469. if (args["body_rotation"] != null)
  470. Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
  471. if (args["control_flags"] != null)
  472. UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
  473. if (args["energy_level"] != null)
  474. EnergyLevel = (float)(args["energy_level"].AsReal());
  475. if (args["god_level"] != null)
  476. Byte.TryParse(args["god_level"].AsString(), out GodLevel);
  477. if (args["always_run"] != null)
  478. AlwaysRun = args["always_run"].AsBoolean();
  479. if (args["prey_agent"] != null)
  480. PreyAgent = args["prey_agent"].AsUUID();
  481. if (args["agent_access"] != null)
  482. Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
  483. if (args["active_group_id"] != null)
  484. ActiveGroupID = args["active_group_id"].AsUUID();
  485. if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
  486. {
  487. OSDArray groups = (OSDArray)(args["groups"]);
  488. Groups = new AgentGroupData[groups.Count];
  489. int i = 0;
  490. foreach (OSD o in groups)
  491. {
  492. if (o.Type == OSDType.Map)
  493. {
  494. Groups[i++] = new AgentGroupData((OSDMap)o);
  495. }
  496. }
  497. }
  498. if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
  499. {
  500. OSDArray anims = (OSDArray)(args["animations"]);
  501. Anims = new Animation[anims.Count];
  502. int i = 0;
  503. foreach (OSD o in anims)
  504. {
  505. if (o.Type == OSDType.Map)
  506. {
  507. Anims[i++] = new Animation((OSDMap)o);
  508. }
  509. }
  510. }
  511. if (args["default_animation"] != null)
  512. {
  513. try
  514. {
  515. DefaultAnim = new Animation((OSDMap)args["default_animation"]);
  516. }
  517. catch
  518. {
  519. DefaultAnim = null;
  520. }
  521. }
  522. if (args["animation_state"] != null)
  523. {
  524. try
  525. {
  526. AnimState = new Animation((OSDMap)args["animation_state"]);
  527. }
  528. catch
  529. {
  530. AnimState = null;
  531. }
  532. }
  533. //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
  534. //{
  535. // OSDArray textures = (OSDArray)(args["agent_textures"]);
  536. // AgentTextures = new UUID[textures.Count];
  537. // int i = 0;
  538. // foreach (OSD o in textures)
  539. // AgentTextures[i++] = o.AsUUID();
  540. //}
  541. Appearance = new AvatarAppearance();
  542. // The code to unpack textures, visuals, wearables and attachments
  543. // should be removed; packed appearance contains the full appearance
  544. // This is retained for backward compatibility only
  545. if (args["texture_entry"] != null)
  546. {
  547. byte[] rawtextures = args["texture_entry"].AsBinary();
  548. Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures,0,rawtextures.Length);
  549. Appearance.SetTextureEntries(textures);
  550. }
  551. if (args["visual_params"] != null)
  552. Appearance.SetVisualParams(args["visual_params"].AsBinary());
  553. if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
  554. {
  555. OSDArray wears = (OSDArray)(args["wearables"]);
  556. int count = wears.Count;
  557. if (count > AvatarWearable.MAX_WEARABLES)
  558. count = AvatarWearable.MAX_WEARABLES;
  559. for (int i = 0; i < count / 2; i++)
  560. {
  561. AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
  562. Appearance.SetWearable(i,awear);
  563. }
  564. }
  565. if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
  566. {
  567. OSDArray attachs = (OSDArray)(args["attachments"]);
  568. foreach (OSD o in attachs)
  569. {
  570. if (o.Type == OSDType.Map)
  571. {
  572. // We know all of these must end up as attachments so we
  573. // append rather than replace to ensure multiple attachments
  574. // per point continues to work
  575. // m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
  576. Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
  577. }
  578. }
  579. }
  580. // end of code to remove
  581. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
  582. Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
  583. else
  584. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
  585. if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
  586. {
  587. OSDArray controls = (OSDArray)(args["controllers"]);
  588. Controllers = new ControllerData[controls.Count];
  589. int i = 0;
  590. foreach (OSD o in controls)
  591. {
  592. if (o.Type == OSDType.Map)
  593. {
  594. Controllers[i++] = new ControllerData((OSDMap)o);
  595. }
  596. }
  597. }
  598. if (args["callback_uri"] != null)
  599. CallbackURI = args["callback_uri"].AsString();
  600. // Attachment objects
  601. if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
  602. {
  603. OSDArray attObjs = (OSDArray)(args["attach_objects"]);
  604. AttachmentObjects = new List<ISceneObject>();
  605. AttachmentObjectStates = new List<string>();
  606. foreach (OSD o in attObjs)
  607. {
  608. if (o.Type == OSDType.Map)
  609. {
  610. OSDMap info = (OSDMap)o;
  611. ISceneObject so = scene.DeserializeObject(info["sog"].AsString());
  612. so.ExtraFromXmlString(info["extra"].AsString());
  613. so.HasGroupChanged = info["modified"].AsBoolean();
  614. AttachmentObjects.Add(so);
  615. AttachmentObjectStates.Add(info["state"].AsString());
  616. }
  617. }
  618. }
  619. if (args["parent_part"] != null)
  620. ParentPart = args["parent_part"].AsUUID();
  621. if (args["sit_offset"] != null)
  622. Vector3.TryParse(args["sit_offset"].AsString(), out SitOffset);
  623. }
  624. public AgentData()
  625. {
  626. }
  627. public AgentData(Hashtable hash)
  628. {
  629. //UnpackUpdateMessage(hash);
  630. }
  631. public void Dump()
  632. {
  633. System.Console.WriteLine("------------ AgentData ------------");
  634. System.Console.WriteLine("UUID: " + AgentID);
  635. System.Console.WriteLine("Region: " + RegionID);
  636. System.Console.WriteLine("Position: " + Position);
  637. }
  638. }
  639. public class CompleteAgentData : AgentData
  640. {
  641. public override OSDMap Pack()
  642. {
  643. return base.Pack();
  644. }
  645. public override void Unpack(OSDMap map, IScene scene)
  646. {
  647. base.Unpack(map, scene);
  648. }
  649. }
  650. }