RemoteNeighourServiceConnector.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 log4net;
  28. using Mono.Addins;
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Reflection;
  32. using Nini.Config;
  33. using OpenSim.Framework;
  34. using OpenSim.Services.Connectors;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Services.Interfaces;
  38. using OpenSim.Server.Base;
  39. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Neighbour
  40. {
  41. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteNeighbourServicesConnector")]
  42. public class RemoteNeighbourServicesConnector :
  43. NeighbourServicesConnector, ISharedRegionModule, INeighbourService
  44. {
  45. private static readonly ILog m_log =
  46. LogManager.GetLogger(
  47. MethodBase.GetCurrentMethod().DeclaringType);
  48. private bool m_Enabled = false;
  49. private LocalNeighbourServicesConnector m_LocalService;
  50. //private string serviceDll;
  51. //private List<Scene> m_Scenes = new List<Scene>();
  52. public Type ReplaceableInterface
  53. {
  54. get { return null; }
  55. }
  56. public string Name
  57. {
  58. get { return "RemoteNeighbourServicesConnector"; }
  59. }
  60. public void Initialise(IConfigSource source)
  61. {
  62. IConfig moduleConfig = source.Configs["Modules"];
  63. if (moduleConfig != null)
  64. {
  65. string name = moduleConfig.GetString("NeighbourServices");
  66. if (name == Name)
  67. {
  68. m_LocalService = new LocalNeighbourServicesConnector();
  69. //IConfig neighbourConfig = source.Configs["NeighbourService"];
  70. //if (neighbourConfig == null)
  71. //{
  72. // m_log.Error("[NEIGHBOUR CONNECTOR]: NeighbourService missing from OpenSim.ini");
  73. // return;
  74. //}
  75. //serviceDll = neighbourConfig.GetString("LocalServiceModule", String.Empty);
  76. //if (serviceDll == String.Empty)
  77. //{
  78. // m_log.Error("[NEIGHBOUR CONNECTOR]: No LocalServiceModule named in section NeighbourService");
  79. // return;
  80. //}
  81. m_Enabled = true;
  82. m_log.Info("[NEIGHBOUR CONNECTOR]: Remote Neighbour connector enabled");
  83. }
  84. }
  85. }
  86. public void PostInitialise()
  87. {
  88. //if (m_Enabled)
  89. //{
  90. // Object[] args = new Object[] { m_Scenes };
  91. // m_LocalService =
  92. // ServerUtils.LoadPlugin<INeighbourService>(serviceDll,
  93. // args);
  94. // if (m_LocalService == null)
  95. // {
  96. // m_log.Error("[NEIGHBOUR CONNECTOR]: Can't load neighbour service");
  97. // Unregister();
  98. // return;
  99. // }
  100. //}
  101. }
  102. public void Close()
  103. {
  104. }
  105. public void AddRegion(Scene scene)
  106. {
  107. if (!m_Enabled)
  108. return;
  109. m_LocalService.AddRegion(scene);
  110. scene.RegisterModuleInterface<INeighbourService>(this);
  111. }
  112. public void RemoveRegion(Scene scene)
  113. {
  114. if (m_Enabled)
  115. m_LocalService.RemoveRegion(scene);
  116. }
  117. public void RegionLoaded(Scene scene)
  118. {
  119. if (!m_Enabled)
  120. return;
  121. m_GridService = scene.GridService;
  122. m_log.InfoFormat("[NEIGHBOUR CONNECTOR]: Enabled remote neighbours for region {0}", scene.RegionInfo.RegionName);
  123. }
  124. #region INeighbourService
  125. public override GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion)
  126. {
  127. GridRegion region = m_LocalService.HelloNeighbour(regionHandle, thisRegion);
  128. if (region != null)
  129. return region;
  130. return base.HelloNeighbour(regionHandle, thisRegion);
  131. }
  132. #endregion INeighbourService
  133. }
  134. }