AgentCircuitData.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. /// How this agent got here
  70. /// </summary>
  71. public uint teleportFlags;
  72. /// <summary>
  73. /// Agent's account first name
  74. /// </summary>
  75. public string firstname;
  76. public UUID InventoryFolder;
  77. /// <summary>
  78. /// Agent's account last name
  79. /// </summary>
  80. public string lastname;
  81. /// <summary>
  82. /// Random Unique GUID for this session. Client gets this at login and it's
  83. /// only supposed to be disclosed over secure channels
  84. /// </summary>
  85. public UUID SecureSessionID;
  86. /// <summary>
  87. /// Non secure Session ID
  88. /// </summary>
  89. public UUID SessionID;
  90. /// <summary>
  91. /// Hypergrid service token; generated by the user domain, consumed by the receiving grid.
  92. /// There is one such unique token for each grid visited.
  93. /// </summary>
  94. public string ServiceSessionID = string.Empty;
  95. /// <summary>
  96. /// Position the Agent's Avatar starts in the region
  97. /// </summary>
  98. public Vector3 startpos;
  99. public Dictionary<string, object> ServiceURLs;
  100. public AgentCircuitData()
  101. {
  102. }
  103. /// <summary>
  104. /// Create AgentCircuitData from a Serializable AgentCircuitData
  105. /// </summary>
  106. /// <param name="cAgent"></param>
  107. public AgentCircuitData(sAgentCircuitData cAgent)
  108. {
  109. AgentID = new UUID(cAgent.AgentID);
  110. SessionID = new UUID(cAgent.SessionID);
  111. SecureSessionID = new UUID(cAgent.SecureSessionID);
  112. startpos = new Vector3(cAgent.startposx, cAgent.startposy, cAgent.startposz);
  113. firstname = cAgent.firstname;
  114. lastname = cAgent.lastname;
  115. circuitcode = cAgent.circuitcode;
  116. child = cAgent.child;
  117. InventoryFolder = new UUID(cAgent.InventoryFolder);
  118. BaseFolder = new UUID(cAgent.BaseFolder);
  119. CapsPath = cAgent.CapsPath;
  120. ChildrenCapSeeds = cAgent.ChildrenCapSeeds;
  121. }
  122. /// <summary>
  123. /// Pack AgentCircuitData into an OSDMap for transmission over LLSD XML or LLSD json
  124. /// </summary>
  125. /// <returns>map of the agent circuit data</returns>
  126. public OSDMap PackAgentCircuitData()
  127. {
  128. OSDMap args = new OSDMap();
  129. args["agent_id"] = OSD.FromUUID(AgentID);
  130. args["base_folder"] = OSD.FromUUID(BaseFolder);
  131. args["caps_path"] = OSD.FromString(CapsPath);
  132. if (ChildrenCapSeeds != null)
  133. {
  134. OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
  135. foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
  136. {
  137. OSDMap pair = new OSDMap();
  138. pair["handle"] = OSD.FromString(kvp.Key.ToString());
  139. pair["seed"] = OSD.FromString(kvp.Value);
  140. childrenSeeds.Add(pair);
  141. }
  142. if (ChildrenCapSeeds.Count > 0)
  143. args["children_seeds"] = childrenSeeds;
  144. }
  145. args["child"] = OSD.FromBoolean(child);
  146. args["circuit_code"] = OSD.FromString(circuitcode.ToString());
  147. args["first_name"] = OSD.FromString(firstname);
  148. args["last_name"] = OSD.FromString(lastname);
  149. args["inventory_folder"] = OSD.FromUUID(InventoryFolder);
  150. args["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  151. args["session_id"] = OSD.FromUUID(SessionID);
  152. args["service_session_id"] = OSD.FromString(ServiceSessionID);
  153. args["start_pos"] = OSD.FromString(startpos.ToString());
  154. args["appearance_serial"] = OSD.FromInteger(Appearance.Serial);
  155. if (Appearance != null)
  156. {
  157. //System.Console.WriteLine("XXX Before packing Wearables");
  158. if ((Appearance.Wearables != null) && (Appearance.Wearables.Length > 0))
  159. {
  160. OSDArray wears = new OSDArray(Appearance.Wearables.Length * 2);
  161. foreach (AvatarWearable awear in Appearance.Wearables)
  162. {
  163. wears.Add(OSD.FromUUID(awear.ItemID));
  164. wears.Add(OSD.FromUUID(awear.AssetID));
  165. //System.Console.WriteLine("XXX ItemID=" + awear.ItemID + " assetID=" + awear.AssetID);
  166. }
  167. args["wearables"] = wears;
  168. }
  169. //System.Console.WriteLine("XXX Before packing Attachments");
  170. Dictionary<int, UUID[]> attachments = Appearance.GetAttachmentDictionary();
  171. if ((attachments != null) && (attachments.Count > 0))
  172. {
  173. OSDArray attachs = new OSDArray(attachments.Count);
  174. foreach (KeyValuePair<int, UUID[]> kvp in attachments)
  175. {
  176. AttachmentData adata = new AttachmentData(kvp.Key, kvp.Value[0], kvp.Value[1]);
  177. attachs.Add(adata.PackUpdateMessage());
  178. //System.Console.WriteLine("XXX att.pt=" + kvp.Key + "; itemID=" + kvp.Value[0] + "; assetID=" + kvp.Value[1]);
  179. }
  180. args["attachments"] = attachs;
  181. }
  182. }
  183. if (ServiceURLs != null && ServiceURLs.Count > 0)
  184. {
  185. OSDArray urls = new OSDArray(ServiceURLs.Count * 2);
  186. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  187. {
  188. //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
  189. urls.Add(OSD.FromString(kvp.Key));
  190. urls.Add(OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString()));
  191. }
  192. args["service_urls"] = urls;
  193. }
  194. return args;
  195. }
  196. /// <summary>
  197. /// Unpack agent circuit data map into an AgentCiruitData object
  198. /// </summary>
  199. /// <param name="args"></param>
  200. public void UnpackAgentCircuitData(OSDMap args)
  201. {
  202. if (args["agent_id"] != null)
  203. AgentID = args["agent_id"].AsUUID();
  204. if (args["base_folder"] != null)
  205. BaseFolder = args["base_folder"].AsUUID();
  206. if (args["caps_path"] != null)
  207. CapsPath = args["caps_path"].AsString();
  208. if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
  209. {
  210. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  211. ChildrenCapSeeds = new Dictionary<ulong, string>();
  212. foreach (OSD o in childrenSeeds)
  213. {
  214. if (o.Type == OSDType.Map)
  215. {
  216. ulong handle = 0;
  217. string seed = "";
  218. OSDMap pair = (OSDMap)o;
  219. if (pair["handle"] != null)
  220. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  221. continue;
  222. if (pair["seed"] != null)
  223. seed = pair["seed"].AsString();
  224. if (!ChildrenCapSeeds.ContainsKey(handle))
  225. ChildrenCapSeeds.Add(handle, seed);
  226. }
  227. }
  228. }
  229. else
  230. ChildrenCapSeeds = new Dictionary<ulong, string>();
  231. if (args["child"] != null)
  232. child = args["child"].AsBoolean();
  233. if (args["circuit_code"] != null)
  234. UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
  235. if (args["first_name"] != null)
  236. firstname = args["first_name"].AsString();
  237. if (args["last_name"] != null)
  238. lastname = args["last_name"].AsString();
  239. if (args["inventory_folder"] != null)
  240. InventoryFolder = args["inventory_folder"].AsUUID();
  241. if (args["secure_session_id"] != null)
  242. SecureSessionID = args["secure_session_id"].AsUUID();
  243. if (args["session_id"] != null)
  244. SessionID = args["session_id"].AsUUID();
  245. if (args["service_session_id"] != null)
  246. ServiceSessionID = args["service_session_id"].AsString();
  247. if (args["start_pos"] != null)
  248. Vector3.TryParse(args["start_pos"].AsString(), out startpos);
  249. Appearance = new AvatarAppearance(AgentID);
  250. if (args["appearance_serial"] != null)
  251. Appearance.Serial = args["appearance_serial"].AsInteger();
  252. if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
  253. {
  254. OSDArray wears = (OSDArray)(args["wearables"]);
  255. for (int i = 0; i < wears.Count / 2; i++)
  256. {
  257. Appearance.Wearables[i].ItemID = wears[i*2].AsUUID();
  258. Appearance.Wearables[i].AssetID = wears[(i*2)+1].AsUUID();
  259. }
  260. }
  261. if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
  262. {
  263. OSDArray attachs = (OSDArray)(args["attachments"]);
  264. AttachmentData[] attachments = new AttachmentData[attachs.Count];
  265. int i = 0;
  266. foreach (OSD o in attachs)
  267. {
  268. if (o.Type == OSDType.Map)
  269. {
  270. attachments[i++] = new AttachmentData((OSDMap)o);
  271. }
  272. }
  273. Appearance.SetAttachments(attachments);
  274. }
  275. ServiceURLs = new Dictionary<string, object>();
  276. if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
  277. {
  278. OSDArray urls = (OSDArray)(args["service_urls"]);
  279. for (int i = 0; i < urls.Count / 2; i++)
  280. {
  281. ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
  282. //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());
  283. }
  284. }
  285. }
  286. }
  287. /// <summary>
  288. /// Serializable Agent Circuit Data
  289. /// </summary>
  290. [Serializable]
  291. public class sAgentCircuitData
  292. {
  293. public Guid AgentID;
  294. public Guid BaseFolder;
  295. public string CapsPath = String.Empty;
  296. public Dictionary<ulong, string> ChildrenCapSeeds;
  297. public bool child;
  298. public uint circuitcode;
  299. public string firstname;
  300. public Guid InventoryFolder;
  301. public string lastname;
  302. public Guid SecureSessionID;
  303. public Guid SessionID;
  304. public float startposx;
  305. public float startposy;
  306. public float startposz;
  307. public sAgentCircuitData()
  308. {
  309. }
  310. public sAgentCircuitData(AgentCircuitData cAgent)
  311. {
  312. AgentID = cAgent.AgentID.Guid;
  313. SessionID = cAgent.SessionID.Guid;
  314. SecureSessionID = cAgent.SecureSessionID.Guid;
  315. startposx = cAgent.startpos.X;
  316. startposy = cAgent.startpos.Y;
  317. startposz = cAgent.startpos.Z;
  318. firstname = cAgent.firstname;
  319. lastname = cAgent.lastname;
  320. circuitcode = cAgent.circuitcode;
  321. child = cAgent.child;
  322. InventoryFolder = cAgent.InventoryFolder.Guid;
  323. BaseFolder = cAgent.BaseFolder.Guid;
  324. CapsPath = cAgent.CapsPath;
  325. ChildrenCapSeeds = cAgent.ChildrenCapSeeds;
  326. }
  327. }
  328. }