LLLoginResponse.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  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 UnverifiedAccountProblem;
  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. UnverifiedAccountProblem = new LLFailedLoginResponse("presence",
  74. "Your account has not yet been verified. Please check " +
  75. "your email and click the provided link.",
  76. "false");
  77. AlreadyLoggedInProblem = new LLFailedLoginResponse("presence",
  78. "You appear to be already logged in. " +
  79. "Please wait a a minute or two and retry. " +
  80. "If this takes longer than a few minutes please contact the grid owner. ",
  81. "false");
  82. InternalError = new LLFailedLoginResponse("Internal Error", "Error generating Login Response", "false");
  83. }
  84. public LLFailedLoginResponse(string key, string value, string login)
  85. {
  86. m_key = key;
  87. m_value = value;
  88. m_login = login;
  89. }
  90. public override Hashtable ToHashtable()
  91. {
  92. Hashtable loginError = new Hashtable();
  93. loginError["reason"] = m_key;
  94. loginError["message"] = m_value;
  95. loginError["login"] = m_login;
  96. return loginError;
  97. }
  98. public override OSD ToOSDMap()
  99. {
  100. OSDMap map = new OSDMap();
  101. map["reason"] = OSD.FromString(m_key);
  102. map["message"] = OSD.FromString(m_value);
  103. map["login"] = OSD.FromString(m_login);
  104. return map;
  105. }
  106. }
  107. /// <summary>
  108. /// A class to handle LL login response.
  109. /// </summary>
  110. public class LLLoginResponse : OpenSim.Services.Interfaces.LoginResponse
  111. {
  112. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  113. private static Hashtable globalTexturesHash;
  114. // Global Textures
  115. private static string sunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
  116. private static string cloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621";
  117. private static string moonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621";
  118. private Hashtable loginFlagsHash;
  119. private Hashtable uiConfigHash;
  120. private ArrayList loginFlags;
  121. private ArrayList globalTextures;
  122. private ArrayList eventCategories;
  123. private ArrayList uiConfig;
  124. private ArrayList classifiedCategories;
  125. private ArrayList inventoryRoot;
  126. private ArrayList initialOutfit;
  127. private ArrayList agentInventory;
  128. private ArrayList inventoryLibraryOwner;
  129. private ArrayList inventoryLibRoot;
  130. private ArrayList inventoryLibrary;
  131. private ArrayList activeGestures;
  132. private UserInfo userProfile;
  133. private UUID agentID;
  134. private UUID sessionID;
  135. private UUID secureSessionID;
  136. private UUID realID;
  137. // Login Flags
  138. private string dst;
  139. private string stipendSinceLogin;
  140. private string gendered;
  141. private string everLoggedIn;
  142. private string login;
  143. private uint simPort;
  144. private uint simHttpPort;
  145. private string simAddress;
  146. private string agentAccess;
  147. private string agentAccessMax;
  148. private Int32 circuitCode;
  149. private uint regionX;
  150. private uint regionY;
  151. // Login
  152. private string firstname;
  153. private string lastname;
  154. // Web map
  155. private string mapTileURL;
  156. // Web Profiles
  157. private string profileURL;
  158. // OpenID
  159. private string openIDURL;
  160. private string searchURL;
  161. // Error Flags
  162. private string errorReason;
  163. private string errorMessage;
  164. private string welcomeMessage;
  165. private string startLocation;
  166. private string allowFirstLife;
  167. private string home;
  168. private string seedCapability;
  169. private string lookAt;
  170. private BuddyList m_buddyList = null;
  171. private string currency;
  172. private string classifiedFee;
  173. private int maxAgentGroups;
  174. static LLLoginResponse()
  175. {
  176. // This is being set, but it's not used
  177. // not sure why.
  178. globalTexturesHash = new Hashtable();
  179. globalTexturesHash["sun_texture_id"] = sunTexture;
  180. globalTexturesHash["cloud_texture_id"] = cloudTexture;
  181. globalTexturesHash["moon_texture_id"] = moonTexture;
  182. }
  183. public LLLoginResponse()
  184. {
  185. loginFlags = new ArrayList();
  186. globalTextures = new ArrayList();
  187. eventCategories = new ArrayList();
  188. uiConfig = new ArrayList();
  189. classifiedCategories = new ArrayList();
  190. uiConfigHash = new Hashtable();
  191. // defaultXmlRpcResponse = new XmlRpcResponse();
  192. userProfile = new UserInfo();
  193. inventoryRoot = new ArrayList();
  194. initialOutfit = new ArrayList();
  195. agentInventory = new ArrayList();
  196. inventoryLibrary = new ArrayList();
  197. inventoryLibraryOwner = new ArrayList();
  198. activeGestures = new ArrayList();
  199. SetDefaultValues();
  200. }
  201. public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, GridUserInfo pinfo,
  202. GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService,
  203. string where, string startlocation, Vector3 position, Vector3 lookAt, List<InventoryItemBase> gestures, string message,
  204. GridRegion home, IPEndPoint clientIP, string mapTileURL, string profileURL, string openIDURL, string searchURL, string currency,
  205. string DSTZone, string destinationsURL, string avatarsURL, UUID realID, string classifiedFee,int maxAgentGroups)
  206. : this()
  207. {
  208. FillOutInventoryData(invSkel, libService);
  209. FillOutActiveGestures(gestures);
  210. CircuitCode = (int)aCircuit.circuitcode;
  211. Lastname = account.LastName;
  212. Firstname = account.FirstName;
  213. AgentID = account.PrincipalID;
  214. SessionID = aCircuit.SessionID;
  215. SecureSessionID = aCircuit.SecureSessionID;
  216. RealID = realID;
  217. Message = message;
  218. BuddList = ConvertFriendListItem(friendsList);
  219. StartLocation = where;
  220. MapTileURL = mapTileURL;
  221. ProfileURL = profileURL;
  222. OpenIDURL = openIDURL;
  223. DestinationsURL = destinationsURL;
  224. AvatarsURL = avatarsURL;
  225. SearchURL = searchURL;
  226. Currency = currency;
  227. ClassifiedFee = classifiedFee;
  228. MaxAgentGroups = maxAgentGroups;
  229. FillOutHomeData(pinfo, home);
  230. LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z);
  231. FillOutRegionData(destination);
  232. m_log.DebugFormat("[LOGIN RESPONSE] LLLoginResponse create. sizeX={0}, sizeY={1}", RegionSizeX, RegionSizeY);
  233. FillOutSeedCap(aCircuit, destination, clientIP);
  234. switch (DSTZone)
  235. {
  236. case "none":
  237. DST = "N";
  238. break;
  239. case "local":
  240. DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
  241. break;
  242. default:
  243. TimeZoneInfo dstTimeZone = null;
  244. string[] tzList = DSTZone.Split(';');
  245. foreach (string tzName in tzList)
  246. {
  247. try
  248. {
  249. dstTimeZone = TimeZoneInfo.FindSystemTimeZoneById(tzName);
  250. }
  251. catch
  252. {
  253. continue;
  254. }
  255. break;
  256. }
  257. if (dstTimeZone == null)
  258. {
  259. m_log.WarnFormat(
  260. "[LLOGIN RESPONSE]: No valid timezone found for DST in {0}, falling back to system time.", tzList);
  261. DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
  262. }
  263. else
  264. {
  265. DST = dstTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
  266. }
  267. break;
  268. }
  269. }
  270. private void FillOutInventoryData(List<InventoryFolderBase> invSkel, ILibraryService libService)
  271. {
  272. InventoryData inventData = null;
  273. try
  274. {
  275. inventData = GetInventorySkeleton(invSkel);
  276. }
  277. catch (Exception e)
  278. {
  279. m_log.WarnFormat(
  280. "[LLLOGIN SERVICE]: Error processing inventory skeleton of agent {0} - {1}",
  281. agentID, e);
  282. // ignore and continue
  283. }
  284. if (inventData != null)
  285. {
  286. ArrayList AgentInventoryArray = inventData.InventoryArray;
  287. Hashtable InventoryRootHash = new Hashtable();
  288. InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
  289. InventoryRoot = new ArrayList();
  290. InventoryRoot.Add(InventoryRootHash);
  291. InventorySkeleton = AgentInventoryArray;
  292. }
  293. // Inventory Library Section
  294. if (libService != null && libService.LibraryRootFolder != null)
  295. {
  296. Hashtable InventoryLibRootHash = new Hashtable();
  297. InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
  298. InventoryLibRoot = new ArrayList();
  299. InventoryLibRoot.Add(InventoryLibRootHash);
  300. InventoryLibraryOwner = GetLibraryOwner(libService.LibraryRootFolder);
  301. InventoryLibrary = GetInventoryLibrary(libService);
  302. }
  303. }
  304. private void FillOutActiveGestures(List<InventoryItemBase> gestures)
  305. {
  306. ArrayList list = new ArrayList();
  307. if (gestures != null)
  308. {
  309. foreach (InventoryItemBase gesture in gestures)
  310. {
  311. Hashtable item = new Hashtable();
  312. item["item_id"] = gesture.ID.ToString();
  313. item["asset_id"] = gesture.AssetID.ToString();
  314. list.Add(item);
  315. }
  316. }
  317. ActiveGestures = list;
  318. }
  319. private void FillOutHomeData(GridUserInfo pinfo, GridRegion home)
  320. {
  321. int x = (int)Util.RegionToWorldLoc(1000);
  322. int y = (int)Util.RegionToWorldLoc(1000);
  323. if (home != null)
  324. {
  325. x = home.RegionLocX;
  326. y = home.RegionLocY;
  327. }
  328. Home = string.Format(
  329. "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
  330. x,
  331. y,
  332. pinfo.HomePosition.X, pinfo.HomePosition.Y, pinfo.HomePosition.Z,
  333. pinfo.HomeLookAt.X, pinfo.HomeLookAt.Y, pinfo.HomeLookAt.Z);
  334. }
  335. private void FillOutRegionData(GridRegion destination)
  336. {
  337. IPEndPoint endPoint = destination.ExternalEndPoint;
  338. if (endPoint == null) return;
  339. SimAddress = endPoint.Address.ToString();
  340. SimPort = (uint)endPoint.Port;
  341. RegionX = (uint)destination.RegionLocX;
  342. RegionY = (uint)destination.RegionLocY;
  343. RegionSizeX = destination.RegionSizeX;
  344. RegionSizeY = destination.RegionSizeY;
  345. }
  346. private void FillOutSeedCap(AgentCircuitData aCircuit, GridRegion destination, IPEndPoint ipepClient)
  347. {
  348. SeedCapability = destination.ServerURI + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath);
  349. }
  350. private void SetDefaultValues()
  351. {
  352. TimeZoneInfo gridTimeZone;
  353. // Disabled for now pending making timezone a config value, which can at some point have a default of
  354. // a ; separated list of possible timezones.
  355. // The problem here is that US/Pacific (or even the Olsen America/Los_Angeles) is not universal across
  356. // windows, mac and various distributions of linux, introducing another element of consistency.
  357. // The server operator needs to be able to control this setting
  358. // try
  359. // {
  360. // // First try to fetch DST from Pacific Standard Time, because this is
  361. // // the one expected by the viewer. "US/Pacific" is the string to search
  362. // // on linux and mac, and should work also on Windows (to confirm)
  363. // gridTimeZone = TimeZoneInfo.FindSystemTimeZoneById("US/Pacific");
  364. // }
  365. // catch (Exception e)
  366. // {
  367. // m_log.WarnFormat(
  368. // "[TIMEZONE]: {0} Falling back to system time. System time should be set to Pacific Standard Time to provide the expected time",
  369. // e.Message);
  370. gridTimeZone = TimeZoneInfo.Local;
  371. // }
  372. DST = gridTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
  373. StipendSinceLogin = "N";
  374. Gendered = "Y";
  375. EverLoggedIn = "Y";
  376. login = "false";
  377. firstname = "Test";
  378. lastname = "User";
  379. agentAccess = "M";
  380. agentAccessMax = "A";
  381. startLocation = "last";
  382. allowFirstLife = "Y";
  383. ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
  384. ErrorReason = "key";
  385. welcomeMessage = "Welcome to OpenSim!";
  386. seedCapability = String.Empty;
  387. home = "{'region_handle':["
  388. + "r" + Util.RegionToWorldLoc(1000).ToString()
  389. + ","
  390. + "r" + Util.RegionToWorldLoc(1000).ToString()
  391. + "], 'position':["
  392. + "r" + userProfile.homepos.X.ToString()
  393. + ","
  394. + "r" + userProfile.homepos.Y.ToString()
  395. + ","
  396. + "r" + userProfile.homepos.Z.ToString()
  397. + "], 'look_at':["
  398. + "r" + userProfile.homelookat.X.ToString()
  399. + ","
  400. + "r" + userProfile.homelookat.Y.ToString()
  401. + ","
  402. + "r" + userProfile.homelookat.Z.ToString()
  403. + "]}";
  404. lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
  405. RegionX = (uint) 255232;
  406. RegionY = (uint) 254976;
  407. // Classifieds;
  408. AddClassifiedCategory((Int32) 1, "Shopping");
  409. AddClassifiedCategory((Int32) 2, "Land Rental");
  410. AddClassifiedCategory((Int32) 3, "Property Rental");
  411. AddClassifiedCategory((Int32) 4, "Special Attraction");
  412. AddClassifiedCategory((Int32) 5, "New Products");
  413. AddClassifiedCategory((Int32) 6, "Employment");
  414. AddClassifiedCategory((Int32) 7, "Wanted");
  415. AddClassifiedCategory((Int32) 8, "Service");
  416. AddClassifiedCategory((Int32) 9, "Personal");
  417. SessionID = UUID.Random();
  418. SecureSessionID = UUID.Random();
  419. AgentID = UUID.Random();
  420. RealID = UUID.Zero;
  421. Hashtable InitialOutfitHash = new Hashtable();
  422. InitialOutfitHash["folder_name"] = "Nightclub Female";
  423. InitialOutfitHash["gender"] = "female";
  424. initialOutfit.Add(InitialOutfitHash);
  425. mapTileURL = String.Empty;
  426. profileURL = String.Empty;
  427. openIDURL = String.Empty;
  428. searchURL = String.Empty;
  429. currency = String.Empty;
  430. ClassifiedFee = "0";
  431. MaxAgentGroups = 42;
  432. }
  433. public override Hashtable ToHashtable()
  434. {
  435. try
  436. {
  437. Hashtable responseData = new Hashtable();
  438. loginFlagsHash = new Hashtable();
  439. loginFlagsHash["daylight_savings"] = DST;
  440. loginFlagsHash["stipend_since_login"] = StipendSinceLogin;
  441. loginFlagsHash["gendered"] = Gendered;
  442. loginFlagsHash["ever_logged_in"] = EverLoggedIn;
  443. loginFlags.Add(loginFlagsHash);
  444. responseData["first_name"] = Firstname;
  445. responseData["last_name"] = Lastname;
  446. responseData["agent_access"] = agentAccess;
  447. responseData["agent_access_max"] = agentAccessMax;
  448. globalTextures.Add(globalTexturesHash);
  449. // this.eventCategories.Add(this.eventCategoriesHash);
  450. AddToUIConfig("allow_first_life", allowFirstLife);
  451. uiConfig.Add(uiConfigHash);
  452. responseData["sim_port"] = (Int32) SimPort;
  453. responseData["sim_ip"] = SimAddress;
  454. responseData["http_port"] = (Int32)SimHttpPort;
  455. responseData["agent_id"] = AgentID.ToString();
  456. responseData["real_id"] = RealID.ToString();
  457. responseData["session_id"] = SessionID.ToString();
  458. responseData["secure_session_id"] = SecureSessionID.ToString();
  459. responseData["circuit_code"] = CircuitCode;
  460. responseData["seconds_since_epoch"] = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  461. responseData["login-flags"] = loginFlags;
  462. responseData["global-textures"] = globalTextures;
  463. responseData["seed_capability"] = seedCapability;
  464. responseData["event_categories"] = eventCategories;
  465. responseData["event_notifications"] = new ArrayList(); // todo
  466. responseData["classified_categories"] = classifiedCategories;
  467. responseData["ui-config"] = uiConfig;
  468. if (agentInventory != null)
  469. {
  470. responseData["inventory-skeleton"] = agentInventory;
  471. responseData["inventory-root"] = inventoryRoot;
  472. }
  473. responseData["inventory-skel-lib"] = inventoryLibrary;
  474. responseData["inventory-lib-root"] = inventoryLibRoot;
  475. responseData["gestures"] = activeGestures;
  476. responseData["inventory-lib-owner"] = inventoryLibraryOwner;
  477. responseData["initial-outfit"] = initialOutfit;
  478. responseData["start_location"] = startLocation;
  479. responseData["seed_capability"] = seedCapability;
  480. responseData["home"] = home;
  481. responseData["look_at"] = lookAt;
  482. responseData["max-agent-groups"] = MaxAgentGroups;
  483. responseData["message"] = welcomeMessage;
  484. responseData["region_x"] = (Int32)(RegionX);
  485. responseData["region_y"] = (Int32)(RegionY);
  486. responseData["region_size_x"] = (Int32)RegionSizeX;
  487. responseData["region_size_y"] = (Int32)RegionSizeY;
  488. m_log.DebugFormat("[LOGIN RESPONSE] returning sizeX={0}, sizeY={1}", RegionSizeX, RegionSizeY);
  489. if (searchURL != String.Empty)
  490. responseData["search"] = searchURL;
  491. if (mapTileURL != String.Empty)
  492. responseData["map-server-url"] = mapTileURL;
  493. if (profileURL != String.Empty)
  494. responseData["profile-server-url"] = profileURL;
  495. if (DestinationsURL != String.Empty)
  496. responseData["destination_guide_url"] = DestinationsURL;
  497. if (AvatarsURL != String.Empty)
  498. responseData["avatar_picker_url"] = AvatarsURL;
  499. // We need to send an openid_token back in the response too
  500. if (openIDURL != String.Empty)
  501. {
  502. responseData["openid_url"] = openIDURL;
  503. responseData["openid_token"] = AgentID.ToString() + ":" + Util.Md5Hash(SecureSessionID.ToString());
  504. }
  505. if (m_buddyList != null)
  506. {
  507. responseData["buddy-list"] = m_buddyList.ToArray();
  508. }
  509. if (currency != String.Empty)
  510. {
  511. // responseData["real_currency"] = currency;
  512. responseData["currency"] = currency;
  513. }
  514. if (ClassifiedFee != String.Empty)
  515. responseData["classified_fee"] = ClassifiedFee;
  516. responseData["login"] = "true";
  517. return responseData;
  518. }
  519. catch (Exception e)
  520. {
  521. m_log.Warn("[CLIENT]: LoginResponse: Error creating Hashtable Response: " + e.Message);
  522. return LLFailedLoginResponse.InternalError.ToHashtable();
  523. }
  524. }
  525. public override OSD ToOSDMap()
  526. {
  527. try
  528. {
  529. OSDMap map = new OSDMap();
  530. map["first_name"] = OSD.FromString(Firstname);
  531. map["last_name"] = OSD.FromString(Lastname);
  532. map["agent_access"] = OSD.FromString(agentAccess);
  533. map["agent_access_max"] = OSD.FromString(agentAccessMax);
  534. map["sim_port"] = OSD.FromInteger(SimPort);
  535. map["sim_ip"] = OSD.FromString(SimAddress);
  536. map["agent_id"] = OSD.FromUUID(AgentID);
  537. map["real_id"] = OSD.FromUUID(RealID);
  538. map["session_id"] = OSD.FromUUID(SessionID);
  539. map["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  540. map["circuit_code"] = OSD.FromInteger(CircuitCode);
  541. map["seconds_since_epoch"] = OSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
  542. #region Login Flags
  543. OSDMap loginFlagsLLSD = new OSDMap();
  544. loginFlagsLLSD["daylight_savings"] = OSD.FromString(DST);
  545. loginFlagsLLSD["stipend_since_login"] = OSD.FromString(StipendSinceLogin);
  546. loginFlagsLLSD["gendered"] = OSD.FromString(Gendered);
  547. loginFlagsLLSD["ever_logged_in"] = OSD.FromString(EverLoggedIn);
  548. map["login-flags"] = WrapOSDMap(loginFlagsLLSD);
  549. #endregion Login Flags
  550. #region Global Textures
  551. OSDMap globalTexturesLLSD = new OSDMap();
  552. globalTexturesLLSD["sun_texture_id"] = OSD.FromString(SunTexture);
  553. globalTexturesLLSD["cloud_texture_id"] = OSD.FromString(CloudTexture);
  554. globalTexturesLLSD["moon_texture_id"] = OSD.FromString(MoonTexture);
  555. map["global-textures"] = WrapOSDMap(globalTexturesLLSD);
  556. #endregion Global Textures
  557. map["seed_capability"] = OSD.FromString(seedCapability);
  558. map["event_categories"] = ArrayListToOSDArray(eventCategories);
  559. //map["event_notifications"] = new OSDArray(); // todo
  560. map["classified_categories"] = ArrayListToOSDArray(classifiedCategories);
  561. #region UI Config
  562. OSDMap uiConfigLLSD = new OSDMap();
  563. uiConfigLLSD["allow_first_life"] = OSD.FromString(allowFirstLife);
  564. map["ui-config"] = WrapOSDMap(uiConfigLLSD);
  565. #endregion UI Config
  566. #region Inventory
  567. map["inventory-skeleton"] = ArrayListToOSDArray(agentInventory);
  568. map["inventory-skel-lib"] = ArrayListToOSDArray(inventoryLibrary);
  569. map["inventory-root"] = ArrayListToOSDArray(inventoryRoot); ;
  570. map["inventory-lib-root"] = ArrayListToOSDArray(inventoryLibRoot);
  571. map["inventory-lib-owner"] = ArrayListToOSDArray(inventoryLibraryOwner);
  572. #endregion Inventory
  573. map["gestures"] = ArrayListToOSDArray(activeGestures);
  574. map["initial-outfit"] = ArrayListToOSDArray(initialOutfit);
  575. map["start_location"] = OSD.FromString(startLocation);
  576. map["seed_capability"] = OSD.FromString(seedCapability);
  577. map["home"] = OSD.FromString(home);
  578. map["look_at"] = OSD.FromString(lookAt);
  579. map["max-agent-groups"] = OSD.FromInteger(MaxAgentGroups);
  580. map["message"] = OSD.FromString(welcomeMessage);
  581. map["region_x"] = OSD.FromInteger(RegionX);
  582. map["region_y"] = OSD.FromInteger(RegionY);
  583. if (mapTileURL != String.Empty)
  584. map["map-server-url"] = OSD.FromString(mapTileURL);
  585. if (profileURL != String.Empty)
  586. map["profile-server-url"] = OSD.FromString(profileURL);
  587. if (openIDURL != String.Empty)
  588. {
  589. map["openid_url"] = OSD.FromString(openIDURL);
  590. map["openid_token"] = OSD.FromString(AgentID.ToString() + ":" + Util.Md5Hash(SecureSessionID.ToString()));
  591. }
  592. if (searchURL != String.Empty)
  593. map["search"] = OSD.FromString(searchURL);
  594. if (ClassifiedFee != String.Empty)
  595. map["classified_fee"] = OSD.FromString(ClassifiedFee);
  596. if (m_buddyList != null)
  597. {
  598. map["buddy-list"] = ArrayListToOSDArray(m_buddyList.ToArray());
  599. }
  600. map["login"] = OSD.FromString("true");
  601. return map;
  602. }
  603. catch (Exception e)
  604. {
  605. m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message);
  606. return LLFailedLoginResponse.InternalError.ToOSDMap();
  607. }
  608. }
  609. public OSDArray ArrayListToOSDArray(ArrayList arrlst)
  610. {
  611. OSDArray llsdBack = new OSDArray();
  612. foreach (Hashtable ht in arrlst)
  613. {
  614. OSDMap mp = new OSDMap();
  615. foreach (DictionaryEntry deHt in ht)
  616. {
  617. mp.Add((string)deHt.Key, OSDString.FromObject(deHt.Value));
  618. }
  619. llsdBack.Add(mp);
  620. }
  621. return llsdBack;
  622. }
  623. private static OSDArray WrapOSDMap(OSDMap wrapMe)
  624. {
  625. OSDArray array = new OSDArray();
  626. array.Add(wrapMe);
  627. return array;
  628. }
  629. public void SetEventCategories(string category, string value)
  630. {
  631. // this.eventCategoriesHash[category] = value;
  632. //TODO
  633. }
  634. public void AddToUIConfig(string itemName, string item)
  635. {
  636. uiConfigHash[itemName] = item;
  637. }
  638. public void AddClassifiedCategory(Int32 ID, string categoryName)
  639. {
  640. Hashtable hash = new Hashtable();
  641. hash["category_name"] = categoryName;
  642. hash["category_id"] = ID;
  643. classifiedCategories.Add(hash);
  644. // this.classifiedCategoriesHash.Clear();
  645. }
  646. private static LLLoginResponse.BuddyList ConvertFriendListItem(FriendInfo[] friendsList)
  647. {
  648. LLLoginResponse.BuddyList buddylistreturn = new LLLoginResponse.BuddyList();
  649. foreach (FriendInfo finfo in friendsList)
  650. {
  651. if (finfo.TheirFlags == -1)
  652. continue;
  653. LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(finfo.Friend);
  654. if (!Util.ParseUniversalUserIdentifier(finfo.Friend, out UUID friendID))
  655. continue; // junk entry
  656. buddyitem.BuddyID = friendID.ToString();
  657. buddyitem.BuddyRightsHave = finfo.TheirFlags;
  658. buddyitem.BuddyRightsGiven = finfo.MyFlags;
  659. buddylistreturn.AddNewBuddy(buddyitem);
  660. }
  661. return buddylistreturn;
  662. }
  663. private InventoryData GetInventorySkeleton(List<InventoryFolderBase> folders)
  664. {
  665. UUID rootID = UUID.Zero;
  666. ArrayList AgentInventoryArray = new ArrayList();
  667. Hashtable TempHash;
  668. foreach (InventoryFolderBase InvFolder in folders)
  669. {
  670. if (InvFolder.ParentID.IsZero() && InvFolder.Name == InventoryFolderBase.ROOT_FOLDER_NAME)
  671. {
  672. rootID = InvFolder.ID;
  673. }
  674. TempHash = new Hashtable();
  675. TempHash["name"] = InvFolder.Name;
  676. TempHash["parent_id"] = InvFolder.ParentID.ToString();
  677. TempHash["version"] = (Int32)InvFolder.Version;
  678. TempHash["type_default"] = (Int32)InvFolder.Type;
  679. TempHash["folder_id"] = InvFolder.ID.ToString();
  680. AgentInventoryArray.Add(TempHash);
  681. }
  682. return new InventoryData(AgentInventoryArray, rootID);
  683. }
  684. /// <summary>
  685. /// Converts the inventory library skeleton into the form required by the rpc request.
  686. /// </summary>
  687. /// <returns></returns>
  688. protected virtual ArrayList GetInventoryLibrary(ILibraryService library)
  689. {
  690. Dictionary<UUID, InventoryFolderImpl> rootFolders = library.GetAllFolders();
  691. // m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count);
  692. //Dictionary<UUID, InventoryFolderImpl> rootFolders = new Dictionary<UUID,InventoryFolderImpl>();
  693. ArrayList folderHashes = new ArrayList();
  694. foreach (InventoryFolderBase folder in rootFolders.Values)
  695. {
  696. Hashtable TempHash = new Hashtable();
  697. TempHash["name"] = folder.Name;
  698. TempHash["parent_id"] = folder.ParentID.ToString();
  699. TempHash["version"] = (Int32)folder.Version;
  700. TempHash["type_default"] = (Int32)folder.Type;
  701. TempHash["folder_id"] = folder.ID.ToString();
  702. folderHashes.Add(TempHash);
  703. }
  704. return folderHashes;
  705. }
  706. /// <summary>
  707. ///
  708. /// </summary>
  709. /// <returns></returns>
  710. protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder)
  711. {
  712. //for now create random inventory library owner
  713. Hashtable TempHash = new Hashtable();
  714. TempHash["agent_id"] = Constants.m_MrOpenSimID.ToString(); // libFolder.Owner
  715. ArrayList inventoryLibOwner = new ArrayList();
  716. inventoryLibOwner.Add(TempHash);
  717. return inventoryLibOwner;
  718. }
  719. public class InventoryData
  720. {
  721. public ArrayList InventoryArray = null;
  722. public UUID RootFolderID = UUID.Zero;
  723. public InventoryData(ArrayList invList, UUID rootID)
  724. {
  725. InventoryArray = invList;
  726. RootFolderID = rootID;
  727. }
  728. }
  729. #region Properties
  730. public string Login
  731. {
  732. get { return login; }
  733. set { login = value; }
  734. }
  735. public string DST
  736. {
  737. get { return dst; }
  738. set { dst = value; }
  739. }
  740. public string StipendSinceLogin
  741. {
  742. get { return stipendSinceLogin; }
  743. set { stipendSinceLogin = value; }
  744. }
  745. public string Gendered
  746. {
  747. get { return gendered; }
  748. set { gendered = value; }
  749. }
  750. public string EverLoggedIn
  751. {
  752. get { return everLoggedIn; }
  753. set { everLoggedIn = value; }
  754. }
  755. public uint SimPort
  756. {
  757. get { return simPort; }
  758. set { simPort = value; }
  759. }
  760. public uint SimHttpPort
  761. {
  762. get { return simHttpPort; }
  763. set { simHttpPort = value; }
  764. }
  765. public string SimAddress
  766. {
  767. get { return simAddress; }
  768. set { simAddress = value; }
  769. }
  770. public UUID AgentID
  771. {
  772. get { return agentID; }
  773. set { agentID = value; }
  774. }
  775. public UUID SessionID
  776. {
  777. get { return sessionID; }
  778. set { sessionID = value; }
  779. }
  780. public UUID SecureSessionID
  781. {
  782. get { return secureSessionID; }
  783. set { secureSessionID = value; }
  784. }
  785. public UUID RealID
  786. {
  787. get { return realID; }
  788. set { realID = value; }
  789. }
  790. public Int32 CircuitCode
  791. {
  792. get { return circuitCode; }
  793. set { circuitCode = value; }
  794. }
  795. public uint RegionX
  796. {
  797. get { return regionX; }
  798. set { regionX = value; }
  799. }
  800. public uint RegionY
  801. {
  802. get { return regionY; }
  803. set { regionY = value; }
  804. }
  805. public int RegionSizeX { get; private set; }
  806. public int RegionSizeY { get; private set; }
  807. public string SunTexture
  808. {
  809. get { return sunTexture; }
  810. set { sunTexture = value; }
  811. }
  812. public string CloudTexture
  813. {
  814. get { return cloudTexture; }
  815. set { cloudTexture = value; }
  816. }
  817. public string MoonTexture
  818. {
  819. get { return moonTexture; }
  820. set { moonTexture = value; }
  821. }
  822. public string Firstname
  823. {
  824. get { return firstname; }
  825. set { firstname = value; }
  826. }
  827. public string Lastname
  828. {
  829. get { return lastname; }
  830. set { lastname = value; }
  831. }
  832. public string AgentAccess
  833. {
  834. get { return agentAccess; }
  835. set { agentAccess = value; }
  836. }
  837. public string AgentAccessMax
  838. {
  839. get { return agentAccessMax; }
  840. set { agentAccessMax = value; }
  841. }
  842. public string StartLocation
  843. {
  844. get { return startLocation; }
  845. set { startLocation = value; }
  846. }
  847. public string LookAt
  848. {
  849. get { return lookAt; }
  850. set { lookAt = value; }
  851. }
  852. public string SeedCapability
  853. {
  854. get { return seedCapability; }
  855. set { seedCapability = value; }
  856. }
  857. public string ErrorReason
  858. {
  859. get { return errorReason; }
  860. set { errorReason = value; }
  861. }
  862. public string ErrorMessage
  863. {
  864. get { return errorMessage; }
  865. set { errorMessage = value; }
  866. }
  867. public ArrayList InventoryRoot
  868. {
  869. get { return inventoryRoot; }
  870. set { inventoryRoot = value; }
  871. }
  872. public ArrayList InventorySkeleton
  873. {
  874. get { return agentInventory; }
  875. set { agentInventory = value; }
  876. }
  877. public ArrayList InventoryLibrary
  878. {
  879. get { return inventoryLibrary; }
  880. set { inventoryLibrary = value; }
  881. }
  882. public ArrayList InventoryLibraryOwner
  883. {
  884. get { return inventoryLibraryOwner; }
  885. set { inventoryLibraryOwner = value; }
  886. }
  887. public ArrayList InventoryLibRoot
  888. {
  889. get { return inventoryLibRoot; }
  890. set { inventoryLibRoot = value; }
  891. }
  892. public ArrayList ActiveGestures
  893. {
  894. get { return activeGestures; }
  895. set { activeGestures = value; }
  896. }
  897. public string Home
  898. {
  899. get { return home; }
  900. set { home = value; }
  901. }
  902. public string MapTileURL
  903. {
  904. get { return mapTileURL; }
  905. set { mapTileURL = value; }
  906. }
  907. public string ProfileURL
  908. {
  909. get { return profileURL; }
  910. set { profileURL = value; }
  911. }
  912. public string OpenIDURL
  913. {
  914. get { return openIDURL; }
  915. set { openIDURL = value; }
  916. }
  917. public string SearchURL
  918. {
  919. get { return searchURL; }
  920. set { searchURL = value; }
  921. }
  922. public string Message
  923. {
  924. get { return welcomeMessage; }
  925. set { welcomeMessage = value; }
  926. }
  927. public BuddyList BuddList
  928. {
  929. get { return m_buddyList; }
  930. set { m_buddyList = value; }
  931. }
  932. public string Currency
  933. {
  934. get { return currency; }
  935. set { currency = value; }
  936. }
  937. public string ClassifiedFee
  938. {
  939. get { return classifiedFee; }
  940. set { classifiedFee = value; }
  941. }
  942. public int MaxAgentGroups
  943. {
  944. get { return maxAgentGroups; }
  945. set { maxAgentGroups = value; }
  946. }
  947. public string DestinationsURL
  948. {
  949. get; set;
  950. }
  951. public string AvatarsURL
  952. {
  953. get; set;
  954. }
  955. #endregion
  956. public class UserInfo
  957. {
  958. public string firstname;
  959. public string lastname;
  960. public ulong homeregionhandle;
  961. public Vector3 homepos;
  962. public Vector3 homelookat;
  963. }
  964. public class BuddyList
  965. {
  966. public List<BuddyInfo> Buddies = new List<BuddyInfo>();
  967. public void AddNewBuddy(BuddyInfo buddy)
  968. {
  969. if (!Buddies.Contains(buddy))
  970. {
  971. Buddies.Add(buddy);
  972. }
  973. }
  974. public ArrayList ToArray()
  975. {
  976. ArrayList buddyArray = new ArrayList();
  977. foreach (BuddyInfo buddy in Buddies)
  978. {
  979. buddyArray.Add(buddy.ToHashTable());
  980. }
  981. return buddyArray;
  982. }
  983. public class BuddyInfo
  984. {
  985. public int BuddyRightsHave = 1;
  986. public int BuddyRightsGiven = 1;
  987. public string BuddyID;
  988. public BuddyInfo(string buddyID)
  989. {
  990. BuddyID = buddyID;
  991. }
  992. public BuddyInfo(UUID buddyID)
  993. {
  994. BuddyID = buddyID.ToString();
  995. }
  996. public Hashtable ToHashTable()
  997. {
  998. Hashtable hTable = new Hashtable();
  999. hTable["buddy_rights_has"] = BuddyRightsHave;
  1000. hTable["buddy_rights_given"] = BuddyRightsGiven;
  1001. hTable["buddy_id"] = BuddyID;
  1002. return hTable;
  1003. }
  1004. }
  1005. }
  1006. }
  1007. }