LLLoginResponse.cs 42 KB

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