RegionReadyModule.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
  37. {
  38. public class RegionReadyModule : INonSharedRegionModule
  39. {
  40. private static readonly ILog m_log =
  41. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  42. private IConfig m_config = null;
  43. private bool m_firstEmptyCompileQueue;
  44. private bool m_oarFileLoading;
  45. private bool m_lastOarLoadedOk;
  46. private int m_channelNotify = -1000;
  47. private bool m_enabled = false;
  48. Scene m_scene = null;
  49. #region INonSharedRegionModule interface
  50. public Type ReplaceableInterface
  51. {
  52. get { return null; }
  53. }
  54. public void Initialise(IConfigSource config)
  55. {
  56. //m_log.Info("[RegionReady] Initialising");
  57. m_config = config.Configs["RegionReady"];
  58. if (m_config != null)
  59. {
  60. m_enabled = m_config.GetBoolean("enabled", false);
  61. if (m_enabled)
  62. {
  63. m_channelNotify = m_config.GetInt("channel_notify", m_channelNotify);
  64. }
  65. }
  66. // if (!m_enabled)
  67. // m_log.Info("[RegionReady] disabled.");
  68. }
  69. public void AddRegion(Scene scene)
  70. {
  71. if (!m_enabled)
  72. return;
  73. m_firstEmptyCompileQueue = true;
  74. m_oarFileLoading = false;
  75. m_lastOarLoadedOk = true;
  76. m_scene = scene;
  77. m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue;
  78. m_scene.EventManager.OnOarFileLoaded += OnOarFileLoaded;
  79. m_log.DebugFormat("[RegionReady]: Enabled for region {0}", scene.RegionInfo.RegionName);
  80. }
  81. public void RemoveRegion(Scene scene)
  82. {
  83. if (!m_enabled)
  84. return;
  85. m_scene.EventManager.OnEmptyScriptCompileQueue -= OnEmptyScriptCompileQueue;
  86. m_scene.EventManager.OnOarFileLoaded -= OnOarFileLoaded;
  87. m_scene = null;
  88. }
  89. public void Close()
  90. {
  91. }
  92. public void RegionLoaded(Scene scene)
  93. {
  94. }
  95. public string Name
  96. {
  97. get { return "RegionReadyModule"; }
  98. }
  99. #endregion
  100. void OnEmptyScriptCompileQueue(int numScriptsFailed, string message)
  101. {
  102. if (m_firstEmptyCompileQueue || m_oarFileLoading)
  103. {
  104. OSChatMessage c = new OSChatMessage();
  105. if (m_firstEmptyCompileQueue)
  106. c.Message = "server_startup,";
  107. else
  108. c.Message = "oar_file_load,";
  109. m_firstEmptyCompileQueue = false;
  110. m_oarFileLoading = false;
  111. m_scene.Backup();
  112. c.From = "RegionReady";
  113. if (m_lastOarLoadedOk)
  114. c.Message += "1,";
  115. else
  116. c.Message += "0,";
  117. c.Channel = m_channelNotify;
  118. c.Message += numScriptsFailed.ToString() + "," + message;
  119. c.Type = ChatTypeEnum.Region;
  120. c.Position = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30);
  121. c.Sender = null;
  122. c.SenderUUID = UUID.Zero;
  123. c.Scene = m_scene;
  124. m_log.InfoFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}",
  125. m_scene.RegionInfo.RegionName, c.Message, m_channelNotify);
  126. m_scene.EventManager.TriggerOnChatBroadcast(this, c);
  127. }
  128. }
  129. void OnOarFileLoaded(Guid requestId, string message)
  130. {
  131. m_oarFileLoading = true;
  132. if (message==String.Empty)
  133. {
  134. m_lastOarLoadedOk = true;
  135. } else {
  136. m_log.InfoFormat("[RegionReady]: Oar file load errors: {0}", message);
  137. m_lastOarLoadedOk = false;
  138. }
  139. }
  140. }
  141. }