AgentCircuitData.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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.Reflection;
  29. using System.Collections.Generic;
  30. using log4net;
  31. using OpenMetaverse;
  32. using OpenMetaverse.StructuredData;
  33. namespace OpenSim.Framework
  34. {
  35. /// <summary>
  36. /// Circuit data for an agent. Connection information shared between
  37. /// regions that accept UDP connections from a client
  38. /// </summary>
  39. public class AgentCircuitData
  40. {
  41. // DEBUG ON
  42. private static readonly ILog m_log =
  43. LogManager.GetLogger(
  44. MethodBase.GetCurrentMethod().DeclaringType);
  45. // DEBUG OFF
  46. /// <summary>
  47. /// Avatar Unique Agent Identifier
  48. /// </summary>
  49. public UUID AgentID;
  50. /// <summary>
  51. /// Avatar's Appearance
  52. /// </summary>
  53. public AvatarAppearance Appearance;
  54. /// <summary>
  55. /// Agent's root inventory folder
  56. /// </summary>
  57. public UUID BaseFolder;
  58. /// <summary>
  59. /// Base Caps path for user
  60. /// </summary>
  61. public string CapsPath = String.Empty;
  62. /// <summary>
  63. /// Seed caps for neighbor regions that the user can see into
  64. /// </summary>
  65. public Dictionary<ulong, string> ChildrenCapSeeds;
  66. /// <summary>
  67. /// Root agent, or Child agent
  68. /// </summary>
  69. public bool child;
  70. /// <summary>
  71. /// Number given to the client when they log-in that they provide
  72. /// as credentials to the UDP server
  73. /// </summary>
  74. public uint circuitcode;
  75. /// <summary>
  76. /// How this agent got here
  77. /// </summary>
  78. public uint teleportFlags;
  79. /// <summary>
  80. /// Agent's account first name
  81. /// </summary>
  82. public string firstname;
  83. public UUID InventoryFolder;
  84. /// <summary>
  85. /// Agent's account last name
  86. /// </summary>
  87. public string lastname;
  88. /// <summary>
  89. /// Random Unique GUID for this session. Client gets this at login and it's
  90. /// only supposed to be disclosed over secure channels
  91. /// </summary>
  92. public UUID SecureSessionID;
  93. /// <summary>
  94. /// Non secure Session ID
  95. /// </summary>
  96. public UUID SessionID;
  97. /// <summary>
  98. /// Hypergrid service token; generated by the user domain, consumed by the receiving grid.
  99. /// There is one such unique token for each grid visited.
  100. /// </summary>
  101. public string ServiceSessionID = string.Empty;
  102. /// <summary>
  103. /// The client's IP address, as captured by the login service
  104. /// </summary>
  105. public string IPAddress;
  106. /// <summary>
  107. /// Viewer's version string as reported by the viewer at login
  108. /// </summary>
  109. public string Viewer;
  110. /// <summary>
  111. /// The channel strinf sent by the viewer at login
  112. /// </summary>
  113. public string Channel;
  114. /// <summary>
  115. /// The Mac address as reported by the viewer at login
  116. /// </summary>
  117. public string Mac;
  118. /// <summary>
  119. /// The id0 as reported by the viewer at login
  120. /// </summary>
  121. public string Id0;
  122. /// <summary>
  123. /// Position the Agent's Avatar starts in the region
  124. /// </summary>
  125. public Vector3 startpos;
  126. public Dictionary<string, object> ServiceURLs;
  127. public AgentCircuitData()
  128. {
  129. }
  130. /// <summary>
  131. /// Create AgentCircuitData from a Serializable AgentCircuitData
  132. /// </summary>
  133. /// <param name="cAgent"></param>
  134. public AgentCircuitData(sAgentCircuitData cAgent)
  135. {
  136. AgentID = new UUID(cAgent.AgentID);
  137. SessionID = new UUID(cAgent.SessionID);
  138. SecureSessionID = new UUID(cAgent.SecureSessionID);
  139. startpos = new Vector3(cAgent.startposx, cAgent.startposy, cAgent.startposz);
  140. firstname = cAgent.firstname;
  141. lastname = cAgent.lastname;
  142. circuitcode = cAgent.circuitcode;
  143. child = cAgent.child;
  144. InventoryFolder = new UUID(cAgent.InventoryFolder);
  145. BaseFolder = new UUID(cAgent.BaseFolder);
  146. CapsPath = cAgent.CapsPath;
  147. ChildrenCapSeeds = cAgent.ChildrenCapSeeds;
  148. Viewer = cAgent.Viewer;
  149. }
  150. /// <summary>
  151. /// Pack AgentCircuitData into an OSDMap for transmission over LLSD XML or LLSD json
  152. /// </summary>
  153. /// <returns>map of the agent circuit data</returns>
  154. public OSDMap PackAgentCircuitData()
  155. {
  156. OSDMap args = new OSDMap();
  157. args["agent_id"] = OSD.FromUUID(AgentID);
  158. args["base_folder"] = OSD.FromUUID(BaseFolder);
  159. args["caps_path"] = OSD.FromString(CapsPath);
  160. if (ChildrenCapSeeds != null)
  161. {
  162. OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
  163. foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
  164. {
  165. OSDMap pair = new OSDMap();
  166. pair["handle"] = OSD.FromString(kvp.Key.ToString());
  167. pair["seed"] = OSD.FromString(kvp.Value);
  168. childrenSeeds.Add(pair);
  169. }
  170. if (ChildrenCapSeeds.Count > 0)
  171. args["children_seeds"] = childrenSeeds;
  172. }
  173. args["child"] = OSD.FromBoolean(child);
  174. args["circuit_code"] = OSD.FromString(circuitcode.ToString());
  175. args["first_name"] = OSD.FromString(firstname);
  176. args["last_name"] = OSD.FromString(lastname);
  177. args["inventory_folder"] = OSD.FromUUID(InventoryFolder);
  178. args["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  179. args["session_id"] = OSD.FromUUID(SessionID);
  180. args["service_session_id"] = OSD.FromString(ServiceSessionID);
  181. args["start_pos"] = OSD.FromString(startpos.ToString());
  182. args["client_ip"] = OSD.FromString(IPAddress);
  183. args["viewer"] = OSD.FromString(Viewer);
  184. args["channel"] = OSD.FromString(Channel);
  185. args["mac"] = OSD.FromString(Mac);
  186. args["id0"] = OSD.FromString(Id0);
  187. if (Appearance != null)
  188. {
  189. args["appearance_serial"] = OSD.FromInteger(Appearance.Serial);
  190. OSDMap appmap = Appearance.Pack();
  191. args["packed_appearance"] = appmap;
  192. }
  193. // Old, bad way. Keeping it fow now for backwards compatibility
  194. // OBSOLETE -- soon to be deleted
  195. if (ServiceURLs != null && ServiceURLs.Count > 0)
  196. {
  197. OSDArray urls = new OSDArray(ServiceURLs.Count * 2);
  198. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  199. {
  200. //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
  201. urls.Add(OSD.FromString(kvp.Key));
  202. urls.Add(OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString()));
  203. }
  204. args["service_urls"] = urls;
  205. }
  206. // again, this time the right way
  207. if (ServiceURLs != null && ServiceURLs.Count > 0)
  208. {
  209. OSDMap urls = new OSDMap();
  210. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  211. {
  212. //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
  213. urls[kvp.Key] = OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString());
  214. }
  215. args["serviceurls"] = urls;
  216. }
  217. return args;
  218. }
  219. /// <summary>
  220. /// Unpack agent circuit data map into an AgentCiruitData object
  221. /// </summary>
  222. /// <param name="args"></param>
  223. public void UnpackAgentCircuitData(OSDMap args)
  224. {
  225. if (args["agent_id"] != null)
  226. AgentID = args["agent_id"].AsUUID();
  227. if (args["base_folder"] != null)
  228. BaseFolder = args["base_folder"].AsUUID();
  229. if (args["caps_path"] != null)
  230. CapsPath = args["caps_path"].AsString();
  231. if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
  232. {
  233. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  234. ChildrenCapSeeds = new Dictionary<ulong, string>();
  235. foreach (OSD o in childrenSeeds)
  236. {
  237. if (o.Type == OSDType.Map)
  238. {
  239. ulong handle = 0;
  240. string seed = "";
  241. OSDMap pair = (OSDMap)o;
  242. if (pair["handle"] != null)
  243. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  244. continue;
  245. if (pair["seed"] != null)
  246. seed = pair["seed"].AsString();
  247. if (!ChildrenCapSeeds.ContainsKey(handle))
  248. ChildrenCapSeeds.Add(handle, seed);
  249. }
  250. }
  251. }
  252. else
  253. ChildrenCapSeeds = new Dictionary<ulong, string>();
  254. if (args["child"] != null)
  255. child = args["child"].AsBoolean();
  256. if (args["circuit_code"] != null)
  257. UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
  258. if (args["first_name"] != null)
  259. firstname = args["first_name"].AsString();
  260. if (args["last_name"] != null)
  261. lastname = args["last_name"].AsString();
  262. if (args["inventory_folder"] != null)
  263. InventoryFolder = args["inventory_folder"].AsUUID();
  264. if (args["secure_session_id"] != null)
  265. SecureSessionID = args["secure_session_id"].AsUUID();
  266. if (args["session_id"] != null)
  267. SessionID = args["session_id"].AsUUID();
  268. if (args["service_session_id"] != null)
  269. ServiceSessionID = args["service_session_id"].AsString();
  270. if (args["client_ip"] != null)
  271. IPAddress = args["client_ip"].AsString();
  272. if (args["viewer"] != null)
  273. Viewer = args["viewer"].AsString();
  274. if (args["channel"] != null)
  275. Channel = args["channel"].AsString();
  276. if (args["mac"] != null)
  277. Mac = args["mac"].AsString();
  278. if (args["id0"] != null)
  279. Id0 = args["id0"].AsString();
  280. if (args["start_pos"] != null)
  281. Vector3.TryParse(args["start_pos"].AsString(), out startpos);
  282. m_log.InfoFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}",AgentID,child,startpos.ToString());
  283. try {
  284. // Unpack various appearance elements
  285. Appearance = new AvatarAppearance(AgentID);
  286. // Eventually this code should be deprecated, use full appearance
  287. // packing in packed_appearance
  288. if (args["appearance_serial"] != null)
  289. Appearance.Serial = args["appearance_serial"].AsInteger();
  290. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
  291. {
  292. Appearance.Unpack((OSDMap)args["packed_appearance"]);
  293. m_log.InfoFormat("[AGENTCIRCUITDATA] unpacked appearance");
  294. }
  295. else
  296. m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
  297. }
  298. catch (Exception e)
  299. {
  300. m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
  301. }
  302. ServiceURLs = new Dictionary<string, object>();
  303. // Try parse the new way, OSDMap
  304. if (args.ContainsKey("serviceurls") && args["serviceurls"] != null && (args["serviceurls"]).Type == OSDType.Map)
  305. {
  306. OSDMap urls = (OSDMap)(args["serviceurls"]);
  307. foreach (KeyValuePair<String, OSD> kvp in urls)
  308. {
  309. ServiceURLs[kvp.Key] = kvp.Value.AsString();
  310. //System.Console.WriteLine("XXX " + kvp.Key + "=" + ServiceURLs[kvp.Key]);
  311. }
  312. }
  313. // else try the old way, OSDArray
  314. // OBSOLETE -- soon to be deleted
  315. else if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
  316. {
  317. OSDArray urls = (OSDArray)(args["service_urls"]);
  318. for (int i = 0; i < urls.Count / 2; i++)
  319. {
  320. ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
  321. //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());
  322. }
  323. }
  324. }
  325. }
  326. /// <summary>
  327. /// Serializable Agent Circuit Data
  328. /// </summary>
  329. [Serializable]
  330. public class sAgentCircuitData
  331. {
  332. public Guid AgentID;
  333. public Guid BaseFolder;
  334. public string CapsPath = String.Empty;
  335. public Dictionary<ulong, string> ChildrenCapSeeds;
  336. public bool child;
  337. public uint circuitcode;
  338. public string firstname;
  339. public Guid InventoryFolder;
  340. public string lastname;
  341. public Guid SecureSessionID;
  342. public Guid SessionID;
  343. public float startposx;
  344. public float startposy;
  345. public float startposz;
  346. public string Viewer;
  347. public string Channel;
  348. public string Mac;
  349. public string Id0;
  350. public sAgentCircuitData()
  351. {
  352. }
  353. public sAgentCircuitData(AgentCircuitData cAgent)
  354. {
  355. AgentID = cAgent.AgentID.Guid;
  356. SessionID = cAgent.SessionID.Guid;
  357. SecureSessionID = cAgent.SecureSessionID.Guid;
  358. startposx = cAgent.startpos.X;
  359. startposy = cAgent.startpos.Y;
  360. startposz = cAgent.startpos.Z;
  361. firstname = cAgent.firstname;
  362. lastname = cAgent.lastname;
  363. circuitcode = cAgent.circuitcode;
  364. child = cAgent.child;
  365. InventoryFolder = cAgent.InventoryFolder.Guid;
  366. BaseFolder = cAgent.BaseFolder.Guid;
  367. CapsPath = cAgent.CapsPath;
  368. ChildrenCapSeeds = cAgent.ChildrenCapSeeds;
  369. Viewer = cAgent.Viewer;
  370. }
  371. }
  372. }