LLLoginResponse.cs 41 KB

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