AgentCircuitData.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. /// Pack AgentCircuitData into an OSDMap for transmission over LLSD XML or LLSD json
  132. /// </summary>
  133. /// <returns>map of the agent circuit data</returns>
  134. public OSDMap PackAgentCircuitData()
  135. {
  136. OSDMap args = new OSDMap();
  137. args["agent_id"] = OSD.FromUUID(AgentID);
  138. args["base_folder"] = OSD.FromUUID(BaseFolder);
  139. args["caps_path"] = OSD.FromString(CapsPath);
  140. if (ChildrenCapSeeds != null)
  141. {
  142. OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
  143. foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
  144. {
  145. OSDMap pair = new OSDMap();
  146. pair["handle"] = OSD.FromString(kvp.Key.ToString());
  147. pair["seed"] = OSD.FromString(kvp.Value);
  148. childrenSeeds.Add(pair);
  149. }
  150. if (ChildrenCapSeeds.Count > 0)
  151. args["children_seeds"] = childrenSeeds;
  152. }
  153. args["child"] = OSD.FromBoolean(child);
  154. args["circuit_code"] = OSD.FromString(circuitcode.ToString());
  155. args["first_name"] = OSD.FromString(firstname);
  156. args["last_name"] = OSD.FromString(lastname);
  157. args["inventory_folder"] = OSD.FromUUID(InventoryFolder);
  158. args["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  159. args["session_id"] = OSD.FromUUID(SessionID);
  160. args["service_session_id"] = OSD.FromString(ServiceSessionID);
  161. args["start_pos"] = OSD.FromString(startpos.ToString());
  162. args["client_ip"] = OSD.FromString(IPAddress);
  163. args["viewer"] = OSD.FromString(Viewer);
  164. args["channel"] = OSD.FromString(Channel);
  165. args["mac"] = OSD.FromString(Mac);
  166. args["id0"] = OSD.FromString(Id0);
  167. if (Appearance != null)
  168. {
  169. args["appearance_serial"] = OSD.FromInteger(Appearance.Serial);
  170. OSDMap appmap = Appearance.Pack();
  171. args["packed_appearance"] = appmap;
  172. }
  173. // Old, bad way. Keeping it fow now for backwards compatibility
  174. // OBSOLETE -- soon to be deleted
  175. if (ServiceURLs != null && ServiceURLs.Count > 0)
  176. {
  177. OSDArray urls = new OSDArray(ServiceURLs.Count * 2);
  178. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  179. {
  180. //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
  181. urls.Add(OSD.FromString(kvp.Key));
  182. urls.Add(OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString()));
  183. }
  184. args["service_urls"] = urls;
  185. }
  186. // again, this time the right way
  187. if (ServiceURLs != null && ServiceURLs.Count > 0)
  188. {
  189. OSDMap urls = new OSDMap();
  190. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  191. {
  192. //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
  193. urls[kvp.Key] = OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString());
  194. }
  195. args["serviceurls"] = urls;
  196. }
  197. return args;
  198. }
  199. /// <summary>
  200. /// Unpack agent circuit data map into an AgentCiruitData object
  201. /// </summary>
  202. /// <param name="args"></param>
  203. public void UnpackAgentCircuitData(OSDMap args)
  204. {
  205. if (args["agent_id"] != null)
  206. AgentID = args["agent_id"].AsUUID();
  207. if (args["base_folder"] != null)
  208. BaseFolder = args["base_folder"].AsUUID();
  209. if (args["caps_path"] != null)
  210. CapsPath = args["caps_path"].AsString();
  211. if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
  212. {
  213. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  214. ChildrenCapSeeds = new Dictionary<ulong, string>();
  215. foreach (OSD o in childrenSeeds)
  216. {
  217. if (o.Type == OSDType.Map)
  218. {
  219. ulong handle = 0;
  220. string seed = "";
  221. OSDMap pair = (OSDMap)o;
  222. if (pair["handle"] != null)
  223. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  224. continue;
  225. if (pair["seed"] != null)
  226. seed = pair["seed"].AsString();
  227. if (!ChildrenCapSeeds.ContainsKey(handle))
  228. ChildrenCapSeeds.Add(handle, seed);
  229. }
  230. }
  231. }
  232. else
  233. ChildrenCapSeeds = new Dictionary<ulong, string>();
  234. if (args["child"] != null)
  235. child = args["child"].AsBoolean();
  236. if (args["circuit_code"] != null)
  237. UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
  238. if (args["first_name"] != null)
  239. firstname = args["first_name"].AsString();
  240. if (args["last_name"] != null)
  241. lastname = args["last_name"].AsString();
  242. if (args["inventory_folder"] != null)
  243. InventoryFolder = args["inventory_folder"].AsUUID();
  244. if (args["secure_session_id"] != null)
  245. SecureSessionID = args["secure_session_id"].AsUUID();
  246. if (args["session_id"] != null)
  247. SessionID = args["session_id"].AsUUID();
  248. if (args["service_session_id"] != null)
  249. ServiceSessionID = args["service_session_id"].AsString();
  250. if (args["client_ip"] != null)
  251. IPAddress = args["client_ip"].AsString();
  252. if (args["viewer"] != null)
  253. Viewer = args["viewer"].AsString();
  254. if (args["channel"] != null)
  255. Channel = args["channel"].AsString();
  256. if (args["mac"] != null)
  257. Mac = args["mac"].AsString();
  258. if (args["id0"] != null)
  259. Id0 = args["id0"].AsString();
  260. if (args["start_pos"] != null)
  261. Vector3.TryParse(args["start_pos"].AsString(), out startpos);
  262. //m_log.InfoFormat("[AGENTCIRCUITDATA]: agentid={0}, child={1}, startpos={2}", AgentID, child, startpos);
  263. try
  264. {
  265. // Unpack various appearance elements
  266. Appearance = new AvatarAppearance();
  267. // Eventually this code should be deprecated, use full appearance
  268. // packing in packed_appearance
  269. if (args["appearance_serial"] != null)
  270. Appearance.Serial = args["appearance_serial"].AsInteger();
  271. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
  272. {
  273. Appearance.Unpack((OSDMap)args["packed_appearance"]);
  274. // m_log.InfoFormat("[AGENTCIRCUITDATA] unpacked appearance");
  275. }
  276. else
  277. {
  278. m_log.Warn("[AGENTCIRCUITDATA]: failed to find a valid packed_appearance");
  279. }
  280. }
  281. catch (Exception e)
  282. {
  283. m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
  284. }
  285. ServiceURLs = new Dictionary<string, object>();
  286. // Try parse the new way, OSDMap
  287. if (args.ContainsKey("serviceurls") && args["serviceurls"] != null && (args["serviceurls"]).Type == OSDType.Map)
  288. {
  289. OSDMap urls = (OSDMap)(args["serviceurls"]);
  290. foreach (KeyValuePair<String, OSD> kvp in urls)
  291. {
  292. ServiceURLs[kvp.Key] = kvp.Value.AsString();
  293. //System.Console.WriteLine("XXX " + kvp.Key + "=" + ServiceURLs[kvp.Key]);
  294. }
  295. }
  296. // else try the old way, OSDArray
  297. // OBSOLETE -- soon to be deleted
  298. else if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
  299. {
  300. OSDArray urls = (OSDArray)(args["service_urls"]);
  301. for (int i = 0; i < urls.Count / 2; i++)
  302. {
  303. ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
  304. //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());
  305. }
  306. }
  307. }
  308. }
  309. }