clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Reflection; |
||
31 | using System.Net; |
||
32 | using System.IO; |
||
33 | using System.Text; |
||
34 | using log4net; |
||
35 | using Mono.Addins; |
||
36 | using Nini.Config; |
||
37 | using OpenMetaverse; |
||
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; |
||
43 | |||
44 | namespace OpenSim.Region.OptionalModules.Scripting.RegionReady |
||
45 | { |
||
46 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RegionReadyModule")] |
||
47 | public class RegionReadyModule : IRegionReadyModule, INonSharedRegionModule |
||
48 | { |
||
49 | private static readonly ILog m_log = |
||
50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
51 | |||
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; |
||
60 | |||
61 | Scene m_scene; |
||
62 | |||
63 | #region INonSharedRegionModule interface |
||
64 | |||
65 | public Type ReplaceableInterface |
||
66 | { |
||
67 | get { return null; } |
||
68 | } |
||
69 | |||
70 | public void Initialise(IConfigSource config) |
||
71 | { |
||
72 | m_config = config.Configs["RegionReady"]; |
||
73 | if (m_config != null) |
||
74 | { |
||
75 | m_enabled = m_config.GetBoolean("enabled", false); |
||
76 | |||
77 | if (m_enabled) |
||
78 | { |
||
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); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | public void AddRegion(Scene scene) |
||
87 | { |
||
88 | if (!m_enabled) |
||
89 | return; |
||
90 | |||
91 | m_scene = scene; |
||
92 | |||
93 | m_scene.RegisterModuleInterface<IRegionReadyModule>(this); |
||
94 | |||
95 | m_firstEmptyCompileQueue = true; |
||
96 | m_oarFileLoading = false; |
||
97 | m_lastOarLoadedOk = true; |
||
98 | |||
99 | m_scene.EventManager.OnOarFileLoaded += OnOarFileLoaded; |
||
100 | |||
101 | m_log.DebugFormat("[RegionReady]: Enabled for region {0}", scene.RegionInfo.RegionName); |
||
102 | |||
103 | if (m_disable_logins) |
||
104 | { |
||
105 | m_scene.LoginLock = true; |
||
106 | m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue; |
||
107 | |||
108 | m_log.InfoFormat("[RegionReady]: Region {0} - LOGINS DISABLED DURING INITIALIZATION.", m_scene.Name); |
||
109 | |||
110 | if (m_uri != string.Empty) |
||
111 | { |
||
112 | RRAlert("disabled"); |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | |||
117 | public void RemoveRegion(Scene scene) |
||
118 | { |
||
119 | if (!m_enabled) |
||
120 | return; |
||
121 | |||
122 | m_scene.EventManager.OnOarFileLoaded -= OnOarFileLoaded; |
||
123 | |||
124 | if (m_disable_logins) |
||
125 | m_scene.EventManager.OnEmptyScriptCompileQueue -= OnEmptyScriptCompileQueue; |
||
126 | |||
127 | if (m_uri != string.Empty) |
||
128 | RRAlert("shutdown"); |
||
129 | |||
130 | m_scene = null; |
||
131 | } |
||
132 | |||
133 | public void Close() |
||
134 | { |
||
135 | } |
||
136 | |||
137 | public void RegionLoaded(Scene scene) |
||
138 | { |
||
139 | } |
||
140 | |||
141 | public string Name |
||
142 | { |
||
143 | get { return "RegionReadyModule"; } |
||
144 | } |
||
145 | |||
146 | #endregion |
||
147 | |||
148 | void OnEmptyScriptCompileQueue(int numScriptsFailed, string message) |
||
149 | { |
||
150 | m_log.DebugFormat("[RegionReady]: Script compile queue empty!"); |
||
151 | |||
152 | if (m_firstEmptyCompileQueue || m_oarFileLoading) |
||
153 | { |
||
154 | OSChatMessage c = new OSChatMessage(); |
||
155 | if (m_firstEmptyCompileQueue) |
||
156 | c.Message = "server_startup,"; |
||
157 | else |
||
158 | c.Message = "oar_file_load,"; |
||
159 | m_firstEmptyCompileQueue = false; |
||
160 | m_oarFileLoading = false; |
||
161 | |||
162 | m_scene.Backup(false); |
||
163 | |||
164 | c.From = "RegionReady"; |
||
165 | if (m_lastOarLoadedOk) |
||
166 | c.Message += "1,"; |
||
167 | else |
||
168 | c.Message += "0,"; |
||
169 | c.Channel = m_channelNotify; |
||
170 | c.Message += numScriptsFailed.ToString() + "," + message; |
||
171 | c.Type = ChatTypeEnum.Region; |
||
172 | c.Position = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30); |
||
173 | c.Sender = null; |
||
174 | c.SenderUUID = UUID.Zero; |
||
175 | c.Scene = m_scene; |
||
176 | |||
177 | m_log.DebugFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}", |
||
178 | m_scene.RegionInfo.RegionName, c.Message, m_channelNotify); |
||
179 | |||
180 | m_scene.EventManager.TriggerOnChatBroadcast(this, c); |
||
181 | |||
182 | TriggerRegionReady(m_scene); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | void OnOarFileLoaded(Guid requestId, List<UUID> loadedScenes, string message) |
||
187 | { |
||
188 | m_oarFileLoading = true; |
||
189 | |||
190 | if (message==String.Empty) |
||
191 | { |
||
192 | m_lastOarLoadedOk = true; |
||
193 | } |
||
194 | else |
||
195 | { |
||
196 | m_log.WarnFormat("[RegionReady]: Oar file load errors: {0}", message); |
||
197 | m_lastOarLoadedOk = false; |
||
198 | } |
||
199 | } |
||
200 | |||
201 | /// <summary> |
||
202 | /// This will be triggered by Scene directly if it contains no scripts on startup. Otherwise it is triggered |
||
203 | /// when the script compile queue is empty after initial region startup. |
||
204 | /// </summary> |
||
205 | /// <param name='scene'></param> |
||
206 | public void TriggerRegionReady(IScene scene) |
||
207 | { |
||
208 | m_scene.EventManager.OnEmptyScriptCompileQueue -= OnEmptyScriptCompileQueue; |
||
209 | m_scene.LoginLock = false; |
||
210 | |||
211 | if (!m_scene.StartDisabled) |
||
212 | { |
||
213 | m_scene.LoginsEnabled = true; |
||
214 | |||
215 | // m_log.InfoFormat("[RegionReady]: Logins enabled for {0}, Oar {1}", |
||
216 | // m_scene.RegionInfo.RegionName, m_oarFileLoading.ToString()); |
||
217 | |||
218 | m_log.InfoFormat( |
||
219 | "[RegionReady]: INITIALIZATION COMPLETE FOR {0} - LOGINS ENABLED", m_scene.Name); |
||
220 | } |
||
221 | |||
222 | m_scene.SceneGridService.InformNeighborsThatRegionisUp( |
||
223 | m_scene.RequestModuleInterface<INeighbourService>(), m_scene.RegionInfo); |
||
224 | |||
225 | if (m_uri != string.Empty) |
||
226 | { |
||
227 | RRAlert("enabled"); |
||
228 | } |
||
229 | |||
230 | m_scene.Ready = true; |
||
231 | } |
||
232 | |||
233 | public void OarLoadingAlert(string msg) |
||
234 | { |
||
235 | // Let's bypass this for now until some better feedback can be established |
||
236 | // |
||
237 | |||
238 | // if (msg == "load") |
||
239 | // { |
||
240 | // m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue; |
||
241 | // m_scene.EventManager.OnOarFileLoaded += OnOarFileLoaded; |
||
242 | // m_scene.EventManager.OnLoginsEnabled += OnLoginsEnabled; |
||
243 | // m_scene.EventManager.OnRezScript += OnRezScript; |
||
244 | // m_oarFileLoading = true; |
||
245 | // m_firstEmptyCompileQueue = true; |
||
246 | // |
||
247 | // m_scene.LoginsDisabled = true; |
||
248 | // m_scene.LoginLock = true; |
||
249 | // if ( m_uri != string.Empty ) |
||
250 | // { |
||
251 | // RRAlert("loading oar"); |
||
252 | // RRAlert("disabled"); |
||
253 | // } |
||
254 | // } |
||
255 | } |
||
256 | |||
257 | public void RRAlert(string status) |
||
258 | { |
||
259 | string request_method = "POST"; |
||
260 | string content_type = "application/json"; |
||
261 | OSDMap RRAlert = new OSDMap(); |
||
262 | |||
263 | RRAlert["alert"] = "region_ready"; |
||
264 | RRAlert["login"] = status; |
||
265 | RRAlert["region_name"] = m_scene.RegionInfo.RegionName; |
||
266 | RRAlert["region_id"] = m_scene.RegionInfo.RegionID; |
||
267 | |||
268 | string strBuffer = ""; |
||
269 | byte[] buffer = new byte[1]; |
||
270 | try |
||
271 | { |
||
272 | strBuffer = OSDParser.SerializeJsonString(RRAlert); |
||
273 | Encoding str = Util.UTF8; |
||
274 | buffer = str.GetBytes(strBuffer); |
||
275 | |||
276 | } |
||
277 | catch (Exception e) |
||
278 | { |
||
279 | m_log.WarnFormat("[RegionReady]: Exception thrown on alert: {0}", e.Message); |
||
280 | } |
||
281 | |||
282 | WebRequest request = WebRequest.Create(m_uri); |
||
283 | request.Method = request_method; |
||
284 | request.ContentType = content_type; |
||
285 | |||
286 | Stream os = null; |
||
287 | try |
||
288 | { |
||
289 | request.ContentLength = buffer.Length; |
||
290 | os = request.GetRequestStream(); |
||
291 | os.Write(buffer, 0, strBuffer.Length); |
||
292 | } |
||
293 | catch(Exception e) |
||
294 | { |
||
295 | m_log.WarnFormat("[RegionReady]: Exception thrown sending alert: {0}", e.Message); |
||
296 | } |
||
297 | finally |
||
298 | { |
||
299 | if (os != null) |
||
300 | os.Close(); |
||
301 | } |
||
302 | } |
||
303 | } |
||
304 | } |