29 using System.Collections.Generic;
30 using System.Reflection;
38 using OpenMetaverse.StructuredData;
39 using OpenSim.Framework;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Services.Interfaces;
46 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"RegionReadyModule")]
49 private static readonly ILog m_log =
50 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private IConfig m_config = null;
53 private bool m_firstEmptyCompileQueue;
54 private bool m_oarFileLoading;
55 private bool m_lastOarLoadedOk;
56 private int m_channelNotify = -1000;
57 private bool m_enabled =
false;
58 private bool m_disable_logins;
59 private string m_uri = string.Empty;
63 #region INonSharedRegionModule interface
65 public Type ReplaceableInterface
72 m_config = config.Configs[
"RegionReady"];
75 m_enabled = m_config.GetBoolean(
"enabled",
false);
79 m_channelNotify = m_config.GetInt(
"channel_notify", m_channelNotify);
80 m_disable_logins = m_config.GetBoolean(
"login_disable",
false);
81 m_uri = m_config.GetString(
"alert_uri",string.Empty);
95 m_firstEmptyCompileQueue =
true;
96 m_oarFileLoading =
false;
97 m_lastOarLoadedOk =
true;
99 m_scene.EventManager.OnOarFileLoaded += OnOarFileLoaded;
101 m_log.DebugFormat(
"[RegionReady]: Enabled for region {0}", scene.RegionInfo.RegionName);
103 if (m_disable_logins)
105 m_scene.LoginLock =
true;
106 m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue;
111 MainConsole.Instance.OutputFormat(
"Region {0} - LOGINS DISABLED DURING INITIALIZATION.", m_scene.Name);
113 if (m_uri !=
string.Empty)
125 m_scene.EventManager.OnOarFileLoaded -= OnOarFileLoaded;
127 if (m_disable_logins)
128 m_scene.EventManager.OnEmptyScriptCompileQueue -= OnEmptyScriptCompileQueue;
130 if (m_uri !=
string.Empty)
146 get {
return "RegionReadyModule"; }
151 void OnEmptyScriptCompileQueue(
int numScriptsFailed,
string message)
153 m_log.DebugFormat(
"[RegionReady]: Script compile queue empty!");
155 if (m_firstEmptyCompileQueue || m_oarFileLoading)
158 if (m_firstEmptyCompileQueue)
159 c.Message =
"server_startup,";
161 c.Message =
"oar_file_load,";
162 m_firstEmptyCompileQueue =
false;
163 m_oarFileLoading =
false;
165 m_scene.Backup(
false);
167 c.From =
"RegionReady";
168 if (m_lastOarLoadedOk)
172 c.Channel = m_channelNotify;
173 c.Message += numScriptsFailed.ToString() +
"," + message;
174 c.Type = ChatTypeEnum.Region;
176 c.Position =
new Vector3((m_scene.RegionInfo.RegionSizeX * 0.5f), (m_scene.RegionInfo.RegionSizeY * 0.5f), 30);
180 c.SenderUUID = UUID.Zero;
183 m_log.DebugFormat(
"[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}",
184 m_scene.RegionInfo.RegionName, c.Message, m_channelNotify);
186 m_scene.EventManager.TriggerOnChatBroadcast(
this, c);
188 TriggerRegionReady(m_scene);
192 void OnOarFileLoaded(Guid requestId, List<UUID> loadedScenes,
string message)
194 m_oarFileLoading =
true;
196 if (message==
String.Empty)
198 m_lastOarLoadedOk =
true;
202 m_log.WarnFormat(
"[RegionReady]: Oar file load errors: {0}", message);
203 m_lastOarLoadedOk =
false;
214 m_scene.EventManager.OnEmptyScriptCompileQueue -= OnEmptyScriptCompileQueue;
215 m_scene.LoginLock =
false;
217 if (!m_scene.StartDisabled)
219 m_scene.LoginsEnabled =
true;
228 MainConsole.Instance.OutputFormat(
"INITIALIZATION COMPLETE FOR {0} - LOGINS ENABLED", m_scene.Name);
231 m_scene.SceneGridService.InformNeighborsThatRegionisUp(
234 if (m_uri !=
string.Empty)
239 m_scene.Ready =
true;
268 string request_method =
"POST";
269 string content_type =
"application/json";
272 RRAlert[
"alert"] =
"region_ready";
273 RRAlert[
"login"] = status;
274 RRAlert[
"region_name"] = m_scene.RegionInfo.RegionName;
275 RRAlert[
"region_id"] = m_scene.RegionInfo.RegionID;
277 string strBuffer =
"";
278 byte[] buffer =
new byte[1];
281 strBuffer = OSDParser.SerializeJsonString(RRAlert);
282 Encoding str = Util.UTF8;
283 buffer = str.GetBytes(strBuffer);
288 m_log.WarnFormat(
"[RegionReady]: Exception thrown on alert: {0}", e.Message);
291 WebRequest request = WebRequest.Create(m_uri);
292 request.Method = request_method;
293 request.ContentType = content_type;
298 request.ContentLength = buffer.Length;
299 os = request.GetRequestStream();
300 os.Write(buffer, 0, strBuffer.Length);
304 m_log.WarnFormat(
"[RegionReady]: Exception thrown sending alert: {0}", e.Message);
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
OpenMetaverse.StructuredData.OSDMap OSDMap
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void OarLoadingAlert(string msg)
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void RRAlert(string status)
Interactive OpenSim region server
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void TriggerRegionReady(IScene scene)
This will be triggered by Scene directly if it contains no scripts on startup. Otherwise it is trigge...