1
0

ChildAgentDataUpdate.cs 33 KB

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