ChildAgentDataUpdate.cs 34 KB

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