ChildAgentDataUpdate.cs 34 KB

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