LLLoginResponse.cs 41 KB

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