UserProfileManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. //we need to sort out how sessions are logged out , currently the sim tells the gridserver
  65. //but if as this suggests the userserver handles it then please have the sim telling the userserver instead
  66. //as it really makes things messy for sandbox mode
  67. //if (!((TheUser.CurrentSessionID == null) && (TheUser.CurrentSecureSessionID == null)))
  68. // {
  69. // response = CreateAlreadyLoggedInResponse();
  70. // }
  71. //else
  72. //{
  73. try
  74. {
  75. Hashtable responseData = new Hashtable();
  76. LLUUID AgentID = TheUser.UUID;
  77. TheUser.InitSessionData();
  78. // SimProfile SimInfo = new SimProfile();
  79. // SimInfo = SimInfo.LoadFromGrid(TheUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
  80. Hashtable GlobalT = new Hashtable();
  81. GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
  82. GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  83. GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  84. ArrayList GlobalTextures = new ArrayList();
  85. GlobalTextures.Add(GlobalT);
  86. Hashtable LoginFlagsHash = new Hashtable();
  87. LoginFlagsHash["daylight_savings"] = "N";
  88. LoginFlagsHash["stipend_since_login"] = "N";
  89. LoginFlagsHash["gendered"] = "Y";
  90. LoginFlagsHash["ever_logged_in"] = "Y";
  91. ArrayList LoginFlags = new ArrayList();
  92. LoginFlags.Add(LoginFlagsHash);
  93. Hashtable uiconfig = new Hashtable();
  94. uiconfig["allow_first_life"] = "Y";
  95. ArrayList ui_config = new ArrayList();
  96. ui_config.Add(uiconfig);
  97. Hashtable ClassifiedCategoriesHash = new Hashtable();
  98. ClassifiedCategoriesHash["category_name"] = "bla bla";
  99. ClassifiedCategoriesHash["category_id"] = (Int32)1;
  100. ArrayList ClassifiedCategories = new ArrayList();
  101. ClassifiedCategories.Add(ClassifiedCategoriesHash);
  102. ArrayList AgentInventory = new ArrayList();
  103. Console.WriteLine("adding inventory to response");
  104. foreach (InventoryFolder InvFolder in TheUser.Inventory.InventoryFolders.Values)
  105. {
  106. Hashtable TempHash = new Hashtable();
  107. Console.WriteLine("adding folder " + InvFolder.FolderName + ", ID: " + InvFolder.FolderID.ToStringHyphenated() + " with parent: " + InvFolder.ParentID.ToStringHyphenated());
  108. TempHash["name"] = InvFolder.FolderName;
  109. TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated();
  110. TempHash["version"] = (Int32)InvFolder.Version;
  111. TempHash["type_default"] = (Int32)InvFolder.DefaultType;
  112. TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated();
  113. AgentInventory.Add(TempHash);
  114. }
  115. Hashtable InventoryRootHash = new Hashtable();
  116. InventoryRootHash["folder_id"] = TheUser.Inventory.InventoryRoot.FolderID.ToStringHyphenated();
  117. ArrayList InventoryRoot = new ArrayList();
  118. InventoryRoot.Add(InventoryRootHash);
  119. Hashtable InitialOutfitHash = new Hashtable();
  120. InitialOutfitHash["folder_name"] = "Nightclub Female";
  121. InitialOutfitHash["gender"] = "female";
  122. ArrayList InitialOutfit = new ArrayList();
  123. InitialOutfit.Add(InitialOutfitHash);
  124. uint circode = (uint)(Util.RandomClass.Next());
  125. //TheUser.AddSimCircuit(circode, SimInfo.UUID);
  126. responseData["last_name"] = TheUser.lastname;
  127. responseData["ui-config"] = ui_config;
  128. responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString();
  129. responseData["login-flags"] = LoginFlags;
  130. responseData["global-textures"] = GlobalTextures;
  131. responseData["classified_categories"] = ClassifiedCategories;
  132. responseData["event_categories"] = new ArrayList();
  133. responseData["inventory-skeleton"] = AgentInventory;
  134. responseData["inventory-skel-lib"] = new ArrayList();
  135. responseData["inventory-root"] = InventoryRoot;
  136. responseData["event_notifications"] = new ArrayList();
  137. responseData["gestures"] = new ArrayList();
  138. responseData["inventory-lib-owner"] = new ArrayList();
  139. responseData["initial-outfit"] = InitialOutfit;
  140. responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  141. responseData["start_location"] = "last";
  142. 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() + "]}";
  143. responseData["message"] = DefaultStartupMsg;
  144. responseData["first_name"] = TheUser.firstname;
  145. responseData["circuit_code"] = (Int32)circode;
  146. responseData["sim_port"] = 9000; //(Int32)SimInfo.sim_port;
  147. responseData["secure_session_id"] = TheUser.CurrentSecureSessionID.ToStringHyphenated();
  148. responseData["look_at"] = "\n[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]\n";
  149. responseData["agent_id"] = AgentID.ToStringHyphenated();
  150. responseData["region_y"] = (Int32)996 * 256; // (Int32)SimInfo.RegionLocY * 256;
  151. responseData["region_x"] = (Int32)997 * 256; //SimInfo.RegionLocX * 256;
  152. responseData["seed_capability"] = null;
  153. responseData["agent_access"] = "M";
  154. responseData["session_id"] = TheUser.CurrentSessionID.ToStringHyphenated();
  155. responseData["login"] = "true";
  156. this.CustomiseResponse(ref responseData, TheUser);
  157. response.Value = responseData;
  158. //TheUser.SendDataToSim(SimInfo);
  159. }
  160. catch (Exception E)
  161. {
  162. Console.WriteLine(E.ToString());
  163. }
  164. //}
  165. }
  166. return response;
  167. }
  168. private static XmlRpcResponse CreateErrorConnectingToGridResponse()
  169. {
  170. XmlRpcResponse response = new XmlRpcResponse();
  171. Hashtable ErrorRespData = new Hashtable();
  172. ErrorRespData["reason"] = "key";
  173. 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";
  174. ErrorRespData["login"] = "false";
  175. response.Value = ErrorRespData;
  176. return response;
  177. }
  178. private static XmlRpcResponse CreateAlreadyLoggedInResponse()
  179. {
  180. XmlRpcResponse response = new XmlRpcResponse();
  181. Hashtable PresenceErrorRespData = new Hashtable();
  182. PresenceErrorRespData["reason"] = "presence";
  183. 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";
  184. PresenceErrorRespData["login"] = "false";
  185. response.Value = PresenceErrorRespData;
  186. return response;
  187. }
  188. public virtual void CustomiseResponse(ref Hashtable response, UserProfile theUser)
  189. {
  190. //default method set up to act as ogs user server
  191. SimProfile SimInfo = new SimProfile();
  192. //get siminfo from grid server
  193. SimInfo = SimInfo.LoadFromGrid(theUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
  194. Int32 circode = (Int32)response["circuit_code"];
  195. theUser.AddSimCircuit((uint)circode, SimInfo.UUID);
  196. 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() + "]}";
  197. response["sim_ip"] = SimInfo.sim_ip.ToString();
  198. response["sim_port"] = (Int32)SimInfo.sim_port;
  199. response["region_y"] = (Int32)SimInfo.RegionLocY * 256;
  200. response["region_x"] = (Int32)SimInfo.RegionLocX * 256;
  201. //default is ogs user server, so let the sim know about the user via a XmlRpcRequest
  202. Console.WriteLine(SimInfo.caps_url);
  203. Hashtable SimParams = new Hashtable();
  204. SimParams["session_id"] = theUser.CurrentSessionID.ToString();
  205. SimParams["secure_session_id"] = theUser.CurrentSecureSessionID.ToString();
  206. SimParams["firstname"] = theUser.firstname;
  207. SimParams["lastname"] = theUser.lastname;
  208. SimParams["agent_id"] = theUser.UUID.ToString();
  209. SimParams["circuit_code"] = (Int32)theUser.Circuits[SimInfo.UUID];
  210. ArrayList SendParams = new ArrayList();
  211. SendParams.Add(SimParams);
  212. XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
  213. XmlRpcResponse GridResp = GridReq.Send(SimInfo.caps_url, 3000);
  214. }
  215. }
  216. }