1
0

LLStandaloneLoginModule.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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.Cache;
  39. using OpenSim.Framework.Capabilities;
  40. using OpenSim.Framework.Servers.HttpServer;
  41. using OpenSim.Region.Framework.Scenes;
  42. using OpenSim.Region.Framework.Interfaces;
  43. namespace OpenSim.Client.Linden
  44. {
  45. public class LLStandaloneLoginModule : ISharedRegionModule, ILoginServiceToRegionsConnector
  46. {
  47. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. protected List<Scene> m_scenes = new List<Scene>();
  49. protected Scene m_firstScene;
  50. protected bool m_enabled = false; // Module is only enabled if running in standalone mode
  51. protected bool authenticate;
  52. protected string welcomeMessage;
  53. protected LLStandaloneLoginService m_loginService;
  54. #region IRegionModule Members
  55. public void Initialise(IConfigSource source)
  56. {
  57. IConfig startupConfig = source.Configs["Startup"];
  58. if (startupConfig != null)
  59. {
  60. m_enabled = !startupConfig.GetBoolean("gridmode", false);
  61. }
  62. if (m_enabled)
  63. {
  64. authenticate = true;
  65. welcomeMessage = "Welcome to OpenSim";
  66. IConfig standaloneConfig = source.Configs["StandAlone"];
  67. if (standaloneConfig != null)
  68. {
  69. authenticate = standaloneConfig.GetBoolean("accounts_authenticate", true);
  70. welcomeMessage = standaloneConfig.GetString("welcome_message");
  71. }
  72. }
  73. }
  74. public void AddRegion(Scene scene)
  75. {
  76. }
  77. public void RemoveRegion(Scene scene)
  78. {
  79. if (m_enabled)
  80. {
  81. RemoveScene(scene);
  82. }
  83. }
  84. public void PostInitialise()
  85. {
  86. }
  87. public void Close()
  88. {
  89. }
  90. public void RegionLoaded(Scene scene)
  91. {
  92. if (m_firstScene == null)
  93. {
  94. m_firstScene = scene;
  95. if (m_enabled)
  96. {
  97. //TODO: fix casting.
  98. LibraryRootFolder rootFolder
  99. = m_firstScene.CommsManager.UserProfileCacheService.LibraryRoot as LibraryRootFolder;
  100. IHttpServer httpServer = MainServer.Instance;
  101. //TODO: fix the casting of the user service, maybe by registering the userManagerBase with scenes, or refactoring so we just need a IUserService reference
  102. m_loginService
  103. = new LLStandaloneLoginService(
  104. (UserManagerBase)m_firstScene.CommsManager.UserAdminService, welcomeMessage,
  105. m_firstScene.InventoryService, m_firstScene.CommsManager.NetworkServersInfo, authenticate,
  106. rootFolder, this);
  107. httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod);
  108. // provides the web form login
  109. httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin);
  110. // Provides the LLSD login
  111. httpServer.SetDefaultLLSDHandler(m_loginService.LLSDLoginMethod);
  112. }
  113. }
  114. if (m_enabled)
  115. {
  116. AddScene(scene);
  117. }
  118. }
  119. public Type ReplaceableInterface
  120. {
  121. get { return null; }
  122. }
  123. public string Name
  124. {
  125. get { return "LLStandaloneLoginModule"; }
  126. }
  127. public bool IsSharedModule
  128. {
  129. get { return true; }
  130. }
  131. #endregion
  132. protected void AddScene(Scene scene)
  133. {
  134. lock (m_scenes)
  135. {
  136. if (!m_scenes.Contains(scene))
  137. {
  138. m_scenes.Add(scene);
  139. }
  140. }
  141. }
  142. protected void RemoveScene(Scene scene)
  143. {
  144. lock (m_scenes)
  145. {
  146. if (m_scenes.Contains(scene))
  147. {
  148. m_scenes.Remove(scene);
  149. }
  150. }
  151. }
  152. public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent, out string reason)
  153. {
  154. Scene scene;
  155. if (TryGetRegion(regionHandle, out scene))
  156. {
  157. return scene.NewUserConnection(agent, (uint)TeleportFlags.ViaLogin, out reason);
  158. }
  159. reason = "Region not found.";
  160. return false;
  161. }
  162. public void LogOffUserFromGrid(ulong regionHandle, UUID AvatarID, UUID RegionSecret, string message)
  163. {
  164. Scene scene;
  165. if (TryGetRegion(regionHandle, out scene))
  166. {
  167. scene.HandleLogOffUserFromGrid(AvatarID, RegionSecret, message);
  168. }
  169. }
  170. public RegionInfo RequestNeighbourInfo(ulong regionhandle)
  171. {
  172. Scene scene;
  173. if (TryGetRegion(regionhandle, out scene))
  174. {
  175. return scene.RegionInfo;
  176. }
  177. return null;
  178. }
  179. public RegionInfo RequestClosestRegion(string region)
  180. {
  181. Scene scene;
  182. if (TryGetRegion(region, out scene))
  183. {
  184. return scene.RegionInfo;
  185. }
  186. else if (m_scenes.Count > 0)
  187. {
  188. return m_scenes[0].RegionInfo;
  189. }
  190. return null;
  191. }
  192. public RegionInfo RequestNeighbourInfo(UUID regionID)
  193. {
  194. Scene scene;
  195. if (TryGetRegion(regionID, out scene))
  196. {
  197. return scene.RegionInfo;
  198. }
  199. return null;
  200. }
  201. protected bool TryGetRegion(ulong regionHandle, out Scene scene)
  202. {
  203. lock (m_scenes)
  204. {
  205. foreach (Scene nextScene in m_scenes)
  206. {
  207. if (nextScene.RegionInfo.RegionHandle == regionHandle)
  208. {
  209. scene = nextScene;
  210. return true;
  211. }
  212. }
  213. }
  214. scene = null;
  215. return false;
  216. }
  217. protected bool TryGetRegion(UUID regionID, out Scene scene)
  218. {
  219. lock (m_scenes)
  220. {
  221. foreach (Scene nextScene in m_scenes)
  222. {
  223. if (nextScene.RegionInfo.RegionID == regionID)
  224. {
  225. scene = nextScene;
  226. return true;
  227. }
  228. }
  229. }
  230. scene = null;
  231. return false;
  232. }
  233. protected bool TryGetRegion(string regionName, out Scene scene)
  234. {
  235. lock (m_scenes)
  236. {
  237. foreach (Scene nextScene in m_scenes)
  238. {
  239. if (nextScene.RegionInfo.RegionName.Equals(regionName, StringComparison.InvariantCultureIgnoreCase))
  240. {
  241. scene = nextScene;
  242. return true;
  243. }
  244. }
  245. }
  246. scene = null;
  247. return false;
  248. }
  249. }
  250. }