ChildAgentDataUpdate.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  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 Dictionary<ulong, string> ChildrenCapSeeds = null;
  88. public OSDMap Pack()
  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)
  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()
  332. {
  333. // m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Pack data");
  334. OSDMap args = new OSDMap();
  335. args["message_type"] = OSD.FromString("AgentData");
  336. args["region_id"] = OSD.FromString(RegionID.ToString());
  337. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  338. args["agent_uuid"] = OSD.FromUUID(AgentID);
  339. args["session_uuid"] = OSD.FromUUID(SessionID);
  340. args["position"] = OSD.FromString(Position.ToString());
  341. args["velocity"] = OSD.FromString(Velocity.ToString());
  342. args["center"] = OSD.FromString(Center.ToString());
  343. args["size"] = OSD.FromString(Size.ToString());
  344. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  345. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  346. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  347. //backwards compatibility
  348. args["changed_grid"] = OSD.FromBoolean(SenderWantsToWaitForRoot);
  349. args["wait_for_root"] = OSD.FromBoolean(SenderWantsToWaitForRoot);
  350. args["far"] = OSD.FromReal(Far);
  351. args["aspect"] = OSD.FromReal(Aspect);
  352. if ((Throttles != null) && (Throttles.Length > 0))
  353. args["throttles"] = OSD.FromBinary(Throttles);
  354. args["locomotion_state"] = OSD.FromString(LocomotionState.ToString());
  355. args["head_rotation"] = OSD.FromString(HeadRotation.ToString());
  356. args["body_rotation"] = OSD.FromString(BodyRotation.ToString());
  357. args["control_flags"] = OSD.FromString(ControlFlags.ToString());
  358. args["energy_level"] = OSD.FromReal(EnergyLevel);
  359. args["god_level"] = OSD.FromString(GodLevel.ToString());
  360. args["always_run"] = OSD.FromBoolean(AlwaysRun);
  361. args["prey_agent"] = OSD.FromUUID(PreyAgent);
  362. args["agent_access"] = OSD.FromString(AgentAccess.ToString());
  363. args["active_group_id"] = OSD.FromUUID(ActiveGroupID);
  364. if ((Groups != null) && (Groups.Length > 0))
  365. {
  366. OSDArray groups = new OSDArray(Groups.Length);
  367. foreach (AgentGroupData agd in Groups)
  368. groups.Add(agd.PackUpdateMessage());
  369. args["groups"] = groups;
  370. }
  371. if (ChildrenCapSeeds != null && ChildrenCapSeeds.Count > 0)
  372. {
  373. OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
  374. foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
  375. {
  376. OSDMap pair = new OSDMap();
  377. pair["handle"] = OSD.FromString(kvp.Key.ToString());
  378. pair["seed"] = OSD.FromString(kvp.Value);
  379. childrenSeeds.Add(pair);
  380. }
  381. args["children_seeds"] = childrenSeeds;
  382. }
  383. if ((Anims != null) && (Anims.Length > 0))
  384. {
  385. OSDArray anims = new OSDArray(Anims.Length);
  386. foreach (Animation aanim in Anims)
  387. anims.Add(aanim.PackUpdateMessage());
  388. args["animations"] = anims;
  389. }
  390. if (DefaultAnim != null)
  391. {
  392. args["default_animation"] = DefaultAnim.PackUpdateMessage();
  393. }
  394. if (AnimState != null)
  395. {
  396. args["animation_state"] = AnimState.PackUpdateMessage();
  397. }
  398. if (MovementAnimationOverRides.Count > 0)
  399. {
  400. OSDArray AOs = new OSDArray(MovementAnimationOverRides.Count);
  401. {
  402. foreach (KeyValuePair<string, UUID> kvp in MovementAnimationOverRides)
  403. {
  404. OSDMap ao = new OSDMap(2);
  405. ao["state"] = OSD.FromString(kvp.Key);
  406. ao["uuid"] = OSD.FromUUID(kvp.Value);
  407. AOs.Add(ao);
  408. }
  409. }
  410. args["movementAO"] = AOs;
  411. }
  412. if (MotionState != 0)
  413. {
  414. args["motion_state"] = OSD.FromInteger(MotionState);
  415. }
  416. if (Appearance != null)
  417. args["packed_appearance"] = Appearance.Pack();
  418. //if ((AgentTextures != null) && (AgentTextures.Length > 0))
  419. //{
  420. // OSDArray textures = new OSDArray(AgentTextures.Length);
  421. // foreach (UUID uuid in AgentTextures)
  422. // textures.Add(OSD.FromUUID(uuid));
  423. // args["agent_textures"] = textures;
  424. //}
  425. // The code to pack textures, visuals, wearables and attachments
  426. // should be removed; packed appearance contains the full appearance
  427. // This is retained for backward compatibility only
  428. /* then lets remove
  429. if (Appearance.Texture != null)
  430. {
  431. byte[] rawtextures = Appearance.Texture.GetBytes();
  432. args["texture_entry"] = OSD.FromBinary(rawtextures);
  433. }
  434. if ((Appearance.VisualParams != null) && (Appearance.VisualParams.Length > 0))
  435. args["visual_params"] = OSD.FromBinary(Appearance.VisualParams);
  436. // We might not pass this in all cases...
  437. if ((Appearance.Wearables != null) && (Appearance.Wearables.Length > 0))
  438. {
  439. OSDArray wears = new OSDArray(Appearance.Wearables.Length);
  440. foreach (AvatarWearable awear in Appearance.Wearables)
  441. wears.Add(awear.Pack());
  442. args["wearables"] = wears;
  443. }
  444. List<AvatarAttachment> attachments = Appearance.GetAttachments();
  445. if ((attachments != null) && (attachments.Count > 0))
  446. {
  447. OSDArray attachs = new OSDArray(attachments.Count);
  448. foreach (AvatarAttachment att in attachments)
  449. attachs.Add(att.Pack());
  450. args["attachments"] = attachs;
  451. }
  452. // End of code to remove
  453. */
  454. if ((Controllers != null) && (Controllers.Length > 0))
  455. {
  456. OSDArray controls = new OSDArray(Controllers.Length);
  457. foreach (ControllerData ctl in Controllers)
  458. controls.Add(ctl.PackUpdateMessage());
  459. args["controllers"] = controls;
  460. }
  461. if ((CallbackURI != null) && (!CallbackURI.Equals("")))
  462. args["callback_uri"] = OSD.FromString(CallbackURI);
  463. // Attachment objects for fatpack messages
  464. if (AttachmentObjects != null)
  465. {
  466. int i = 0;
  467. OSDArray attObjs = new OSDArray(AttachmentObjects.Count);
  468. foreach (ISceneObject so in AttachmentObjects)
  469. {
  470. OSDMap info = new OSDMap(4);
  471. info["sog"] = OSD.FromString(so.ToXml2());
  472. info["extra"] = OSD.FromString(so.ExtraToXmlString());
  473. info["modified"] = OSD.FromBoolean(so.HasGroupChanged);
  474. try
  475. {
  476. info["state"] = OSD.FromString(AttachmentObjectStates[i++]);
  477. }
  478. catch (IndexOutOfRangeException)
  479. {
  480. m_log.WarnFormat("[CHILD AGENT DATA]: scripts list is shorter than object list.");
  481. }
  482. attObjs.Add(info);
  483. }
  484. args["attach_objects"] = attObjs;
  485. }
  486. args["parent_part"] = OSD.FromUUID(ParentPart);
  487. args["sit_offset"] = OSD.FromString(SitOffset.ToString());
  488. return args;
  489. }
  490. /// <summary>
  491. /// Deserialization of agent data.
  492. /// Avoiding reflection makes it painful to write, but that's the price!
  493. /// </summary>
  494. /// <param name="hash"></param>
  495. public virtual void Unpack(OSDMap args, IScene scene)
  496. {
  497. //m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");
  498. if (args.ContainsKey("region_id"))
  499. UUID.TryParse(args["region_id"].AsString(), out RegionID);
  500. if (args["circuit_code"] != null)
  501. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  502. if (args["agent_uuid"] != null)
  503. AgentID = args["agent_uuid"].AsUUID();
  504. if (args["session_uuid"] != null)
  505. SessionID = args["session_uuid"].AsUUID();
  506. if (args["position"] != null)
  507. Vector3.TryParse(args["position"].AsString(), out Position);
  508. if (args["velocity"] != null)
  509. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  510. if (args["center"] != null)
  511. Vector3.TryParse(args["center"].AsString(), out Center);
  512. if (args["size"] != null)
  513. Vector3.TryParse(args["size"].AsString(), out Size);
  514. if (args["at_axis"] != null)
  515. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  516. if (args["left_axis"] != null)
  517. Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
  518. if (args["up_axis"] != null)
  519. Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
  520. if (args.ContainsKey("wait_for_root") && args["wait_for_root"] != null)
  521. SenderWantsToWaitForRoot = args["wait_for_root"].AsBoolean();
  522. if (args["far"] != null)
  523. Far = (float)(args["far"].AsReal());
  524. if (args["aspect"] != null)
  525. Aspect = (float)args["aspect"].AsReal();
  526. if (args["throttles"] != null)
  527. Throttles = args["throttles"].AsBinary();
  528. if (args["locomotion_state"] != null)
  529. UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
  530. if (args["head_rotation"] != null)
  531. Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
  532. if (args["body_rotation"] != null)
  533. Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
  534. if (args["control_flags"] != null)
  535. UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
  536. if (args["energy_level"] != null)
  537. EnergyLevel = (float)(args["energy_level"].AsReal());
  538. if (args["god_level"] != null)
  539. Byte.TryParse(args["god_level"].AsString(), out GodLevel);
  540. if (args["always_run"] != null)
  541. AlwaysRun = args["always_run"].AsBoolean();
  542. if (args["prey_agent"] != null)
  543. PreyAgent = args["prey_agent"].AsUUID();
  544. if (args["agent_access"] != null)
  545. Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
  546. if (args["active_group_id"] != null)
  547. ActiveGroupID = args["active_group_id"].AsUUID();
  548. if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
  549. {
  550. OSDArray groups = (OSDArray)(args["groups"]);
  551. Groups = new AgentGroupData[groups.Count];
  552. int i = 0;
  553. foreach (OSD o in groups)
  554. {
  555. if (o.Type == OSDType.Map)
  556. {
  557. Groups[i++] = new AgentGroupData((OSDMap)o);
  558. }
  559. }
  560. }
  561. if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) &&
  562. (args["children_seeds"].Type == OSDType.Array))
  563. {
  564. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  565. ChildrenCapSeeds = new Dictionary<ulong, string>();
  566. foreach (OSD o in childrenSeeds)
  567. {
  568. if (o.Type == OSDType.Map)
  569. {
  570. ulong handle = 0;
  571. string seed = "";
  572. OSDMap pair = (OSDMap)o;
  573. if (pair["handle"] != null)
  574. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  575. continue;
  576. if (pair["seed"] != null)
  577. seed = pair["seed"].AsString();
  578. if (!ChildrenCapSeeds.ContainsKey(handle))
  579. ChildrenCapSeeds.Add(handle, seed);
  580. }
  581. }
  582. }
  583. if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
  584. {
  585. OSDArray anims = (OSDArray)(args["animations"]);
  586. Anims = new Animation[anims.Count];
  587. int i = 0;
  588. foreach (OSD o in anims)
  589. {
  590. if (o.Type == OSDType.Map)
  591. {
  592. Anims[i++] = new Animation((OSDMap)o);
  593. }
  594. }
  595. }
  596. if (args["default_animation"] != null)
  597. {
  598. try
  599. {
  600. DefaultAnim = new Animation((OSDMap)args["default_animation"]);
  601. }
  602. catch
  603. {
  604. DefaultAnim = null;
  605. }
  606. }
  607. if (args["animation_state"] != null)
  608. {
  609. try
  610. {
  611. AnimState = new Animation((OSDMap)args["animation_state"]);
  612. }
  613. catch
  614. {
  615. AnimState = null;
  616. }
  617. }
  618. MovementAnimationOverRides.Clear();
  619. if (args["movementAO"] != null && args["movementAO"].Type == OSDType.Array)
  620. {
  621. OSDArray AOs = (OSDArray)(args["movementAO"]);
  622. int count = AOs.Count;
  623. for (int i = 0; i < count; i++)
  624. {
  625. OSDMap ao = (OSDMap)AOs[i];
  626. if (ao["state"] != null && ao["uuid"] != null)
  627. {
  628. string state = ao["state"].AsString();
  629. UUID id = ao["uuid"].AsUUID();
  630. MovementAnimationOverRides[state] = id;
  631. }
  632. }
  633. }
  634. if (args.ContainsKey("motion_state"))
  635. MotionState = (byte)args["motion_state"].AsInteger();
  636. //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
  637. //{
  638. // OSDArray textures = (OSDArray)(args["agent_textures"]);
  639. // AgentTextures = new UUID[textures.Count];
  640. // int i = 0;
  641. // foreach (OSD o in textures)
  642. // AgentTextures[i++] = o.AsUUID();
  643. //}
  644. // packed_appearence should contain all appearance information
  645. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
  646. {
  647. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] got packed appearance");
  648. Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
  649. }
  650. else
  651. {
  652. // if missing try the old pack method
  653. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance, checking old method");
  654. Appearance = new AvatarAppearance();
  655. // The code to unpack textures, visuals, wearables and attachments
  656. // should be removed; packed appearance contains the full appearance
  657. // This is retained for backward compatibility only
  658. if (args["texture_entry"] != null)
  659. {
  660. byte[] rawtextures = args["texture_entry"].AsBinary();
  661. Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
  662. Appearance.SetTextureEntries(textures);
  663. }
  664. if (args["visual_params"] != null)
  665. Appearance.SetVisualParams(args["visual_params"].AsBinary());
  666. if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
  667. {
  668. OSDArray wears = (OSDArray)(args["wearables"]);
  669. int count = wears.Count;
  670. if (count > AvatarWearable.MAX_WEARABLES)
  671. count = AvatarWearable.MAX_WEARABLES;
  672. for (int i = 0; i < count / 2; i++)
  673. {
  674. AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
  675. Appearance.SetWearable(i, awear);
  676. }
  677. }
  678. if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
  679. {
  680. OSDArray attachs = (OSDArray)(args["attachments"]);
  681. foreach (OSD o in attachs)
  682. {
  683. if (o.Type == OSDType.Map)
  684. {
  685. // We know all of these must end up as attachments so we
  686. // append rather than replace to ensure multiple attachments
  687. // per point continues to work
  688. // m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
  689. Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
  690. }
  691. }
  692. }
  693. // end of code to remove
  694. }
  695. /* moved above
  696. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
  697. Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
  698. else
  699. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
  700. */
  701. if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
  702. {
  703. OSDArray controls = (OSDArray)(args["controllers"]);
  704. Controllers = new ControllerData[controls.Count];
  705. int i = 0;
  706. foreach (OSD o in controls)
  707. {
  708. if (o.Type == OSDType.Map)
  709. {
  710. Controllers[i++] = new ControllerData((OSDMap)o);
  711. }
  712. }
  713. }
  714. if (args["callback_uri"] != null)
  715. CallbackURI = args["callback_uri"].AsString();
  716. // Attachment objects
  717. if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
  718. {
  719. OSDArray attObjs = (OSDArray)(args["attach_objects"]);
  720. AttachmentObjects = new List<ISceneObject>();
  721. AttachmentObjectStates = new List<string>();
  722. foreach (OSD o in attObjs)
  723. {
  724. if (o.Type == OSDType.Map)
  725. {
  726. OSDMap info = (OSDMap)o;
  727. ISceneObject so = scene.DeserializeObject(info["sog"].AsString());
  728. so.ExtraFromXmlString(info["extra"].AsString());
  729. so.HasGroupChanged = info["modified"].AsBoolean();
  730. AttachmentObjects.Add(so);
  731. AttachmentObjectStates.Add(info["state"].AsString());
  732. }
  733. }
  734. }
  735. if (args["parent_part"] != null)
  736. ParentPart = args["parent_part"].AsUUID();
  737. if (args["sit_offset"] != null)
  738. Vector3.TryParse(args["sit_offset"].AsString(), out SitOffset);
  739. }
  740. public AgentData()
  741. {
  742. }
  743. public AgentData(Hashtable hash)
  744. {
  745. //UnpackUpdateMessage(hash);
  746. }
  747. public void Dump()
  748. {
  749. System.Console.WriteLine("------------ AgentData ------------");
  750. System.Console.WriteLine("UUID: " + AgentID);
  751. System.Console.WriteLine("Region: " + RegionID);
  752. System.Console.WriteLine("Position: " + Position);
  753. }
  754. }
  755. public class CompleteAgentData : AgentData
  756. {
  757. public override OSDMap Pack()
  758. {
  759. return base.Pack();
  760. }
  761. public override void Unpack(OSDMap map, IScene scene)
  762. {
  763. base.Unpack(map, scene);
  764. }
  765. }
  766. }