LLLoginResponse.cs 36 KB

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