LLLoginResponse.cs 42 KB

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