LLStandaloneLoginModule.cs 9.2 KB

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