Main.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 OpenSimulator 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 System.Reflection;
  31. using log4net;
  32. using log4net.Config;
  33. using OpenMetaverse;
  34. using OpenSim.Data;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Communications;
  37. using OpenSim.Framework.Communications.Cache;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Framework.Servers;
  40. using OpenSim.Framework.Servers.HttpServer;
  41. using OpenSim.Framework.Statistics;
  42. using OpenSim.Grid.Communications.OGS1;
  43. using OpenSim.Grid.Framework;
  44. using OpenSim.Grid.UserServer.Modules;
  45. namespace OpenSim.Grid.UserServer
  46. {
  47. /// <summary>
  48. /// Grid user server main class
  49. /// </summary>
  50. public class OpenUser_Main : BaseOpenSimServer, IGridServiceCore
  51. {
  52. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  53. protected UserConfig Cfg;
  54. protected UserDataBaseService m_userDataBaseService;
  55. public UserManager m_userManager;
  56. protected UserServerAvatarAppearanceModule m_avatarAppearanceModule;
  57. protected UserServerFriendsModule m_friendsModule;
  58. public UserLoginService m_loginService;
  59. public UserLoginAuthService m_loginAuthService;
  60. public MessageServersConnector m_messagesService;
  61. protected GridInfoServiceModule m_gridInfoService;
  62. protected UserServerCommandModule m_consoleCommandModule;
  63. protected UserServerEventDispatchModule m_eventDispatcher;
  64. protected AvatarCreationModule m_appearanceModule;
  65. public static void Main(string[] args)
  66. {
  67. XmlConfigurator.Configure();
  68. m_log.Info("Launching UserServer...");
  69. OpenUser_Main userserver = new OpenUser_Main();
  70. userserver.Startup();
  71. userserver.Work();
  72. }
  73. public OpenUser_Main()
  74. {
  75. m_console = new LocalConsole("User");
  76. MainConsole.Instance = m_console;
  77. }
  78. public void Work()
  79. {
  80. m_console.Output("Enter help for a list of commands\n");
  81. while (true)
  82. {
  83. m_console.Prompt();
  84. }
  85. }
  86. protected override void StartupSpecific()
  87. {
  88. IInterServiceInventoryServices inventoryService = StartupCoreComponents();
  89. m_stats = StatsManager.StartCollectingUserStats();
  90. //setup services/modules
  91. StartupUserServerModules();
  92. StartOtherComponents(inventoryService);
  93. //PostInitialise the modules
  94. PostInitialiseModules();
  95. //register http handlers and start http server
  96. m_log.Info("[STARTUP]: Starting HTTP process");
  97. RegisterHttpHandlers();
  98. m_httpServer.Start();
  99. base.StartupSpecific();
  100. }
  101. protected virtual IInterServiceInventoryServices StartupCoreComponents()
  102. {
  103. Cfg = new UserConfig("USER SERVER", (Path.Combine(Util.configDir(), "UserServer_Config.xml")));
  104. m_httpServer = new BaseHttpServer(Cfg.HttpPort);
  105. RegisterInterface<CommandConsole>(m_console);
  106. RegisterInterface<UserConfig>(Cfg);
  107. //Should be in modules?
  108. IInterServiceInventoryServices inventoryService = new OGS1InterServiceInventoryService(Cfg.InventoryUrl);
  109. // IRegionProfileRouter regionProfileService = new RegionProfileServiceProxy();
  110. RegisterInterface<IInterServiceInventoryServices>(inventoryService);
  111. // RegisterInterface<IRegionProfileRouter>(regionProfileService);
  112. return inventoryService;
  113. }
  114. /// <summary>
  115. /// Start up the user manager
  116. /// </summary>
  117. /// <param name="inventoryService"></param>
  118. protected virtual void StartupUserServerModules()
  119. {
  120. m_log.Info("[STARTUP]: Establishing data connection");
  121. //we only need core components so we can request them from here
  122. IInterServiceInventoryServices inventoryService;
  123. TryGet<IInterServiceInventoryServices>(out inventoryService);
  124. CommunicationsManager commsManager = new UserServerCommsManager(inventoryService);
  125. //setup database access service, for now this has to be created before the other modules.
  126. m_userDataBaseService = new UserDataBaseService(commsManager);
  127. m_userDataBaseService.Initialise(this);
  128. //TODO: change these modules so they fetch the databaseService class in the PostInitialise method
  129. m_userManager = new UserManager(m_userDataBaseService);
  130. m_userManager.Initialise(this);
  131. m_avatarAppearanceModule = new UserServerAvatarAppearanceModule(m_userDataBaseService);
  132. m_avatarAppearanceModule.Initialise(this);
  133. m_friendsModule = new UserServerFriendsModule(m_userDataBaseService);
  134. m_friendsModule.Initialise(this);
  135. m_consoleCommandModule = new UserServerCommandModule();
  136. m_consoleCommandModule.Initialise(this);
  137. m_messagesService = new MessageServersConnector();
  138. m_messagesService.Initialise(this);
  139. m_gridInfoService = new GridInfoServiceModule();
  140. m_gridInfoService.Initialise(this);
  141. }
  142. protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService)
  143. {
  144. m_appearanceModule = new AvatarCreationModule(m_userDataBaseService, Cfg, inventoryService);
  145. m_appearanceModule.Initialise(this);
  146. StartupLoginService(inventoryService);
  147. //
  148. // Get the minimum defaultLevel to access to the grid
  149. //
  150. m_loginService.setloginlevel((int)Cfg.DefaultUserLevel);
  151. RegisterInterface<UserLoginService>(m_loginService); //TODO: should be done in the login service
  152. m_eventDispatcher = new UserServerEventDispatchModule(m_userManager, m_messagesService, m_loginService);
  153. m_eventDispatcher.Initialise(this);
  154. }
  155. /// <summary>
  156. /// Start up the login service
  157. /// </summary>
  158. /// <param name="inventoryService"></param>
  159. protected virtual void StartupLoginService(IInterServiceInventoryServices inventoryService)
  160. {
  161. m_loginService = new UserLoginService(
  162. m_userDataBaseService, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile), Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy());
  163. if (Cfg.EnableHGLogin)
  164. m_loginAuthService = new UserLoginAuthService(m_userDataBaseService, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile),
  165. Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy());
  166. }
  167. protected virtual void PostInitialiseModules()
  168. {
  169. m_consoleCommandModule.PostInitialise(); //it will register its Console command handlers in here
  170. m_userDataBaseService.PostInitialise();
  171. m_messagesService.PostInitialise();
  172. m_eventDispatcher.PostInitialise(); //it will register event handlers in here
  173. m_gridInfoService.PostInitialise();
  174. m_userManager.PostInitialise();
  175. m_avatarAppearanceModule.PostInitialise();
  176. m_friendsModule.PostInitialise();
  177. m_avatarAppearanceModule.PostInitialise();
  178. }
  179. protected virtual void RegisterHttpHandlers()
  180. {
  181. m_loginService.RegisterHandlers(m_httpServer, Cfg.EnableLLSDLogin, true);
  182. if (m_loginAuthService != null)
  183. m_loginAuthService.RegisterHandlers(m_httpServer);
  184. m_userManager.RegisterHandlers(m_httpServer);
  185. m_friendsModule.RegisterHandlers(m_httpServer);
  186. m_avatarAppearanceModule.RegisterHandlers(m_httpServer);
  187. m_messagesService.RegisterHandlers(m_httpServer);
  188. m_gridInfoService.RegisterHandlers(m_httpServer);
  189. m_avatarAppearanceModule.RegisterHandlers(m_httpServer);
  190. }
  191. public override void ShutdownSpecific()
  192. {
  193. m_eventDispatcher.Close();
  194. }
  195. #region IUGAIMCore
  196. protected Dictionary<Type, object> m_moduleInterfaces = new Dictionary<Type, object>();
  197. /// <summary>
  198. /// Register an Module interface.
  199. /// </summary>
  200. /// <typeparam name="T"></typeparam>
  201. /// <param name="iface"></param>
  202. public void RegisterInterface<T>(T iface)
  203. {
  204. lock (m_moduleInterfaces)
  205. {
  206. if (!m_moduleInterfaces.ContainsKey(typeof(T)))
  207. {
  208. m_moduleInterfaces.Add(typeof(T), iface);
  209. }
  210. }
  211. }
  212. public bool TryGet<T>(out T iface)
  213. {
  214. if (m_moduleInterfaces.ContainsKey(typeof(T)))
  215. {
  216. iface = (T)m_moduleInterfaces[typeof(T)];
  217. return true;
  218. }
  219. iface = default(T);
  220. return false;
  221. }
  222. public T Get<T>()
  223. {
  224. return (T)m_moduleInterfaces[typeof(T)];
  225. }
  226. public BaseHttpServer GetHttpServer()
  227. {
  228. return m_httpServer;
  229. }
  230. #endregion
  231. public void TestResponse(List<InventoryFolderBase> resp)
  232. {
  233. m_console.Output("response got");
  234. }
  235. }
  236. }