LocalUserProfileManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 System;
  28. using System.Collections.Generic;
  29. using System.Collections;
  30. using System.Text;
  31. using OpenSim.Framework.User;
  32. using OpenSim.Framework.Grid;
  33. using OpenSim.Framework.Inventory;
  34. using OpenSim.Framework.Interfaces;
  35. using OpenSim.Framework.Types;
  36. using libsecondlife;
  37. namespace OpenSim.UserServer
  38. {
  39. public class LocalUserProfileManager : UserProfileManager
  40. {
  41. private IGridServer m_gridServer;
  42. private int m_port;
  43. private string m_ipAddr;
  44. private uint regionX;
  45. private uint regionY;
  46. private AddNewSessionHandler AddSession;
  47. public LocalUserProfileManager(IGridServer gridServer, int simPort, string ipAddr , uint regX, uint regY)
  48. {
  49. m_gridServer = gridServer;
  50. m_port = simPort;
  51. m_ipAddr = ipAddr;
  52. regionX = regX;
  53. regionY = regY;
  54. }
  55. public void SetSessionHandler(AddNewSessionHandler sessionHandler)
  56. {
  57. this.AddSession = sessionHandler;
  58. }
  59. public override void InitUserProfiles()
  60. {
  61. // TODO: need to load from database
  62. }
  63. public override void CustomiseResponse(ref System.Collections.Hashtable response, UserProfile theUser)
  64. {
  65. Int32 circode = (Int32)response["circuit_code"];
  66. theUser.AddSimCircuit((uint)circode, LLUUID.Random());
  67. response["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() + "]}";
  68. response["sim_port"] = m_port;
  69. response["sim_ip"] = m_ipAddr;
  70. response["region_y"] = (Int32)regionY* 256;
  71. response["region_x"] = (Int32)regionX* 256;
  72. string first;
  73. string last;
  74. if (response.Contains("first_name"))
  75. {
  76. first = (string)response["first_name"];
  77. }
  78. else
  79. {
  80. first = "test";
  81. }
  82. if (response.Contains("last_name"))
  83. {
  84. last = (string)response["last_name"];
  85. }
  86. else
  87. {
  88. last = "User";
  89. }
  90. ArrayList InventoryList = (ArrayList)response["inventory-skeleton"];
  91. Hashtable Inventory1 = (Hashtable)InventoryList[0];
  92. Login _login = new Login();
  93. //copy data to login object
  94. _login.First = first;
  95. _login.Last = last;
  96. _login.Agent = new LLUUID((string)response["agent_id"]) ;
  97. _login.Session = new LLUUID((string)response["session_id"]);
  98. _login.SecureSession = new LLUUID((string)response["secure_session_id"]);
  99. _login.CircuitCode =(uint) circode;
  100. _login.BaseFolder = null;
  101. _login.InventoryFolder = new LLUUID((string)Inventory1["folder_id"]);
  102. //working on local computer if so lets add to the gridserver's list of sessions?
  103. /*if (m_gridServer.GetName() == "Local")
  104. {
  105. Console.WriteLine("adding login data to gridserver");
  106. ((LocalGridBase)this.m_gridServer).AddNewSession(_login);
  107. }*/
  108. ulong reghand = Helpers.UIntsToLong((regionX * 256), (regionY * 256));
  109. this.AddSession(reghand, _login);
  110. }
  111. }
  112. }