1
0

AgentCircuitData.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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.Generic;
  29. using OpenMetaverse;
  30. using OpenMetaverse.StructuredData;
  31. namespace OpenSim.Framework
  32. {
  33. /// <summary>
  34. /// Circuit data for an agent. Connection information shared between
  35. /// regions that accept UDP connections from a client
  36. /// </summary>
  37. public class AgentCircuitData
  38. {
  39. /// <summary>
  40. /// Avatar Unique Agent Identifier
  41. /// </summary>
  42. public UUID AgentID;
  43. /// <summary>
  44. /// Avatar's Appearance
  45. /// </summary>
  46. public AvatarAppearance Appearance;
  47. /// <summary>
  48. /// Agent's root inventory folder
  49. /// </summary>
  50. public UUID BaseFolder;
  51. /// <summary>
  52. /// Base Caps path for user
  53. /// </summary>
  54. public string CapsPath = String.Empty;
  55. /// <summary>
  56. /// Seed caps for neighbor regions that the user can see into
  57. /// </summary>
  58. public Dictionary<ulong, string> ChildrenCapSeeds;
  59. /// <summary>
  60. /// Root agent, or Child agent
  61. /// </summary>
  62. public bool child;
  63. /// <summary>
  64. /// Number given to the client when they log-in that they provide
  65. /// as credentials to the UDP server
  66. /// </summary>
  67. public uint circuitcode;
  68. /// <summary>
  69. /// Agent's account first name
  70. /// </summary>
  71. public string firstname;
  72. public UUID InventoryFolder;
  73. /// <summary>
  74. /// Agent's account last name
  75. /// </summary>
  76. public string lastname;
  77. /// <summary>
  78. /// Random Unique GUID for this session. Client gets this at login and it's
  79. /// only supposed to be disclosed over secure channels
  80. /// </summary>
  81. public UUID SecureSessionID;
  82. /// <summary>
  83. /// Non secure Session ID
  84. /// </summary>
  85. public UUID SessionID;
  86. /// <summary>
  87. /// Position the Agent's Avatar starts in the region
  88. /// </summary>
  89. public Vector3 startpos;
  90. public AgentCircuitData()
  91. {
  92. }
  93. /// <summary>
  94. /// Create AgentCircuitData from a Serializable AgentCircuitData
  95. /// </summary>
  96. /// <param name="cAgent"></param>
  97. public AgentCircuitData(sAgentCircuitData cAgent)
  98. {
  99. AgentID = new UUID(cAgent.AgentID);
  100. SessionID = new UUID(cAgent.SessionID);
  101. SecureSessionID = new UUID(cAgent.SecureSessionID);
  102. startpos = new Vector3(cAgent.startposx, cAgent.startposy, cAgent.startposz);
  103. firstname = cAgent.firstname;
  104. lastname = cAgent.lastname;
  105. circuitcode = cAgent.circuitcode;
  106. child = cAgent.child;
  107. InventoryFolder = new UUID(cAgent.InventoryFolder);
  108. BaseFolder = new UUID(cAgent.BaseFolder);
  109. CapsPath = cAgent.CapsPath;
  110. ChildrenCapSeeds = cAgent.ChildrenCapSeeds;
  111. }
  112. /// <summary>
  113. /// Pack AgentCircuitData into an OSDMap for transmission over LLSD XML or LLSD json
  114. /// </summary>
  115. /// <returns>map of the agent circuit data</returns>
  116. public OSDMap PackAgentCircuitData()
  117. {
  118. OSDMap args = new OSDMap();
  119. args["agent_id"] = OSD.FromUUID(AgentID);
  120. args["base_folder"] = OSD.FromUUID(BaseFolder);
  121. args["caps_path"] = OSD.FromString(CapsPath);
  122. OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
  123. foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
  124. {
  125. OSDMap pair = new OSDMap();
  126. pair["handle"] = OSD.FromString(kvp.Key.ToString());
  127. pair["seed"] = OSD.FromString(kvp.Value);
  128. childrenSeeds.Add(pair);
  129. }
  130. if (ChildrenCapSeeds.Count > 0)
  131. args["children_seeds"] = childrenSeeds;
  132. args["child"] = OSD.FromBoolean(child);
  133. args["circuit_code"] = OSD.FromString(circuitcode.ToString());
  134. args["first_name"] = OSD.FromString(firstname);
  135. args["last_name"] = OSD.FromString(lastname);
  136. args["inventory_folder"] = OSD.FromUUID(InventoryFolder);
  137. args["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  138. args["session_id"] = OSD.FromUUID(SessionID);
  139. args["start_pos"] = OSD.FromString(startpos.ToString());
  140. return args;
  141. }
  142. /// <summary>
  143. /// Unpack agent circuit data map into an AgentCiruitData object
  144. /// </summary>
  145. /// <param name="args"></param>
  146. public void UnpackAgentCircuitData(OSDMap args)
  147. {
  148. if (args["agent_id"] != null)
  149. AgentID = args["agent_id"].AsUUID();
  150. if (args["base_folder"] != null)
  151. BaseFolder = args["base_folder"].AsUUID();
  152. if (args["caps_path"] != null)
  153. CapsPath = args["caps_path"].AsString();
  154. if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
  155. {
  156. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  157. ChildrenCapSeeds = new Dictionary<ulong, string>();
  158. foreach (OSD o in childrenSeeds)
  159. {
  160. if (o.Type == OSDType.Map)
  161. {
  162. ulong handle = 0;
  163. string seed = "";
  164. OSDMap pair = (OSDMap)o;
  165. if (pair["handle"] != null)
  166. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  167. continue;
  168. if (pair["seed"] != null)
  169. seed = pair["seed"].AsString();
  170. if (!ChildrenCapSeeds.ContainsKey(handle))
  171. ChildrenCapSeeds.Add(handle, seed);
  172. }
  173. }
  174. }
  175. if (args["child"] != null)
  176. child = args["child"].AsBoolean();
  177. if (args["circuit_code"] != null)
  178. UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
  179. if (args["first_name"] != null)
  180. firstname = args["first_name"].AsString();
  181. if (args["last_name"] != null)
  182. lastname = args["last_name"].AsString();
  183. if (args["inventory_folder"] != null)
  184. InventoryFolder = args["inventory_folder"].AsUUID();
  185. if (args["secure_session_id"] != null)
  186. SecureSessionID = args["secure_session_id"].AsUUID();
  187. if (args["session_id"] != null)
  188. SessionID = args["session_id"].AsUUID();
  189. if (args["start_pos"] != null)
  190. Vector3.TryParse(args["start_pos"].AsString(), out startpos);
  191. }
  192. }
  193. /// <summary>
  194. /// Serializable Agent Circuit Data
  195. /// </summary>
  196. [Serializable]
  197. public class sAgentCircuitData
  198. {
  199. public Guid AgentID;
  200. public Guid BaseFolder;
  201. public string CapsPath = String.Empty;
  202. public Dictionary<ulong, string> ChildrenCapSeeds;
  203. public bool child;
  204. public uint circuitcode;
  205. public string firstname;
  206. public Guid InventoryFolder;
  207. public string lastname;
  208. public Guid SecureSessionID;
  209. public Guid SessionID;
  210. public float startposx;
  211. public float startposy;
  212. public float startposz;
  213. public sAgentCircuitData()
  214. {
  215. }
  216. public sAgentCircuitData(AgentCircuitData cAgent)
  217. {
  218. AgentID = cAgent.AgentID.Guid;
  219. SessionID = cAgent.SessionID.Guid;
  220. SecureSessionID = cAgent.SecureSessionID.Guid;
  221. startposx = cAgent.startpos.X;
  222. startposy = cAgent.startpos.Y;
  223. startposz = cAgent.startpos.Z;
  224. firstname = cAgent.firstname;
  225. lastname = cAgent.lastname;
  226. circuitcode = cAgent.circuitcode;
  227. child = cAgent.child;
  228. InventoryFolder = cAgent.InventoryFolder.Guid;
  229. BaseFolder = cAgent.BaseFolder.Guid;
  230. CapsPath = cAgent.CapsPath;
  231. ChildrenCapSeeds = cAgent.ChildrenCapSeeds;
  232. }
  233. }
  234. }