LLLoginResponse.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  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. // finfo.Friend may not be a simple uuid
  655. UUID friendID = UUID.Zero;
  656. if (UUID.TryParse(finfo.Friend, out friendID))
  657. buddyitem.BuddyID = finfo.Friend;
  658. else
  659. {
  660. string tmp;
  661. if (Util.ParseUniversalUserIdentifier(finfo.Friend, out friendID, out tmp, out tmp, out tmp, out tmp))
  662. buddyitem.BuddyID = friendID.ToString();
  663. else
  664. // junk entry
  665. continue;
  666. }
  667. buddyitem.BuddyRightsHave = (int)finfo.TheirFlags;
  668. buddyitem.BuddyRightsGiven = (int)finfo.MyFlags;
  669. buddylistreturn.AddNewBuddy(buddyitem);
  670. }
  671. return buddylistreturn;
  672. }
  673. private InventoryData GetInventorySkeleton(List<InventoryFolderBase> folders)
  674. {
  675. UUID rootID = UUID.Zero;
  676. ArrayList AgentInventoryArray = new ArrayList();
  677. Hashtable TempHash;
  678. foreach (InventoryFolderBase InvFolder in folders)
  679. {
  680. if (InvFolder.ParentID == UUID.Zero && InvFolder.Name == InventoryFolderBase.ROOT_FOLDER_NAME)
  681. {
  682. rootID = InvFolder.ID;
  683. }
  684. TempHash = new Hashtable();
  685. TempHash["name"] = InvFolder.Name;
  686. TempHash["parent_id"] = InvFolder.ParentID.ToString();
  687. TempHash["version"] = (Int32)InvFolder.Version;
  688. TempHash["type_default"] = (Int32)InvFolder.Type;
  689. TempHash["folder_id"] = InvFolder.ID.ToString();
  690. AgentInventoryArray.Add(TempHash);
  691. }
  692. return new InventoryData(AgentInventoryArray, rootID);
  693. }
  694. /// <summary>
  695. /// Converts the inventory library skeleton into the form required by the rpc request.
  696. /// </summary>
  697. /// <returns></returns>
  698. protected virtual ArrayList GetInventoryLibrary(ILibraryService library)
  699. {
  700. Dictionary<UUID, InventoryFolderImpl> rootFolders = library.GetAllFolders();
  701. // m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count);
  702. //Dictionary<UUID, InventoryFolderImpl> rootFolders = new Dictionary<UUID,InventoryFolderImpl>();
  703. ArrayList folderHashes = new ArrayList();
  704. foreach (InventoryFolderBase folder in rootFolders.Values)
  705. {
  706. Hashtable TempHash = new Hashtable();
  707. TempHash["name"] = folder.Name;
  708. TempHash["parent_id"] = folder.ParentID.ToString();
  709. TempHash["version"] = (Int32)folder.Version;
  710. TempHash["type_default"] = (Int32)folder.Type;
  711. TempHash["folder_id"] = folder.ID.ToString();
  712. folderHashes.Add(TempHash);
  713. }
  714. return folderHashes;
  715. }
  716. /// <summary>
  717. ///
  718. /// </summary>
  719. /// <returns></returns>
  720. protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder)
  721. {
  722. //for now create random inventory library owner
  723. Hashtable TempHash = new Hashtable();
  724. TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; // libFolder.Owner
  725. ArrayList inventoryLibOwner = new ArrayList();
  726. inventoryLibOwner.Add(TempHash);
  727. return inventoryLibOwner;
  728. }
  729. public class InventoryData
  730. {
  731. public ArrayList InventoryArray = null;
  732. public UUID RootFolderID = UUID.Zero;
  733. public InventoryData(ArrayList invList, UUID rootID)
  734. {
  735. InventoryArray = invList;
  736. RootFolderID = rootID;
  737. }
  738. }
  739. #region Properties
  740. public string Login
  741. {
  742. get { return login; }
  743. set { login = value; }
  744. }
  745. public string DST
  746. {
  747. get { return dst; }
  748. set { dst = value; }
  749. }
  750. public string StipendSinceLogin
  751. {
  752. get { return stipendSinceLogin; }
  753. set { stipendSinceLogin = value; }
  754. }
  755. public string Gendered
  756. {
  757. get { return gendered; }
  758. set { gendered = value; }
  759. }
  760. public string EverLoggedIn
  761. {
  762. get { return everLoggedIn; }
  763. set { everLoggedIn = value; }
  764. }
  765. public uint SimPort
  766. {
  767. get { return simPort; }
  768. set { simPort = value; }
  769. }
  770. public uint SimHttpPort
  771. {
  772. get { return simHttpPort; }
  773. set { simHttpPort = value; }
  774. }
  775. public string SimAddress
  776. {
  777. get { return simAddress; }
  778. set { simAddress = value; }
  779. }
  780. public UUID AgentID
  781. {
  782. get { return agentID; }
  783. set { agentID = value; }
  784. }
  785. public UUID SessionID
  786. {
  787. get { return sessionID; }
  788. set { sessionID = value; }
  789. }
  790. public UUID SecureSessionID
  791. {
  792. get { return secureSessionID; }
  793. set { secureSessionID = value; }
  794. }
  795. public UUID RealID
  796. {
  797. get { return realID; }
  798. set { realID = value; }
  799. }
  800. public Int32 CircuitCode
  801. {
  802. get { return circuitCode; }
  803. set { circuitCode = value; }
  804. }
  805. public uint RegionX
  806. {
  807. get { return regionX; }
  808. set { regionX = value; }
  809. }
  810. public uint RegionY
  811. {
  812. get { return regionY; }
  813. set { regionY = value; }
  814. }
  815. public int RegionSizeX { get; private set; }
  816. public int RegionSizeY { get; private set; }
  817. public string SunTexture
  818. {
  819. get { return sunTexture; }
  820. set { sunTexture = value; }
  821. }
  822. public string CloudTexture
  823. {
  824. get { return cloudTexture; }
  825. set { cloudTexture = value; }
  826. }
  827. public string MoonTexture
  828. {
  829. get { return moonTexture; }
  830. set { moonTexture = value; }
  831. }
  832. public string Firstname
  833. {
  834. get { return firstname; }
  835. set { firstname = value; }
  836. }
  837. public string Lastname
  838. {
  839. get { return lastname; }
  840. set { lastname = value; }
  841. }
  842. public string AgentAccess
  843. {
  844. get { return agentAccess; }
  845. set { agentAccess = value; }
  846. }
  847. public string AgentAccessMax
  848. {
  849. get { return agentAccessMax; }
  850. set { agentAccessMax = value; }
  851. }
  852. public string StartLocation
  853. {
  854. get { return startLocation; }
  855. set { startLocation = value; }
  856. }
  857. public string LookAt
  858. {
  859. get { return lookAt; }
  860. set { lookAt = value; }
  861. }
  862. public string SeedCapability
  863. {
  864. get { return seedCapability; }
  865. set { seedCapability = value; }
  866. }
  867. public string ErrorReason
  868. {
  869. get { return errorReason; }
  870. set { errorReason = value; }
  871. }
  872. public string ErrorMessage
  873. {
  874. get { return errorMessage; }
  875. set { errorMessage = value; }
  876. }
  877. public ArrayList InventoryRoot
  878. {
  879. get { return inventoryRoot; }
  880. set { inventoryRoot = value; }
  881. }
  882. public ArrayList InventorySkeleton
  883. {
  884. get { return agentInventory; }
  885. set { agentInventory = value; }
  886. }
  887. public ArrayList InventoryLibrary
  888. {
  889. get { return inventoryLibrary; }
  890. set { inventoryLibrary = value; }
  891. }
  892. public ArrayList InventoryLibraryOwner
  893. {
  894. get { return inventoryLibraryOwner; }
  895. set { inventoryLibraryOwner = value; }
  896. }
  897. public ArrayList InventoryLibRoot
  898. {
  899. get { return inventoryLibRoot; }
  900. set { inventoryLibRoot = value; }
  901. }
  902. public ArrayList ActiveGestures
  903. {
  904. get { return activeGestures; }
  905. set { activeGestures = value; }
  906. }
  907. public string Home
  908. {
  909. get { return home; }
  910. set { home = value; }
  911. }
  912. public string MapTileURL
  913. {
  914. get { return mapTileURL; }
  915. set { mapTileURL = value; }
  916. }
  917. public string ProfileURL
  918. {
  919. get { return profileURL; }
  920. set { profileURL = value; }
  921. }
  922. public string OpenIDURL
  923. {
  924. get { return openIDURL; }
  925. set { openIDURL = value; }
  926. }
  927. public string SearchURL
  928. {
  929. get { return searchURL; }
  930. set { searchURL = value; }
  931. }
  932. public string Message
  933. {
  934. get { return welcomeMessage; }
  935. set { welcomeMessage = value; }
  936. }
  937. public BuddyList BuddList
  938. {
  939. get { return m_buddyList; }
  940. set { m_buddyList = value; }
  941. }
  942. public string Currency
  943. {
  944. get { return currency; }
  945. set { currency = value; }
  946. }
  947. public string ClassifiedFee
  948. {
  949. get { return classifiedFee; }
  950. set { classifiedFee = value; }
  951. }
  952. public int MaxAgentGroups
  953. {
  954. get { return maxAgentGroups; }
  955. set { maxAgentGroups = value; }
  956. }
  957. public string DestinationsURL
  958. {
  959. get; set;
  960. }
  961. public string AvatarsURL
  962. {
  963. get; set;
  964. }
  965. #endregion
  966. public class UserInfo
  967. {
  968. public string firstname;
  969. public string lastname;
  970. public ulong homeregionhandle;
  971. public Vector3 homepos;
  972. public Vector3 homelookat;
  973. }
  974. public class BuddyList
  975. {
  976. public List<BuddyInfo> Buddies = new List<BuddyInfo>();
  977. public void AddNewBuddy(BuddyInfo buddy)
  978. {
  979. if (!Buddies.Contains(buddy))
  980. {
  981. Buddies.Add(buddy);
  982. }
  983. }
  984. public ArrayList ToArray()
  985. {
  986. ArrayList buddyArray = new ArrayList();
  987. foreach (BuddyInfo buddy in Buddies)
  988. {
  989. buddyArray.Add(buddy.ToHashTable());
  990. }
  991. return buddyArray;
  992. }
  993. public class BuddyInfo
  994. {
  995. public int BuddyRightsHave = 1;
  996. public int BuddyRightsGiven = 1;
  997. public string BuddyID;
  998. public BuddyInfo(string buddyID)
  999. {
  1000. BuddyID = buddyID;
  1001. }
  1002. public BuddyInfo(UUID buddyID)
  1003. {
  1004. BuddyID = buddyID.ToString();
  1005. }
  1006. public Hashtable ToHashTable()
  1007. {
  1008. Hashtable hTable = new Hashtable();
  1009. hTable["buddy_rights_has"] = BuddyRightsHave;
  1010. hTable["buddy_rights_given"] = BuddyRightsGiven;
  1011. hTable["buddy_id"] = BuddyID;
  1012. return hTable;
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }