UserProfileManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Collections;
  31. using System.Text;
  32. using System.Text.RegularExpressions;
  33. using System.Xml;
  34. using libsecondlife;
  35. using Nwc.XmlRpc;
  36. using OpenSim.Framework.Sims;
  37. using OpenSim.Framework.Inventory;
  38. using OpenSim.Framework.Utilities;
  39. namespace OpenSim.Framework.User
  40. {
  41. public class UserProfileManager : UserProfileManagerBase
  42. {
  43. public string GridURL;
  44. public string GridSendKey;
  45. public string GridRecvKey;
  46. public string DefaultStartupMsg;
  47. public UserProfileManager()
  48. {
  49. }
  50. public void SetKeys(string sendKey, string recvKey, string url, string message)
  51. {
  52. GridRecvKey = recvKey;
  53. GridSendKey = sendKey;
  54. GridURL = url;
  55. DefaultStartupMsg = message;
  56. }
  57. public virtual string ParseXMLRPC(string requestBody)
  58. {
  59. XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
  60. switch (request.MethodName)
  61. {
  62. case "login_to_simulator":
  63. XmlRpcResponse response = XmlRpcLoginMethod(request);
  64. return (Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(response), "utf-16", "utf-8"));
  65. }
  66. return "";
  67. }
  68. public string RestDeleteUserSessionMethod( string request, string path, string param )
  69. {
  70. LLUUID sessionid = new LLUUID(param); // get usersessions/sessionid
  71. foreach (libsecondlife.LLUUID UUID in UserProfiles.Keys)
  72. {
  73. if ( UserProfiles[UUID].CurrentSessionID == sessionid)
  74. {
  75. UserProfiles[UUID].CurrentSessionID = null;
  76. UserProfiles[UUID].CurrentSecureSessionID = null;
  77. UserProfiles[UUID].Circuits.Clear();
  78. }
  79. }
  80. return "OK";
  81. }
  82. public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
  83. {
  84. XmlRpcResponse response = new XmlRpcResponse();
  85. Hashtable requestData = (Hashtable)request.Params[0];
  86. bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
  87. bool GoodLogin = false;
  88. string firstname = "";
  89. string lastname = "";
  90. string passwd = "";
  91. if (GoodXML)
  92. {
  93. firstname = (string)requestData["first"];
  94. lastname = (string)requestData["last"];
  95. passwd = (string)requestData["passwd"];
  96. GoodLogin = AuthenticateUser(firstname, lastname, passwd);
  97. }
  98. if (!(GoodXML && GoodLogin))
  99. {
  100. response = CreateErrorConnectingToGridResponse();
  101. }
  102. else
  103. {
  104. UserProfile TheUser = GetProfileByName(firstname, lastname);
  105. //we need to sort out how sessions are logged out , currently the sim tells the gridserver
  106. //but if as this suggests the userserver handles it then please have the sim telling the userserver instead
  107. //as it really makes things messy for sandbox mode
  108. //if (!((TheUser.CurrentSessionID == null) && (TheUser.CurrentSecureSessionID == null)))
  109. // {
  110. // response = CreateAlreadyLoggedInResponse();
  111. // }
  112. //else
  113. //{
  114. try
  115. {
  116. Hashtable responseData = new Hashtable();
  117. LLUUID AgentID = TheUser.UUID;
  118. TheUser.InitSessionData();
  119. //for loading data from a grid server, make any changes in CustomiseResponse() (or create a sub class of this and override that method)
  120. //SimProfile SimInfo = new SimProfile();
  121. //SimInfo = SimInfo.LoadFromGrid(TheUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
  122. Hashtable GlobalT = new Hashtable();
  123. GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
  124. GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  125. GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
  126. ArrayList GlobalTextures = new ArrayList();
  127. GlobalTextures.Add(GlobalT);
  128. Hashtable LoginFlagsHash = new Hashtable();
  129. LoginFlagsHash["daylight_savings"] = "N";
  130. LoginFlagsHash["stipend_since_login"] = "N";
  131. LoginFlagsHash["gendered"] = "Y";
  132. LoginFlagsHash["ever_logged_in"] = "Y";
  133. ArrayList LoginFlags = new ArrayList();
  134. LoginFlags.Add(LoginFlagsHash);
  135. Hashtable uiconfig = new Hashtable();
  136. uiconfig["allow_first_life"] = "Y";
  137. ArrayList ui_config = new ArrayList();
  138. ui_config.Add(uiconfig);
  139. Hashtable ClassifiedCategoriesHash = new Hashtable();
  140. ClassifiedCategoriesHash["category_name"] = "bla bla";
  141. ClassifiedCategoriesHash["category_id"] = (Int32)1;
  142. ArrayList ClassifiedCategories = new ArrayList();
  143. ClassifiedCategories.Add(ClassifiedCategoriesHash);
  144. ArrayList AgentInventory = new ArrayList();
  145. Console.WriteLine("adding inventory to response");
  146. Hashtable TempHash;
  147. foreach (InventoryFolder InvFolder in TheUser.Inventory.InventoryFolders.Values)
  148. {
  149. TempHash = new Hashtable();
  150. Console.WriteLine("adding folder " + InvFolder.FolderName + ", ID: " + InvFolder.FolderID.ToStringHyphenated() + " with parent: " + InvFolder.ParentID.ToStringHyphenated());
  151. TempHash["name"] = InvFolder.FolderName;
  152. TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated();
  153. TempHash["version"] = (Int32)InvFolder.Version;
  154. TempHash["type_default"] = (Int32)InvFolder.DefaultType;
  155. TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated();
  156. AgentInventory.Add(TempHash);
  157. }
  158. Hashtable InventoryRootHash = new Hashtable();
  159. InventoryRootHash["folder_id"] = TheUser.Inventory.InventoryRoot.FolderID.ToStringHyphenated();
  160. ArrayList InventoryRoot = new ArrayList();
  161. InventoryRoot.Add(InventoryRootHash);
  162. Hashtable InitialOutfitHash = new Hashtable();
  163. InitialOutfitHash["folder_name"] = "Nightclub Female";
  164. InitialOutfitHash["gender"] = "female";
  165. ArrayList InitialOutfit = new ArrayList();
  166. InitialOutfit.Add(InitialOutfitHash);
  167. uint circode = (uint)(Util.RandomClass.Next());
  168. //TheUser.AddSimCircuit(circode, SimInfo.UUID);
  169. responseData["last_name"] = TheUser.lastname;
  170. responseData["ui-config"] = ui_config;
  171. responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString();
  172. responseData["login-flags"] = LoginFlags;
  173. responseData["global-textures"] = GlobalTextures;
  174. responseData["classified_categories"] = ClassifiedCategories;
  175. responseData["event_categories"] = new ArrayList();
  176. responseData["inventory-skeleton"] = AgentInventory;
  177. responseData["inventory-skel-lib"] = new ArrayList();
  178. responseData["inventory-root"] = InventoryRoot;
  179. responseData["event_notifications"] = new ArrayList();
  180. responseData["gestures"] = new ArrayList();
  181. responseData["inventory-lib-owner"] = new ArrayList();
  182. responseData["initial-outfit"] = InitialOutfit;
  183. responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  184. responseData["start_location"] = "last";
  185. responseData["home"] = "{'region_handle':[r" + (0 * 256).ToString() + ",r" + (0 * 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() + "]}";
  186. responseData["message"] = DefaultStartupMsg;
  187. responseData["first_name"] = TheUser.firstname;
  188. responseData["circuit_code"] = (Int32)circode;
  189. responseData["sim_port"] = 0; //(Int32)SimInfo.sim_port;
  190. responseData["secure_session_id"] = TheUser.CurrentSecureSessionID.ToStringHyphenated();
  191. responseData["look_at"] = "\n[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]\n";
  192. responseData["agent_id"] = AgentID.ToStringHyphenated();
  193. responseData["region_y"] = (Int32)0 * 256; // (Int32)SimInfo.RegionLocY * 256;
  194. responseData["region_x"] = (Int32)0 * 256; //SimInfo.RegionLocX * 256;
  195. responseData["seed_capability"] = "";
  196. responseData["agent_access"] = "M";
  197. responseData["session_id"] = TheUser.CurrentSessionID.ToStringHyphenated();
  198. responseData["login"] = "true";
  199. this.CustomiseResponse(ref responseData, TheUser);
  200. response.Value = responseData;
  201. // TheUser.SendDataToSim(SimInfo);
  202. return response;
  203. }
  204. catch (Exception E)
  205. {
  206. Console.WriteLine(E.ToString());
  207. }
  208. //}
  209. }
  210. return response;
  211. }
  212. private static XmlRpcResponse CreateErrorConnectingToGridResponse()
  213. {
  214. XmlRpcResponse response = new XmlRpcResponse();
  215. Hashtable ErrorRespData = new Hashtable();
  216. ErrorRespData["reason"] = "key";
  217. 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";
  218. ErrorRespData["login"] = "false";
  219. response.Value = ErrorRespData;
  220. return response;
  221. }
  222. private static XmlRpcResponse CreateAlreadyLoggedInResponse()
  223. {
  224. XmlRpcResponse response = new XmlRpcResponse();
  225. Hashtable PresenceErrorRespData = new Hashtable();
  226. PresenceErrorRespData["reason"] = "presence";
  227. 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";
  228. PresenceErrorRespData["login"] = "false";
  229. response.Value = PresenceErrorRespData;
  230. return response;
  231. }
  232. public virtual void CustomiseResponse(ref Hashtable response, UserProfile theUser)
  233. {
  234. //default method set up to act as ogs user server
  235. SimProfile SimInfo= new SimProfile();
  236. //get siminfo from grid server
  237. SimInfo = SimInfo.LoadFromGrid(theUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
  238. Int32 circode = (Int32)Convert.ToUInt32(response["circuit_code"]);
  239. theUser.AddSimCircuit((uint)circode, SimInfo.UUID);
  240. 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() + "]}";
  241. response["sim_ip"] = SimInfo.sim_ip;
  242. response["sim_port"] = (Int32)SimInfo.sim_port;
  243. response["region_y"] = (Int32)SimInfo.RegionLocY * 256;
  244. response["region_x"] = (Int32)SimInfo.RegionLocX * 256;
  245. //default is ogs user server, so let the sim know about the user via a XmlRpcRequest
  246. Console.WriteLine(SimInfo.caps_url);
  247. Hashtable SimParams = new Hashtable();
  248. SimParams["session_id"] = theUser.CurrentSessionID.ToString();
  249. SimParams["secure_session_id"] = theUser.CurrentSecureSessionID.ToString();
  250. SimParams["firstname"] = theUser.firstname;
  251. SimParams["lastname"] = theUser.lastname;
  252. SimParams["agent_id"] = theUser.UUID.ToString();
  253. SimParams["circuit_code"] = (Int32)circode;
  254. SimParams["startpos_x"] = theUser.homepos.X.ToString();
  255. SimParams["startpos_y"] = theUser.homepos.Y.ToString();
  256. SimParams["startpos_z"] = theUser.homepos.Z.ToString();
  257. ArrayList SendParams = new ArrayList();
  258. SendParams.Add(SimParams);
  259. XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
  260. XmlRpcResponse GridResp = GridReq.Send(SimInfo.caps_url, 3000);
  261. }
  262. }
  263. }