ChildAgentDataUpdate.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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 OpenSim 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 OpenMetaverse;
  31. using OpenMetaverse.StructuredData;
  32. namespace OpenSim.Framework
  33. {
  34. // Soon to be dismissed
  35. [Serializable]
  36. public class ChildAgentDataUpdate
  37. {
  38. public Guid ActiveGroupID;
  39. public Guid AgentID;
  40. public bool alwaysrun;
  41. public float AVHeight;
  42. public sLLVector3 cameraPosition;
  43. public float drawdistance;
  44. public float godlevel;
  45. public uint GroupAccess;
  46. public sLLVector3 Position;
  47. public ulong regionHandle;
  48. public byte[] throttles;
  49. public sLLVector3 Velocity;
  50. public ChildAgentDataUpdate()
  51. {
  52. }
  53. //public ChildAgentDataUpdate(AgentData agent)
  54. //{
  55. // ActiveGroupID = agent.ActiveGroupID.Guid;
  56. // AgentID = agent.AgentID.Guid;
  57. // alwaysrun = agent.AlwaysRun;
  58. // AVHeight = agent.Size.Z;
  59. // cameraPosition = new sLLVector3(agent.Center);
  60. // drawdistance = agent.Far;
  61. // godlevel = (float)agent.GodLevel;
  62. // if (agent.Groups.Length > 0)
  63. // GroupAccess = (uint)agent.Groups[0].GroupPowers;
  64. // Position = new sLLVector3(agent.Position);
  65. // regionHandle = agent.RegionHandle;
  66. // throttles = agent.Throttles;
  67. // Velocity = new sLLVector3(agent.Velocity);
  68. //}
  69. //public ChildAgentDataUpdate(AgentPosition agent)
  70. //{
  71. // AgentID = agent.AgentID.Guid;
  72. // AVHeight = agent.Size.Z;
  73. // cameraPosition = new sLLVector3(agent.Center);
  74. // drawdistance = agent.Far;
  75. // Position = new sLLVector3(agent.Position);
  76. // regionHandle = agent.RegionHandle;
  77. // throttles = agent.Throttles;
  78. // Velocity = new sLLVector3(agent.Velocity);
  79. //}
  80. }
  81. /*
  82. public interface IAgentData
  83. {
  84. UUID AgentID { get; set; }
  85. OSDMap PackUpdateMessage();
  86. void UnpackUpdateMessage(OSDMap map);
  87. }
  88. /// <summary>
  89. /// Replacement for ChildAgentDataUpdate. Used over RESTComms and LocalComms.
  90. /// </summary>
  91. public class AgentPosition : IAgentData
  92. {
  93. private UUID m_id;
  94. public UUID AgentID
  95. {
  96. get { return m_id; }
  97. set { m_id = value; }
  98. }
  99. public ulong RegionHandle;
  100. public uint CircuitCode;
  101. public UUID SessionID;
  102. public float Far;
  103. public Vector3 Position;
  104. public Vector3 Velocity;
  105. public Vector3 Center;
  106. public Vector3 Size;
  107. public Vector3 AtAxis;
  108. public Vector3 LeftAxis;
  109. public Vector3 UpAxis;
  110. public bool ChangedGrid;
  111. // This probably shouldn't be here
  112. public byte[] Throttles;
  113. public OSDMap PackUpdateMessage()
  114. {
  115. OSDMap args = new OSDMap();
  116. args["message_type"] = OSD.FromString("AgentPosition");
  117. args["region_handle"] = OSD.FromString(RegionHandle.ToString());
  118. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  119. args["agent_uuid"] = OSD.FromUUID(AgentID);
  120. args["session_uuid"] = OSD.FromUUID(SessionID);
  121. args["position"] = OSD.FromString(Position.ToString());
  122. args["velocity"] = OSD.FromString(Velocity.ToString());
  123. args["center"] = OSD.FromString(Center.ToString());
  124. args["size"] = OSD.FromString(Size.ToString());
  125. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  126. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  127. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  128. args["far"] = OSD.FromReal(Far);
  129. args["changed_grid"] = OSD.FromBoolean(ChangedGrid);
  130. if ((Throttles != null) && (Throttles.Length > 0))
  131. args["throttles"] = OSD.FromBinary(Throttles);
  132. return args;
  133. }
  134. public void UnpackUpdateMessage(OSDMap args)
  135. {
  136. if (args.ContainsKey("region_handle"))
  137. UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
  138. if (args["circuit_code"] != null)
  139. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  140. if (args["agent_uuid"] != null)
  141. AgentID = args["agent_uuid"].AsUUID();
  142. if (args["session_uuid"] != null)
  143. SessionID = args["session_uuid"].AsUUID();
  144. if (args["position"] != null)
  145. Vector3.TryParse(args["position"].AsString(), out Position);
  146. if (args["velocity"] != null)
  147. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  148. if (args["center"] != null)
  149. Vector3.TryParse(args["center"].AsString(), out Center);
  150. if (args["size"] != null)
  151. Vector3.TryParse(args["size"].AsString(), out Size);
  152. if (args["at_axis"] != null)
  153. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  154. if (args["left_axis"] != null)
  155. Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
  156. if (args["up_axis"] != null)
  157. Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
  158. if (args["changed_grid"] != null)
  159. ChangedGrid = args["changed_grid"].AsBoolean();
  160. if (args["far"] != null)
  161. Far = (float)(args["far"].AsReal());
  162. if (args["throttles"] != null)
  163. Throttles = args["throttles"].AsBinary();
  164. }
  165. /// <summary>
  166. /// Soon to be decommissioned
  167. /// </summary>
  168. /// <param name="cAgent"></param>
  169. public void CopyFrom(ChildAgentDataUpdate cAgent)
  170. {
  171. AgentID = new UUID(cAgent.AgentID);
  172. // next: ???
  173. Size = new Vector3();
  174. Size.Z = cAgent.AVHeight;
  175. Center = new Vector3(cAgent.cameraPosition.x, cAgent.cameraPosition.y, cAgent.cameraPosition.z);
  176. Far = cAgent.drawdistance;
  177. Position = new Vector3(cAgent.Position.x, cAgent.Position.y, cAgent.Position.z);
  178. RegionHandle = cAgent.regionHandle;
  179. Throttles = cAgent.throttles;
  180. Velocity = new Vector3(cAgent.Velocity.x, cAgent.Velocity.y, cAgent.Velocity.z);
  181. }
  182. }
  183. public class AgentGroupData
  184. {
  185. public UUID GroupID;
  186. public ulong GroupPowers;
  187. public bool AcceptNotices;
  188. public AgentGroupData(UUID id, ulong powers, bool notices)
  189. {
  190. GroupID = id;
  191. GroupPowers = powers;
  192. AcceptNotices = notices;
  193. }
  194. public AgentGroupData(OSDMap args)
  195. {
  196. UnpackUpdateMessage(args);
  197. }
  198. public OSDMap PackUpdateMessage()
  199. {
  200. OSDMap groupdata = new OSDMap();
  201. groupdata["group_id"] = OSD.FromUUID(GroupID);
  202. groupdata["group_powers"] = OSD.FromString(GroupPowers.ToString());
  203. groupdata["accept_notices"] = OSD.FromBoolean(AcceptNotices);
  204. return groupdata;
  205. }
  206. public void UnpackUpdateMessage(OSDMap args)
  207. {
  208. if (args["group_id"] != null)
  209. GroupID = args["group_id"].AsUUID();
  210. if (args["group_powers"] != null)
  211. UInt64.TryParse((string)args["group_powers"].AsString(), out GroupPowers);
  212. if (args["accept_notices"] != null)
  213. AcceptNotices = args["accept_notices"].AsBoolean();
  214. }
  215. }
  216. public class AgentAnimationData
  217. {
  218. public UUID Animation;
  219. public UUID ObjectID;
  220. public AgentAnimationData(OSDMap args)
  221. {
  222. UnpackUpdateMessage(args);
  223. }
  224. public OSDMap PackUpdateMessage()
  225. {
  226. OSDMap anim = new OSDMap();
  227. anim["animation"] = OSD.FromUUID(Animation);
  228. anim["object_id"] = OSD.FromUUID(ObjectID);
  229. return anim;
  230. }
  231. public void UnpackUpdateMessage(OSDMap args)
  232. {
  233. if (args["animation"] != null)
  234. Animation = args["animation"].AsUUID();
  235. if (args["object_id"] != null)
  236. ObjectID = args["object_id"].AsUUID();
  237. }
  238. }
  239. public class AgentData : IAgentData
  240. {
  241. private UUID m_id;
  242. public UUID AgentID
  243. {
  244. get { return m_id; }
  245. set { m_id = value; }
  246. }
  247. public ulong RegionHandle;
  248. public uint CircuitCode;
  249. public UUID SessionID;
  250. public Vector3 Position;
  251. public Vector3 Velocity;
  252. public Vector3 Center;
  253. public Vector3 Size;
  254. public Vector3 AtAxis;
  255. public Vector3 LeftAxis;
  256. public Vector3 UpAxis;
  257. public bool ChangedGrid;
  258. public float Far;
  259. public float Aspect;
  260. //public int[] Throttles;
  261. public byte[] Throttles;
  262. public uint LocomotionState;
  263. public Quaternion HeadRotation;
  264. public Quaternion BodyRotation;
  265. public uint ControlFlags;
  266. public float EnergyLevel;
  267. public Byte GodLevel;
  268. public bool AlwaysRun;
  269. public UUID PreyAgent;
  270. public Byte AgentAccess;
  271. public UUID[] AgentTextures;
  272. public UUID ActiveGroupID;
  273. public AgentGroupData[] Groups;
  274. public AgentAnimationData[] Anims;
  275. public UUID GranterID;
  276. public Dictionary<string, string> NVPairs;
  277. public byte[] VisualParams;
  278. public string CallbackURI;
  279. public OSDMap PackUpdateMessage()
  280. {
  281. OSDMap args = new OSDMap();
  282. args["message_type"] = OSD.FromString("AgentData");
  283. args["region_handle"] = OSD.FromString(RegionHandle.ToString());
  284. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  285. args["agent_uuid"] = OSD.FromUUID(AgentID);
  286. args["session_uuid"] = OSD.FromUUID(SessionID);
  287. args["position"] = OSD.FromString(Position.ToString());
  288. args["velocity"] = OSD.FromString(Velocity.ToString());
  289. args["center"] = OSD.FromString(Center.ToString());
  290. args["size"] = OSD.FromString(Size.ToString());
  291. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  292. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  293. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  294. args["changed_grid"] = OSD.FromBoolean(ChangedGrid);
  295. args["far"] = OSD.FromReal(Far);
  296. args["aspect"] = OSD.FromReal(Aspect);
  297. if ((Throttles != null) && (Throttles.Length > 0))
  298. args["throttles"] = OSD.FromBinary(Throttles);
  299. args["locomotion_state"] = OSD.FromString(LocomotionState.ToString());
  300. args["head_rotation"] = OSD.FromString(HeadRotation.ToString());
  301. args["body_rotation"] = OSD.FromString(BodyRotation.ToString());
  302. args["control_flags"] = OSD.FromString(ControlFlags.ToString());
  303. args["energy_level"] = OSD.FromReal(EnergyLevel);
  304. args["god_level"] = OSD.FromString(GodLevel.ToString());
  305. args["always_run"] = OSD.FromBoolean(AlwaysRun);
  306. args["prey_agent"] = OSD.FromUUID(PreyAgent);
  307. args["agent_access"] = OSD.FromString(AgentAccess.ToString());
  308. if ((AgentTextures != null) && (AgentTextures.Length > 0))
  309. {
  310. OSDArray textures = new OSDArray(AgentTextures.Length);
  311. foreach (UUID uuid in AgentTextures)
  312. textures.Add(OSD.FromUUID(uuid));
  313. args["agent_textures"] = textures;
  314. }
  315. args["active_group_id"] = OSD.FromUUID(ActiveGroupID);
  316. if ((Groups != null) && (Groups.Length > 0))
  317. {
  318. OSDArray groups = new OSDArray(Groups.Length);
  319. foreach (AgentGroupData agd in Groups)
  320. groups.Add(agd.PackUpdateMessage());
  321. args["groups"] = groups;
  322. }
  323. if ((Anims != null) && (Anims.Length > 0))
  324. {
  325. OSDArray anims = new OSDArray(Anims.Length);
  326. foreach (AgentAnimationData aanim in Anims)
  327. anims.Add(aanim.PackUpdateMessage());
  328. args["animations"] = anims;
  329. }
  330. if ((VisualParams != null) && (VisualParams.Length > 0))
  331. args["visual_params"] = OSD.FromBinary(VisualParams);
  332. // Last few fields are still missing: granter and NVPais
  333. if ((CallbackURI != null) && (!CallbackURI.Equals("")))
  334. args["callback_uri"] = OSD.FromString(CallbackURI);
  335. return args;
  336. }
  337. /// <summary>
  338. /// Deserialization of agent data.
  339. /// Avoiding reflection makes it painful to write, but that's the price!
  340. /// </summary>
  341. /// <param name="hash"></param>
  342. public void UnpackUpdateMessage(OSDMap args)
  343. {
  344. if (args.ContainsKey("region_handle"))
  345. UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
  346. if (args["circuit_code"] != null)
  347. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  348. if (args["agent_uuid"] != null)
  349. AgentID = args["agent_uuid"].AsUUID();
  350. if (args["session_uuid"] != null)
  351. SessionID = args["session_uuid"].AsUUID();
  352. if (args["position"] != null)
  353. Vector3.TryParse(args["position"].AsString(), out Position);
  354. if (args["velocity"] != null)
  355. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  356. if (args["center"] != null)
  357. Vector3.TryParse(args["center"].AsString(), out Center);
  358. if (args["size"] != null)
  359. Vector3.TryParse(args["size"].AsString(), out Size);
  360. if (args["at_axis"] != null)
  361. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  362. if (args["left_axis"] != null)
  363. Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
  364. if (args["up_axis"] != null)
  365. Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
  366. if (args["changed_grid"] != null)
  367. ChangedGrid = args["changed_grid"].AsBoolean();
  368. if (args["far"] != null)
  369. Far = (float)(args["far"].AsReal());
  370. if (args["aspect"] != null)
  371. Aspect = (float)args["aspect"].AsReal();
  372. if (args["throttles"] != null)
  373. Throttles = args["throttles"].AsBinary();
  374. if (args["locomotion_state"] != null)
  375. UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
  376. if (args["head_rotation"] != null)
  377. Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
  378. if (args["body_rotation"] != null)
  379. Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
  380. if (args["control_flags"] != null)
  381. UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
  382. if (args["energy_level"] != null)
  383. EnergyLevel = (float)(args["energy_level"].AsReal());
  384. if (args["god_level"] != null)
  385. Byte.TryParse(args["god_level"].AsString(), out GodLevel);
  386. if (args["always_run"] != null)
  387. AlwaysRun = args["always_run"].AsBoolean();
  388. if (args["prey_agent"] != null)
  389. PreyAgent = args["prey_agent"].AsUUID();
  390. if (args["agent_access"] != null)
  391. Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
  392. if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
  393. {
  394. OSDArray textures = (OSDArray)(args["agent_textures"]);
  395. AgentTextures = new UUID[textures.Count];
  396. int i = 0;
  397. foreach (OSD o in textures)
  398. AgentTextures[i++] = o.AsUUID();
  399. }
  400. if (args["active_group_id"] != null)
  401. ActiveGroupID = args["active_group_id"].AsUUID();
  402. if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
  403. {
  404. OSDArray groups = (OSDArray)(args["groups"]);
  405. Groups = new AgentGroupData[groups.Count];
  406. int i = 0;
  407. foreach (OSD o in groups)
  408. {
  409. if (o.Type == OSDType.Map)
  410. {
  411. Groups[i++] = new AgentGroupData((OSDMap)o);
  412. }
  413. }
  414. }
  415. if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
  416. {
  417. OSDArray anims = (OSDArray)(args["animations"]);
  418. Anims = new AgentAnimationData[anims.Count];
  419. int i = 0;
  420. foreach (OSD o in anims)
  421. {
  422. if (o.Type == OSDType.Map)
  423. {
  424. Anims[i++] = new AgentAnimationData((OSDMap)o);
  425. }
  426. }
  427. }
  428. if (args["visual_params"] != null)
  429. VisualParams = args["visual_params"].AsBinary();
  430. if (args["callback_uri"] != null)
  431. CallbackURI = args["callback_uri"].AsString();
  432. }
  433. public AgentData()
  434. {
  435. }
  436. public AgentData(Hashtable hash)
  437. {
  438. //UnpackUpdateMessage(hash);
  439. }
  440. /// <summary>
  441. /// Soon to be decommissioned
  442. /// </summary>
  443. /// <param name="cAgent"></param>
  444. public void CopyFrom(ChildAgentDataUpdate cAgent)
  445. {
  446. ActiveGroupID = new UUID(cAgent.ActiveGroupID);
  447. AgentID = new UUID(cAgent.AgentID);
  448. AlwaysRun = cAgent.alwaysrun;
  449. // next: ???
  450. Size = new Vector3();
  451. Size.Z = cAgent.AVHeight;
  452. Center = new Vector3(cAgent.cameraPosition.x, cAgent.cameraPosition.y, cAgent.cameraPosition.z);
  453. Far = cAgent.drawdistance;
  454. // downcasting ???
  455. GodLevel = (byte)(cAgent.godlevel);
  456. Groups = new AgentGroupData[1];
  457. Groups[0] = new AgentGroupData(new UUID(cAgent.ActiveGroupID), cAgent.GroupAccess, true);
  458. Position = new Vector3(cAgent.Position.x, cAgent.Position.y, cAgent.Position.z);
  459. RegionHandle = cAgent.regionHandle;
  460. Throttles = cAgent.throttles;
  461. Velocity = new Vector3(cAgent.Velocity.x, cAgent.Velocity.y, cAgent.Velocity.z);
  462. }
  463. public void Dump()
  464. {
  465. m_log.Info("------------ AgentData ------------");
  466. m_log.Info("UUID: " + AgentID);
  467. m_log.Info("Region: " + RegionHandle);
  468. m_log.Info("Position: " + Position);
  469. }
  470. }
  471. */
  472. }