LLLoginResponse.cs 36 KB

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