ChildAgentDataUpdate.cs 33 KB

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