Main.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.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.IO;
  31. using libsecondlife;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Framework.Console;
  35. using OpenSim.Framework.Servers;
  36. using OpenSim.Framework.Statistics;
  37. namespace OpenSim.Grid.UserServer
  38. {
  39. /// <summary>
  40. /// </summary>
  41. public class OpenUser_Main : BaseOpenSimServer, conscmd_callback
  42. {
  43. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  44. private UserConfig Cfg;
  45. public UserManager m_userManager;
  46. public UserLoginService m_loginService;
  47. public MessageServersConnector m_messagesService;
  48. private LLUUID m_lastCreatedUser = LLUUID.Random();
  49. [STAThread]
  50. public static void Main(string[] args)
  51. {
  52. log4net.Config.XmlConfigurator.Configure();
  53. m_log.Info("Launching UserServer...");
  54. OpenUser_Main userserver = new OpenUser_Main();
  55. userserver.Startup();
  56. userserver.Work();
  57. }
  58. private OpenUser_Main()
  59. {
  60. m_console = new ConsoleBase("OpenUser", this);
  61. MainConsole.Instance = m_console;
  62. }
  63. private void Work()
  64. {
  65. m_console.Notice("Enter help for a list of commands\n");
  66. while (true)
  67. {
  68. m_console.Prompt();
  69. }
  70. }
  71. public void Startup()
  72. {
  73. Cfg = new UserConfig("USER SERVER", (Path.Combine(Util.configDir(), "UserServer_Config.xml")));
  74. StatsManager.StartCollectingUserStats();
  75. m_log.Info("[REGION]: Establishing data connection");
  76. m_userManager = new UserManager();
  77. m_userManager._config = Cfg;
  78. m_userManager.AddPlugin(Cfg.DatabaseProvider);
  79. m_loginService = new UserLoginService(
  80. m_userManager, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg);
  81. m_messagesService = new MessageServersConnector();
  82. m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation;
  83. m_log.Info("[REGION]: Starting HTTP process");
  84. BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort);
  85. httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod);
  86. httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin);
  87. httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod);
  88. httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName);
  89. httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID);
  90. httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar);
  91. httpServer.AddXmlRPCHandler("add_new_user_friend", m_userManager.XmlRpcResponseXmlRPCAddUserFriend);
  92. httpServer.AddXmlRPCHandler("remove_user_friend", m_userManager.XmlRpcResponseXmlRPCRemoveUserFriend);
  93. httpServer.AddXmlRPCHandler("update_user_friend_perms", m_userManager.XmlRpcResponseXmlRPCUpdateUserFriendPerms);
  94. httpServer.AddXmlRPCHandler("get_user_friend_list", m_userManager.XmlRpcResponseXmlRPCGetUserFriendList);
  95. httpServer.AddXmlRPCHandler("logout_of_simulator", m_userManager.XmlRPCLogOffUserMethodUUID);
  96. // Message Server ---> User Server
  97. httpServer.AddXmlRPCHandler("register_messageserver", m_messagesService.XmlRPCRegisterMessageServer);
  98. httpServer.AddXmlRPCHandler("agent_change_region", m_messagesService.XmlRPCUserMovedtoRegion);
  99. httpServer.AddXmlRPCHandler("deregister_messageserver", m_messagesService.XmlRPCDeRegisterMessageServer);
  100. httpServer.AddStreamHandler(
  101. new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod));
  102. httpServer.Start();
  103. m_log.Info("[SERVER]: Userserver 0.5 - Startup complete");
  104. }
  105. public void do_create(string what)
  106. {
  107. switch (what)
  108. {
  109. case "user":
  110. string tempfirstname;
  111. string templastname;
  112. string tempMD5Passwd;
  113. uint regX = 1000;
  114. uint regY = 1000;
  115. tempfirstname = m_console.CmdPrompt("First name");
  116. templastname = m_console.CmdPrompt("Last name");
  117. //tempMD5Passwd = m_console.PasswdPrompt("Password");
  118. tempMD5Passwd = m_console.CmdPrompt("Password");
  119. regX = Convert.ToUInt32(m_console.CmdPrompt("Start Region X"));
  120. regY = Convert.ToUInt32(m_console.CmdPrompt("Start Region Y"));
  121. if (null != m_userManager.GetUserProfile(tempfirstname, templastname))
  122. {
  123. m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", tempfirstname, templastname);
  124. break;
  125. }
  126. tempMD5Passwd = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + String.Empty);
  127. LLUUID userID = new LLUUID();
  128. try
  129. {
  130. userID =
  131. m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
  132. } catch (Exception ex)
  133. {
  134. m_log.ErrorFormat("[USERS]: Error creating user: {0}", ex.ToString());
  135. }
  136. try
  137. {
  138. RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/",
  139. userID.UUID);
  140. }
  141. catch (Exception ex)
  142. {
  143. m_log.ErrorFormat("[USERS]: Error creating inventory for user: {0}", ex.ToString());
  144. }
  145. m_lastCreatedUser = userID;
  146. break;
  147. }
  148. }
  149. public override void RunCmd(string cmd, string[] cmdparams)
  150. {
  151. base.RunCmd(cmd, cmdparams);
  152. switch (cmd)
  153. {
  154. case "help":
  155. m_console.Notice("create user - create a new user");
  156. m_console.Notice("stats - statistical information for this server");
  157. m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
  158. break;
  159. case "create":
  160. do_create(cmdparams[0]);
  161. break;
  162. case "shutdown":
  163. m_loginService.OnUserLoggedInAtLocation -= NotifyMessageServersUserLoggedInToLocation;
  164. m_console.Close();
  165. Environment.Exit(0);
  166. break;
  167. case "stats":
  168. m_console.Notice(StatsManager.UserStats.Report());
  169. break;
  170. case "test-inventory":
  171. // RestObjectPosterResponse<List<InventoryFolderBase>> requester = new RestObjectPosterResponse<List<InventoryFolderBase>>();
  172. // requester.ReturnResponseVal = TestResponse;
  173. // requester.BeginPostObject<LLUUID>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser);
  174. SynchronousRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>("POST",
  175. m_userManager.
  176. _config.
  177. InventoryUrl +
  178. "RootFolders/",
  179. m_lastCreatedUser);
  180. break;
  181. }
  182. }
  183. public void TestResponse(List<InventoryFolderBase> resp)
  184. {
  185. m_console.Notice("response got");
  186. }
  187. public void NotifyMessageServersUserLoggedInToLocation(LLUUID agentID, LLUUID sessionID, LLUUID RegionID, ulong regionhandle, LLVector3 Position)
  188. {
  189. m_messagesService.TellMessageServersAboutUser(agentID, sessionID, RegionID, regionhandle, Position);
  190. }
  191. /*private void ConfigDB(IGenericConfig configData)
  192. {
  193. try
  194. {
  195. string attri = String.Empty;
  196. attri = configData.GetAttribute("DataBaseProvider");
  197. if (attri == String.Empty)
  198. {
  199. StorageDll = "OpenSim.Framework.Data.DB4o.dll";
  200. configData.SetAttribute("DataBaseProvider", "OpenSim.Framework.Data.DB4o.dll");
  201. }
  202. else
  203. {
  204. StorageDll = attri;
  205. }
  206. configData.Commit();
  207. }
  208. catch
  209. {
  210. }
  211. }*/
  212. }
  213. }