AgentCircuitData.cs 15 KB

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