HGStandaloneLoginModule.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Text.RegularExpressions;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications;
  38. using OpenSim.Framework.Communications.Services;
  39. using OpenSim.Framework.Communications.Cache;
  40. using OpenSim.Framework.Capabilities;
  41. using OpenSim.Framework.Servers.HttpServer;
  42. using OpenSim.Region.Framework.Scenes;
  43. using OpenSim.Region.Framework.Interfaces;
  44. namespace OpenSim.Region.CoreModules.Hypergrid
  45. {
  46. public class HGStandaloneLoginModule : IRegionModule, ILoginServiceToRegionsConnector
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. protected List<Scene> m_scenes = new List<Scene>();
  50. protected Scene m_firstScene;
  51. protected bool m_enabled = false; // Module is only enabled if running in standalone mode
  52. public bool RegionLoginsEnabled
  53. {
  54. get
  55. {
  56. if (m_firstScene != null)
  57. {
  58. return m_firstScene.CommsManager.GridService.RegionLoginsEnabled;
  59. }
  60. else
  61. {
  62. return false;
  63. }
  64. }
  65. }
  66. protected HGLoginAuthService m_loginService;
  67. #region IRegionModule Members
  68. public void Initialise(Scene scene, IConfigSource source)
  69. {
  70. if (m_firstScene == null)
  71. {
  72. m_firstScene = scene;
  73. IConfig startupConfig = source.Configs["Startup"];
  74. if (startupConfig != null)
  75. {
  76. m_enabled = !startupConfig.GetBoolean("gridmode", false);
  77. }
  78. if (m_enabled)
  79. {
  80. m_log.Debug("[HGLogin]: HGlogin module enabled");
  81. bool authenticate = true;
  82. string welcomeMessage = "Welcome to OpenSim";
  83. IConfig standaloneConfig = source.Configs["StandAlone"];
  84. if (standaloneConfig != null)
  85. {
  86. authenticate = standaloneConfig.GetBoolean("accounts_authenticate", true);
  87. welcomeMessage = standaloneConfig.GetString("welcome_message");
  88. }
  89. //TODO: fix casting.
  90. LibraryRootFolder rootFolder = m_firstScene.CommsManager.UserProfileCacheService.LibraryRoot as LibraryRootFolder;
  91. IHttpServer httpServer = MainServer.Instance;
  92. //TODO: fix the casting of the user service, maybe by registering the userManagerBase with scenes, or refactoring so we just need a IUserService reference
  93. m_loginService
  94. = new HGLoginAuthService(
  95. (UserManagerBase)m_firstScene.CommsManager.UserAdminService,
  96. welcomeMessage,
  97. m_firstScene.CommsManager.InterServiceInventoryService,
  98. m_firstScene.CommsManager.NetworkServersInfo,
  99. authenticate,
  100. rootFolder,
  101. this);
  102. httpServer.AddXmlRPCHandler("hg_login", m_loginService.XmlRpcLoginMethod);
  103. httpServer.AddXmlRPCHandler("check_auth_session", m_loginService.XmlRPCCheckAuthSession, false);
  104. }
  105. }
  106. if (m_enabled)
  107. {
  108. AddScene(scene);
  109. }
  110. }
  111. public void PostInitialise()
  112. {
  113. }
  114. public void Close()
  115. {
  116. }
  117. public string Name
  118. {
  119. get { return "HGStandaloneLoginModule"; }
  120. }
  121. public bool IsSharedModule
  122. {
  123. get { return true; }
  124. }
  125. #endregion
  126. protected void AddScene(Scene scene)
  127. {
  128. lock (m_scenes)
  129. {
  130. if (!m_scenes.Contains(scene))
  131. {
  132. m_scenes.Add(scene);
  133. }
  134. }
  135. }
  136. public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent, out string reason)
  137. {
  138. reason = String.Empty;
  139. return true;
  140. }
  141. public void LogOffUserFromGrid(ulong regionHandle, UUID AvatarID, UUID RegionSecret, string message)
  142. {
  143. Scene scene;
  144. if (TryGetRegion(regionHandle, out scene))
  145. {
  146. scene.HandleLogOffUserFromGrid(AvatarID, RegionSecret, message);
  147. }
  148. }
  149. public RegionInfo RequestNeighbourInfo(ulong regionhandle)
  150. {
  151. Scene scene;
  152. if (TryGetRegion(regionhandle, out scene))
  153. {
  154. return scene.RegionInfo;
  155. }
  156. return null;
  157. }
  158. public RegionInfo RequestClosestRegion(string region)
  159. {
  160. Scene scene;
  161. if (TryGetRegion(region, out scene))
  162. {
  163. return scene.RegionInfo;
  164. }
  165. return null;
  166. }
  167. public RegionInfo RequestNeighbourInfo(UUID regionID)
  168. {
  169. Scene scene;
  170. if (TryGetRegion(regionID, out scene))
  171. {
  172. return scene.RegionInfo;
  173. }
  174. return null;
  175. }
  176. protected bool TryGetRegion(ulong regionHandle, out Scene scene)
  177. {
  178. lock (m_scenes)
  179. {
  180. foreach (Scene nextScene in m_scenes)
  181. {
  182. if (nextScene.RegionInfo.RegionHandle == regionHandle)
  183. {
  184. scene = nextScene;
  185. return true;
  186. }
  187. }
  188. }
  189. scene = null;
  190. return false;
  191. }
  192. protected bool TryGetRegion(UUID regionID, out Scene scene)
  193. {
  194. lock (m_scenes)
  195. {
  196. foreach (Scene nextScene in m_scenes)
  197. {
  198. if (nextScene.RegionInfo.RegionID == regionID)
  199. {
  200. scene = nextScene;
  201. return true;
  202. }
  203. }
  204. }
  205. scene = null;
  206. return false;
  207. }
  208. protected bool TryGetRegion(string regionName, out Scene scene)
  209. {
  210. lock (m_scenes)
  211. {
  212. foreach (Scene nextScene in m_scenes)
  213. {
  214. if (nextScene.RegionInfo.RegionName == regionName)
  215. {
  216. scene = nextScene;
  217. return true;
  218. }
  219. }
  220. }
  221. scene = null;
  222. return false;
  223. }
  224. }
  225. }