1
0

LLLoginResponse.cs 40 KB

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