ChildAgentDataUpdate.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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(EntityTransferContext ctx);
  60. void Unpack(OSDMap map, IScene scene, EntityTransferContext ctx);
  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 Dictionary<ulong, string> ChildrenCapSeeds = null;
  88. public OSDMap Pack(EntityTransferContext ctx)
  89. {
  90. OSDMap args = new OSDMap();
  91. args["message_type"] = OSD.FromString("AgentPosition");
  92. args["region_handle"] = OSD.FromString(RegionHandle.ToString());
  93. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  94. args["agent_uuid"] = OSD.FromUUID(AgentID);
  95. args["session_uuid"] = OSD.FromUUID(SessionID);
  96. args["position"] = OSD.FromString(Position.ToString());
  97. args["velocity"] = OSD.FromString(Velocity.ToString());
  98. args["center"] = OSD.FromString(Center.ToString());
  99. args["size"] = OSD.FromString(Size.ToString());
  100. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  101. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  102. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  103. args["far"] = OSD.FromReal(Far);
  104. args["changed_grid"] = OSD.FromBoolean(ChangedGrid);
  105. if ((Throttles != null) && (Throttles.Length > 0))
  106. args["throttles"] = OSD.FromBinary(Throttles);
  107. if (ChildrenCapSeeds != null && ChildrenCapSeeds.Count > 0)
  108. {
  109. OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
  110. foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
  111. {
  112. OSDMap pair = new OSDMap();
  113. pair["handle"] = OSD.FromString(kvp.Key.ToString());
  114. pair["seed"] = OSD.FromString(kvp.Value);
  115. childrenSeeds.Add(pair);
  116. }
  117. args["children_seeds"] = childrenSeeds;
  118. }
  119. return args;
  120. }
  121. public void Unpack(OSDMap args, IScene scene, EntityTransferContext ctx)
  122. {
  123. if (args.ContainsKey("region_handle"))
  124. UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
  125. if (args["circuit_code"] != null)
  126. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  127. if (args["agent_uuid"] != null)
  128. AgentID = args["agent_uuid"].AsUUID();
  129. if (args["session_uuid"] != null)
  130. SessionID = args["session_uuid"].AsUUID();
  131. if (args["position"] != null)
  132. Vector3.TryParse(args["position"].AsString(), out Position);
  133. if (args["velocity"] != null)
  134. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  135. if (args["center"] != null)
  136. Vector3.TryParse(args["center"].AsString(), out Center);
  137. if (args["size"] != null)
  138. Vector3.TryParse(args["size"].AsString(), out Size);
  139. if (args["at_axis"] != null)
  140. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  141. if (args["left_axis"] != null)
  142. Vector3.TryParse(args["left_axis"].AsString(), out LeftAxis);
  143. if (args["up_axis"] != null)
  144. Vector3.TryParse(args["up_axis"].AsString(), out UpAxis);
  145. if (args["changed_grid"] != null)
  146. ChangedGrid = args["changed_grid"].AsBoolean();
  147. if (args["far"] != null)
  148. Far = (float)(args["far"].AsReal());
  149. if (args["throttles"] != null)
  150. Throttles = args["throttles"].AsBinary();
  151. if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) &&
  152. (args["children_seeds"].Type == OSDType.Array))
  153. {
  154. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  155. ChildrenCapSeeds = new Dictionary<ulong, string>();
  156. foreach (OSD o in childrenSeeds)
  157. {
  158. if (o.Type == OSDType.Map)
  159. {
  160. ulong handle = 0;
  161. string seed = "";
  162. OSDMap pair = (OSDMap)o;
  163. if (pair["handle"] != null)
  164. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  165. continue;
  166. if (pair["seed"] != null)
  167. seed = pair["seed"].AsString();
  168. if (!ChildrenCapSeeds.ContainsKey(handle))
  169. ChildrenCapSeeds.Add(handle, seed);
  170. }
  171. }
  172. }
  173. }
  174. /// <summary>
  175. /// Soon to be decommissioned
  176. /// </summary>
  177. /// <param name="cAgent"></param>
  178. public void CopyFrom(ChildAgentDataUpdate cAgent, UUID sid)
  179. {
  180. AgentID = new UUID(cAgent.AgentID);
  181. SessionID = sid;
  182. // next: ???
  183. Size = new Vector3();
  184. Size.Z = cAgent.AVHeight;
  185. Center = cAgent.cameraPosition;
  186. Far = cAgent.drawdistance;
  187. Position = cAgent.Position;
  188. RegionHandle = cAgent.regionHandle;
  189. Throttles = cAgent.throttles;
  190. Velocity = cAgent.Velocity;
  191. }
  192. }
  193. public class AgentGroupData
  194. {
  195. public UUID GroupID;
  196. public ulong GroupPowers;
  197. public bool AcceptNotices;
  198. public AgentGroupData(UUID id, ulong powers, bool notices)
  199. {
  200. GroupID = id;
  201. GroupPowers = powers;
  202. AcceptNotices = notices;
  203. }
  204. public AgentGroupData(OSDMap args)
  205. {
  206. UnpackUpdateMessage(args);
  207. }
  208. public OSDMap PackUpdateMessage()
  209. {
  210. OSDMap groupdata = new OSDMap();
  211. groupdata["group_id"] = OSD.FromUUID(GroupID);
  212. groupdata["group_powers"] = OSD.FromString(GroupPowers.ToString());
  213. groupdata["accept_notices"] = OSD.FromBoolean(AcceptNotices);
  214. return groupdata;
  215. }
  216. public void UnpackUpdateMessage(OSDMap args)
  217. {
  218. if (args["group_id"] != null)
  219. GroupID = args["group_id"].AsUUID();
  220. if (args["group_powers"] != null)
  221. UInt64.TryParse((string)args["group_powers"].AsString(), out GroupPowers);
  222. if (args["accept_notices"] != null)
  223. AcceptNotices = args["accept_notices"].AsBoolean();
  224. }
  225. }
  226. public class ControllerData
  227. {
  228. public UUID ObjectID;
  229. public UUID ItemID;
  230. public uint IgnoreControls;
  231. public uint EventControls;
  232. public ControllerData(UUID obj, UUID item, uint ignore, uint ev)
  233. {
  234. ObjectID = obj;
  235. ItemID = item;
  236. IgnoreControls = ignore;
  237. EventControls = ev;
  238. }
  239. public ControllerData(OSDMap args)
  240. {
  241. UnpackUpdateMessage(args);
  242. }
  243. public OSDMap PackUpdateMessage()
  244. {
  245. OSDMap controldata = new OSDMap();
  246. controldata["object"] = OSD.FromUUID(ObjectID);
  247. controldata["item"] = OSD.FromUUID(ItemID);
  248. controldata["ignore"] = OSD.FromInteger(IgnoreControls);
  249. controldata["event"] = OSD.FromInteger(EventControls);
  250. return controldata;
  251. }
  252. public void UnpackUpdateMessage(OSDMap args)
  253. {
  254. if (args["object"] != null)
  255. ObjectID = args["object"].AsUUID();
  256. if (args["item"] != null)
  257. ItemID = args["item"].AsUUID();
  258. if (args["ignore"] != null)
  259. IgnoreControls = (uint)args["ignore"].AsInteger();
  260. if (args["event"] != null)
  261. EventControls = (uint)args["event"].AsInteger();
  262. }
  263. }
  264. public class AgentData : IAgentData
  265. {
  266. private UUID m_id;
  267. public UUID AgentID
  268. {
  269. get { return m_id; }
  270. set { m_id = value; }
  271. }
  272. public UUID RegionID;
  273. public uint CircuitCode;
  274. public UUID SessionID;
  275. public Vector3 Position;
  276. public Vector3 Velocity;
  277. public Vector3 Center;
  278. public Vector3 Size;
  279. public Vector3 AtAxis;
  280. public Vector3 LeftAxis;
  281. public Vector3 UpAxis;
  282. /// <summary>
  283. /// Signal on a V2 teleport that Scene.IncomingChildAgentDataUpdate(AgentData ad) should wait for the
  284. /// scene presence to become root (triggered when the viewer sends a CompleteAgentMovement UDP packet after
  285. /// establishing the connection triggered by it's receipt of a TeleportFinish EQ message).
  286. /// </summary>
  287. public bool SenderWantsToWaitForRoot;
  288. public float Far;
  289. public float Aspect;
  290. //public int[] Throttles;
  291. public byte[] Throttles;
  292. public uint LocomotionState;
  293. public Quaternion HeadRotation;
  294. public Quaternion BodyRotation;
  295. public uint ControlFlags;
  296. public float EnergyLevel;
  297. public Byte GodLevel;
  298. public bool AlwaysRun;
  299. public UUID PreyAgent;
  300. public Byte AgentAccess;
  301. public UUID ActiveGroupID;
  302. public AgentGroupData[] Groups;
  303. public Dictionary<ulong, string> ChildrenCapSeeds = null;
  304. public Animation[] Anims;
  305. public Animation DefaultAnim = null;
  306. public Animation AnimState = null;
  307. public Byte MotionState = 0;
  308. public UUID GranterID;
  309. public UUID ParentPart;
  310. public Vector3 SitOffset;
  311. // Appearance
  312. public AvatarAppearance Appearance;
  313. // DEBUG ON
  314. private static readonly ILog m_log =
  315. LogManager.GetLogger(
  316. MethodBase.GetCurrentMethod().DeclaringType);
  317. // DEBUG OFF
  318. /*
  319. public byte[] AgentTextures;
  320. public byte[] VisualParams;
  321. public UUID[] Wearables;
  322. public AvatarAttachment[] Attachments;
  323. */
  324. // Scripted
  325. public ControllerData[] Controllers;
  326. public string CallbackURI;
  327. // These two must have the same Count
  328. public List<ISceneObject> AttachmentObjects;
  329. public List<string> AttachmentObjectStates;
  330. public Dictionary<string, UUID> MovementAnimationOverRides = new Dictionary<string, UUID>();
  331. public virtual OSDMap Pack(EntityTransferContext ctx)
  332. {
  333. int wearablesCount = -1;
  334. // m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Pack data");
  335. OSDMap args = new OSDMap();
  336. args["message_type"] = OSD.FromString("AgentData");
  337. args["region_id"] = OSD.FromString(RegionID.ToString());
  338. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  339. args["agent_uuid"] = OSD.FromUUID(AgentID);
  340. args["session_uuid"] = OSD.FromUUID(SessionID);
  341. args["position"] = OSD.FromString(Position.ToString());
  342. args["velocity"] = OSD.FromString(Velocity.ToString());
  343. args["center"] = OSD.FromString(Center.ToString());
  344. args["size"] = OSD.FromString(Size.ToString());
  345. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  346. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  347. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  348. //backwards compatibility
  349. args["changed_grid"] = OSD.FromBoolean(SenderWantsToWaitForRoot);
  350. args["wait_for_root"] = OSD.FromBoolean(SenderWantsToWaitForRoot);
  351. args["far"] = OSD.FromReal(Far);
  352. args["aspect"] = OSD.FromReal(Aspect);
  353. if ((Throttles != null) && (Throttles.Length > 0))
  354. args["throttles"] = OSD.FromBinary(Throttles);
  355. args["locomotion_state"] = OSD.FromString(LocomotionState.ToString());
  356. args["head_rotation"] = OSD.FromString(HeadRotation.ToString());
  357. args["body_rotation"] = OSD.FromString(BodyRotation.ToString());
  358. args["control_flags"] = OSD.FromString(ControlFlags.ToString());
  359. args["energy_level"] = OSD.FromReal(EnergyLevel);
  360. args["god_level"] = OSD.FromString(GodLevel.ToString());
  361. args["always_run"] = OSD.FromBoolean(AlwaysRun);
  362. args["prey_agent"] = OSD.FromUUID(PreyAgent);
  363. args["agent_access"] = OSD.FromString(AgentAccess.ToString());
  364. args["active_group_id"] = OSD.FromUUID(ActiveGroupID);
  365. if ((Groups != null) && (Groups.Length > 0))
  366. {
  367. OSDArray groups = new OSDArray(Groups.Length);
  368. foreach (AgentGroupData agd in Groups)
  369. groups.Add(agd.PackUpdateMessage());
  370. args["groups"] = groups;
  371. }
  372. if (ChildrenCapSeeds != null && ChildrenCapSeeds.Count > 0)
  373. {
  374. OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
  375. foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
  376. {
  377. OSDMap pair = new OSDMap();
  378. pair["handle"] = OSD.FromString(kvp.Key.ToString());
  379. pair["seed"] = OSD.FromString(kvp.Value);
  380. childrenSeeds.Add(pair);
  381. }
  382. args["children_seeds"] = childrenSeeds;
  383. }
  384. if ((Anims != null) && (Anims.Length > 0))
  385. {
  386. OSDArray anims = new OSDArray(Anims.Length);
  387. foreach (Animation aanim in Anims)
  388. anims.Add(aanim.PackUpdateMessage());
  389. args["animations"] = anims;
  390. }
  391. if (DefaultAnim != null)
  392. {
  393. args["default_animation"] = DefaultAnim.PackUpdateMessage();
  394. }
  395. if (AnimState != null)
  396. {
  397. args["animation_state"] = AnimState.PackUpdateMessage();
  398. }
  399. if (MovementAnimationOverRides.Count > 0)
  400. {
  401. OSDArray AOs = new OSDArray(MovementAnimationOverRides.Count);
  402. {
  403. foreach (KeyValuePair<string, UUID> kvp in MovementAnimationOverRides)
  404. {
  405. OSDMap ao = new OSDMap(2);
  406. ao["state"] = OSD.FromString(kvp.Key);
  407. ao["uuid"] = OSD.FromUUID(kvp.Value);
  408. AOs.Add(ao);
  409. }
  410. }
  411. args["movementAO"] = AOs;
  412. }
  413. if (MotionState != 0)
  414. {
  415. args["motion_state"] = OSD.FromInteger(MotionState);
  416. }
  417. if (Appearance != null)
  418. args["packed_appearance"] = Appearance.Pack(ctx);
  419. //if ((AgentTextures != null) && (AgentTextures.Length > 0))
  420. //{
  421. // OSDArray textures = new OSDArray(AgentTextures.Length);
  422. // foreach (UUID uuid in AgentTextures)
  423. // textures.Add(OSD.FromUUID(uuid));
  424. // args["agent_textures"] = textures;
  425. //}
  426. // The code to pack textures, visuals, wearables and attachments
  427. // should be removed; packed appearance contains the full appearance
  428. // This is retained for backward compatibility only
  429. /* then lets remove
  430. if (Appearance.Texture != null)
  431. {
  432. byte[] rawtextures = Appearance.Texture.GetBytes();
  433. args["texture_entry"] = OSD.FromBinary(rawtextures);
  434. }
  435. if ((Appearance.VisualParams != null) && (Appearance.VisualParams.Length > 0))
  436. args["visual_params"] = OSD.FromBinary(Appearance.VisualParams);
  437. // We might not pass this in all cases...
  438. if ((Appearance.Wearables != null) && (Appearance.Wearables.Length > 0))
  439. {
  440. OSDArray wears = new OSDArray(Appearance.Wearables.Length);
  441. foreach (AvatarWearable awear in Appearance.Wearables)
  442. wears.Add(awear.Pack());
  443. args["wearables"] = wears;
  444. }
  445. List<AvatarAttachment> attachments = Appearance.GetAttachments();
  446. if ((attachments != null) && (attachments.Count > 0))
  447. {
  448. OSDArray attachs = new OSDArray(attachments.Count);
  449. foreach (AvatarAttachment att in attachments)
  450. attachs.Add(att.Pack());
  451. args["attachments"] = attachs;
  452. }
  453. // End of code to remove
  454. */
  455. if ((Controllers != null) && (Controllers.Length > 0))
  456. {
  457. OSDArray controls = new OSDArray(Controllers.Length);
  458. foreach (ControllerData ctl in Controllers)
  459. controls.Add(ctl.PackUpdateMessage());
  460. args["controllers"] = controls;
  461. }
  462. if ((CallbackURI != null) && (!CallbackURI.Equals("")))
  463. args["callback_uri"] = OSD.FromString(CallbackURI);
  464. // Attachment objects for fatpack messages
  465. if (AttachmentObjects != null)
  466. {
  467. int i = 0;
  468. OSDArray attObjs = new OSDArray(AttachmentObjects.Count);
  469. foreach (ISceneObject so in AttachmentObjects)
  470. {
  471. OSDMap info = new OSDMap(4);
  472. info["sog"] = OSD.FromString(so.ToXml2());
  473. info["extra"] = OSD.FromString(so.ExtraToXmlString());
  474. info["modified"] = OSD.FromBoolean(so.HasGroupChanged);
  475. try
  476. {
  477. info["state"] = OSD.FromString(AttachmentObjectStates[i++]);
  478. }
  479. catch (IndexOutOfRangeException)
  480. {
  481. m_log.WarnFormat("[CHILD AGENT DATA]: scripts list is shorter than object list.");
  482. }
  483. attObjs.Add(info);
  484. }
  485. args["attach_objects"] = attObjs;
  486. }
  487. args["parent_part"] = OSD.FromUUID(ParentPart);
  488. args["sit_offset"] = OSD.FromString(SitOffset.ToString());
  489. return args;
  490. }
  491. /// <summary>
  492. /// Deserialization of agent data.
  493. /// Avoiding reflection makes it painful to write, but that's the price!
  494. /// </summary>
  495. /// <param name="hash"></param>
  496. public virtual void Unpack(OSDMap args, IScene scene, EntityTransferContext ctx)
  497. {
  498. //m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");
  499. if (args.ContainsKey("region_id"))
  500. UUID.TryParse(args["region_id"].AsString(), out RegionID);
  501. if (args["circuit_code"] != null)
  502. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  503. if (args["agent_uuid"] != null)
  504. AgentID = args["agent_uuid"].AsUUID();
  505. if (args["session_uuid"] != null)
  506. SessionID = args["session_uuid"].AsUUID();
  507. if (args["position"] != null)
  508. Vector3.TryParse(args["position"].AsString(), out Position);
  509. if (args["velocity"] != null)
  510. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  511. if (args["center"] != null)
  512. Vector3.TryParse(args["center"].AsString(), out Center);
  513. if (args["size"] != null)
  514. Vector3.TryParse(args["size"].AsString(), out Size);
  515. if (args["at_axis"] != null)
  516. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  517. if (args["left_axis"] != null)
  518. Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
  519. if (args["up_axis"] != null)
  520. Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
  521. if (args.ContainsKey("wait_for_root") && args["wait_for_root"] != null)
  522. SenderWantsToWaitForRoot = args["wait_for_root"].AsBoolean();
  523. if (args["far"] != null)
  524. Far = (float)(args["far"].AsReal());
  525. if (args["aspect"] != null)
  526. Aspect = (float)args["aspect"].AsReal();
  527. if (args["throttles"] != null)
  528. Throttles = args["throttles"].AsBinary();
  529. if (args["locomotion_state"] != null)
  530. UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
  531. if (args["head_rotation"] != null)
  532. Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
  533. if (args["body_rotation"] != null)
  534. Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
  535. if (args["control_flags"] != null)
  536. UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
  537. if (args["energy_level"] != null)
  538. EnergyLevel = (float)(args["energy_level"].AsReal());
  539. if (args["god_level"] != null)
  540. Byte.TryParse(args["god_level"].AsString(), out GodLevel);
  541. if (args["always_run"] != null)
  542. AlwaysRun = args["always_run"].AsBoolean();
  543. if (args["prey_agent"] != null)
  544. PreyAgent = args["prey_agent"].AsUUID();
  545. if (args["agent_access"] != null)
  546. Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
  547. if (args["active_group_id"] != null)
  548. ActiveGroupID = args["active_group_id"].AsUUID();
  549. if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
  550. {
  551. OSDArray groups = (OSDArray)(args["groups"]);
  552. Groups = new AgentGroupData[groups.Count];
  553. int i = 0;
  554. foreach (OSD o in groups)
  555. {
  556. if (o.Type == OSDType.Map)
  557. {
  558. Groups[i++] = new AgentGroupData((OSDMap)o);
  559. }
  560. }
  561. }
  562. if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) &&
  563. (args["children_seeds"].Type == OSDType.Array))
  564. {
  565. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  566. ChildrenCapSeeds = new Dictionary<ulong, string>();
  567. foreach (OSD o in childrenSeeds)
  568. {
  569. if (o.Type == OSDType.Map)
  570. {
  571. ulong handle = 0;
  572. string seed = "";
  573. OSDMap pair = (OSDMap)o;
  574. if (pair["handle"] != null)
  575. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  576. continue;
  577. if (pair["seed"] != null)
  578. seed = pair["seed"].AsString();
  579. if (!ChildrenCapSeeds.ContainsKey(handle))
  580. ChildrenCapSeeds.Add(handle, seed);
  581. }
  582. }
  583. }
  584. if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
  585. {
  586. OSDArray anims = (OSDArray)(args["animations"]);
  587. Anims = new Animation[anims.Count];
  588. int i = 0;
  589. foreach (OSD o in anims)
  590. {
  591. if (o.Type == OSDType.Map)
  592. {
  593. Anims[i++] = new Animation((OSDMap)o);
  594. }
  595. }
  596. }
  597. if (args["default_animation"] != null)
  598. {
  599. try
  600. {
  601. DefaultAnim = new Animation((OSDMap)args["default_animation"]);
  602. }
  603. catch
  604. {
  605. DefaultAnim = null;
  606. }
  607. }
  608. if (args["animation_state"] != null)
  609. {
  610. try
  611. {
  612. AnimState = new Animation((OSDMap)args["animation_state"]);
  613. }
  614. catch
  615. {
  616. AnimState = null;
  617. }
  618. }
  619. MovementAnimationOverRides.Clear();
  620. if (args["movementAO"] != null && args["movementAO"].Type == OSDType.Array)
  621. {
  622. OSDArray AOs = (OSDArray)(args["movementAO"]);
  623. int count = AOs.Count;
  624. for (int i = 0; i < count; i++)
  625. {
  626. OSDMap ao = (OSDMap)AOs[i];
  627. if (ao["state"] != null && ao["uuid"] != null)
  628. {
  629. string state = ao["state"].AsString();
  630. UUID id = ao["uuid"].AsUUID();
  631. MovementAnimationOverRides[state] = id;
  632. }
  633. }
  634. }
  635. if (args.ContainsKey("motion_state"))
  636. MotionState = (byte)args["motion_state"].AsInteger();
  637. //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
  638. //{
  639. // OSDArray textures = (OSDArray)(args["agent_textures"]);
  640. // AgentTextures = new UUID[textures.Count];
  641. // int i = 0;
  642. // foreach (OSD o in textures)
  643. // AgentTextures[i++] = o.AsUUID();
  644. //}
  645. // packed_appearence should contain all appearance information
  646. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
  647. {
  648. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] got packed appearance");
  649. Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
  650. }
  651. else
  652. {
  653. // if missing try the old pack method
  654. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance, checking old method");
  655. Appearance = new AvatarAppearance();
  656. // The code to unpack textures, visuals, wearables and attachments
  657. // should be removed; packed appearance contains the full appearance
  658. // This is retained for backward compatibility only
  659. if (args["texture_entry"] != null)
  660. {
  661. byte[] rawtextures = args["texture_entry"].AsBinary();
  662. Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
  663. Appearance.SetTextureEntries(textures);
  664. }
  665. if (args["visual_params"] != null)
  666. Appearance.SetVisualParams(args["visual_params"].AsBinary());
  667. if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
  668. {
  669. OSDArray wears = (OSDArray)(args["wearables"]);
  670. for (int i = 0; i < wears.Count / 2; i++)
  671. {
  672. AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
  673. Appearance.SetWearable(i, awear);
  674. }
  675. }
  676. if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
  677. {
  678. OSDArray attachs = (OSDArray)(args["attachments"]);
  679. foreach (OSD o in attachs)
  680. {
  681. if (o.Type == OSDType.Map)
  682. {
  683. // We know all of these must end up as attachments so we
  684. // append rather than replace to ensure multiple attachments
  685. // per point continues to work
  686. // m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
  687. Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
  688. }
  689. }
  690. }
  691. // end of code to remove
  692. }
  693. /* moved above
  694. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
  695. Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
  696. else
  697. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
  698. */
  699. if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
  700. {
  701. OSDArray controls = (OSDArray)(args["controllers"]);
  702. Controllers = new ControllerData[controls.Count];
  703. int i = 0;
  704. foreach (OSD o in controls)
  705. {
  706. if (o.Type == OSDType.Map)
  707. {
  708. Controllers[i++] = new ControllerData((OSDMap)o);
  709. }
  710. }
  711. }
  712. if (args["callback_uri"] != null)
  713. CallbackURI = args["callback_uri"].AsString();
  714. // Attachment objects
  715. if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
  716. {
  717. OSDArray attObjs = (OSDArray)(args["attach_objects"]);
  718. AttachmentObjects = new List<ISceneObject>();
  719. AttachmentObjectStates = new List<string>();
  720. foreach (OSD o in attObjs)
  721. {
  722. if (o.Type == OSDType.Map)
  723. {
  724. OSDMap info = (OSDMap)o;
  725. ISceneObject so = scene.DeserializeObject(info["sog"].AsString());
  726. so.ExtraFromXmlString(info["extra"].AsString());
  727. so.HasGroupChanged = info["modified"].AsBoolean();
  728. AttachmentObjects.Add(so);
  729. AttachmentObjectStates.Add(info["state"].AsString());
  730. }
  731. }
  732. }
  733. if (args["parent_part"] != null)
  734. ParentPart = args["parent_part"].AsUUID();
  735. if (args["sit_offset"] != null)
  736. Vector3.TryParse(args["sit_offset"].AsString(), out SitOffset);
  737. }
  738. public AgentData()
  739. {
  740. }
  741. public AgentData(Hashtable hash)
  742. {
  743. //UnpackUpdateMessage(hash);
  744. }
  745. public void Dump()
  746. {
  747. System.Console.WriteLine("------------ AgentData ------------");
  748. System.Console.WriteLine("UUID: " + AgentID);
  749. System.Console.WriteLine("Region: " + RegionID);
  750. System.Console.WriteLine("Position: " + Position);
  751. }
  752. }
  753. public class CompleteAgentData : AgentData
  754. {
  755. public override OSDMap Pack(EntityTransferContext ctx)
  756. {
  757. return base.Pack(ctx);
  758. }
  759. public override void Unpack(OSDMap map, IScene scene, EntityTransferContext ctx)
  760. {
  761. base.Unpack(map, scene, ctx);
  762. }
  763. }
  764. }