HGOpenSimNode.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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.Reflection;
  30. using System.Xml;
  31. using log4net;
  32. using Nini.Config;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications;
  35. using OpenSim.Framework.Communications.Cache;
  36. using OpenSim.Framework.Console;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Region.Communications.Hypergrid;
  39. using OpenSim.Region.Communications.Local;
  40. using OpenSim.Region.Framework;
  41. using OpenSim.Region.Framework.Scenes;
  42. using OpenSim.Region.Framework.Scenes.Hypergrid;
  43. namespace OpenSim
  44. {
  45. public class HGOpenSimNode : OpenSim
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. public IHyperlink HGServices = null;
  49. private uint m_autoMappingX = 0;
  50. private uint m_autoMappingY = 0;
  51. private bool m_enableAutoMapping = false;
  52. public HGOpenSimNode(IConfigSource configSource) : base(configSource)
  53. {
  54. }
  55. /// <summary>
  56. /// Performs initialisation of the scene, such as loading configuration from disk.
  57. /// </summary>
  58. protected override void StartupSpecific()
  59. {
  60. m_log.Info("====================================================================");
  61. m_log.Info("=================== STARTING HYPERGRID NODE ========================");
  62. m_log.Info("====================================================================");
  63. base.StartupSpecific();
  64. MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [<x> <y>] <cr>", "Set local coordinate to map HG regions to", RunCommand);
  65. MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-region", "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", "Link a hypergrid region", RunCommand);
  66. }
  67. //protected override void InitialiseStandaloneServices(LibraryRootFolder libraryRootFolder)
  68. //{
  69. // // Standalone mode
  70. // HGInventoryService inventoryService = new HGInventoryService(m_networkServersInfo.InventoryURL, null, false);
  71. // inventoryService.AddPlugin(m_configSettings.StandaloneInventoryPlugin, m_configSettings.StandaloneInventorySource);
  72. // LocalUserServices userService =
  73. // new LocalUserServices(
  74. // m_networkServersInfo.DefaultHomeLocX, m_networkServersInfo.DefaultHomeLocY, inventoryService);
  75. // userService.AddPlugin(m_configSettings.StandaloneUserPlugin, m_configSettings.StandaloneUserSource);
  76. // //LocalBackEndServices backendService = new LocalBackEndServices();
  77. // HGGridServicesStandalone gridService = new HGGridServicesStandalone(m_networkServersInfo, m_httpServer, m_assetCache, m_sceneManager);
  78. // LocalLoginService loginService =
  79. // new LocalLoginService(
  80. // userService, m_configSettings.StandaloneWelcomeMessage, inventoryService, gridService.LocalBackend, m_networkServersInfo,
  81. // m_configSettings.StandaloneAuthenticate, libraryRootFolder);
  82. // m_commsManager = new HGCommunicationsStandalone(m_networkServersInfo, m_httpServer, m_assetCache,
  83. // userService, userService, inventoryService, gridService, userService, libraryRootFolder, m_configSettings.DumpAssetsToFile);
  84. // inventoryService.UserProfileCache = m_commsManager.UserProfileCacheService;
  85. // HGServices = gridService;
  86. // // set up XMLRPC handler for client's initial login request message
  87. // m_httpServer.AddXmlRPCHandler("login_to_simulator", loginService.XmlRpcLoginMethod);
  88. // // provides the web form login
  89. // m_httpServer.AddHTTPHandler("login", loginService.ProcessHTMLLogin);
  90. // // Provides the LLSD login
  91. // m_httpServer.SetDefaultLLSDHandler(loginService.LLSDLoginMethod);
  92. // // provide grid info
  93. // // m_gridInfoService = new GridInfoService(m_config.Source.Configs["Startup"].GetString("inifile", Path.Combine(Util.configDir(), "OpenSim.ini")));
  94. // m_gridInfoService = new GridInfoService(m_config.Source);
  95. // m_httpServer.AddXmlRPCHandler("get_grid_info", m_gridInfoService.XmlRpcGridInfoMethod);
  96. // m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info", m_gridInfoService.RestGetGridInfoMethod));
  97. //}
  98. //protected override void InitialiseGridServices(LibraryRootFolder libraryRootFolder)
  99. //{
  100. // m_commsManager = new HGCommunicationsGridMode(m_networkServersInfo, m_httpServer, m_assetCache, m_sceneManager, libraryRootFolder);
  101. // HGServices = ((HGCommunicationsGridMode)m_commsManager).HGServices;
  102. // m_httpServer.AddStreamHandler(new SimStatusHandler());
  103. //}
  104. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  105. AgentCircuitManager circuitManager)
  106. {
  107. HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices);
  108. return
  109. new HGScene(
  110. regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager,
  111. m_moduleLoader, m_configSettings.DumpAssetsToFile, m_configSettings.PhysicalPrim,
  112. m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
  113. }
  114. new void RunCommand(string module, string[] cp)
  115. {
  116. List<string> cmdparams = new List<string>(cp);
  117. if (cmdparams.Count < 1)
  118. return;
  119. string command = cmdparams[0];
  120. cmdparams.RemoveAt(0);
  121. if (command.Equals("link-mapping"))
  122. {
  123. if (cmdparams.Count == 2)
  124. {
  125. try
  126. {
  127. m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
  128. m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
  129. m_enableAutoMapping = true;
  130. }
  131. catch (Exception)
  132. {
  133. m_autoMappingX = 0;
  134. m_autoMappingY = 0;
  135. m_enableAutoMapping = false;
  136. }
  137. }
  138. }
  139. else if (command.Equals("link-region"))
  140. {
  141. if (cmdparams.Count < 3)
  142. {
  143. if ((cmdparams.Count == 1) || (cmdparams.Count == 2))
  144. {
  145. LoadXmlLinkFile(cmdparams);
  146. }
  147. else
  148. {
  149. LinkRegionCmdUsage();
  150. }
  151. return;
  152. }
  153. if (cmdparams[2].Contains(":"))
  154. { // New format
  155. uint xloc, yloc;
  156. string mapName;
  157. try
  158. {
  159. xloc = Convert.ToUInt32(cmdparams[0]);
  160. yloc = Convert.ToUInt32(cmdparams[1]);
  161. mapName = cmdparams[2];
  162. if (cmdparams.Count > 3)
  163. for (int i = 3; i < cmdparams.Count; i++)
  164. mapName += " " + cmdparams[i];
  165. m_log.Info(">> MapName: " + mapName);
  166. //internalPort = Convert.ToUInt32(cmdparams[4]);
  167. //remotingPort = Convert.ToUInt32(cmdparams[5]);
  168. }
  169. catch (Exception e)
  170. {
  171. m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
  172. LinkRegionCmdUsage();
  173. return;
  174. }
  175. HGHyperlink.TryLinkRegionToCoords(m_sceneManager.CurrentOrFirstScene, null, mapName, xloc, yloc);
  176. }
  177. else
  178. { // old format
  179. RegionInfo regInfo;
  180. uint xloc, yloc;
  181. uint externalPort;
  182. string externalHostName;
  183. try
  184. {
  185. xloc = Convert.ToUInt32(cmdparams[0]);
  186. yloc = Convert.ToUInt32(cmdparams[1]);
  187. externalPort = Convert.ToUInt32(cmdparams[3]);
  188. externalHostName = cmdparams[2];
  189. //internalPort = Convert.ToUInt32(cmdparams[4]);
  190. //remotingPort = Convert.ToUInt32(cmdparams[5]);
  191. }
  192. catch (Exception e)
  193. {
  194. m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
  195. LinkRegionCmdUsage();
  196. return;
  197. }
  198. //if (TryCreateLink(xloc, yloc, externalPort, externalHostName, out regInfo))
  199. if (HGHyperlink.TryCreateLink(m_sceneManager.CurrentOrFirstScene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo))
  200. {
  201. if (cmdparams.Count >= 5)
  202. {
  203. regInfo.RegionName = "";
  204. for (int i = 4; i < cmdparams.Count; i++)
  205. regInfo.RegionName += cmdparams[i] + " ";
  206. }
  207. }
  208. }
  209. return;
  210. }
  211. }
  212. private void LoadXmlLinkFile(List<string> cmdparams)
  213. {
  214. //use http://www.hgurl.com/hypergrid.xml for test
  215. try
  216. {
  217. XmlReader r = XmlReader.Create(cmdparams[0]);
  218. XmlConfigSource cs = new XmlConfigSource(r);
  219. string[] excludeSections = null;
  220. if (cmdparams.Count == 2)
  221. {
  222. if (cmdparams[1].ToLower().StartsWith("excludelist:"))
  223. {
  224. string excludeString = cmdparams[1].ToLower();
  225. excludeString = excludeString.Remove(0, 12);
  226. char[] splitter = { ';' };
  227. excludeSections = excludeString.Split(splitter);
  228. }
  229. }
  230. for (int i = 0; i < cs.Configs.Count; i++)
  231. {
  232. bool skip = false;
  233. if ((excludeSections != null) && (excludeSections.Length > 0))
  234. {
  235. for (int n = 0; n < excludeSections.Length; n++)
  236. {
  237. if (excludeSections[n] == cs.Configs[i].Name.ToLower())
  238. {
  239. skip = true;
  240. break;
  241. }
  242. }
  243. }
  244. if (!skip)
  245. {
  246. ReadLinkFromConfig(cs.Configs[i]);
  247. }
  248. }
  249. }
  250. catch (Exception e)
  251. {
  252. m_log.Error(e.ToString());
  253. }
  254. }
  255. private void ReadLinkFromConfig(IConfig config)
  256. {
  257. RegionInfo regInfo;
  258. uint xloc, yloc;
  259. uint externalPort;
  260. string externalHostName;
  261. uint realXLoc, realYLoc;
  262. xloc = Convert.ToUInt32(config.GetString("xloc", "0"));
  263. yloc = Convert.ToUInt32(config.GetString("yloc", "0"));
  264. externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
  265. externalHostName = config.GetString("externalHostName", "");
  266. realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
  267. realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
  268. if (m_enableAutoMapping)
  269. {
  270. xloc = (uint)((xloc % 100) + m_autoMappingX);
  271. yloc = (uint)((yloc % 100) + m_autoMappingY);
  272. }
  273. if (((realXLoc == 0) && (realYLoc == 0)) || (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
  274. {
  275. if (HGHyperlink.TryCreateLink(m_sceneManager.CurrentOrFirstScene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo))
  276. {
  277. regInfo.RegionName = config.GetString("localName", "");
  278. }
  279. }
  280. }
  281. private void LinkRegionCmdUsage()
  282. {
  283. m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
  284. m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
  285. m_log.Info("Usage: link-region <URI_of_xml> [<exclude>]");
  286. }
  287. }
  288. }