ChildAgentDataUpdate.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  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. if (args.ContainsKey("region_id"))
  487. UUID.TryParse(args["region_id"].AsString(), out RegionID);
  488. if (args["circuit_code"] != null)
  489. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  490. if (args["agent_uuid"] != null)
  491. AgentID = args["agent_uuid"].AsUUID();
  492. if (args["session_uuid"] != null)
  493. SessionID = args["session_uuid"].AsUUID();
  494. if (args["position"] != null)
  495. Vector3.TryParse(args["position"].AsString(), out Position);
  496. if (args["velocity"] != null)
  497. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  498. if (args["center"] != null)
  499. Vector3.TryParse(args["center"].AsString(), out Center);
  500. if (args["size"] != null)
  501. Vector3.TryParse(args["size"].AsString(), out Size);
  502. if (args["at_axis"] != null)
  503. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  504. if (args["left_axis"] != null)
  505. Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
  506. if (args["up_axis"] != null)
  507. Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
  508. if (args.ContainsKey("wait_for_root") && args["wait_for_root"] != null)
  509. SenderWantsToWaitForRoot = args["wait_for_root"].AsBoolean();
  510. if (args["far"] != null)
  511. Far = (float)(args["far"].AsReal());
  512. if (args["aspect"] != null)
  513. Aspect = (float)args["aspect"].AsReal();
  514. if (args["throttles"] != null)
  515. Throttles = args["throttles"].AsBinary();
  516. if (args["locomotion_state"] != null)
  517. UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
  518. if (args["head_rotation"] != null)
  519. Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
  520. if (args["body_rotation"] != null)
  521. Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
  522. if (args["control_flags"] != null)
  523. UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
  524. if (args["energy_level"] != null)
  525. EnergyLevel = (float)(args["energy_level"].AsReal());
  526. //if (args["god_level"] != null)
  527. // Byte.TryParse(args["god_level"].AsString(), out GodLevel);
  528. if (args.ContainsKey("god_data") && args["god_data"] != null)
  529. GodData = args["god_data"];
  530. if (args["always_run"] != null)
  531. AlwaysRun = args["always_run"].AsBoolean();
  532. if (args["prey_agent"] != null)
  533. PreyAgent = args["prey_agent"].AsUUID();
  534. if (args["agent_access"] != null)
  535. Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
  536. if (args.ContainsKey("agent_cof") && args["agent_cof"] != null)
  537. agentCOF = args["agent_cof"].AsUUID();
  538. if (args.ContainsKey("crossingflags") && args["crossingflags"] != null)
  539. CrossingFlags = (byte)args["crossingflags"].AsInteger();
  540. if(CrossingFlags != 0)
  541. {
  542. if (args.ContainsKey("crossExtraFlags") && args["crossExtraFlags"] != null)
  543. CrossExtraFlags = (byte)args["crossExtraFlags"].AsInteger();
  544. }
  545. if (args.ContainsKey("active_group_id") && args["active_group_id"] != null)
  546. ActiveGroupID = args["active_group_id"].AsUUID();
  547. if (args.ContainsKey("active_group_name") && args["active_group_name"] != null)
  548. ActiveGroupName = args["active_group_name"].AsString();
  549. if(args.ContainsKey("active_group_title") && args["active_group_title"] != null)
  550. ActiveGroupTitle = args["active_group_title"].AsString();
  551. if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) &&
  552. (args["children_seeds"].Type == OSDType.Array))
  553. {
  554. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  555. ChildrenCapSeeds = new Dictionary<ulong, string>();
  556. foreach (OSD o in childrenSeeds)
  557. {
  558. if (o.Type == OSDType.Map)
  559. {
  560. ulong handle = 0;
  561. string seed = "";
  562. OSDMap pair = (OSDMap)o;
  563. if (pair["handle"] != null)
  564. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  565. continue;
  566. if (pair["seed"] != null)
  567. seed = pair["seed"].AsString();
  568. if (!ChildrenCapSeeds.ContainsKey(handle))
  569. ChildrenCapSeeds.Add(handle, seed);
  570. }
  571. }
  572. }
  573. if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
  574. {
  575. OSDArray anims = (OSDArray)(args["animations"]);
  576. Anims = new Animation[anims.Count];
  577. int i = 0;
  578. foreach (OSD o in anims)
  579. {
  580. if (o.Type == OSDType.Map)
  581. {
  582. Anims[i++] = new Animation((OSDMap)o);
  583. }
  584. }
  585. }
  586. if (args["default_animation"] != null)
  587. {
  588. try
  589. {
  590. DefaultAnim = new Animation((OSDMap)args["default_animation"]);
  591. }
  592. catch
  593. {
  594. DefaultAnim = null;
  595. }
  596. }
  597. if (args["animation_state"] != null)
  598. {
  599. try
  600. {
  601. AnimState = new Animation((OSDMap)args["animation_state"]);
  602. }
  603. catch
  604. {
  605. AnimState = null;
  606. }
  607. }
  608. MovementAnimationOverRides.Clear();
  609. if (args["movementAO"] != null && args["movementAO"].Type == OSDType.Array)
  610. {
  611. OSDArray AOs = (OSDArray)(args["movementAO"]);
  612. int count = AOs.Count;
  613. for (int i = 0; i < count; i++)
  614. {
  615. OSDMap ao = (OSDMap)AOs[i];
  616. if (ao["state"] != null && ao["uuid"] != null)
  617. {
  618. string state = ao["state"].AsString();
  619. UUID id = ao["uuid"].AsUUID();
  620. MovementAnimationOverRides[state] = id;
  621. }
  622. }
  623. }
  624. if (args.ContainsKey("motion_state"))
  625. MotionState = (byte)args["motion_state"].AsInteger();
  626. //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
  627. //{
  628. // OSDArray textures = (OSDArray)(args["agent_textures"]);
  629. // AgentTextures = new UUID[textures.Count];
  630. // int i = 0;
  631. // foreach (OSD o in textures)
  632. // AgentTextures[i++] = o.AsUUID();
  633. //}
  634. // packed_appearence should contain all appearance information
  635. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
  636. {
  637. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] got packed appearance");
  638. Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
  639. }
  640. else
  641. {
  642. // if missing try the old pack method
  643. m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance, checking old method");
  644. Appearance = new AvatarAppearance();
  645. // The code to unpack textures, visuals, wearables and attachments
  646. // should be removed; packed appearance contains the full appearance
  647. // This is retained for backward compatibility only
  648. if (args["texture_entry"] != null)
  649. {
  650. byte[] rawtextures = args["texture_entry"].AsBinary();
  651. Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
  652. Appearance.SetTextureEntries(textures);
  653. }
  654. if (args["visual_params"] != null)
  655. Appearance.SetVisualParams(args["visual_params"].AsBinary());
  656. if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
  657. {
  658. OSDArray wears = (OSDArray)(args["wearables"]);
  659. for (int i = 0; i < wears.Count / 2; i++)
  660. {
  661. AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
  662. Appearance.SetWearable(i, awear);
  663. }
  664. }
  665. if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
  666. {
  667. OSDArray attachs = (OSDArray)(args["attachments"]);
  668. foreach (OSD o in attachs)
  669. {
  670. if (o.Type == OSDType.Map)
  671. {
  672. // We know all of these must end up as attachments so we
  673. // append rather than replace to ensure multiple attachments
  674. // per point continues to work
  675. // m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
  676. Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
  677. }
  678. }
  679. }
  680. // end of code to remove
  681. }
  682. if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
  683. {
  684. OSDArray controls = (OSDArray)(args["controllers"]);
  685. Controllers = new ControllerData[controls.Count];
  686. int i = 0;
  687. foreach (OSD o in controls)
  688. {
  689. if (o.Type == OSDType.Map)
  690. {
  691. Controllers[i++] = new ControllerData((OSDMap)o);
  692. }
  693. }
  694. }
  695. if (args["callback_uri"] != null)
  696. CallbackURI = args["callback_uri"].AsString();
  697. if (args["cb_uri"] != null)
  698. NewCallbackURI = args["cb_uri"].AsString();
  699. // Attachment objects
  700. if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
  701. {
  702. OSDArray attObjs = (OSDArray)(args["attach_objects"]);
  703. AttachmentObjects = new List<ISceneObject>();
  704. AttachmentObjectStates = new List<string>();
  705. foreach (OSD o in attObjs)
  706. {
  707. if (o.Type == OSDType.Map)
  708. {
  709. OSDMap info = (OSDMap)o;
  710. ISceneObject so = scene.DeserializeObject(info["sog"].AsString());
  711. so.ExtraFromXmlString(info["extra"].AsString());
  712. so.HasGroupChanged = info["modified"].AsBoolean();
  713. AttachmentObjects.Add(so);
  714. AttachmentObjectStates.Add(info["state"].AsString());
  715. }
  716. }
  717. }
  718. if (args["parent_part"] != null)
  719. ParentPart = args["parent_part"].AsUUID();
  720. if (args["sit_offset"] != null)
  721. Vector3.TryParse(args["sit_offset"].AsString(), out SitOffset);
  722. }
  723. public AgentData()
  724. {
  725. }
  726. public AgentData(Hashtable hash)
  727. {
  728. //UnpackUpdateMessage(hash);
  729. }
  730. public void Dump()
  731. {
  732. System.Console.WriteLine("------------ AgentData ------------");
  733. System.Console.WriteLine("UUID: " + AgentID);
  734. System.Console.WriteLine("Region: " + RegionID);
  735. System.Console.WriteLine("Position: " + Position);
  736. }
  737. }
  738. public class CompleteAgentData : AgentData
  739. {
  740. public override OSDMap Pack(EntityTransferContext ctx)
  741. {
  742. return base.Pack(ctx);
  743. }
  744. public override void Unpack(OSDMap map, IScene scene, EntityTransferContext ctx)
  745. {
  746. base.Unpack(map, scene, ctx);
  747. }
  748. }
  749. }