1
0

ChildAgentDataUpdate.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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 Vector3 cameraPosition;
  43. public float drawdistance;
  44. public float godlevel;
  45. public uint GroupAccess;
  46. public Vector3 Position;
  47. public ulong regionHandle;
  48. public byte[] throttles;
  49. public Vector3 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 = cAgent.cameraPosition;
  148. Far = cAgent.drawdistance;
  149. Position = cAgent.Position;
  150. RegionHandle = cAgent.regionHandle;
  151. Throttles = cAgent.throttles;
  152. Velocity = cAgent.Velocity;
  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 AttachmentData
  189. {
  190. public int AttachPoint;
  191. public UUID ItemID;
  192. public UUID AssetID;
  193. public AttachmentData(int point, UUID item, UUID asset)
  194. {
  195. AttachPoint = point;
  196. ItemID = item;
  197. AssetID = asset;
  198. }
  199. public AttachmentData(OSDMap args)
  200. {
  201. UnpackUpdateMessage(args);
  202. }
  203. public OSDMap PackUpdateMessage()
  204. {
  205. OSDMap attachdata = new OSDMap();
  206. attachdata["point"] = OSD.FromInteger(AttachPoint);
  207. attachdata["item"] = OSD.FromUUID(ItemID);
  208. attachdata["asset"] = OSD.FromUUID(AssetID);
  209. return attachdata;
  210. }
  211. public void UnpackUpdateMessage(OSDMap args)
  212. {
  213. if (args["point"] != null)
  214. AttachPoint = args["point"].AsInteger();
  215. if (args["item"] != null)
  216. ItemID = args["item"].AsUUID();
  217. if (args["asset"] != null)
  218. AssetID = args["asset"].AsUUID();
  219. }
  220. }
  221. public class AgentData : IAgentData
  222. {
  223. private UUID m_id;
  224. public UUID AgentID
  225. {
  226. get { return m_id; }
  227. set { m_id = value; }
  228. }
  229. public UUID RegionID;
  230. public uint CircuitCode;
  231. public UUID SessionID;
  232. public Vector3 Position;
  233. public Vector3 Velocity;
  234. public Vector3 Center;
  235. public Vector3 Size;
  236. public Vector3 AtAxis;
  237. public Vector3 LeftAxis;
  238. public Vector3 UpAxis;
  239. public bool ChangedGrid;
  240. public float Far;
  241. public float Aspect;
  242. //public int[] Throttles;
  243. public byte[] Throttles;
  244. public uint LocomotionState;
  245. public Quaternion HeadRotation;
  246. public Quaternion BodyRotation;
  247. public uint ControlFlags;
  248. public float EnergyLevel;
  249. public Byte GodLevel;
  250. public bool AlwaysRun;
  251. public UUID PreyAgent;
  252. public Byte AgentAccess;
  253. public UUID ActiveGroupID;
  254. public AgentGroupData[] Groups;
  255. public Animation[] Anims;
  256. public UUID GranterID;
  257. // Appearance
  258. public byte[] AgentTextures;
  259. public byte[] VisualParams;
  260. public UUID[] Wearables;
  261. public AttachmentData[] Attachments;
  262. public string CallbackURI;
  263. public virtual OSDMap Pack()
  264. {
  265. OSDMap args = new OSDMap();
  266. args["message_type"] = OSD.FromString("AgentData");
  267. args["region_id"] = OSD.FromString(RegionID.ToString());
  268. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  269. args["agent_uuid"] = OSD.FromUUID(AgentID);
  270. args["session_uuid"] = OSD.FromUUID(SessionID);
  271. args["position"] = OSD.FromString(Position.ToString());
  272. args["velocity"] = OSD.FromString(Velocity.ToString());
  273. args["center"] = OSD.FromString(Center.ToString());
  274. args["size"] = OSD.FromString(Size.ToString());
  275. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  276. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  277. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  278. args["changed_grid"] = OSD.FromBoolean(ChangedGrid);
  279. args["far"] = OSD.FromReal(Far);
  280. args["aspect"] = OSD.FromReal(Aspect);
  281. if ((Throttles != null) && (Throttles.Length > 0))
  282. args["throttles"] = OSD.FromBinary(Throttles);
  283. args["locomotion_state"] = OSD.FromString(LocomotionState.ToString());
  284. args["head_rotation"] = OSD.FromString(HeadRotation.ToString());
  285. args["body_rotation"] = OSD.FromString(BodyRotation.ToString());
  286. args["control_flags"] = OSD.FromString(ControlFlags.ToString());
  287. args["energy_level"] = OSD.FromReal(EnergyLevel);
  288. args["god_level"] = OSD.FromString(GodLevel.ToString());
  289. args["always_run"] = OSD.FromBoolean(AlwaysRun);
  290. args["prey_agent"] = OSD.FromUUID(PreyAgent);
  291. args["agent_access"] = OSD.FromString(AgentAccess.ToString());
  292. args["active_group_id"] = OSD.FromUUID(ActiveGroupID);
  293. if ((Groups != null) && (Groups.Length > 0))
  294. {
  295. OSDArray groups = new OSDArray(Groups.Length);
  296. foreach (AgentGroupData agd in Groups)
  297. groups.Add(agd.PackUpdateMessage());
  298. args["groups"] = groups;
  299. }
  300. if ((Anims != null) && (Anims.Length > 0))
  301. {
  302. OSDArray anims = new OSDArray(Anims.Length);
  303. foreach (Animation aanim in Anims)
  304. anims.Add(aanim.PackUpdateMessage());
  305. args["animations"] = anims;
  306. }
  307. //if ((AgentTextures != null) && (AgentTextures.Length > 0))
  308. //{
  309. // OSDArray textures = new OSDArray(AgentTextures.Length);
  310. // foreach (UUID uuid in AgentTextures)
  311. // textures.Add(OSD.FromUUID(uuid));
  312. // args["agent_textures"] = textures;
  313. //}
  314. if ((AgentTextures != null) && (AgentTextures.Length > 0))
  315. args["texture_entry"] = OSD.FromBinary(AgentTextures);
  316. if ((VisualParams != null) && (VisualParams.Length > 0))
  317. args["visual_params"] = OSD.FromBinary(VisualParams);
  318. // We might not pass this in all cases...
  319. if ((Wearables != null) && (Wearables.Length > 0))
  320. {
  321. OSDArray wears = new OSDArray(Wearables.Length);
  322. foreach (UUID uuid in Wearables)
  323. wears.Add(OSD.FromUUID(uuid));
  324. args["wearables"] = wears;
  325. }
  326. if ((Attachments != null) && (Attachments.Length > 0))
  327. {
  328. OSDArray attachs = new OSDArray(Attachments.Length);
  329. foreach (AttachmentData att in Attachments)
  330. attachs.Add(att.PackUpdateMessage());
  331. args["attachments"] = attachs;
  332. }
  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 virtual void Unpack(OSDMap args)
  343. {
  344. if (args.ContainsKey("region_id"))
  345. UUID.TryParse(args["region_id"].AsString(), out RegionID);
  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["active_group_id"] != null)
  393. ActiveGroupID = args["active_group_id"].AsUUID();
  394. if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
  395. {
  396. OSDArray groups = (OSDArray)(args["groups"]);
  397. Groups = new AgentGroupData[groups.Count];
  398. int i = 0;
  399. foreach (OSD o in groups)
  400. {
  401. if (o.Type == OSDType.Map)
  402. {
  403. Groups[i++] = new AgentGroupData((OSDMap)o);
  404. }
  405. }
  406. }
  407. if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
  408. {
  409. OSDArray anims = (OSDArray)(args["animations"]);
  410. Anims = new Animation[anims.Count];
  411. int i = 0;
  412. foreach (OSD o in anims)
  413. {
  414. if (o.Type == OSDType.Map)
  415. {
  416. Anims[i++] = new Animation((OSDMap)o);
  417. }
  418. }
  419. }
  420. //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
  421. //{
  422. // OSDArray textures = (OSDArray)(args["agent_textures"]);
  423. // AgentTextures = new UUID[textures.Count];
  424. // int i = 0;
  425. // foreach (OSD o in textures)
  426. // AgentTextures[i++] = o.AsUUID();
  427. //}
  428. if (args["texture_entry"] != null)
  429. AgentTextures = args["texture_entry"].AsBinary();
  430. if (args["visual_params"] != null)
  431. VisualParams = args["visual_params"].AsBinary();
  432. if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
  433. {
  434. OSDArray wears = (OSDArray)(args["wearables"]);
  435. Wearables = new UUID[wears.Count];
  436. int i = 0;
  437. foreach (OSD o in wears)
  438. Wearables[i++] = o.AsUUID();
  439. }
  440. if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
  441. {
  442. OSDArray attachs = (OSDArray)(args["attachments"]);
  443. Attachments = new AttachmentData[attachs.Count];
  444. int i = 0;
  445. foreach (OSD o in attachs)
  446. {
  447. if (o.Type == OSDType.Map)
  448. {
  449. Attachments[i++] = new AttachmentData((OSDMap)o);
  450. }
  451. }
  452. }
  453. if (args["callback_uri"] != null)
  454. CallbackURI = args["callback_uri"].AsString();
  455. }
  456. public AgentData()
  457. {
  458. }
  459. public AgentData(Hashtable hash)
  460. {
  461. //UnpackUpdateMessage(hash);
  462. }
  463. public void Dump()
  464. {
  465. System.Console.WriteLine("------------ AgentData ------------");
  466. System.Console.WriteLine("UUID: " + AgentID);
  467. System.Console.WriteLine("Region: " + RegionID);
  468. System.Console.WriteLine("Position: " + Position);
  469. }
  470. }
  471. public class CompleteAgentData : AgentData
  472. {
  473. public override OSDMap Pack()
  474. {
  475. return base.Pack();
  476. }
  477. public override void Unpack(OSDMap map)
  478. {
  479. base.Unpack(map);
  480. }
  481. }
  482. }