LoginResponse.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. * Copyright (c) OpenSim project, http://sim.opensecondlife.org/
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of the <organization> nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
  16. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  19. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. */
  27. using Nwc.XmlRpc;
  28. using System;
  29. using System.IO;
  30. using System.Net;
  31. using System.Net.Sockets;
  32. using System.Text;
  33. using System.Text.RegularExpressions;
  34. using System.Threading;
  35. using System.Collections;
  36. using System.Security.Cryptography;
  37. using System.Xml;
  38. using libsecondlife;
  39. using OpenSim;
  40. using OpenSim.Framework.Interfaces;
  41. using OpenSim.Framework.Grid;
  42. using OpenSim.Framework.Inventory;
  43. using OpenSim.Framework.User;
  44. using OpenSim.Framework.Utilities;
  45. namespace OpenSim.UserServer
  46. {
  47. /// <summary>
  48. /// A temp class to handle login response.
  49. /// Should make use of UserProfileManager where possible.
  50. /// </summary>
  51. public class LoginResponse
  52. {
  53. private Hashtable loginFlagsHash;
  54. private Hashtable globalTexturesHash;
  55. private Hashtable loginError;
  56. private ArrayList loginFlags;
  57. private ArrayList globalTextures;
  58. // Login Flags
  59. private string dst;
  60. private string stipendSinceLogin;
  61. private string gendered;
  62. private string everLoggedIn;
  63. private string login;
  64. private string simPort;
  65. private string simAddress;
  66. private string agentID;
  67. private string sessionID;
  68. private string secureSessionID;
  69. private Int32 circuitCode;
  70. // Global Textures
  71. private string sunTexture;
  72. private string cloudTexture;
  73. private string moonTexture;
  74. // Error Flags
  75. private string errorReason;
  76. private string errorMessage;
  77. // Response
  78. private XmlRpcResponse xmlRpcResponse;
  79. private XmlRpcResponse defaultXmlRpcResponse;
  80. private string defaultTextResponse;
  81. public LoginResponse()
  82. {
  83. this.loginFlags = new ArrayList();
  84. this.globalTextures = new ArrayList();
  85. this.SetDefaultValues();
  86. } // LoginServer
  87. // This will go away as we replace new-login.dat:
  88. private void GetDefaultResponse()
  89. {
  90. try
  91. {
  92. // read in default response string
  93. StreamReader SR;
  94. string lines;
  95. SR = File.OpenText("new-login.dat");
  96. this.defaultTextResponse = "";
  97. while (!SR.EndOfStream)
  98. {
  99. lines = SR.ReadLine();
  100. this.defaultTextResponse += lines;
  101. }
  102. SR.Close();
  103. this.defaultXmlRpcResponse = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this.defaultTextResponse);
  104. }
  105. catch (Exception E)
  106. {
  107. Console.WriteLine(E.ToString());
  108. }
  109. } // GetDefaultResponse
  110. public void SetDefaultValues()
  111. {
  112. this.GetDefaultResponse();
  113. this.DST = "N";
  114. this.StipendSinceLogin = "N";
  115. this.Gendered = "Y";
  116. this.EverLoggedIn = "Y";
  117. this.login = "false";
  118. this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
  119. this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  120. this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  121. this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
  122. this.ErrorReason = "key";
  123. } // SetDefaultValues
  124. private XmlRpcResponse GenerateResponse(string reason, string message, string login)
  125. {
  126. // Overwrite any default values;
  127. this.xmlRpcResponse = new XmlRpcResponse();
  128. // Ensure Login Failed message/reason;
  129. this.ErrorMessage = message;
  130. this.ErrorReason = reason;
  131. this.loginError = new Hashtable();
  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 LoginFailedResponse()
  139. {
  140. return (this.GenerateResponse("key", "You have entered an invalid name/password combination. Check Caps/lock.", "false"));
  141. } // LoginFailedResponse
  142. public XmlRpcResponse ConnectionFailedResponse()
  143. {
  144. return (this.LoginFailedResponse());
  145. } // CreateErrorConnectingToGridResponse()
  146. public XmlRpcResponse CreateAlreadyLoggedInResponse()
  147. {
  148. return(this.GenerateResponse("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 ToXmlRpcResponse()
  151. {
  152. this.xmlRpcResponse = this.defaultXmlRpcResponse;
  153. Hashtable responseData = (Hashtable)this.xmlRpcResponse.Value;
  154. this.loginFlagsHash = new Hashtable();
  155. this.loginFlagsHash["daylight_savings"] = this.DST;
  156. this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin;
  157. this.loginFlagsHash["gendered"] = this.Gendered;
  158. this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn;
  159. this.loginFlags.Add(this.loginFlagsHash);
  160. this.globalTexturesHash = new Hashtable();
  161. this.globalTexturesHash["sun_texture_id"] = this.SunTexture;
  162. this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture;
  163. this.globalTexturesHash["moon_texture_id"] = this.MoonTexture;
  164. this.globalTextures.Add(this.globalTexturesHash);
  165. responseData["sim_port"] = Int32.Parse(this.SimPort);
  166. responseData["sim_ip"] = this.SimAddress;
  167. responseData["agent_id"] = this.AgentID;
  168. responseData["session_id"] = this.SessionID;
  169. responseData["secure_session_id"] = this.SecureSessionID;
  170. responseData["circuit_code"] = this.CircuitCode;
  171. responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  172. responseData["login-flags"] = this.loginFlags;
  173. responseData["global-textures"] = this.globalTextures;
  174. return (this.xmlRpcResponse);
  175. } // ToXmlRpcResponse
  176. public string Login
  177. {
  178. get
  179. {
  180. return this.login;
  181. }
  182. set
  183. {
  184. this.login = value;
  185. }
  186. } // Login
  187. public string DST
  188. {
  189. get
  190. {
  191. return this.dst;
  192. }
  193. set
  194. {
  195. this.dst = value;
  196. }
  197. } // DST
  198. public string StipendSinceLogin
  199. {
  200. get
  201. {
  202. return this.stipendSinceLogin;
  203. }
  204. set
  205. {
  206. this.stipendSinceLogin = value;
  207. }
  208. } // StipendSinceLogin
  209. public string Gendered
  210. {
  211. get
  212. {
  213. return this.gendered;
  214. }
  215. set
  216. {
  217. this.gendered = value;
  218. }
  219. } // Gendered
  220. public string EverLoggedIn
  221. {
  222. get
  223. {
  224. return this.everLoggedIn;
  225. }
  226. set
  227. {
  228. this.everLoggedIn = value;
  229. }
  230. } // EverLoggedIn
  231. public string SimPort
  232. {
  233. get
  234. {
  235. return this.simPort;
  236. }
  237. set
  238. {
  239. this.simPort = value;
  240. }
  241. } // SimPort
  242. public string SimAddress
  243. {
  244. get
  245. {
  246. return this.simAddress;
  247. }
  248. set
  249. {
  250. this.simAddress = value;
  251. }
  252. } // SimAddress
  253. public string AgentID
  254. {
  255. get
  256. {
  257. return this.agentID;
  258. }
  259. set
  260. {
  261. this.agentID = value;
  262. }
  263. } // AgentID
  264. public string SessionID
  265. {
  266. get
  267. {
  268. return this.sessionID;
  269. }
  270. set
  271. {
  272. this.sessionID = value;
  273. }
  274. } // SessionID
  275. public string SecureSessionID
  276. {
  277. get
  278. {
  279. return this.secureSessionID;
  280. }
  281. set
  282. {
  283. this.secureSessionID = value;
  284. }
  285. } // SecureSessionID
  286. public Int32 CircuitCode
  287. {
  288. get
  289. {
  290. return this.circuitCode;
  291. }
  292. set
  293. {
  294. this.circuitCode = value;
  295. }
  296. } // CircuitCode
  297. public string SunTexture
  298. {
  299. get
  300. {
  301. return this.sunTexture;
  302. }
  303. set
  304. {
  305. this.sunTexture = value;
  306. }
  307. } // SunTexture
  308. public string CloudTexture
  309. {
  310. get
  311. {
  312. return this.cloudTexture;
  313. }
  314. set
  315. {
  316. this.cloudTexture = value;
  317. }
  318. } // CloudTexture
  319. public string MoonTexture
  320. {
  321. get
  322. {
  323. return this.moonTexture;
  324. }
  325. set
  326. {
  327. this.moonTexture = value;
  328. }
  329. } // MoonTexture
  330. public string ErrorReason
  331. {
  332. get
  333. {
  334. return this.errorReason;
  335. }
  336. set
  337. {
  338. this.errorReason = value;
  339. }
  340. } // ErrorReason
  341. public string ErrorMessage
  342. {
  343. get
  344. {
  345. return this.errorMessage;
  346. }
  347. set
  348. {
  349. this.errorMessage = value;
  350. }
  351. } // ErrorMessage
  352. } // LoginResponse
  353. } // namespace OpenSim.UserServer