UserProfileManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Xml;
  7. using libsecondlife;
  8. using Nwc.XmlRpc;
  9. using OpenSim.Framework.Sims;
  10. using OpenSim.Framework.Inventory;
  11. using OpenSim.Framework.Utilities;
  12. namespace OpenSim.Framework.User
  13. {
  14. public class UserProfileManager : UserProfileManagerBase
  15. {
  16. public string GridURL;
  17. public string GridSendKey;
  18. public string GridRecvKey;
  19. public string DefaultStartupMsg;
  20. public UserProfileManager()
  21. {
  22. }
  23. public void SetKeys(string sendKey, string recvKey, string url, string message)
  24. {
  25. GridRecvKey = recvKey;
  26. GridSendKey = sendKey;
  27. GridURL = url;
  28. DefaultStartupMsg = message;
  29. }
  30. public virtual string ParseXMLRPC(string requestBody)
  31. {
  32. XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
  33. switch (request.MethodName)
  34. {
  35. case "login_to_simulator":
  36. XmlRpcResponse response = XmlRpcLoginMethod(request);
  37. return (Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(response), "utf-16", "utf-8"));
  38. }
  39. return "";
  40. }
  41. public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
  42. {
  43. XmlRpcResponse response = new XmlRpcResponse();
  44. Hashtable requestData = (Hashtable)request.Params[0];
  45. bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
  46. bool GoodLogin = false;
  47. string firstname = "";
  48. string lastname = "";
  49. string passwd = "";
  50. if (GoodXML)
  51. {
  52. firstname = (string)requestData["first"];
  53. lastname = (string)requestData["last"];
  54. passwd = (string)requestData["passwd"];
  55. GoodLogin = AuthenticateUser(firstname, lastname, passwd);
  56. }
  57. if (!(GoodXML && GoodLogin))
  58. {
  59. response = CreateErrorConnectingToGridResponse();
  60. }
  61. else
  62. {
  63. UserProfile TheUser = GetProfileByName(firstname, lastname);
  64. if (!((TheUser.CurrentSessionID == null) && (TheUser.CurrentSecureSessionID == null)))
  65. {
  66. response = CreateAlreadyLoggedInResponse();
  67. }
  68. else
  69. {
  70. try
  71. {
  72. Hashtable responseData = new Hashtable();
  73. LLUUID AgentID = TheUser.UUID;
  74. TheUser.InitSessionData();
  75. // SimProfile SimInfo = new SimProfile();
  76. // SimInfo = SimInfo.LoadFromGrid(TheUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
  77. Hashtable GlobalT = new Hashtable();
  78. GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
  79. GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  80. GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  81. ArrayList GlobalTextures = new ArrayList();
  82. GlobalTextures.Add(GlobalT);
  83. Hashtable LoginFlagsHash = new Hashtable();
  84. LoginFlagsHash["daylight_savings"] = "N";
  85. LoginFlagsHash["stipend_since_login"] = "N";
  86. LoginFlagsHash["gendered"] = "Y";
  87. LoginFlagsHash["ever_logged_in"] = "Y";
  88. ArrayList LoginFlags = new ArrayList();
  89. LoginFlags.Add(LoginFlagsHash);
  90. Hashtable uiconfig = new Hashtable();
  91. uiconfig["allow_first_life"] = "Y";
  92. ArrayList ui_config = new ArrayList();
  93. ui_config.Add(uiconfig);
  94. Hashtable ClassifiedCategoriesHash = new Hashtable();
  95. ClassifiedCategoriesHash["category_name"] = "bla bla";
  96. ClassifiedCategoriesHash["category_id"] = (Int32)1;
  97. ArrayList ClassifiedCategories = new ArrayList();
  98. ClassifiedCategories.Add(ClassifiedCategoriesHash);
  99. ArrayList AgentInventory = new ArrayList();
  100. foreach (InventoryFolder InvFolder in TheUser.Inventory.InventoryFolders.Values)
  101. {
  102. Hashtable TempHash = new Hashtable();
  103. TempHash["name"] = InvFolder.FolderName;
  104. TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated();
  105. TempHash["version"] = (Int32)InvFolder.Version;
  106. TempHash["type_default"] = (Int32)InvFolder.DefaultType;
  107. TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated();
  108. AgentInventory.Add(TempHash);
  109. }
  110. Hashtable InventoryRootHash = new Hashtable();
  111. InventoryRootHash["folder_id"] = TheUser.Inventory.InventoryRoot.FolderID.ToStringHyphenated();
  112. ArrayList InventoryRoot = new ArrayList();
  113. InventoryRoot.Add(InventoryRootHash);
  114. Hashtable InitialOutfitHash = new Hashtable();
  115. InitialOutfitHash["folder_name"] = "Nightclub Female";
  116. InitialOutfitHash["gender"] = "female";
  117. ArrayList InitialOutfit = new ArrayList();
  118. InitialOutfit.Add(InitialOutfitHash);
  119. uint circode = (uint)(Util.RandomClass.Next());
  120. //TheUser.AddSimCircuit(circode, SimInfo.UUID);
  121. responseData["last_name"] = "\"" + TheUser.firstname + "\"";
  122. responseData["ui-config"] = ui_config;
  123. responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString();
  124. responseData["login-flags"] = LoginFlags;
  125. responseData["global-textures"] = GlobalTextures;
  126. responseData["classified_categories"] = ClassifiedCategories;
  127. responseData["event_categories"] = new ArrayList();
  128. responseData["inventory-skeleton"] = AgentInventory;
  129. responseData["inventory-skel-lib"] = new ArrayList();
  130. responseData["inventory-root"] = InventoryRoot;
  131. responseData["event_notifications"] = new ArrayList();
  132. responseData["gestures"] = new ArrayList();
  133. responseData["inventory-lib-owner"] = new ArrayList();
  134. responseData["initial-outfit"] = InitialOutfit;
  135. responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  136. responseData["start_location"] = "last";
  137. responseData["home"] = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + TheUser.homepos.X.ToString() + ",r" + TheUser.homepos.Y.ToString() + ",r" + TheUser.homepos.Z.ToString() + "], 'look_at':[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]}";
  138. responseData["message"] = DefaultStartupMsg;
  139. responseData["first_name"] = "\"" + firstname + "\"";
  140. responseData["circuit_code"] = (Int32)circode;
  141. responseData["sim_port"] = 9000; //(Int32)SimInfo.sim_port;
  142. responseData["secure_session_id"] = TheUser.CurrentSecureSessionID.ToStringHyphenated();
  143. responseData["look_at"] = "\n[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]\n";
  144. responseData["agent_id"] = AgentID.ToStringHyphenated();
  145. responseData["region_y"] = (Int32)996 * 256; // (Int32)SimInfo.RegionLocY * 256;
  146. responseData["region_x"] = (Int32)997 * 256; //SimInfo.RegionLocX * 256;
  147. responseData["seed_capability"] = null;
  148. responseData["agent_access"] = "M";
  149. responseData["session_id"] = TheUser.CurrentSessionID.ToStringHyphenated();
  150. responseData["login"] = "true";
  151. this.CustomiseResponse(ref responseData, TheUser);
  152. response.Value = responseData;
  153. //TheUser.SendDataToSim(SimInfo);
  154. }
  155. catch (Exception E)
  156. {
  157. Console.WriteLine(E.ToString());
  158. }
  159. }
  160. }
  161. return response;
  162. }
  163. private static XmlRpcResponse CreateErrorConnectingToGridResponse()
  164. {
  165. XmlRpcResponse response = new XmlRpcResponse();
  166. Hashtable ErrorRespData = new Hashtable();
  167. ErrorRespData["reason"] = "key";
  168. ErrorRespData["message"] = "Error connecting to grid. Please double check your login details and check with the grid owner if you are sure these are correct";
  169. ErrorRespData["login"] = "false";
  170. response.Value = ErrorRespData;
  171. return response;
  172. }
  173. private static XmlRpcResponse CreateAlreadyLoggedInResponse()
  174. {
  175. XmlRpcResponse response = new XmlRpcResponse();
  176. Hashtable PresenceErrorRespData = new Hashtable();
  177. PresenceErrorRespData["reason"] = "presence";
  178. PresenceErrorRespData["message"] = "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";
  179. PresenceErrorRespData["login"] = "false";
  180. response.Value = PresenceErrorRespData;
  181. return response;
  182. }
  183. public virtual void CustomiseResponse(ref Hashtable response, UserProfile theUser)
  184. {
  185. //default method set up to act as ogs user server
  186. SimProfile SimInfo = new SimProfile();
  187. //get siminfo from grid server
  188. SimInfo = SimInfo.LoadFromGrid(theUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
  189. uint circode = (uint)response["circuit_code"];
  190. theUser.AddSimCircuit(circode, SimInfo.UUID);
  191. response["home"] = "{'region_handle':[r" + (SimInfo.RegionLocX * 256).ToString() + ",r" + (SimInfo.RegionLocY * 256).ToString() + "], 'position':[r" + theUser.homepos.X.ToString() + ",r" + theUser.homepos.Y.ToString() + ",r" + theUser.homepos.Z.ToString() + "], 'look_at':[r" + theUser.homelookat.X.ToString() + ",r" + theUser.homelookat.Y.ToString() + ",r" + theUser.homelookat.Z.ToString() + "]}";
  192. response["sim_ip"] = SimInfo.sim_ip.ToString();
  193. response["sim_port"] = (Int32)SimInfo.sim_port;
  194. response["region_y"] = (Int32) SimInfo.RegionLocY * 256;
  195. response["region_x"] = (Int32) SimInfo.RegionLocX * 256;
  196. //default is ogs user server, so let the sim know about the user via a XmlRpcRequest
  197. Console.WriteLine(SimInfo.caps_url);
  198. Hashtable SimParams = new Hashtable();
  199. SimParams["session_id"] = theUser.CurrentSessionID.ToString();
  200. SimParams["secure_session_id"] = theUser.CurrentSecureSessionID.ToString();
  201. SimParams["firstname"] = theUser.firstname;
  202. SimParams["lastname"] = theUser.lastname;
  203. SimParams["agent_id"] = theUser.UUID.ToString();
  204. SimParams["circuit_code"] = (Int32)theUser.Circuits[SimInfo.UUID];
  205. ArrayList SendParams = new ArrayList();
  206. SendParams.Add(SimParams);
  207. XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
  208. XmlRpcResponse GridResp = GridReq.Send(SimInfo.caps_url, 3000);
  209. }
  210. }
  211. }