LLLoginResponse.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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. responseData["openid_url"] = openIDURL;
  502. if (m_buddyList != null)
  503. {
  504. responseData["buddy-list"] = m_buddyList.ToArray();
  505. }
  506. if (currency != String.Empty)
  507. {
  508. // responseData["real_currency"] = currency;
  509. responseData["currency"] = currency;
  510. }
  511. if (ClassifiedFee != String.Empty)
  512. responseData["classified_fee"] = ClassifiedFee;
  513. responseData["login"] = "true";
  514. return responseData;
  515. }
  516. catch (Exception e)
  517. {
  518. m_log.Warn("[CLIENT]: LoginResponse: Error creating Hashtable Response: " + e.Message);
  519. return LLFailedLoginResponse.InternalError.ToHashtable();
  520. }
  521. }
  522. public override OSD ToOSDMap()
  523. {
  524. try
  525. {
  526. OSDMap map = new OSDMap();
  527. map["first_name"] = OSD.FromString(Firstname);
  528. map["last_name"] = OSD.FromString(Lastname);
  529. map["agent_access"] = OSD.FromString(agentAccess);
  530. map["agent_access_max"] = OSD.FromString(agentAccessMax);
  531. map["sim_port"] = OSD.FromInteger(SimPort);
  532. map["sim_ip"] = OSD.FromString(SimAddress);
  533. map["agent_id"] = OSD.FromUUID(AgentID);
  534. map["real_id"] = OSD.FromUUID(RealID);
  535. map["session_id"] = OSD.FromUUID(SessionID);
  536. map["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  537. map["circuit_code"] = OSD.FromInteger(CircuitCode);
  538. map["seconds_since_epoch"] = OSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
  539. #region Login Flags
  540. OSDMap loginFlagsLLSD = new OSDMap();
  541. loginFlagsLLSD["daylight_savings"] = OSD.FromString(DST);
  542. loginFlagsLLSD["stipend_since_login"] = OSD.FromString(StipendSinceLogin);
  543. loginFlagsLLSD["gendered"] = OSD.FromString(Gendered);
  544. loginFlagsLLSD["ever_logged_in"] = OSD.FromString(EverLoggedIn);
  545. map["login-flags"] = WrapOSDMap(loginFlagsLLSD);
  546. #endregion Login Flags
  547. #region Global Textures
  548. OSDMap globalTexturesLLSD = new OSDMap();
  549. globalTexturesLLSD["sun_texture_id"] = OSD.FromString(SunTexture);
  550. globalTexturesLLSD["cloud_texture_id"] = OSD.FromString(CloudTexture);
  551. globalTexturesLLSD["moon_texture_id"] = OSD.FromString(MoonTexture);
  552. map["global-textures"] = WrapOSDMap(globalTexturesLLSD);
  553. #endregion Global Textures
  554. map["seed_capability"] = OSD.FromString(seedCapability);
  555. map["event_categories"] = ArrayListToOSDArray(eventCategories);
  556. //map["event_notifications"] = new OSDArray(); // todo
  557. map["classified_categories"] = ArrayListToOSDArray(classifiedCategories);
  558. #region UI Config
  559. OSDMap uiConfigLLSD = new OSDMap();
  560. uiConfigLLSD["allow_first_life"] = OSD.FromString(allowFirstLife);
  561. map["ui-config"] = WrapOSDMap(uiConfigLLSD);
  562. #endregion UI Config
  563. #region Inventory
  564. map["inventory-skeleton"] = ArrayListToOSDArray(agentInventory);
  565. map["inventory-skel-lib"] = ArrayListToOSDArray(inventoryLibrary);
  566. map["inventory-root"] = ArrayListToOSDArray(inventoryRoot); ;
  567. map["inventory-lib-root"] = ArrayListToOSDArray(inventoryLibRoot);
  568. map["inventory-lib-owner"] = ArrayListToOSDArray(inventoryLibraryOwner);
  569. #endregion Inventory
  570. map["gestures"] = ArrayListToOSDArray(activeGestures);
  571. map["initial-outfit"] = ArrayListToOSDArray(initialOutfit);
  572. map["start_location"] = OSD.FromString(startLocation);
  573. map["seed_capability"] = OSD.FromString(seedCapability);
  574. map["home"] = OSD.FromString(home);
  575. map["look_at"] = OSD.FromString(lookAt);
  576. map["max-agent-groups"] = OSD.FromInteger(MaxAgentGroups);
  577. map["message"] = OSD.FromString(welcomeMessage);
  578. map["region_x"] = OSD.FromInteger(RegionX);
  579. map["region_y"] = OSD.FromInteger(RegionY);
  580. if (mapTileURL != String.Empty)
  581. map["map-server-url"] = OSD.FromString(mapTileURL);
  582. if (profileURL != String.Empty)
  583. map["profile-server-url"] = OSD.FromString(profileURL);
  584. if (openIDURL != String.Empty)
  585. map["openid_url"] = OSD.FromString(openIDURL);
  586. if (searchURL != String.Empty)
  587. map["search"] = OSD.FromString(searchURL);
  588. if (ClassifiedFee != String.Empty)
  589. map["classified_fee"] = OSD.FromString(ClassifiedFee);
  590. if (m_buddyList != null)
  591. {
  592. map["buddy-list"] = ArrayListToOSDArray(m_buddyList.ToArray());
  593. }
  594. map["login"] = OSD.FromString("true");
  595. return map;
  596. }
  597. catch (Exception e)
  598. {
  599. m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message);
  600. return LLFailedLoginResponse.InternalError.ToOSDMap();
  601. }
  602. }
  603. public OSDArray ArrayListToOSDArray(ArrayList arrlst)
  604. {
  605. OSDArray llsdBack = new OSDArray();
  606. foreach (Hashtable ht in arrlst)
  607. {
  608. OSDMap mp = new OSDMap();
  609. foreach (DictionaryEntry deHt in ht)
  610. {
  611. mp.Add((string)deHt.Key, OSDString.FromObject(deHt.Value));
  612. }
  613. llsdBack.Add(mp);
  614. }
  615. return llsdBack;
  616. }
  617. private static OSDArray WrapOSDMap(OSDMap wrapMe)
  618. {
  619. OSDArray array = new OSDArray();
  620. array.Add(wrapMe);
  621. return array;
  622. }
  623. public void SetEventCategories(string category, string value)
  624. {
  625. // this.eventCategoriesHash[category] = value;
  626. //TODO
  627. }
  628. public void AddToUIConfig(string itemName, string item)
  629. {
  630. uiConfigHash[itemName] = item;
  631. }
  632. public void AddClassifiedCategory(Int32 ID, string categoryName)
  633. {
  634. Hashtable hash = new Hashtable();
  635. hash["category_name"] = categoryName;
  636. hash["category_id"] = ID;
  637. classifiedCategories.Add(hash);
  638. // this.classifiedCategoriesHash.Clear();
  639. }
  640. private static LLLoginResponse.BuddyList ConvertFriendListItem(FriendInfo[] friendsList)
  641. {
  642. LLLoginResponse.BuddyList buddylistreturn = new LLLoginResponse.BuddyList();
  643. foreach (FriendInfo finfo in friendsList)
  644. {
  645. if (finfo.TheirFlags == -1)
  646. continue;
  647. LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(finfo.Friend);
  648. // finfo.Friend may not be a simple uuid
  649. UUID friendID = UUID.Zero;
  650. if (UUID.TryParse(finfo.Friend, out friendID))
  651. buddyitem.BuddyID = finfo.Friend;
  652. else
  653. {
  654. string tmp;
  655. if (Util.ParseUniversalUserIdentifier(finfo.Friend, out friendID, out tmp, out tmp, out tmp, out tmp))
  656. buddyitem.BuddyID = friendID.ToString();
  657. else
  658. // junk entry
  659. continue;
  660. }
  661. buddyitem.BuddyRightsHave = (int)finfo.TheirFlags;
  662. buddyitem.BuddyRightsGiven = (int)finfo.MyFlags;
  663. buddylistreturn.AddNewBuddy(buddyitem);
  664. }
  665. return buddylistreturn;
  666. }
  667. private InventoryData GetInventorySkeleton(List<InventoryFolderBase> folders)
  668. {
  669. UUID rootID = UUID.Zero;
  670. ArrayList AgentInventoryArray = new ArrayList();
  671. Hashtable TempHash;
  672. foreach (InventoryFolderBase InvFolder in folders)
  673. {
  674. if (InvFolder.ParentID == UUID.Zero && InvFolder.Name == InventoryFolderBase.ROOT_FOLDER_NAME)
  675. {
  676. rootID = InvFolder.ID;
  677. }
  678. TempHash = new Hashtable();
  679. TempHash["name"] = InvFolder.Name;
  680. TempHash["parent_id"] = InvFolder.ParentID.ToString();
  681. TempHash["version"] = (Int32)InvFolder.Version;
  682. TempHash["type_default"] = (Int32)InvFolder.Type;
  683. TempHash["folder_id"] = InvFolder.ID.ToString();
  684. AgentInventoryArray.Add(TempHash);
  685. }
  686. return new InventoryData(AgentInventoryArray, rootID);
  687. }
  688. /// <summary>
  689. /// Converts the inventory library skeleton into the form required by the rpc request.
  690. /// </summary>
  691. /// <returns></returns>
  692. protected virtual ArrayList GetInventoryLibrary(ILibraryService library)
  693. {
  694. Dictionary<UUID, InventoryFolderImpl> rootFolders = library.GetAllFolders();
  695. // m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count);
  696. //Dictionary<UUID, InventoryFolderImpl> rootFolders = new Dictionary<UUID,InventoryFolderImpl>();
  697. ArrayList folderHashes = new ArrayList();
  698. foreach (InventoryFolderBase folder in rootFolders.Values)
  699. {
  700. Hashtable TempHash = new Hashtable();
  701. TempHash["name"] = folder.Name;
  702. TempHash["parent_id"] = folder.ParentID.ToString();
  703. TempHash["version"] = (Int32)folder.Version;
  704. TempHash["type_default"] = (Int32)folder.Type;
  705. TempHash["folder_id"] = folder.ID.ToString();
  706. folderHashes.Add(TempHash);
  707. }
  708. return folderHashes;
  709. }
  710. /// <summary>
  711. ///
  712. /// </summary>
  713. /// <returns></returns>
  714. protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder)
  715. {
  716. //for now create random inventory library owner
  717. Hashtable TempHash = new Hashtable();
  718. TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; // libFolder.Owner
  719. ArrayList inventoryLibOwner = new ArrayList();
  720. inventoryLibOwner.Add(TempHash);
  721. return inventoryLibOwner;
  722. }
  723. public class InventoryData
  724. {
  725. public ArrayList InventoryArray = null;
  726. public UUID RootFolderID = UUID.Zero;
  727. public InventoryData(ArrayList invList, UUID rootID)
  728. {
  729. InventoryArray = invList;
  730. RootFolderID = rootID;
  731. }
  732. }
  733. #region Properties
  734. public string Login
  735. {
  736. get { return login; }
  737. set { login = value; }
  738. }
  739. public string DST
  740. {
  741. get { return dst; }
  742. set { dst = value; }
  743. }
  744. public string StipendSinceLogin
  745. {
  746. get { return stipendSinceLogin; }
  747. set { stipendSinceLogin = value; }
  748. }
  749. public string Gendered
  750. {
  751. get { return gendered; }
  752. set { gendered = value; }
  753. }
  754. public string EverLoggedIn
  755. {
  756. get { return everLoggedIn; }
  757. set { everLoggedIn = value; }
  758. }
  759. public uint SimPort
  760. {
  761. get { return simPort; }
  762. set { simPort = value; }
  763. }
  764. public uint SimHttpPort
  765. {
  766. get { return simHttpPort; }
  767. set { simHttpPort = value; }
  768. }
  769. public string SimAddress
  770. {
  771. get { return simAddress; }
  772. set { simAddress = value; }
  773. }
  774. public UUID AgentID
  775. {
  776. get { return agentID; }
  777. set { agentID = value; }
  778. }
  779. public UUID SessionID
  780. {
  781. get { return sessionID; }
  782. set { sessionID = value; }
  783. }
  784. public UUID SecureSessionID
  785. {
  786. get { return secureSessionID; }
  787. set { secureSessionID = value; }
  788. }
  789. public UUID RealID
  790. {
  791. get { return realID; }
  792. set { realID = value; }
  793. }
  794. public Int32 CircuitCode
  795. {
  796. get { return circuitCode; }
  797. set { circuitCode = value; }
  798. }
  799. public uint RegionX
  800. {
  801. get { return regionX; }
  802. set { regionX = value; }
  803. }
  804. public uint RegionY
  805. {
  806. get { return regionY; }
  807. set { regionY = value; }
  808. }
  809. public int RegionSizeX { get; private set; }
  810. public int RegionSizeY { get; private set; }
  811. public string SunTexture
  812. {
  813. get { return sunTexture; }
  814. set { sunTexture = value; }
  815. }
  816. public string CloudTexture
  817. {
  818. get { return cloudTexture; }
  819. set { cloudTexture = value; }
  820. }
  821. public string MoonTexture
  822. {
  823. get { return moonTexture; }
  824. set { moonTexture = value; }
  825. }
  826. public string Firstname
  827. {
  828. get { return firstname; }
  829. set { firstname = value; }
  830. }
  831. public string Lastname
  832. {
  833. get { return lastname; }
  834. set { lastname = value; }
  835. }
  836. public string AgentAccess
  837. {
  838. get { return agentAccess; }
  839. set { agentAccess = value; }
  840. }
  841. public string AgentAccessMax
  842. {
  843. get { return agentAccessMax; }
  844. set { agentAccessMax = value; }
  845. }
  846. public string StartLocation
  847. {
  848. get { return startLocation; }
  849. set { startLocation = value; }
  850. }
  851. public string LookAt
  852. {
  853. get { return lookAt; }
  854. set { lookAt = value; }
  855. }
  856. public string SeedCapability
  857. {
  858. get { return seedCapability; }
  859. set { seedCapability = value; }
  860. }
  861. public string ErrorReason
  862. {
  863. get { return errorReason; }
  864. set { errorReason = value; }
  865. }
  866. public string ErrorMessage
  867. {
  868. get { return errorMessage; }
  869. set { errorMessage = value; }
  870. }
  871. public ArrayList InventoryRoot
  872. {
  873. get { return inventoryRoot; }
  874. set { inventoryRoot = value; }
  875. }
  876. public ArrayList InventorySkeleton
  877. {
  878. get { return agentInventory; }
  879. set { agentInventory = value; }
  880. }
  881. public ArrayList InventoryLibrary
  882. {
  883. get { return inventoryLibrary; }
  884. set { inventoryLibrary = value; }
  885. }
  886. public ArrayList InventoryLibraryOwner
  887. {
  888. get { return inventoryLibraryOwner; }
  889. set { inventoryLibraryOwner = value; }
  890. }
  891. public ArrayList InventoryLibRoot
  892. {
  893. get { return inventoryLibRoot; }
  894. set { inventoryLibRoot = value; }
  895. }
  896. public ArrayList ActiveGestures
  897. {
  898. get { return activeGestures; }
  899. set { activeGestures = value; }
  900. }
  901. public string Home
  902. {
  903. get { return home; }
  904. set { home = value; }
  905. }
  906. public string MapTileURL
  907. {
  908. get { return mapTileURL; }
  909. set { mapTileURL = value; }
  910. }
  911. public string ProfileURL
  912. {
  913. get { return profileURL; }
  914. set { profileURL = value; }
  915. }
  916. public string OpenIDURL
  917. {
  918. get { return openIDURL; }
  919. set { openIDURL = value; }
  920. }
  921. public string SearchURL
  922. {
  923. get { return searchURL; }
  924. set { searchURL = value; }
  925. }
  926. public string Message
  927. {
  928. get { return welcomeMessage; }
  929. set { welcomeMessage = value; }
  930. }
  931. public BuddyList BuddList
  932. {
  933. get { return m_buddyList; }
  934. set { m_buddyList = value; }
  935. }
  936. public string Currency
  937. {
  938. get { return currency; }
  939. set { currency = value; }
  940. }
  941. public string ClassifiedFee
  942. {
  943. get { return classifiedFee; }
  944. set { classifiedFee = value; }
  945. }
  946. public int MaxAgentGroups
  947. {
  948. get { return maxAgentGroups; }
  949. set { maxAgentGroups = value; }
  950. }
  951. public string DestinationsURL
  952. {
  953. get; set;
  954. }
  955. public string AvatarsURL
  956. {
  957. get; set;
  958. }
  959. #endregion
  960. public class UserInfo
  961. {
  962. public string firstname;
  963. public string lastname;
  964. public ulong homeregionhandle;
  965. public Vector3 homepos;
  966. public Vector3 homelookat;
  967. }
  968. public class BuddyList
  969. {
  970. public List<BuddyInfo> Buddies = new List<BuddyInfo>();
  971. public void AddNewBuddy(BuddyInfo buddy)
  972. {
  973. if (!Buddies.Contains(buddy))
  974. {
  975. Buddies.Add(buddy);
  976. }
  977. }
  978. public ArrayList ToArray()
  979. {
  980. ArrayList buddyArray = new ArrayList();
  981. foreach (BuddyInfo buddy in Buddies)
  982. {
  983. buddyArray.Add(buddy.ToHashTable());
  984. }
  985. return buddyArray;
  986. }
  987. public class BuddyInfo
  988. {
  989. public int BuddyRightsHave = 1;
  990. public int BuddyRightsGiven = 1;
  991. public string BuddyID;
  992. public BuddyInfo(string buddyID)
  993. {
  994. BuddyID = buddyID;
  995. }
  996. public BuddyInfo(UUID buddyID)
  997. {
  998. BuddyID = buddyID.ToString();
  999. }
  1000. public Hashtable ToHashTable()
  1001. {
  1002. Hashtable hTable = new Hashtable();
  1003. hTable["buddy_rights_has"] = BuddyRightsHave;
  1004. hTable["buddy_rights_given"] = BuddyRightsGiven;
  1005. hTable["buddy_id"] = BuddyID;
  1006. return hTable;
  1007. }
  1008. }
  1009. }
  1010. }
  1011. }