ChildAgentDataUpdate.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 OpenMetaverse;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using OSD = OpenMetaverse.StructuredData.OSD;
  32. using OSDMap = OpenMetaverse.StructuredData.OSDMap;
  33. using OSDArray = OpenMetaverse.StructuredData.OSDArray;
  34. using OSDParser = OpenMetaverse.StructuredData.OSDParser;
  35. namespace OpenSim.Framework
  36. {
  37. // Soon to be dismissed
  38. [Serializable]
  39. public class ChildAgentDataUpdate
  40. {
  41. public Guid ActiveGroupID;
  42. public Guid AgentID;
  43. public bool alwaysrun;
  44. public float AVHeight;
  45. public sLLVector3 cameraPosition;
  46. public float drawdistance;
  47. public float godlevel;
  48. public uint GroupAccess;
  49. public sLLVector3 Position;
  50. public ulong regionHandle;
  51. public byte[] throttles;
  52. public sLLVector3 Velocity;
  53. public ChildAgentDataUpdate()
  54. {
  55. }
  56. public ChildAgentDataUpdate(AgentData agent)
  57. {
  58. if (agent.ActiveGroupID != null)
  59. ActiveGroupID = agent.ActiveGroupID.Guid;
  60. if (agent.AgentID != null)
  61. AgentID = agent.AgentID.Guid;
  62. alwaysrun = agent.AlwaysRun;
  63. if (agent.Size != null)
  64. AVHeight = agent.Size.Z;
  65. if (agent.Center != null)
  66. cameraPosition = new sLLVector3(agent.Center);
  67. drawdistance = agent.Far;
  68. godlevel = (float)agent.GodLevel;
  69. if (agent.Groups.Length > 0)
  70. GroupAccess = (uint)agent.Groups[0].GroupPowers;
  71. if (agent.Position != null)
  72. Position = new sLLVector3(agent.Position);
  73. regionHandle = agent.RegionHandle;
  74. throttles = agent.Throttles;
  75. if (agent.Velocity != null)
  76. Velocity = new sLLVector3(agent.Velocity);
  77. }
  78. }
  79. public class AgentGroupData
  80. {
  81. public UUID GroupID;
  82. public ulong GroupPowers;
  83. public bool AcceptNotices;
  84. public AgentGroupData(UUID id, ulong powers, bool notices)
  85. {
  86. GroupID = id;
  87. GroupPowers = powers;
  88. AcceptNotices = notices;
  89. }
  90. }
  91. public class AgentAnimationData
  92. {
  93. public UUID Animation;
  94. public UUID ObjectID;
  95. }
  96. public class AgentData
  97. {
  98. public ulong RegionHandle;
  99. public uint CircuitCode;
  100. public UUID AgentID;
  101. public UUID SessionID;
  102. public Vector3 Position;
  103. public Vector3 Velocity;
  104. public Vector3 Center;
  105. public Vector3 Size;
  106. public Vector3 AtAxis;
  107. public Vector3 LeftAxis;
  108. public Vector3 UpAxis;
  109. public bool ChangedGrid;
  110. public float Far;
  111. public float Aspect;
  112. //public int[] Throttles;
  113. public byte[] Throttles;
  114. public uint LocomotionState;
  115. public Quaternion HeadRotation;
  116. public Quaternion BodyRotation;
  117. public uint ControlFlags;
  118. public float EnergyLevel;
  119. public Byte GodLevel;
  120. public bool AlwaysRun;
  121. public UUID PreyAgent;
  122. public Byte AgentAccess;
  123. public UUID[] AgentTextures;
  124. public UUID ActiveGroupID;
  125. public AgentGroupData[] Groups;
  126. public AgentAnimationData[] Anims;
  127. public UUID GranterID;
  128. public Dictionary<string, string> NVPairs;
  129. byte[] VisualParams;
  130. public OSDMap PackUpdateMessage()
  131. {
  132. OSDMap args = new OSDMap();
  133. args["region_handle"] = OSD.FromString(RegionHandle.ToString());
  134. args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
  135. if (AgentID != null)
  136. args["agent_uuid"] = OSD.FromUUID(AgentID);
  137. if (SessionID != null)
  138. args["session_uuid"] = OSD.FromUUID(SessionID);
  139. if (Position != null)
  140. args["position"] = OSD.FromString(Position.ToString());
  141. if (Velocity != null)
  142. args["velocity"] = OSD.FromString(Velocity.ToString());
  143. if (Center != null)
  144. args["center"] = OSD.FromString(Center.ToString());
  145. if (Size != null)
  146. args["size"] = OSD.FromString(Size.ToString());
  147. if (AtAxis != null)
  148. args["at_axis"] = OSD.FromString(AtAxis.ToString());
  149. if (LeftAxis != null)
  150. args["left_axis"] = OSD.FromString(LeftAxis.ToString());
  151. if (UpAxis != null)
  152. args["up_axis"] = OSD.FromString(UpAxis.ToString());
  153. args["changed_grid"] = OSD.FromBoolean(ChangedGrid);
  154. args["far"] = OSD.FromReal(Far);
  155. args["aspect"] = OSD.FromReal(Aspect);
  156. if ((Throttles != null) && (Throttles.Length > 0))
  157. args["throttles"] = OSD.FromBinary(Throttles);
  158. args["locomotion_state"] = OSD.FromString(LocomotionState.ToString());
  159. if (HeadRotation != null)
  160. args["head_rotation"] = OSD.FromString(HeadRotation.ToString());
  161. if (BodyRotation != null)
  162. args["body_rotation"] = OSD.FromString(BodyRotation.ToString());
  163. args["control_flags"] = OSD.FromString(ControlFlags.ToString());
  164. args["energy_level"] = OSD.FromReal(EnergyLevel);
  165. args["god_level"] = OSD.FromString(GodLevel.ToString());
  166. args["always_run"] = OSD.FromBoolean(AlwaysRun);
  167. if (PreyAgent != null)
  168. args["prey_agent"] = OSD.FromUUID(PreyAgent);
  169. args["agent_access"] = OSD.FromString(AgentAccess.ToString());
  170. if ((AgentTextures != null) && (AgentTextures.Length > 0))
  171. {
  172. OSDArray textures = new OSDArray(AgentTextures.Length);
  173. foreach (UUID uuid in AgentTextures)
  174. textures.Add(OSD.FromUUID(uuid));
  175. args["agent_textures"] = textures;
  176. }
  177. if (ActiveGroupID != null)
  178. args["active_group_id"] = OSD.FromUUID(ActiveGroupID);
  179. // Last few fields are still missing
  180. return args;
  181. }
  182. /// <summary>
  183. /// Deserialization of agent data.
  184. /// Avoiding reflection makes it painful to write, but that's the price!
  185. /// </summary>
  186. /// <param name="hash"></param>
  187. public void UnpackUpdateMessage(OSDMap args)
  188. {
  189. if (args.ContainsKey("region_handle"))
  190. UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
  191. if (args["circuit_code"] != null)
  192. UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
  193. if (args["agent_uuid"] != null)
  194. AgentID = args["agent_uuid"].AsUUID();
  195. if (args["session_uuid"] != null)
  196. SessionID = args["session_uuid"].AsUUID();
  197. if (args["position"] != null)
  198. Vector3.TryParse(args["position"].AsString(), out Position);
  199. if (args["velocity"] != null)
  200. Vector3.TryParse(args["velocity"].AsString(), out Velocity);
  201. if (args["center"] != null)
  202. Vector3.TryParse(args["center"].AsString(), out Center);
  203. if (args["size"] != null)
  204. Vector3.TryParse(args["size"].AsString(), out Size);
  205. if (args["at_axis"] != null)
  206. Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
  207. if (args["left_axis"] != null)
  208. Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
  209. if (args["up_axis"] != null)
  210. Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
  211. if (args["changed_grid"] != null)
  212. ChangedGrid = args["changed_grid"].AsBoolean();
  213. if (args["far"] != null)
  214. Far = (float)(args["far"].AsReal());
  215. if (args["aspect"] != null)
  216. Aspect = (float)args["aspect"].AsReal();
  217. if (args["throttles"] != null)
  218. Throttles = args["throttles"].AsBinary();
  219. if (args["locomotion_state"] != null)
  220. UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
  221. if (args["head_rotation"] != null)
  222. Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
  223. if (args["body_rotation"] != null)
  224. Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
  225. if (args["control_flags"] != null)
  226. UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
  227. if (args["energy_level"] != null)
  228. EnergyLevel = (float)(args["energy_level"].AsReal());
  229. if (args["god_level"] != null)
  230. Byte.TryParse(args["god_level"].AsString(), out GodLevel);
  231. if (args["always_run"] != null)
  232. AlwaysRun = args["always_run"].AsBoolean();
  233. if (args["prey_agent"] != null)
  234. PreyAgent = args["prey_agent"].AsUUID();
  235. if (args["agent_access"] != null)
  236. Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
  237. if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OpenMetaverse.StructuredData.OSDType.Array)
  238. {
  239. OSDArray textures = (OSDArray)(args["agent_textures"]);
  240. AgentTextures = new UUID[textures.Count];
  241. int i = 0;
  242. foreach (OSD o in textures)
  243. AgentTextures[i++] = o.AsUUID();
  244. }
  245. if (args["active_group_id"] != null)
  246. ActiveGroupID = args["active_group_id"].AsUUID();
  247. }
  248. public AgentData()
  249. {
  250. }
  251. public AgentData(Hashtable hash)
  252. {
  253. //UnpackUpdateMessage(hash);
  254. }
  255. /// <summary>
  256. /// Soon to be decommissioned
  257. /// </summary>
  258. /// <param name="cAgent"></param>
  259. public void CopyFrom(ChildAgentDataUpdate cAgent)
  260. {
  261. if (cAgent.ActiveGroupID != null)
  262. ActiveGroupID = new UUID(cAgent.ActiveGroupID);
  263. if (cAgent.AgentID != null)
  264. AgentID = new UUID(cAgent.AgentID);
  265. AlwaysRun = cAgent.alwaysrun;
  266. // next: ???
  267. Size = new Vector3();
  268. Size.Z = cAgent.AVHeight;
  269. if (cAgent.cameraPosition != null)
  270. Center = new Vector3(cAgent.cameraPosition.x, cAgent.cameraPosition.y, cAgent.cameraPosition.z);
  271. Far = cAgent.drawdistance;
  272. // downcasting ???
  273. GodLevel = (byte)(cAgent.godlevel);
  274. if (cAgent.ActiveGroupID != null)
  275. {
  276. Groups = new AgentGroupData[1];
  277. Groups[0] = new AgentGroupData(new UUID(cAgent.ActiveGroupID), cAgent.GroupAccess, true);
  278. }
  279. if (cAgent.Position != null)
  280. Position = new Vector3(cAgent.Position.x, cAgent.Position.y, cAgent.Position.z);
  281. RegionHandle = cAgent.regionHandle;
  282. Throttles = cAgent.throttles;
  283. if (cAgent.Velocity != null)
  284. Velocity = new Vector3(cAgent.Velocity.x, cAgent.Velocity.y, cAgent.Velocity.z);
  285. }
  286. public void Dump()
  287. {
  288. System.Console.WriteLine("------------ AgentData ------------");
  289. System.Console.WriteLine("UUID: " + AgentID);
  290. System.Console.WriteLine("Region: " + RegionHandle);
  291. System.Console.WriteLine("Position: " + Position);
  292. }
  293. }
  294. }