aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs170
1 files changed, 170 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
new file mode 100644
index 0000000..1b02bb0
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
@@ -0,0 +1,170 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31
32using log4net;
33using Nini.Config;
34using OpenMetaverse;
35
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39
40namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
41{
42 public class RegionReadyModule : INonSharedRegionModule
43 {
44 private static readonly ILog m_log =
45 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 private IConfig m_config = null;
48 private bool m_firstEmptyCompileQueue;
49 private bool m_oarFileLoading;
50 private bool m_lastOarLoadedOk;
51 private int m_channelNotify = -1000;
52 private bool m_enabled = false;
53
54 Scene m_scene = null;
55
56 #region INonSharedRegionModule interface
57
58 public Type ReplaceableInterface
59 {
60 get { return null; }
61 }
62
63 public void Initialise(IConfigSource config)
64 {
65 m_log.Info("[RegionReady] Initialising");
66
67 m_config = config.Configs["RegionReady"];
68
69 if (m_config != null)
70 {
71 m_enabled = m_config.GetBoolean("enabled", false);
72 if (m_enabled)
73 {
74 m_channelNotify = m_config.GetInt("channel_notify", m_channelNotify);
75 }
76 }
77
78 if (!m_enabled)
79 m_log.Info("[RegionReady] disabled.");
80 }
81
82 public void AddRegion(Scene scene)
83 {
84 if (!m_enabled)
85 return;
86
87 m_firstEmptyCompileQueue = true;
88 m_oarFileLoading = false;
89 m_lastOarLoadedOk = true;
90
91 m_scene = scene;
92
93 m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue;
94 m_scene.EventManager.OnOarFileLoaded += OnOarFileLoaded;
95
96 m_log.InfoFormat("[RegionReady]: Enabled for region {0}", scene.RegionInfo.RegionName);
97 }
98
99 public void RemoveRegion(Scene scene)
100 {
101 if (!m_enabled)
102 return;
103
104 m_scene.EventManager.OnEmptyScriptCompileQueue -= OnEmptyScriptCompileQueue;
105 m_scene.EventManager.OnOarFileLoaded -= OnOarFileLoaded;
106
107 m_scene = null;
108 }
109
110 public void Close()
111 {
112 }
113
114 public void RegionLoaded(Scene scene)
115 {
116 }
117
118 public string Name
119 {
120 get { return "RegionReadyModule"; }
121 }
122
123 #endregion
124
125
126 void OnEmptyScriptCompileQueue(int numScriptsFailed, string message)
127 {
128 if (m_firstEmptyCompileQueue || m_oarFileLoading)
129 {
130 OSChatMessage c = new OSChatMessage();
131 if (m_firstEmptyCompileQueue)
132 c.Message = "server_startup,";
133 else
134 c.Message = "oar_file_load,";
135 m_firstEmptyCompileQueue = false;
136 m_oarFileLoading = false;
137
138 m_scene.Backup();
139
140 c.From = "RegionReady";
141 if (m_lastOarLoadedOk)
142 c.Message += "1,";
143 else
144 c.Message += "0,";
145 c.Channel = m_channelNotify;
146 c.Message += numScriptsFailed.ToString() + "," + message;
147 c.Type = ChatTypeEnum.Region;
148 c.Position = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30);
149 c.Sender = null;
150 c.SenderUUID = UUID.Zero;
151
152 m_log.InfoFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}",
153 m_scene.RegionInfo.RegionName, c.Message, m_channelNotify);
154 m_scene.EventManager.TriggerOnChatBroadcast(this, c);
155 }
156 }
157
158 void OnOarFileLoaded(Guid requestId, string message)
159 {
160 m_oarFileLoading = true;
161 if (message==String.Empty)
162 {
163 m_lastOarLoadedOk = true;
164 } else {
165 m_log.InfoFormat("[RegionReady]: Oar file load errors: {0}", message);
166 m_lastOarLoadedOk = false;
167 }
168 }
169 }
170}