LLLoginResponse.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  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;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Reflection;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Capabilities;
  34. using OpenSim.Services.Interfaces;
  35. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  36. using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
  37. using log4net;
  38. using OpenMetaverse;
  39. using OpenMetaverse.StructuredData;
  40. using OSDArray = OpenMetaverse.StructuredData.OSDArray;
  41. using OSDMap = OpenMetaverse.StructuredData.OSDMap;
  42. namespace OpenSim.Services.LLLoginService
  43. {
  44. public class LLFailedLoginResponse : OpenSim.Services.Interfaces.FailedLoginResponse
  45. {
  46. protected string m_key;
  47. protected string m_value;
  48. protected string m_login;
  49. public static LLFailedLoginResponse UserProblem;
  50. public static LLFailedLoginResponse GridProblem;
  51. public static LLFailedLoginResponse InventoryProblem;
  52. public static LLFailedLoginResponse DeadRegionProblem;
  53. public static LLFailedLoginResponse LoginBlockedProblem;
  54. public static LLFailedLoginResponse AlreadyLoggedInProblem;
  55. public static LLFailedLoginResponse InternalError;
  56. static LLFailedLoginResponse()
  57. {
  58. UserProblem = new LLFailedLoginResponse("key",
  59. "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.",
  60. "false");
  61. GridProblem = new LLFailedLoginResponse("key",
  62. "Error connecting to the desired location. Try connecting to another region.",
  63. "false");
  64. InventoryProblem = new LLFailedLoginResponse("key",
  65. "The inventory service is not responding. Please notify your login region operator.",
  66. "false");
  67. DeadRegionProblem = new LLFailedLoginResponse("key",
  68. "The region you are attempting to log into is not responding. Please select another region and try again.",
  69. "false");
  70. LoginBlockedProblem = new LLFailedLoginResponse("presence",
  71. "Logins are currently restricted. Please try again later.",
  72. "false");
  73. AlreadyLoggedInProblem = new LLFailedLoginResponse("presence",
  74. "You appear to be already logged in. " +
  75. "If this is not the case please wait for your session to timeout. " +
  76. "If this takes longer than a few minutes please contact the grid owner. " +
  77. "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.",
  78. "false");
  79. InternalError = new LLFailedLoginResponse("Internal Error", "Error generating Login Response", "false");
  80. }
  81. public LLFailedLoginResponse(string key, string value, string login)
  82. {
  83. m_key = key;
  84. m_value = value;
  85. m_login = login;
  86. }
  87. public override Hashtable ToHashtable()
  88. {
  89. Hashtable loginError = new Hashtable();
  90. loginError["reason"] = m_key;
  91. loginError["message"] = m_value;
  92. loginError["login"] = m_login;
  93. return loginError;
  94. }
  95. public override OSD ToOSDMap()
  96. {
  97. OSDMap map = new OSDMap();
  98. map["reason"] = OSD.FromString(m_key);
  99. map["message"] = OSD.FromString(m_value);
  100. map["login"] = OSD.FromString(m_login);
  101. return map;
  102. }
  103. }
  104. /// <summary>
  105. /// A class to handle LL login response.
  106. /// </summary>
  107. public class LLLoginResponse : OpenSim.Services.Interfaces.LoginResponse
  108. {
  109. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  110. private static Hashtable globalTexturesHash;
  111. // Global Textures
  112. private static string sunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
  113. private static string cloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621";
  114. private static string moonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621";
  115. private Hashtable loginFlagsHash;
  116. private Hashtable uiConfigHash;
  117. private ArrayList loginFlags;
  118. private ArrayList globalTextures;
  119. private ArrayList eventCategories;
  120. private ArrayList uiConfig;
  121. private ArrayList classifiedCategories;
  122. private ArrayList inventoryRoot;
  123. private ArrayList initialOutfit;
  124. private ArrayList agentInventory;
  125. private ArrayList inventoryLibraryOwner;
  126. private ArrayList inventoryLibRoot;
  127. private ArrayList inventoryLibrary;
  128. private ArrayList activeGestures;
  129. private UserInfo userProfile;
  130. private UUID agentID;
  131. private UUID sessionID;
  132. private UUID secureSessionID;
  133. // Login Flags
  134. private string dst;
  135. private string stipendSinceLogin;
  136. private string gendered;
  137. private string everLoggedIn;
  138. private string login;
  139. private uint simPort;
  140. private uint simHttpPort;
  141. private string simAddress;
  142. private string agentAccess;
  143. private string agentAccessMax;
  144. private Int32 circuitCode;
  145. private uint regionX;
  146. private uint regionY;
  147. // Login
  148. private string firstname;
  149. private string lastname;
  150. // Web map
  151. private string mapTileURL;
  152. private string searchURL;
  153. // Error Flags
  154. private string errorReason;
  155. private string errorMessage;
  156. private string welcomeMessage;
  157. private string startLocation;
  158. private string allowFirstLife;
  159. private string home;
  160. private string seedCapability;
  161. private string lookAt;
  162. private BuddyList m_buddyList = null;
  163. static LLLoginResponse()
  164. {
  165. // This is being set, but it's not used
  166. // not sure why.
  167. globalTexturesHash = new Hashtable();
  168. globalTexturesHash["sun_texture_id"] = sunTexture;
  169. globalTexturesHash["cloud_texture_id"] = cloudTexture;
  170. globalTexturesHash["moon_texture_id"] = moonTexture;
  171. }
  172. public LLLoginResponse()
  173. {
  174. loginFlags = new ArrayList();
  175. globalTextures = new ArrayList();
  176. eventCategories = new ArrayList();
  177. uiConfig = new ArrayList();
  178. classifiedCategories = new ArrayList();
  179. uiConfigHash = new Hashtable();
  180. // defaultXmlRpcResponse = new XmlRpcResponse();
  181. userProfile = new UserInfo();
  182. inventoryRoot = new ArrayList();
  183. initialOutfit = new ArrayList();
  184. agentInventory = new ArrayList();
  185. inventoryLibrary = new ArrayList();
  186. inventoryLibraryOwner = new ArrayList();
  187. activeGestures = new ArrayList();
  188. SetDefaultValues();
  189. }
  190. public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, GridUserInfo pinfo,
  191. GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService,
  192. string where, string startlocation, Vector3 position, Vector3 lookAt, List<InventoryItemBase> gestures, string message,
  193. GridRegion home, IPEndPoint clientIP, string mapTileURL, string searchURL)
  194. : this()
  195. {
  196. FillOutInventoryData(invSkel, libService);
  197. FillOutActiveGestures(gestures);
  198. CircuitCode = (int)aCircuit.circuitcode;
  199. Lastname = account.LastName;
  200. Firstname = account.FirstName;
  201. AgentID = account.PrincipalID;
  202. SessionID = aCircuit.SessionID;
  203. SecureSessionID = aCircuit.SecureSessionID;
  204. Message = message;
  205. BuddList = ConvertFriendListItem(friendsList);
  206. StartLocation = where;
  207. MapTileURL = mapTileURL;
  208. SearchURL = searchURL;
  209. FillOutHomeData(pinfo, home);
  210. LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z);
  211. FillOutRegionData(destination);
  212. FillOutSeedCap(aCircuit, destination, clientIP);
  213. }
  214. private void FillOutInventoryData(List<InventoryFolderBase> invSkel, ILibraryService libService)
  215. {
  216. InventoryData inventData = null;
  217. try
  218. {
  219. inventData = GetInventorySkeleton(invSkel);
  220. }
  221. catch (Exception e)
  222. {
  223. m_log.WarnFormat(
  224. "[LLLOGIN SERVICE]: Error processing inventory skeleton of agent {0} - {1}",
  225. agentID, e);
  226. // ignore and continue
  227. }
  228. if (inventData != null)
  229. {
  230. ArrayList AgentInventoryArray = inventData.InventoryArray;
  231. Hashtable InventoryRootHash = new Hashtable();
  232. InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
  233. InventoryRoot = new ArrayList();
  234. InventoryRoot.Add(InventoryRootHash);
  235. InventorySkeleton = AgentInventoryArray;
  236. }
  237. // Inventory Library Section
  238. if (libService != null && libService.LibraryRootFolder != null)
  239. {
  240. Hashtable InventoryLibRootHash = new Hashtable();
  241. InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
  242. InventoryLibRoot = new ArrayList();
  243. InventoryLibRoot.Add(InventoryLibRootHash);
  244. InventoryLibraryOwner = GetLibraryOwner(libService.LibraryRootFolder);
  245. InventoryLibrary = GetInventoryLibrary(libService);
  246. }
  247. }
  248. private void FillOutActiveGestures(List<InventoryItemBase> gestures)
  249. {
  250. ArrayList list = new ArrayList();
  251. if (gestures != null)
  252. {
  253. foreach (InventoryItemBase gesture in gestures)
  254. {
  255. Hashtable item = new Hashtable();
  256. item["item_id"] = gesture.ID.ToString();
  257. item["asset_id"] = gesture.AssetID.ToString();
  258. list.Add(item);
  259. }
  260. }
  261. ActiveGestures = list;
  262. }
  263. private void FillOutHomeData(GridUserInfo pinfo, GridRegion home)
  264. {
  265. int x = 1000 * (int)Constants.RegionSize, y = 1000 * (int)Constants.RegionSize;
  266. if (home != null)
  267. {
  268. x = home.RegionLocX;
  269. y = home.RegionLocY;
  270. }
  271. Home = string.Format(
  272. "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
  273. x,
  274. y,
  275. pinfo.HomePosition.X, pinfo.HomePosition.Y, pinfo.HomePosition.Z,
  276. pinfo.HomeLookAt.X, pinfo.HomeLookAt.Y, pinfo.HomeLookAt.Z);
  277. }
  278. private void FillOutRegionData(GridRegion destination)
  279. {
  280. IPEndPoint endPoint = destination.ExternalEndPoint;
  281. SimAddress = endPoint.Address.ToString();
  282. SimPort = (uint)endPoint.Port;
  283. RegionX = (uint)destination.RegionLocX;
  284. RegionY = (uint)destination.RegionLocY;
  285. }
  286. private void FillOutSeedCap(AgentCircuitData aCircuit, GridRegion destination, IPEndPoint ipepClient)
  287. {
  288. SeedCapability = destination.ServerURI + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath);
  289. }
  290. private void SetDefaultValues()
  291. {
  292. DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
  293. StipendSinceLogin = "N";
  294. Gendered = "Y";
  295. EverLoggedIn = "Y";
  296. login = "false";
  297. firstname = "Test";
  298. lastname = "User";
  299. agentAccess = "M";
  300. agentAccessMax = "A";
  301. startLocation = "last";
  302. allowFirstLife = "Y";
  303. ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
  304. ErrorReason = "key";
  305. welcomeMessage = "Welcome to OpenSim!";
  306. seedCapability = String.Empty;
  307. home = "{'region_handle':[r" + (1000*Constants.RegionSize).ToString() + ",r" + (1000*Constants.RegionSize).ToString() + "], 'position':[r" +
  308. userProfile.homepos.X.ToString() + ",r" + userProfile.homepos.Y.ToString() + ",r" +
  309. userProfile.homepos.Z.ToString() + "], 'look_at':[r" + userProfile.homelookat.X.ToString() + ",r" +
  310. userProfile.homelookat.Y.ToString() + ",r" + userProfile.homelookat.Z.ToString() + "]}";
  311. lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
  312. RegionX = (uint) 255232;
  313. RegionY = (uint) 254976;
  314. // Classifieds;
  315. AddClassifiedCategory((Int32) 1, "Shopping");
  316. AddClassifiedCategory((Int32) 2, "Land Rental");
  317. AddClassifiedCategory((Int32) 3, "Property Rental");
  318. AddClassifiedCategory((Int32) 4, "Special Attraction");
  319. AddClassifiedCategory((Int32) 5, "New Products");
  320. AddClassifiedCategory((Int32) 6, "Employment");
  321. AddClassifiedCategory((Int32) 7, "Wanted");
  322. AddClassifiedCategory((Int32) 8, "Service");
  323. AddClassifiedCategory((Int32) 9, "Personal");
  324. SessionID = UUID.Random();
  325. SecureSessionID = UUID.Random();
  326. AgentID = UUID.Random();
  327. Hashtable InitialOutfitHash = new Hashtable();
  328. InitialOutfitHash["folder_name"] = "Nightclub Female";
  329. InitialOutfitHash["gender"] = "female";
  330. initialOutfit.Add(InitialOutfitHash);
  331. mapTileURL = String.Empty;
  332. searchURL = String.Empty;
  333. }
  334. public override Hashtable ToHashtable()
  335. {
  336. try
  337. {
  338. Hashtable responseData = new Hashtable();
  339. loginFlagsHash = new Hashtable();
  340. loginFlagsHash["daylight_savings"] = DST;
  341. loginFlagsHash["stipend_since_login"] = StipendSinceLogin;
  342. loginFlagsHash["gendered"] = Gendered;
  343. loginFlagsHash["ever_logged_in"] = EverLoggedIn;
  344. loginFlags.Add(loginFlagsHash);
  345. responseData["first_name"] = Firstname;
  346. responseData["last_name"] = Lastname;
  347. responseData["agent_access"] = agentAccess;
  348. responseData["agent_access_max"] = agentAccessMax;
  349. globalTextures.Add(globalTexturesHash);
  350. // this.eventCategories.Add(this.eventCategoriesHash);
  351. AddToUIConfig("allow_first_life", allowFirstLife);
  352. uiConfig.Add(uiConfigHash);
  353. responseData["sim_port"] = (Int32) SimPort;
  354. responseData["sim_ip"] = SimAddress;
  355. responseData["http_port"] = (Int32)SimHttpPort;
  356. responseData["agent_id"] = AgentID.ToString();
  357. responseData["session_id"] = SessionID.ToString();
  358. responseData["secure_session_id"] = SecureSessionID.ToString();
  359. responseData["circuit_code"] = CircuitCode;
  360. responseData["seconds_since_epoch"] = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  361. responseData["login-flags"] = loginFlags;
  362. responseData["global-textures"] = globalTextures;
  363. responseData["seed_capability"] = seedCapability;
  364. responseData["event_categories"] = eventCategories;
  365. responseData["event_notifications"] = new ArrayList(); // todo
  366. responseData["classified_categories"] = classifiedCategories;
  367. responseData["ui-config"] = uiConfig;
  368. if (agentInventory != null)
  369. {
  370. responseData["inventory-skeleton"] = agentInventory;
  371. responseData["inventory-root"] = inventoryRoot;
  372. }
  373. responseData["inventory-skel-lib"] = inventoryLibrary;
  374. responseData["inventory-lib-root"] = inventoryLibRoot;
  375. responseData["gestures"] = activeGestures;
  376. responseData["inventory-lib-owner"] = inventoryLibraryOwner;
  377. responseData["initial-outfit"] = initialOutfit;
  378. responseData["start_location"] = startLocation;
  379. responseData["seed_capability"] = seedCapability;
  380. responseData["home"] = home;
  381. responseData["look_at"] = lookAt;
  382. responseData["message"] = welcomeMessage;
  383. responseData["region_x"] = (Int32)(RegionX);
  384. responseData["region_y"] = (Int32)(RegionY);
  385. if (searchURL != String.Empty)
  386. responseData["search"] = searchURL;
  387. if (mapTileURL != String.Empty)
  388. responseData["map-server-url"] = mapTileURL;
  389. if (m_buddyList != null)
  390. {
  391. responseData["buddy-list"] = m_buddyList.ToArray();
  392. }
  393. responseData["login"] = "true";
  394. return responseData;
  395. }
  396. catch (Exception e)
  397. {
  398. m_log.Warn("[CLIENT]: LoginResponse: Error creating Hashtable Response: " + e.Message);
  399. return LLFailedLoginResponse.InternalError.ToHashtable();
  400. }
  401. }
  402. public override OSD ToOSDMap()
  403. {
  404. try
  405. {
  406. OSDMap map = new OSDMap();
  407. map["first_name"] = OSD.FromString(Firstname);
  408. map["last_name"] = OSD.FromString(Lastname);
  409. map["agent_access"] = OSD.FromString(agentAccess);
  410. map["agent_access_max"] = OSD.FromString(agentAccessMax);
  411. map["sim_port"] = OSD.FromInteger(SimPort);
  412. map["sim_ip"] = OSD.FromString(SimAddress);
  413. map["agent_id"] = OSD.FromUUID(AgentID);
  414. map["session_id"] = OSD.FromUUID(SessionID);
  415. map["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  416. map["circuit_code"] = OSD.FromInteger(CircuitCode);
  417. map["seconds_since_epoch"] = OSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
  418. #region Login Flags
  419. OSDMap loginFlagsLLSD = new OSDMap();
  420. loginFlagsLLSD["daylight_savings"] = OSD.FromString(DST);
  421. loginFlagsLLSD["stipend_since_login"] = OSD.FromString(StipendSinceLogin);
  422. loginFlagsLLSD["gendered"] = OSD.FromString(Gendered);
  423. loginFlagsLLSD["ever_logged_in"] = OSD.FromString(EverLoggedIn);
  424. map["login-flags"] = WrapOSDMap(loginFlagsLLSD);
  425. #endregion Login Flags
  426. #region Global Textures
  427. OSDMap globalTexturesLLSD = new OSDMap();
  428. globalTexturesLLSD["sun_texture_id"] = OSD.FromString(SunTexture);
  429. globalTexturesLLSD["cloud_texture_id"] = OSD.FromString(CloudTexture);
  430. globalTexturesLLSD["moon_texture_id"] = OSD.FromString(MoonTexture);
  431. map["global-textures"] = WrapOSDMap(globalTexturesLLSD);
  432. #endregion Global Textures
  433. map["seed_capability"] = OSD.FromString(seedCapability);
  434. map["event_categories"] = ArrayListToOSDArray(eventCategories);
  435. //map["event_notifications"] = new OSDArray(); // todo
  436. map["classified_categories"] = ArrayListToOSDArray(classifiedCategories);
  437. #region UI Config
  438. OSDMap uiConfigLLSD = new OSDMap();
  439. uiConfigLLSD["allow_first_life"] = OSD.FromString(allowFirstLife);
  440. map["ui-config"] = WrapOSDMap(uiConfigLLSD);
  441. #endregion UI Config
  442. #region Inventory
  443. map["inventory-skeleton"] = ArrayListToOSDArray(agentInventory);
  444. map["inventory-skel-lib"] = ArrayListToOSDArray(inventoryLibrary);
  445. map["inventory-root"] = ArrayListToOSDArray(inventoryRoot); ;
  446. map["inventory-lib-root"] = ArrayListToOSDArray(inventoryLibRoot);
  447. map["inventory-lib-owner"] = ArrayListToOSDArray(inventoryLibraryOwner);
  448. #endregion Inventory
  449. map["gestures"] = ArrayListToOSDArray(activeGestures);
  450. map["initial-outfit"] = ArrayListToOSDArray(initialOutfit);
  451. map["start_location"] = OSD.FromString(startLocation);
  452. map["seed_capability"] = OSD.FromString(seedCapability);
  453. map["home"] = OSD.FromString(home);
  454. map["look_at"] = OSD.FromString(lookAt);
  455. map["message"] = OSD.FromString(welcomeMessage);
  456. map["region_x"] = OSD.FromInteger(RegionX);
  457. map["region_y"] = OSD.FromInteger(RegionY);
  458. if (mapTileURL != String.Empty)
  459. map["map-server-url"] = OSD.FromString(mapTileURL);
  460. if (searchURL != String.Empty)
  461. map["search"] = OSD.FromString(searchURL);
  462. if (m_buddyList != null)
  463. {
  464. map["buddy-list"] = ArrayListToOSDArray(m_buddyList.ToArray());
  465. }
  466. map["login"] = OSD.FromString("true");
  467. return map;
  468. }
  469. catch (Exception e)
  470. {
  471. m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message);
  472. return LLFailedLoginResponse.InternalError.ToOSDMap();
  473. }
  474. }
  475. public OSDArray ArrayListToOSDArray(ArrayList arrlst)
  476. {
  477. OSDArray llsdBack = new OSDArray();
  478. foreach (Hashtable ht in arrlst)
  479. {
  480. OSDMap mp = new OSDMap();
  481. foreach (DictionaryEntry deHt in ht)
  482. {
  483. mp.Add((string)deHt.Key, OSDString.FromObject(deHt.Value));
  484. }
  485. llsdBack.Add(mp);
  486. }
  487. return llsdBack;
  488. }
  489. private static OSDArray WrapOSDMap(OSDMap wrapMe)
  490. {
  491. OSDArray array = new OSDArray();
  492. array.Add(wrapMe);
  493. return array;
  494. }
  495. public void SetEventCategories(string category, string value)
  496. {
  497. // this.eventCategoriesHash[category] = value;
  498. //TODO
  499. }
  500. public void AddToUIConfig(string itemName, string item)
  501. {
  502. uiConfigHash[itemName] = item;
  503. }
  504. public void AddClassifiedCategory(Int32 ID, string categoryName)
  505. {
  506. Hashtable hash = new Hashtable();
  507. hash["category_name"] = categoryName;
  508. hash["category_id"] = ID;
  509. classifiedCategories.Add(hash);
  510. // this.classifiedCategoriesHash.Clear();
  511. }
  512. private static LLLoginResponse.BuddyList ConvertFriendListItem(FriendInfo[] friendsList)
  513. {
  514. LLLoginResponse.BuddyList buddylistreturn = new LLLoginResponse.BuddyList();
  515. foreach (FriendInfo finfo in friendsList)
  516. {
  517. if (finfo.TheirFlags == -1)
  518. continue;
  519. LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(finfo.Friend);
  520. buddyitem.BuddyID = finfo.Friend;
  521. buddyitem.BuddyRightsHave = (int)finfo.TheirFlags;
  522. buddyitem.BuddyRightsGiven = (int)finfo.MyFlags;
  523. buddylistreturn.AddNewBuddy(buddyitem);
  524. }
  525. return buddylistreturn;
  526. }
  527. private InventoryData GetInventorySkeleton(List<InventoryFolderBase> folders)
  528. {
  529. UUID rootID = UUID.Zero;
  530. ArrayList AgentInventoryArray = new ArrayList();
  531. Hashtable TempHash;
  532. foreach (InventoryFolderBase InvFolder in folders)
  533. {
  534. if (InvFolder.ParentID == UUID.Zero && InvFolder.Name == "My Inventory")
  535. {
  536. rootID = InvFolder.ID;
  537. }
  538. TempHash = new Hashtable();
  539. TempHash["name"] = InvFolder.Name;
  540. TempHash["parent_id"] = InvFolder.ParentID.ToString();
  541. TempHash["version"] = (Int32)InvFolder.Version;
  542. TempHash["type_default"] = (Int32)InvFolder.Type;
  543. TempHash["folder_id"] = InvFolder.ID.ToString();
  544. AgentInventoryArray.Add(TempHash);
  545. }
  546. return new InventoryData(AgentInventoryArray, rootID);
  547. }
  548. /// <summary>
  549. /// Converts the inventory library skeleton into the form required by the rpc request.
  550. /// </summary>
  551. /// <returns></returns>
  552. protected virtual ArrayList GetInventoryLibrary(ILibraryService library)
  553. {
  554. Dictionary<UUID, InventoryFolderImpl> rootFolders = library.GetAllFolders();
  555. // m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count);
  556. //Dictionary<UUID, InventoryFolderImpl> rootFolders = new Dictionary<UUID,InventoryFolderImpl>();
  557. ArrayList folderHashes = new ArrayList();
  558. foreach (InventoryFolderBase folder in rootFolders.Values)
  559. {
  560. Hashtable TempHash = new Hashtable();
  561. TempHash["name"] = folder.Name;
  562. TempHash["parent_id"] = folder.ParentID.ToString();
  563. TempHash["version"] = (Int32)folder.Version;
  564. TempHash["type_default"] = (Int32)folder.Type;
  565. TempHash["folder_id"] = folder.ID.ToString();
  566. folderHashes.Add(TempHash);
  567. }
  568. return folderHashes;
  569. }
  570. /// <summary>
  571. ///
  572. /// </summary>
  573. /// <returns></returns>
  574. protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder)
  575. {
  576. //for now create random inventory library owner
  577. Hashtable TempHash = new Hashtable();
  578. TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; // libFolder.Owner
  579. ArrayList inventoryLibOwner = new ArrayList();
  580. inventoryLibOwner.Add(TempHash);
  581. return inventoryLibOwner;
  582. }
  583. public class InventoryData
  584. {
  585. public ArrayList InventoryArray = null;
  586. public UUID RootFolderID = UUID.Zero;
  587. public InventoryData(ArrayList invList, UUID rootID)
  588. {
  589. InventoryArray = invList;
  590. RootFolderID = rootID;
  591. }
  592. }
  593. #region Properties
  594. public string Login
  595. {
  596. get { return login; }
  597. set { login = value; }
  598. }
  599. public string DST
  600. {
  601. get { return dst; }
  602. set { dst = value; }
  603. }
  604. public string StipendSinceLogin
  605. {
  606. get { return stipendSinceLogin; }
  607. set { stipendSinceLogin = value; }
  608. }
  609. public string Gendered
  610. {
  611. get { return gendered; }
  612. set { gendered = value; }
  613. }
  614. public string EverLoggedIn
  615. {
  616. get { return everLoggedIn; }
  617. set { everLoggedIn = value; }
  618. }
  619. public uint SimPort
  620. {
  621. get { return simPort; }
  622. set { simPort = value; }
  623. }
  624. public uint SimHttpPort
  625. {
  626. get { return simHttpPort; }
  627. set { simHttpPort = value; }
  628. }
  629. public string SimAddress
  630. {
  631. get { return simAddress; }
  632. set { simAddress = value; }
  633. }
  634. public UUID AgentID
  635. {
  636. get { return agentID; }
  637. set { agentID = value; }
  638. }
  639. public UUID SessionID
  640. {
  641. get { return sessionID; }
  642. set { sessionID = value; }
  643. }
  644. public UUID SecureSessionID
  645. {
  646. get { return secureSessionID; }
  647. set { secureSessionID = value; }
  648. }
  649. public Int32 CircuitCode
  650. {
  651. get { return circuitCode; }
  652. set { circuitCode = value; }
  653. }
  654. public uint RegionX
  655. {
  656. get { return regionX; }
  657. set { regionX = value; }
  658. }
  659. public uint RegionY
  660. {
  661. get { return regionY; }
  662. set { regionY = value; }
  663. }
  664. public string SunTexture
  665. {
  666. get { return sunTexture; }
  667. set { sunTexture = value; }
  668. }
  669. public string CloudTexture
  670. {
  671. get { return cloudTexture; }
  672. set { cloudTexture = value; }
  673. }
  674. public string MoonTexture
  675. {
  676. get { return moonTexture; }
  677. set { moonTexture = value; }
  678. }
  679. public string Firstname
  680. {
  681. get { return firstname; }
  682. set { firstname = value; }
  683. }
  684. public string Lastname
  685. {
  686. get { return lastname; }
  687. set { lastname = value; }
  688. }
  689. public string AgentAccess
  690. {
  691. get { return agentAccess; }
  692. set { agentAccess = value; }
  693. }
  694. public string AgentAccessMax
  695. {
  696. get { return agentAccessMax; }
  697. set { agentAccessMax = value; }
  698. }
  699. public string StartLocation
  700. {
  701. get { return startLocation; }
  702. set { startLocation = value; }
  703. }
  704. public string LookAt
  705. {
  706. get { return lookAt; }
  707. set { lookAt = value; }
  708. }
  709. public string SeedCapability
  710. {
  711. get { return seedCapability; }
  712. set { seedCapability = value; }
  713. }
  714. public string ErrorReason
  715. {
  716. get { return errorReason; }
  717. set { errorReason = value; }
  718. }
  719. public string ErrorMessage
  720. {
  721. get { return errorMessage; }
  722. set { errorMessage = value; }
  723. }
  724. public ArrayList InventoryRoot
  725. {
  726. get { return inventoryRoot; }
  727. set { inventoryRoot = value; }
  728. }
  729. public ArrayList InventorySkeleton
  730. {
  731. get { return agentInventory; }
  732. set { agentInventory = value; }
  733. }
  734. public ArrayList InventoryLibrary
  735. {
  736. get { return inventoryLibrary; }
  737. set { inventoryLibrary = value; }
  738. }
  739. public ArrayList InventoryLibraryOwner
  740. {
  741. get { return inventoryLibraryOwner; }
  742. set { inventoryLibraryOwner = value; }
  743. }
  744. public ArrayList InventoryLibRoot
  745. {
  746. get { return inventoryLibRoot; }
  747. set { inventoryLibRoot = value; }
  748. }
  749. public ArrayList ActiveGestures
  750. {
  751. get { return activeGestures; }
  752. set { activeGestures = value; }
  753. }
  754. public string Home
  755. {
  756. get { return home; }
  757. set { home = value; }
  758. }
  759. public string MapTileURL
  760. {
  761. get { return mapTileURL; }
  762. set { mapTileURL = value; }
  763. }
  764. public string SearchURL
  765. {
  766. get { return searchURL; }
  767. set { searchURL = value; }
  768. }
  769. public string Message
  770. {
  771. get { return welcomeMessage; }
  772. set { welcomeMessage = value; }
  773. }
  774. public BuddyList BuddList
  775. {
  776. get { return m_buddyList; }
  777. set { m_buddyList = value; }
  778. }
  779. #endregion
  780. public class UserInfo
  781. {
  782. public string firstname;
  783. public string lastname;
  784. public ulong homeregionhandle;
  785. public Vector3 homepos;
  786. public Vector3 homelookat;
  787. }
  788. public class BuddyList
  789. {
  790. public List<BuddyInfo> Buddies = new List<BuddyInfo>();
  791. public void AddNewBuddy(BuddyInfo buddy)
  792. {
  793. if (!Buddies.Contains(buddy))
  794. {
  795. Buddies.Add(buddy);
  796. }
  797. }
  798. public ArrayList ToArray()
  799. {
  800. ArrayList buddyArray = new ArrayList();
  801. foreach (BuddyInfo buddy in Buddies)
  802. {
  803. buddyArray.Add(buddy.ToHashTable());
  804. }
  805. return buddyArray;
  806. }
  807. public class BuddyInfo
  808. {
  809. public int BuddyRightsHave = 1;
  810. public int BuddyRightsGiven = 1;
  811. public string BuddyID;
  812. public BuddyInfo(string buddyID)
  813. {
  814. BuddyID = buddyID;
  815. }
  816. public BuddyInfo(UUID buddyID)
  817. {
  818. BuddyID = buddyID.ToString();
  819. }
  820. public Hashtable ToHashTable()
  821. {
  822. Hashtable hTable = new Hashtable();
  823. hTable["buddy_rights_has"] = BuddyRightsHave;
  824. hTable["buddy_rights_given"] = BuddyRightsGiven;
  825. hTable["buddy_id"] = BuddyID;
  826. return hTable;
  827. }
  828. }
  829. }
  830. }
  831. }