LoginResponse.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. using System;
  2. using System.Collections;
  3. using libsecondlife;
  4. using Nwc.XmlRpc;
  5. using OpenSim.Framework.Console;
  6. namespace OpenSim.Framework.UserManagement
  7. {
  8. /// <summary>
  9. /// A temp class to handle login response.
  10. /// Should make use of UserProfileManager where possible.
  11. /// </summary>
  12. public class LoginResponse
  13. {
  14. private Hashtable loginFlagsHash;
  15. private Hashtable globalTexturesHash;
  16. private Hashtable loginError;
  17. private Hashtable eventCategoriesHash;
  18. private Hashtable uiConfigHash;
  19. private Hashtable classifiedCategoriesHash;
  20. private ArrayList loginFlags;
  21. private ArrayList globalTextures;
  22. private ArrayList eventCategories;
  23. private ArrayList uiConfig;
  24. private ArrayList classifiedCategories;
  25. private ArrayList inventoryRoot;
  26. private ArrayList initialOutfit;
  27. private ArrayList agentInventory;
  28. private UserInfo userProfile;
  29. private LLUUID agentID;
  30. private LLUUID sessionID;
  31. private LLUUID secureSessionID;
  32. // Login Flags
  33. private string dst;
  34. private string stipendSinceLogin;
  35. private string gendered;
  36. private string everLoggedIn;
  37. private string login;
  38. private int simPort;
  39. private string simAddress;
  40. private string agentAccess;
  41. private Int32 circuitCode;
  42. private uint regionX;
  43. private uint regionY;
  44. // Login
  45. private string firstname;
  46. private string lastname;
  47. // Global Textures
  48. private string sunTexture;
  49. private string cloudTexture;
  50. private string moonTexture;
  51. // Error Flags
  52. private string errorReason;
  53. private string errorMessage;
  54. // Response
  55. private XmlRpcResponse xmlRpcResponse;
  56. private XmlRpcResponse defaultXmlRpcResponse;
  57. private string welcomeMessage;
  58. private string startLocation;
  59. private string allowFirstLife;
  60. private string home;
  61. private string seedCapability;
  62. private string lookAt;
  63. public LoginResponse()
  64. {
  65. this.loginFlags = new ArrayList();
  66. this.globalTextures = new ArrayList();
  67. this.eventCategories = new ArrayList();
  68. this.uiConfig = new ArrayList();
  69. this.classifiedCategories = new ArrayList();
  70. this.loginError = new Hashtable();
  71. this.eventCategoriesHash = new Hashtable();
  72. this.classifiedCategoriesHash = new Hashtable();
  73. this.uiConfigHash = new Hashtable();
  74. this.defaultXmlRpcResponse = new XmlRpcResponse();
  75. this.userProfile = new UserInfo();
  76. this.inventoryRoot = new ArrayList();
  77. this.initialOutfit = new ArrayList();
  78. this.agentInventory = new ArrayList();
  79. this.xmlRpcResponse = new XmlRpcResponse();
  80. this.defaultXmlRpcResponse = new XmlRpcResponse();
  81. this.SetDefaultValues();
  82. } // LoginServer
  83. public void SetDefaultValues()
  84. {
  85. this.DST = "N";
  86. this.StipendSinceLogin = "N";
  87. this.Gendered = "Y";
  88. this.EverLoggedIn = "Y";
  89. this.login = "false";
  90. this.firstname = "Test";
  91. this.lastname = "User";
  92. this.agentAccess = "M";
  93. this.startLocation = "last";
  94. this.allowFirstLife = "Y";
  95. this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
  96. this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  97. this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  98. this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
  99. this.ErrorReason = "key";
  100. this.welcomeMessage = "Welcome to OpenSim!";
  101. this.seedCapability = "";
  102. this.home = "{'region_handle':[r" + (1000 * 256).ToString() + ",r" + (1000 * 256).ToString() + "], 'position':[r" + this.userProfile.homepos.X.ToString() + ",r" + this.userProfile.homepos.Y.ToString() + ",r" + this.userProfile.homepos.Z.ToString() + "], 'look_at':[r" + this.userProfile.homelookat.X.ToString() + ",r" + this.userProfile.homelookat.Y.ToString() + ",r" + this.userProfile.homelookat.Z.ToString() + "]}";
  103. this.lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
  104. this.RegionX = (uint)255232;
  105. this.RegionY = (uint)254976;
  106. // Classifieds;
  107. this.AddClassifiedCategory((Int32)1, "Shopping");
  108. this.AddClassifiedCategory((Int32)2, "Land Rental");
  109. this.AddClassifiedCategory((Int32)3, "Property Rental");
  110. this.AddClassifiedCategory((Int32)4, "Special Attraction");
  111. this.AddClassifiedCategory((Int32)5, "New Products");
  112. this.AddClassifiedCategory((Int32)6, "Employment");
  113. this.AddClassifiedCategory((Int32)7, "Wanted");
  114. this.AddClassifiedCategory((Int32)8, "Service");
  115. this.AddClassifiedCategory((Int32)9, "Personal");
  116. this.SessionID = LLUUID.Random();
  117. this.SecureSessionID = LLUUID.Random();
  118. this.AgentID = LLUUID.Random();
  119. Hashtable InitialOutfitHash = new Hashtable();
  120. InitialOutfitHash["folder_name"] = "Nightclub Female";
  121. InitialOutfitHash["gender"] = "female";
  122. this.initialOutfit.Add(InitialOutfitHash);
  123. } // SetDefaultValues
  124. #region Login Failure Methods
  125. public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login)
  126. {
  127. // Overwrite any default values;
  128. this.xmlRpcResponse = new XmlRpcResponse();
  129. // Ensure Login Failed message/reason;
  130. this.ErrorMessage = message;
  131. this.ErrorReason = reason;
  132. this.loginError["reason"] = this.ErrorReason;
  133. this.loginError["message"] = this.ErrorMessage;
  134. this.loginError["login"] = login;
  135. this.xmlRpcResponse.Value = this.loginError;
  136. return (this.xmlRpcResponse);
  137. } // GenerateResponse
  138. public XmlRpcResponse CreateFailedResponse()
  139. {
  140. return (this.CreateLoginFailedResponse());
  141. } // CreateErrorConnectingToGridResponse()
  142. public XmlRpcResponse CreateLoginFailedResponse()
  143. {
  144. return (this.GenerateFailureResponse("key", "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", "false"));
  145. } // LoginFailedResponse
  146. public XmlRpcResponse CreateAlreadyLoggedInResponse()
  147. {
  148. return (this.GenerateFailureResponse("presence", "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner", "false"));
  149. } // CreateAlreadyLoggedInResponse()
  150. public XmlRpcResponse CreateDeadRegionResponse()
  151. {
  152. return (this.GenerateFailureResponse("key", "The region you are attempting to log into is not responding. Please select another region and try again.", "false"));
  153. }
  154. public XmlRpcResponse CreateGridErrorResponse()
  155. {
  156. return (this.GenerateFailureResponse("key", "Error connecting to grid. Could not percieve credentials from login XML.", "false"));
  157. }
  158. #endregion
  159. public XmlRpcResponse ToXmlRpcResponse()
  160. {
  161. try
  162. {
  163. Hashtable responseData = new Hashtable();
  164. this.loginFlagsHash = new Hashtable();
  165. this.loginFlagsHash["daylight_savings"] = this.DST;
  166. this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin;
  167. this.loginFlagsHash["gendered"] = this.Gendered;
  168. this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn;
  169. this.loginFlags.Add(this.loginFlagsHash);
  170. responseData["first_name"] = this.Firstname;
  171. responseData["last_name"] = this.Lastname;
  172. responseData["agent_access"] = this.agentAccess;
  173. this.globalTexturesHash = new Hashtable();
  174. this.globalTexturesHash["sun_texture_id"] = this.SunTexture;
  175. this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture;
  176. this.globalTexturesHash["moon_texture_id"] = this.MoonTexture;
  177. this.globalTextures.Add(this.globalTexturesHash);
  178. this.eventCategories.Add(this.eventCategoriesHash);
  179. this.AddToUIConfig("allow_first_life", this.allowFirstLife);
  180. this.uiConfig.Add(this.uiConfigHash);
  181. responseData["sim_port"] =(Int32) this.SimPort;
  182. responseData["sim_ip"] = this.SimAddress;
  183. MainLog.Instance.Warn("SIM IP: " + responseData["sim_ip"] + "; SIM PORT: " + responseData["sim_port"]);
  184. responseData["agent_id"] = this.AgentID.ToStringHyphenated();
  185. responseData["session_id"] = this.SessionID.ToStringHyphenated();
  186. responseData["secure_session_id"] = this.SecureSessionID.ToStringHyphenated();
  187. responseData["circuit_code"] = this.CircuitCode;
  188. responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  189. responseData["login-flags"] = this.loginFlags;
  190. responseData["global-textures"] = this.globalTextures;
  191. responseData["seed_capability"] = this.seedCapability;
  192. responseData["event_categories"] = this.eventCategories;
  193. responseData["event_notifications"] = new ArrayList(); // todo
  194. responseData["classified_categories"] = this.classifiedCategories;
  195. responseData["ui-config"] = this.uiConfig;
  196. responseData["inventory-skeleton"] = this.agentInventory;
  197. responseData["inventory-skel-lib"] = new ArrayList(); // todo
  198. responseData["inventory-root"] = this.inventoryRoot;
  199. responseData["gestures"] = new ArrayList(); // todo
  200. responseData["inventory-lib-owner"] = new ArrayList(); // todo
  201. responseData["initial-outfit"] = this.initialOutfit;
  202. responseData["start_location"] = this.startLocation;
  203. responseData["seed_capability"] = this.seedCapability;
  204. responseData["home"] = this.home;
  205. responseData["look_at"] = this.lookAt;
  206. responseData["message"] = this.welcomeMessage;
  207. responseData["region_x"] = (Int32)this.RegionX * 256;
  208. responseData["region_y"] = (Int32)this.RegionY * 256;
  209. //responseData["inventory-lib-root"] = new ArrayList(); // todo
  210. //responseData["buddy-list"] = new ArrayList(); // todo
  211. responseData["login"] = "true";
  212. this.xmlRpcResponse.Value = responseData;
  213. return (this.xmlRpcResponse);
  214. }
  215. catch (Exception e)
  216. {
  217. MainLog.Instance.WriteLine(
  218. LogPriority.LOW,
  219. "LoginResponse: Error creating XML-RPC Response: " + e.Message
  220. );
  221. return (this.GenerateFailureResponse("Internal Error", "Error generating Login Response", "false"));
  222. }
  223. } // ToXmlRpcResponse
  224. public void SetEventCategories(string category, string value)
  225. {
  226. this.eventCategoriesHash[category] = value;
  227. } // SetEventCategories
  228. public void AddToUIConfig(string itemName, string item)
  229. {
  230. this.uiConfigHash[itemName] = item;
  231. } // SetUIConfig
  232. public void AddClassifiedCategory(Int32 ID, string categoryName)
  233. {
  234. this.classifiedCategoriesHash["category_name"] = categoryName;
  235. this.classifiedCategoriesHash["category_id"] = ID;
  236. this.classifiedCategories.Add(this.classifiedCategoriesHash);
  237. // this.classifiedCategoriesHash.Clear();
  238. } // SetClassifiedCategory
  239. #region Properties
  240. public string Login
  241. {
  242. get
  243. {
  244. return this.login;
  245. }
  246. set
  247. {
  248. this.login = value;
  249. }
  250. } // Login
  251. public string DST
  252. {
  253. get
  254. {
  255. return this.dst;
  256. }
  257. set
  258. {
  259. this.dst = value;
  260. }
  261. } // DST
  262. public string StipendSinceLogin
  263. {
  264. get
  265. {
  266. return this.stipendSinceLogin;
  267. }
  268. set
  269. {
  270. this.stipendSinceLogin = value;
  271. }
  272. } // StipendSinceLogin
  273. public string Gendered
  274. {
  275. get
  276. {
  277. return this.gendered;
  278. }
  279. set
  280. {
  281. this.gendered = value;
  282. }
  283. } // Gendered
  284. public string EverLoggedIn
  285. {
  286. get
  287. {
  288. return this.everLoggedIn;
  289. }
  290. set
  291. {
  292. this.everLoggedIn = value;
  293. }
  294. } // EverLoggedIn
  295. public int SimPort
  296. {
  297. get
  298. {
  299. return this.simPort;
  300. }
  301. set
  302. {
  303. this.simPort = value;
  304. }
  305. } // SimPort
  306. public string SimAddress
  307. {
  308. get
  309. {
  310. return this.simAddress;
  311. }
  312. set
  313. {
  314. this.simAddress = value;
  315. }
  316. } // SimAddress
  317. public LLUUID AgentID
  318. {
  319. get
  320. {
  321. return this.agentID;
  322. }
  323. set
  324. {
  325. this.agentID = value;
  326. }
  327. } // AgentID
  328. public LLUUID SessionID
  329. {
  330. get
  331. {
  332. return this.sessionID;
  333. }
  334. set
  335. {
  336. this.sessionID = value;
  337. }
  338. } // SessionID
  339. public LLUUID SecureSessionID
  340. {
  341. get
  342. {
  343. return this.secureSessionID;
  344. }
  345. set
  346. {
  347. this.secureSessionID = value;
  348. }
  349. } // SecureSessionID
  350. public Int32 CircuitCode
  351. {
  352. get
  353. {
  354. return this.circuitCode;
  355. }
  356. set
  357. {
  358. this.circuitCode = value;
  359. }
  360. } // CircuitCode
  361. public uint RegionX
  362. {
  363. get
  364. {
  365. return this.regionX;
  366. }
  367. set
  368. {
  369. this.regionX = value;
  370. }
  371. } // RegionX
  372. public uint RegionY
  373. {
  374. get
  375. {
  376. return this.regionY;
  377. }
  378. set
  379. {
  380. this.regionY = value;
  381. }
  382. } // RegionY
  383. public string SunTexture
  384. {
  385. get
  386. {
  387. return this.sunTexture;
  388. }
  389. set
  390. {
  391. this.sunTexture = value;
  392. }
  393. } // SunTexture
  394. public string CloudTexture
  395. {
  396. get
  397. {
  398. return this.cloudTexture;
  399. }
  400. set
  401. {
  402. this.cloudTexture = value;
  403. }
  404. } // CloudTexture
  405. public string MoonTexture
  406. {
  407. get
  408. {
  409. return this.moonTexture;
  410. }
  411. set
  412. {
  413. this.moonTexture = value;
  414. }
  415. } // MoonTexture
  416. public string Firstname
  417. {
  418. get
  419. {
  420. return this.firstname;
  421. }
  422. set
  423. {
  424. this.firstname = value;
  425. }
  426. } // Firstname
  427. public string Lastname
  428. {
  429. get
  430. {
  431. return this.lastname;
  432. }
  433. set
  434. {
  435. this.lastname = value;
  436. }
  437. } // Lastname
  438. public string AgentAccess
  439. {
  440. get
  441. {
  442. return this.agentAccess;
  443. }
  444. set
  445. {
  446. this.agentAccess = value;
  447. }
  448. }
  449. public string StartLocation
  450. {
  451. get
  452. {
  453. return this.startLocation;
  454. }
  455. set
  456. {
  457. this.startLocation = value;
  458. }
  459. } // StartLocation
  460. public string LookAt
  461. {
  462. get
  463. {
  464. return this.lookAt;
  465. }
  466. set
  467. {
  468. this.lookAt = value;
  469. }
  470. }
  471. public string SeedCapability
  472. {
  473. get
  474. {
  475. return this.seedCapability;
  476. }
  477. set
  478. {
  479. this.seedCapability = value;
  480. }
  481. } // SeedCapability
  482. public string ErrorReason
  483. {
  484. get
  485. {
  486. return this.errorReason;
  487. }
  488. set
  489. {
  490. this.errorReason = value;
  491. }
  492. } // ErrorReason
  493. public string ErrorMessage
  494. {
  495. get
  496. {
  497. return this.errorMessage;
  498. }
  499. set
  500. {
  501. this.errorMessage = value;
  502. }
  503. } // ErrorMessage
  504. public ArrayList InventoryRoot
  505. {
  506. get
  507. {
  508. return this.inventoryRoot;
  509. }
  510. set
  511. {
  512. this.inventoryRoot = value;
  513. }
  514. }
  515. public ArrayList InventorySkeleton
  516. {
  517. get
  518. {
  519. return this.agentInventory;
  520. }
  521. set
  522. {
  523. this.agentInventory = value;
  524. }
  525. }
  526. public string Home
  527. {
  528. get
  529. {
  530. return this.home;
  531. }
  532. set
  533. {
  534. this.home = value;
  535. }
  536. }
  537. public string Message
  538. {
  539. get
  540. {
  541. return this.welcomeMessage;
  542. }
  543. set
  544. {
  545. this.welcomeMessage = value;
  546. }
  547. }
  548. #endregion
  549. public class UserInfo
  550. {
  551. public string firstname;
  552. public string lastname;
  553. public ulong homeregionhandle;
  554. public LLVector3 homepos;
  555. public LLVector3 homelookat;
  556. }
  557. }
  558. }