RegionReady.cs 5.4 KB

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