HGOpenSimNode.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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.IO;
  31. using System.Net;
  32. using System.Reflection;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Console;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Statistics;
  39. using OpenSim.Region.ClientStack;
  40. using OpenSim.Framework.Communications;
  41. using OpenSim.Framework.Communications.Cache;
  42. using OpenSim.Region.Communications.Local;
  43. using OpenSim.Region.Communications.Hypergrid;
  44. using OpenSim.Region.Environment;
  45. using OpenSim.Region.Environment.Interfaces;
  46. using OpenSim.Region.Environment.Scenes;
  47. using OpenSim.Region.Environment.Scenes.Hypergrid;
  48. using Timer = System.Timers.Timer;
  49. namespace OpenSim
  50. {
  51. public class HGOpenSimNode : OpenSim
  52. {
  53. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  54. private IHyperlink HGServices = null;
  55. public HGOpenSimNode(IConfigSource configSource) : base(configSource)
  56. {
  57. }
  58. /// <summary>
  59. /// Performs initialisation of the scene, such as loading configuration from disk.
  60. /// </summary>
  61. protected override void StartupSpecific()
  62. {
  63. m_log.Info("====================================================================");
  64. m_log.Info("=================== STARTING HYPERGRID NODE ========================");
  65. m_log.Info("====================================================================");
  66. base.StartupSpecific();
  67. }
  68. protected override void InitialiseStandaloneServices(LibraryRootFolder libraryRootFolder)
  69. {
  70. // Standalone mode
  71. HGInventoryService inventoryService = new HGInventoryService(m_networkServersInfo.InventoryURL, null, false);
  72. inventoryService.AddPlugin(m_configSettings.StandaloneInventoryPlugin, m_configSettings.StandaloneInventorySource);
  73. LocalUserServices userService =
  74. new LocalUserServices(
  75. m_networkServersInfo.DefaultHomeLocX, m_networkServersInfo.DefaultHomeLocY, inventoryService);
  76. userService.AddPlugin(m_configSettings.StandaloneUserPlugin, m_configSettings.StandaloneUserSource);
  77. //LocalBackEndServices backendService = new LocalBackEndServices();
  78. HGGridServicesStandalone gridService = new HGGridServicesStandalone(m_networkServersInfo, m_httpServer, m_assetCache, m_sceneManager);
  79. LocalLoginService loginService =
  80. new LocalLoginService(
  81. userService, m_configSettings.StandaloneWelcomeMessage, inventoryService, gridService.LocalBackend, m_networkServersInfo,
  82. m_configSettings.StandaloneAuthenticate, libraryRootFolder);
  83. m_commsManager = new HGCommunicationsStandalone(m_networkServersInfo, m_httpServer, m_assetCache,
  84. userService, userService, inventoryService, gridService, gridService, userService, libraryRootFolder, m_configSettings.DumpAssetsToFile);
  85. inventoryService.UserProfileCache = m_commsManager.UserProfileCacheService;
  86. HGServices = gridService;
  87. // set up XMLRPC handler for client's initial login request message
  88. m_httpServer.AddXmlRPCHandler("login_to_simulator", loginService.XmlRpcLoginMethod);
  89. // provides the web form login
  90. m_httpServer.AddHTTPHandler("login", loginService.ProcessHTMLLogin);
  91. // Provides the LLSD login
  92. m_httpServer.SetDefaultLLSDHandler(loginService.LLSDLoginMethod);
  93. // provide grid info
  94. // m_gridInfoService = new GridInfoService(m_config.Source.Configs["Startup"].GetString("inifile", Path.Combine(Util.configDir(), "OpenSim.ini")));
  95. m_gridInfoService = new GridInfoService(m_config.Source);
  96. m_httpServer.AddXmlRPCHandler("get_grid_info", m_gridInfoService.XmlRpcGridInfoMethod);
  97. m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info", m_gridInfoService.RestGetGridInfoMethod));
  98. }
  99. protected override void InitialiseGridServices(LibraryRootFolder libraryRootFolder)
  100. {
  101. m_commsManager = new HGCommunicationsGridMode(m_networkServersInfo, m_httpServer, m_assetCache, m_sceneManager, libraryRootFolder);
  102. HGServices = ((HGCommunicationsGridMode)m_commsManager).HGServices;
  103. m_httpServer.AddStreamHandler(new SimStatusHandler());
  104. }
  105. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  106. AgentCircuitManager circuitManager)
  107. {
  108. HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices);
  109. return
  110. new HGScene(regionInfo, circuitManager, m_commsManager, sceneGridService, m_assetCache,
  111. storageManager, m_httpServer,
  112. m_moduleLoader, m_configSettings.DumpAssetsToFile, m_configSettings.PhysicalPrim, m_configSettings.See_into_region_from_neighbor, m_config.Source,
  113. m_version);
  114. }
  115. public override void RunCmd(string command, string[] cmdparams)
  116. {
  117. if (command.Equals("link-region"))
  118. {
  119. // link-region <Xloc> <Yloc> <HostName> <HttpPort> <LocalName>
  120. if (cmdparams.Length < 4)
  121. {
  122. LinkRegionCmdUsage();
  123. return;
  124. }
  125. RegionInfo regInfo = new RegionInfo();
  126. uint xloc, yloc;
  127. uint externalPort;
  128. try
  129. {
  130. xloc = Convert.ToUInt32(cmdparams[0]);
  131. yloc = Convert.ToUInt32(cmdparams[1]);
  132. externalPort = Convert.ToUInt32(cmdparams[3]);
  133. //internalPort = Convert.ToUInt32(cmdparams[4]);
  134. //remotingPort = Convert.ToUInt32(cmdparams[5]);
  135. }
  136. catch (Exception e)
  137. {
  138. m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
  139. LinkRegionCmdUsage();
  140. return;
  141. }
  142. regInfo.RegionLocX = xloc;
  143. regInfo.RegionLocY = yloc;
  144. regInfo.ExternalHostName = cmdparams[2];
  145. regInfo.HttpPort = externalPort;
  146. //regInfo.RemotingPort = remotingPort;
  147. try
  148. {
  149. regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0);
  150. }
  151. catch (Exception e)
  152. {
  153. m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
  154. LinkRegionCmdUsage();
  155. return;
  156. }
  157. regInfo.RemotingAddress = regInfo.ExternalEndPoint.Address.ToString();
  158. // Finally, link it
  159. try
  160. {
  161. m_sceneManager.CurrentOrFirstScene.CommsManager.GridService.RegisterRegion(regInfo);
  162. }
  163. catch (Exception e)
  164. {
  165. m_log.Warn("[HGrid] Unable to link region: " + e.StackTrace);
  166. }
  167. if (cmdparams.Length >= 5)
  168. {
  169. regInfo.RegionName = "";
  170. for (int i = 4; i < cmdparams.Length; i++)
  171. regInfo.RegionName += cmdparams[i] + " ";
  172. }
  173. }
  174. base.RunCmd(command, cmdparams);
  175. }
  176. private void LinkRegionCmdUsage()
  177. {
  178. Console.WriteLine("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
  179. }
  180. }
  181. }