LocalInterregionComms.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 OpenSim 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.Net.Sockets;
  32. using System.Reflection;
  33. using System.Threading;
  34. using System.Xml;
  35. using OpenMetaverse;
  36. using log4net;
  37. using Nini.Config;
  38. using Nwc.XmlRpc;
  39. using OpenSim.Framework;
  40. using OpenSim.Framework.Communications.Cache;
  41. using OpenSim.Region.Environment.Interfaces;
  42. using OpenSim.Region.Interfaces;
  43. using OpenSim.Region.Environment.Scenes;
  44. namespace OpenSim.Region.Environment.Modules.Communications.Local
  45. {
  46. public class LocalInterregionComms : IRegionModule, IInterregionCommsOut, IInterregionCommsIn
  47. {
  48. private bool m_enabled = false;
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private List<Scene> m_sceneList = new List<Scene>();
  51. #region Events
  52. public event ChildAgentUpdateReceived OnChildAgentUpdate;
  53. #endregion /* Events */
  54. #region IRegionModule
  55. public void Initialise(Scene scene, IConfigSource config)
  56. {
  57. if (m_sceneList.Count == 0)
  58. {
  59. IConfig startupConfig = config.Configs["Communications"];
  60. if ((startupConfig == null) ||
  61. (startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTCommms") == "LocalComms"))
  62. m_enabled = true;
  63. }
  64. if (!m_enabled)
  65. return;
  66. Init(scene);
  67. }
  68. public void PostInitialise()
  69. {
  70. }
  71. public void Close()
  72. {
  73. }
  74. public string Name
  75. {
  76. get { return "LocalInterregionCommsModule"; }
  77. }
  78. public bool IsSharedModule
  79. {
  80. get { return true; }
  81. }
  82. /// <summary>
  83. /// Can be called from other modules.
  84. /// </summary>
  85. /// <param name="scene"></param>
  86. public void Init(Scene scene)
  87. {
  88. if (!m_sceneList.Contains(scene))
  89. {
  90. lock (m_sceneList)
  91. {
  92. m_sceneList.Add(scene);
  93. if (m_enabled)
  94. scene.RegisterModuleInterface<IInterregionCommsOut>(this);
  95. scene.RegisterModuleInterface<IInterregionCommsIn>(this);
  96. }
  97. }
  98. }
  99. #endregion /* IRegionModule */
  100. #region IInterregionComms
  101. public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData)
  102. {
  103. lock (m_sceneList)
  104. {
  105. foreach (Scene s in m_sceneList)
  106. {
  107. if (s.RegionInfo.RegionHandle == regionHandle)
  108. {
  109. //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate");
  110. return s.IncomingChildAgentDataUpdate(cAgentData);
  111. //if (OnChildAgentUpdate != null)
  112. // return OnChildAgentUpdate(cAgentData);
  113. }
  114. }
  115. }
  116. m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
  117. return false;
  118. }
  119. #endregion /* IInterregionComms */
  120. }
  121. }