ChildAgentDataUpdate.cs 19 KB

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