LLLoginResponse.cs 39 KB

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