diff options
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs | 92 |
1 files changed, 90 insertions, 2 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs index 122ad40..eed6450 100644 --- a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs | |||
@@ -28,10 +28,14 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Net; | ||
32 | using System.IO; | ||
33 | using System.Text; | ||
31 | 34 | ||
32 | using log4net; | 35 | using log4net; |
33 | using Nini.Config; | 36 | using Nini.Config; |
34 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | using OpenMetaverse.StructuredData; | ||
35 | 39 | ||
36 | using OpenSim.Framework; | 40 | using OpenSim.Framework; |
37 | using OpenSim.Region.Framework.Interfaces; | 41 | using OpenSim.Region.Framework.Interfaces; |
@@ -50,6 +54,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
50 | private bool m_lastOarLoadedOk; | 54 | private bool m_lastOarLoadedOk; |
51 | private int m_channelNotify = -1000; | 55 | private int m_channelNotify = -1000; |
52 | private bool m_enabled = false; | 56 | private bool m_enabled = false; |
57 | private bool m_disable_logins = false; | ||
58 | private string m_uri = string.Empty; | ||
53 | 59 | ||
54 | Scene m_scene = null; | 60 | Scene m_scene = null; |
55 | 61 | ||
@@ -68,10 +74,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
68 | if (m_config != null) | 74 | if (m_config != null) |
69 | { | 75 | { |
70 | m_enabled = m_config.GetBoolean("enabled", false); | 76 | m_enabled = m_config.GetBoolean("enabled", false); |
77 | |||
71 | if (m_enabled) | 78 | if (m_enabled) |
72 | { | 79 | { |
73 | m_channelNotify = m_config.GetInt("channel_notify", m_channelNotify); | 80 | m_channelNotify = m_config.GetInt("channel_notify", m_channelNotify); |
74 | } | 81 | m_disable_logins = m_config.GetBoolean("login_disable", false); |
82 | m_uri = m_config.GetString("alert_uri",string.Empty); | ||
83 | } | ||
75 | } | 84 | } |
76 | 85 | ||
77 | // if (!m_enabled) | 86 | // if (!m_enabled) |
@@ -91,8 +100,21 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
91 | 100 | ||
92 | m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue; | 101 | m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue; |
93 | m_scene.EventManager.OnOarFileLoaded += OnOarFileLoaded; | 102 | m_scene.EventManager.OnOarFileLoaded += OnOarFileLoaded; |
103 | m_scene.EventManager.OnLoginsEnabled += OnLoginsEnabled; | ||
94 | 104 | ||
95 | m_log.DebugFormat("[RegionReady]: Enabled for region {0}", scene.RegionInfo.RegionName); | 105 | m_log.DebugFormat("[RegionReady]: Enabled for region {0}", scene.RegionInfo.RegionName); |
106 | |||
107 | if(m_disable_logins == true) | ||
108 | { | ||
109 | scene.LoginLock = true; | ||
110 | scene.LoginsDisabled = true; | ||
111 | m_log.InfoFormat("[RegionReady]: Logins disabled for {0}",m_scene.RegionInfo.RegionName); | ||
112 | |||
113 | if(m_uri != string.Empty) | ||
114 | { | ||
115 | RRAlert("disabled"); | ||
116 | } | ||
117 | } | ||
96 | } | 118 | } |
97 | 119 | ||
98 | public void RemoveRegion(Scene scene) | 120 | public void RemoveRegion(Scene scene) |
@@ -150,7 +172,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
150 | 172 | ||
151 | m_log.InfoFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}", | 173 | m_log.InfoFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}", |
152 | m_scene.RegionInfo.RegionName, c.Message, m_channelNotify); | 174 | m_scene.RegionInfo.RegionName, c.Message, m_channelNotify); |
153 | m_scene.EventManager.TriggerOnChatBroadcast(this, c); | 175 | |
176 | m_scene.EventManager.TriggerOnChatBroadcast(this, c); | ||
177 | m_scene.EventManager.TriggerLoginsEnabled(m_scene.RegionInfo.RegionName); | ||
154 | } | 178 | } |
155 | } | 179 | } |
156 | 180 | ||
@@ -165,5 +189,69 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
165 | m_lastOarLoadedOk = false; | 189 | m_lastOarLoadedOk = false; |
166 | } | 190 | } |
167 | } | 191 | } |
192 | |||
193 | void OnLoginsEnabled(string regionName) | ||
194 | { | ||
195 | if (m_disable_logins == true) | ||
196 | { | ||
197 | if (m_scene.StartDisabled == false) | ||
198 | { | ||
199 | m_scene.LoginsDisabled = false; | ||
200 | m_scene.LoginLock = false; | ||
201 | m_log.InfoFormat("[RegionReady]: Logins enabled for {0}", m_scene.RegionInfo.RegionName); | ||
202 | if ( m_uri != string.Empty ) | ||
203 | { | ||
204 | RRAlert("enabled"); | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | public void RRAlert(string status) | ||
211 | { | ||
212 | string request_method = "POST"; | ||
213 | string content_type = "application/json"; | ||
214 | OSDMap RRAlert = new OSDMap(); | ||
215 | |||
216 | RRAlert["alert"] = "region_ready"; | ||
217 | RRAlert["login"] = status; | ||
218 | RRAlert["region_name"] = m_scene.RegionInfo.RegionName; | ||
219 | RRAlert["region_id"] = m_scene.RegionInfo.RegionID; | ||
220 | |||
221 | string strBuffer = ""; | ||
222 | byte[] buffer = new byte[1]; | ||
223 | try | ||
224 | { | ||
225 | strBuffer = OSDParser.SerializeJsonString(RRAlert); | ||
226 | Encoding str = Util.UTF8; | ||
227 | buffer = str.GetBytes(strBuffer); | ||
228 | |||
229 | } | ||
230 | catch (Exception e) | ||
231 | { | ||
232 | m_log.WarnFormat("[RegionReady]: Exception thrown on alert: {0}", e.Message); | ||
233 | } | ||
234 | |||
235 | WebRequest request = WebRequest.Create(m_uri); | ||
236 | request.Method = request_method; | ||
237 | request.ContentType = content_type; | ||
238 | |||
239 | Stream os = null; | ||
240 | try | ||
241 | { | ||
242 | request.ContentLength = buffer.Length; | ||
243 | os = request.GetRequestStream(); | ||
244 | os.Write(buffer, 0, strBuffer.Length); | ||
245 | } | ||
246 | catch(Exception e) | ||
247 | { | ||
248 | m_log.WarnFormat("[RegionReady]: Exception thrown sending alert: {0}", e.Message); | ||
249 | } | ||
250 | finally | ||
251 | { | ||
252 | if (os != null) | ||
253 | os.Close(); | ||
254 | } | ||
255 | } | ||
168 | } | 256 | } |
169 | } | 257 | } |