LocalPresenceServiceConnector.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 OpenSim.Region.Framework.Interfaces;
  31. using OpenSim.Region.Framework.Scenes;
  32. using OpenSim.Server.Base;
  33. using OpenSim.Services.Interfaces;
  34. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  35. using OpenMetaverse;
  36. using log4net;
  37. using Nini.Config;
  38. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
  39. {
  40. public class LocalPresenceServicesConnector : ISharedRegionModule, IPresenceService
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. private bool m_Enabled = false;
  44. private PresenceDetector m_PresenceDetector;
  45. /// <summary>
  46. /// Underlying presence service. Do not use directly.
  47. /// </summary>
  48. public IPresenceService m_PresenceService;
  49. public LocalPresenceServicesConnector()
  50. {
  51. }
  52. public LocalPresenceServicesConnector(IConfigSource source)
  53. {
  54. Initialise(source);
  55. }
  56. #region ISharedRegionModule
  57. public Type ReplaceableInterface
  58. {
  59. get { return null; }
  60. }
  61. public string Name
  62. {
  63. get { return "LocalPresenceServicesConnector"; }
  64. }
  65. public void Initialise(IConfigSource source)
  66. {
  67. IConfig moduleConfig = source.Configs["Modules"];
  68. if (moduleConfig != null)
  69. {
  70. string name = moduleConfig.GetString("PresenceServices", "");
  71. if (name == Name)
  72. {
  73. IConfig inventoryConfig = source.Configs["PresenceService"];
  74. if (inventoryConfig == null)
  75. {
  76. m_log.Error("[LOCAL PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini");
  77. return;
  78. }
  79. string serviceDll = inventoryConfig.GetString("LocalServiceModule", String.Empty);
  80. if (serviceDll == String.Empty)
  81. {
  82. m_log.Error("[LOCAL PRESENCE CONNECTOR]: No LocalServiceModule named in section PresenceService");
  83. return;
  84. }
  85. Object[] args = new Object[] { source };
  86. m_log.DebugFormat("[LOCAL PRESENCE CONNECTOR]: Service dll = {0}", serviceDll);
  87. m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(serviceDll, args);
  88. if (m_PresenceService == null)
  89. {
  90. m_log.Error("[LOCAL PRESENCE CONNECTOR]: Can't load presence service");
  91. //return;
  92. throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
  93. }
  94. //Init(source);
  95. m_PresenceDetector = new PresenceDetector(this);
  96. m_Enabled = true;
  97. m_log.Info("[LOCAL PRESENCE CONNECTOR]: Local presence connector enabled");
  98. }
  99. }
  100. }
  101. public void PostInitialise()
  102. {
  103. }
  104. public void Close()
  105. {
  106. }
  107. public void AddRegion(Scene scene)
  108. {
  109. if (!m_Enabled)
  110. return;
  111. // m_log.DebugFormat(
  112. // "[LOCAL PRESENCE CONNECTOR]: Registering IPresenceService to scene {0}", scene.RegionInfo.RegionName);
  113. scene.RegisterModuleInterface<IPresenceService>(this);
  114. m_PresenceDetector.AddRegion(scene);
  115. m_log.InfoFormat("[LOCAL PRESENCE CONNECTOR]: Enabled local presence for region {0}", scene.RegionInfo.RegionName);
  116. }
  117. public void RemoveRegion(Scene scene)
  118. {
  119. if (!m_Enabled)
  120. return;
  121. m_PresenceDetector.RemoveRegion(scene);
  122. }
  123. public void RegionLoaded(Scene scene)
  124. {
  125. if (!m_Enabled)
  126. return;
  127. }
  128. #endregion
  129. #region IPresenceService
  130. public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
  131. {
  132. m_log.Warn("[LOCAL PRESENCE CONNECTOR]: LoginAgent connector not implemented at the simulators");
  133. return false;
  134. }
  135. public bool LogoutAgent(UUID sessionID)
  136. {
  137. return m_PresenceService.LogoutAgent(sessionID);
  138. }
  139. public bool LogoutRegionAgents(UUID regionID)
  140. {
  141. return m_PresenceService.LogoutRegionAgents(regionID);
  142. }
  143. public bool ReportAgent(UUID sessionID, UUID regionID)
  144. {
  145. return m_PresenceService.ReportAgent(sessionID, regionID);
  146. }
  147. public PresenceInfo GetAgent(UUID sessionID)
  148. {
  149. return m_PresenceService.GetAgent(sessionID);
  150. }
  151. public PresenceInfo[] GetAgents(string[] userIDs)
  152. {
  153. return m_PresenceService.GetAgents(userIDs);
  154. }
  155. #endregion
  156. }
  157. }