Main.cs 11 KB

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