AgentCircuitData.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. /// Agent's full name.
  90. /// </summary>
  91. public string Name { get { return string.Format("{0} {1}", firstname, lastname); } }
  92. /// <summary>
  93. /// Random Unique GUID for this session. Client gets this at login and it's
  94. /// only supposed to be disclosed over secure channels
  95. /// </summary>
  96. public UUID SecureSessionID;
  97. /// <summary>
  98. /// Non secure Session ID
  99. /// </summary>
  100. public UUID SessionID;
  101. /// <summary>
  102. /// Hypergrid service token; generated by the user domain, consumed by the receiving grid.
  103. /// There is one such unique token for each grid visited.
  104. /// </summary>
  105. public string ServiceSessionID = string.Empty;
  106. /// <summary>
  107. /// The client's IP address, as captured by the login service
  108. /// </summary>
  109. public string IPAddress;
  110. /// <summary>
  111. /// Viewer's version string as reported by the viewer at login
  112. /// </summary>
  113. public string Viewer;
  114. /// <summary>
  115. /// The channel strinf sent by the viewer at login
  116. /// </summary>
  117. public string Channel;
  118. /// <summary>
  119. /// The Mac address as reported by the viewer at login
  120. /// </summary>
  121. public string Mac;
  122. /// <summary>
  123. /// The id0 as reported by the viewer at login
  124. /// </summary>
  125. public string Id0;
  126. /// <summary>
  127. /// Position the Agent's Avatar starts in the region
  128. /// </summary>
  129. public Vector3 startpos;
  130. public Dictionary<string, object> ServiceURLs;
  131. public AgentCircuitData()
  132. {
  133. }
  134. /// <summary>
  135. /// Pack AgentCircuitData into an OSDMap for transmission over LLSD XML or LLSD json
  136. /// </summary>
  137. /// <returns>map of the agent circuit data</returns>
  138. public OSDMap PackAgentCircuitData()
  139. {
  140. OSDMap args = new OSDMap();
  141. args["agent_id"] = OSD.FromUUID(AgentID);
  142. args["base_folder"] = OSD.FromUUID(BaseFolder);
  143. args["caps_path"] = OSD.FromString(CapsPath);
  144. if (ChildrenCapSeeds != null)
  145. {
  146. OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
  147. foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
  148. {
  149. OSDMap pair = new OSDMap();
  150. pair["handle"] = OSD.FromString(kvp.Key.ToString());
  151. pair["seed"] = OSD.FromString(kvp.Value);
  152. childrenSeeds.Add(pair);
  153. }
  154. if (ChildrenCapSeeds.Count > 0)
  155. args["children_seeds"] = childrenSeeds;
  156. }
  157. args["child"] = OSD.FromBoolean(child);
  158. args["circuit_code"] = OSD.FromString(circuitcode.ToString());
  159. args["first_name"] = OSD.FromString(firstname);
  160. args["last_name"] = OSD.FromString(lastname);
  161. args["inventory_folder"] = OSD.FromUUID(InventoryFolder);
  162. args["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  163. args["session_id"] = OSD.FromUUID(SessionID);
  164. args["service_session_id"] = OSD.FromString(ServiceSessionID);
  165. args["start_pos"] = OSD.FromString(startpos.ToString());
  166. args["client_ip"] = OSD.FromString(IPAddress);
  167. args["viewer"] = OSD.FromString(Viewer);
  168. args["channel"] = OSD.FromString(Channel);
  169. args["mac"] = OSD.FromString(Mac);
  170. args["id0"] = OSD.FromString(Id0);
  171. if (Appearance != null)
  172. {
  173. args["appearance_serial"] = OSD.FromInteger(Appearance.Serial);
  174. OSDMap appmap = Appearance.Pack();
  175. args["packed_appearance"] = appmap;
  176. }
  177. // Old, bad way. Keeping it fow now for backwards compatibility
  178. // OBSOLETE -- soon to be deleted
  179. if (ServiceURLs != null && ServiceURLs.Count > 0)
  180. {
  181. OSDArray urls = new OSDArray(ServiceURLs.Count * 2);
  182. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  183. {
  184. //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
  185. urls.Add(OSD.FromString(kvp.Key));
  186. urls.Add(OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString()));
  187. }
  188. args["service_urls"] = urls;
  189. }
  190. // again, this time the right way
  191. if (ServiceURLs != null && ServiceURLs.Count > 0)
  192. {
  193. OSDMap urls = new OSDMap();
  194. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  195. {
  196. //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
  197. urls[kvp.Key] = OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString());
  198. }
  199. args["serviceurls"] = urls;
  200. }
  201. return args;
  202. }
  203. /// <summary>
  204. /// Unpack agent circuit data map into an AgentCiruitData object
  205. /// </summary>
  206. /// <param name="args"></param>
  207. public void UnpackAgentCircuitData(OSDMap args)
  208. {
  209. if (args["agent_id"] != null)
  210. AgentID = args["agent_id"].AsUUID();
  211. if (args["base_folder"] != null)
  212. BaseFolder = args["base_folder"].AsUUID();
  213. if (args["caps_path"] != null)
  214. CapsPath = args["caps_path"].AsString();
  215. if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
  216. {
  217. OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
  218. ChildrenCapSeeds = new Dictionary<ulong, string>();
  219. foreach (OSD o in childrenSeeds)
  220. {
  221. if (o.Type == OSDType.Map)
  222. {
  223. ulong handle = 0;
  224. string seed = "";
  225. OSDMap pair = (OSDMap)o;
  226. if (pair["handle"] != null)
  227. if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
  228. continue;
  229. if (pair["seed"] != null)
  230. seed = pair["seed"].AsString();
  231. if (!ChildrenCapSeeds.ContainsKey(handle))
  232. ChildrenCapSeeds.Add(handle, seed);
  233. }
  234. }
  235. }
  236. else
  237. ChildrenCapSeeds = new Dictionary<ulong, string>();
  238. if (args["child"] != null)
  239. child = args["child"].AsBoolean();
  240. if (args["circuit_code"] != null)
  241. UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
  242. if (args["first_name"] != null)
  243. firstname = args["first_name"].AsString();
  244. if (args["last_name"] != null)
  245. lastname = args["last_name"].AsString();
  246. if (args["inventory_folder"] != null)
  247. InventoryFolder = args["inventory_folder"].AsUUID();
  248. if (args["secure_session_id"] != null)
  249. SecureSessionID = args["secure_session_id"].AsUUID();
  250. if (args["session_id"] != null)
  251. SessionID = args["session_id"].AsUUID();
  252. if (args["service_session_id"] != null)
  253. ServiceSessionID = args["service_session_id"].AsString();
  254. if (args["client_ip"] != null)
  255. IPAddress = args["client_ip"].AsString();
  256. if (args["viewer"] != null)
  257. Viewer = args["viewer"].AsString();
  258. if (args["channel"] != null)
  259. Channel = args["channel"].AsString();
  260. if (args["mac"] != null)
  261. Mac = args["mac"].AsString();
  262. if (args["id0"] != null)
  263. Id0 = args["id0"].AsString();
  264. if (args["start_pos"] != null)
  265. Vector3.TryParse(args["start_pos"].AsString(), out startpos);
  266. //m_log.InfoFormat("[AGENTCIRCUITDATA]: agentid={0}, child={1}, startpos={2}", AgentID, child, startpos);
  267. try
  268. {
  269. // Unpack various appearance elements
  270. Appearance = new AvatarAppearance();
  271. // Eventually this code should be deprecated, use full appearance
  272. // packing in packed_appearance
  273. if (args["appearance_serial"] != null)
  274. Appearance.Serial = args["appearance_serial"].AsInteger();
  275. if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
  276. {
  277. Appearance.Unpack((OSDMap)args["packed_appearance"]);
  278. // m_log.InfoFormat("[AGENTCIRCUITDATA] unpacked appearance");
  279. }
  280. else
  281. {
  282. m_log.Warn("[AGENTCIRCUITDATA]: failed to find a valid packed_appearance");
  283. }
  284. }
  285. catch (Exception e)
  286. {
  287. m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
  288. }
  289. ServiceURLs = new Dictionary<string, object>();
  290. // Try parse the new way, OSDMap
  291. if (args.ContainsKey("serviceurls") && args["serviceurls"] != null && (args["serviceurls"]).Type == OSDType.Map)
  292. {
  293. OSDMap urls = (OSDMap)(args["serviceurls"]);
  294. foreach (KeyValuePair<String, OSD> kvp in urls)
  295. {
  296. ServiceURLs[kvp.Key] = kvp.Value.AsString();
  297. //System.Console.WriteLine("XXX " + kvp.Key + "=" + ServiceURLs[kvp.Key]);
  298. }
  299. }
  300. // else try the old way, OSDArray
  301. // OBSOLETE -- soon to be deleted
  302. else if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
  303. {
  304. OSDArray urls = (OSDArray)(args["service_urls"]);
  305. for (int i = 0; i < urls.Count / 2; i++)
  306. {
  307. ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
  308. //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());
  309. }
  310. }
  311. }
  312. }
  313. }