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