HGOpenSimNode.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. private 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. MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-URI", "link-URI <URL of xml files>", "ok", RunCommand);
  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(
  111. regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager,
  112. m_moduleLoader, m_configSettings.DumpAssetsToFile, m_configSettings.PhysicalPrim,
  113. m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
  114. }
  115. new void RunCommand(string module, string[] cp)
  116. {
  117. List<string> cmdparams = new List<string>(cp);
  118. if (cmdparams.Count < 1)
  119. return;
  120. string command = cmdparams[0];
  121. cmdparams.RemoveAt(0);
  122. if (command.Equals("link-URI"))
  123. {
  124. if (cmdparams.Count > 1 | cmdparams.Count < 1)
  125. {
  126. m_log.Info("Invalid usage");
  127. m_log.Info("link-URI <URL of xml files>");
  128. return;
  129. }
  130. m_log.Info(cmdparams[0].ToString());
  131. LoadXmlLinkFile(cmdparams[0].ToString());
  132. }
  133. if (command.Equals("link-mapping"))
  134. {
  135. if (cmdparams.Count == 2)
  136. {
  137. try
  138. {
  139. // m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
  140. // m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
  141. // m_enableAutoMapping = true;
  142. }
  143. catch (Exception)
  144. {
  145. // m_autoMappingX = 0;
  146. // m_autoMappingY = 0;
  147. // m_enableAutoMapping = false;
  148. }
  149. }
  150. }
  151. else if (command.Equals("link-region"))
  152. {
  153. if (cmdparams.Count < 3)
  154. {
  155. LinkRegionCmdUsage();
  156. return;
  157. }
  158. if (cmdparams[2].Contains(":"))
  159. { // New format
  160. uint xloc, yloc;
  161. string mapName;
  162. try
  163. {
  164. xloc = Convert.ToUInt32(cmdparams[0]);
  165. yloc = Convert.ToUInt32(cmdparams[1]);
  166. mapName = cmdparams[2];
  167. if (cmdparams.Count > 3)
  168. for (int i = 3; i < cmdparams.Count; i++)
  169. mapName += " " + cmdparams[i];
  170. Console.WriteLine(">> MapName: " + mapName);
  171. //internalPort = Convert.ToUInt32(cmdparams[4]);
  172. //remotingPort = Convert.ToUInt32(cmdparams[5]);
  173. }
  174. catch (Exception e)
  175. {
  176. m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
  177. LinkRegionCmdUsage();
  178. return;
  179. }
  180. HGHyperlink.TryLinkRegionToCoords(m_sceneManager.CurrentOrFirstScene, null, mapName, xloc, yloc);
  181. }
  182. else
  183. { // old format
  184. RegionInfo regInfo;
  185. uint xloc, yloc;
  186. uint externalPort;
  187. string externalHostName;
  188. try
  189. {
  190. xloc = Convert.ToUInt32(cmdparams[0]);
  191. yloc = Convert.ToUInt32(cmdparams[1]);
  192. externalPort = Convert.ToUInt32(cmdparams[3]);
  193. externalHostName = cmdparams[2];
  194. //internalPort = Convert.ToUInt32(cmdparams[4]);
  195. //remotingPort = Convert.ToUInt32(cmdparams[5]);
  196. }
  197. catch (Exception e)
  198. {
  199. m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
  200. LinkRegionCmdUsage();
  201. return;
  202. }
  203. //if (TryCreateLink(xloc, yloc, externalPort, externalHostName, out regInfo))
  204. if (HGHyperlink.TryCreateLink(m_sceneManager.CurrentOrFirstScene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo))
  205. {
  206. if (cmdparams.Count >= 5)
  207. {
  208. regInfo.RegionName = "";
  209. for (int i = 4; i < cmdparams.Count; i++)
  210. regInfo.RegionName += cmdparams[i] + " ";
  211. }
  212. }
  213. }
  214. return;
  215. }
  216. }
  217. private void LoadXmlLinkFile(string URI)
  218. {
  219. //use http://www.hgurl.com/hypergrid.xml for test
  220. RegionInfo RegInfo;
  221. try
  222. {
  223. XmlReader r = XmlReader.Create(URI);
  224. XmlConfigSource reader = new XmlConfigSource(r);
  225. for (int t = 0; t < reader.Configs.Count; t++)
  226. {
  227. m_log.Info(reader.Configs[t].Name);
  228. m_log.Info(reader.Configs[t].Get("xloc").ToString());
  229. string region_Name = reader.Configs[t].Name;
  230. uint xloc = (uint)reader.Configs[t].GetInt("xloc");
  231. uint yloc = (uint)reader.Configs[t].GetInt("yloc");
  232. uint externalPort = (uint)reader.Configs[t].GetInt("externalPort");
  233. string externalHostName = reader.Configs[t].Get("externalHostName");
  234. HGHyperlink.TryCreateLink(m_sceneManager.CurrentOrFirstScene, null, xloc, yloc, region_Name, externalPort, externalHostName, out RegInfo);
  235. }
  236. r.Close();
  237. }
  238. catch (Exception e)
  239. {
  240. m_log.Info(e.ToString());
  241. }
  242. }
  243. /*
  244. private void LoadXmlLinkFile(string[] cmdparams)
  245. {
  246. try
  247. {
  248. XmlReader r = XmlReader.Create(cmdparams[0]);
  249. XmlConfigSource cs = new XmlConfigSource(r);
  250. string[] excludeSections = null;
  251. if (cmdparams.Length == 2)
  252. {
  253. if (cmdparams[1].ToLower().StartsWith("excludelist:"))
  254. {
  255. string excludeString = cmdparams[1].ToLower();
  256. excludeString = excludeString.Remove(0, 12);
  257. char[] splitter = { ';' };
  258. excludeSections = excludeString.Split(splitter);
  259. }
  260. }
  261. for (int i = 0; i < cs.Configs.Count; i++)
  262. {
  263. bool skip = false;
  264. if ((excludeSections != null) && (excludeSections.Length > 0))
  265. {
  266. for (int n = 0; n < excludeSections.Length; n++)
  267. {
  268. if (excludeSections[n] == cs.Configs[i].Name.ToLower())
  269. {
  270. skip = true;
  271. break;
  272. }
  273. }
  274. }
  275. if (!skip)
  276. {
  277. ReadLinkFromConfig(cs.Configs[i]);
  278. }
  279. }
  280. }
  281. catch (Exception e)
  282. {
  283. Console.WriteLine(e.ToString());
  284. }
  285. }
  286. */
  287. /*
  288. private void ReadLinkFromConfig(IConfig config)
  289. {
  290. RegionInfo regInfo;
  291. uint xloc, yloc;
  292. uint externalPort;
  293. string externalHostName;
  294. uint realXLoc, realYLoc;
  295. xloc = Convert.ToUInt32(config.GetString("xloc", "0"));
  296. yloc = Convert.ToUInt32(config.GetString("yloc", "0"));
  297. externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
  298. externalHostName = config.GetString("externalHostName", "");
  299. realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
  300. realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
  301. if (m_enableAutoMapping)
  302. {
  303. xloc = (uint)((xloc % 100) + m_autoMappingX);
  304. yloc = (uint)((yloc % 100) + m_autoMappingY);
  305. }
  306. if (((realXLoc == 0) && (realYLoc == 0)) || (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
  307. {
  308. if (HGHyperlink.TryCreateLink(m_sceneManager.CurrentOrFirstScene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo))
  309. {
  310. regInfo.RegionName = config.GetString("localName", "");
  311. }
  312. }
  313. }
  314. */
  315. private void LinkRegionCmdUsage()
  316. {
  317. Console.WriteLine("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
  318. Console.WriteLine("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
  319. }
  320. }
  321. }