diff options
author | Dr Scofield | 2009-02-11 14:35:07 +0000 |
---|---|---|
committer | Dr Scofield | 2009-02-11 14:35:07 +0000 |
commit | f70e580f861e4dc0c3f9224491478d22320cf5f2 (patch) | |
tree | b764a9abb2f42f93d855bad0eea258a61e36537a /OpenSim/Region | |
parent | If an instance contains only one region, select it in the console by default (diff) | |
download | opensim-SC_OLD-f70e580f861e4dc0c3f9224491478d22320cf5f2.zip opensim-SC_OLD-f70e580f861e4dc0c3f9224491478d22320cf5f2.tar.gz opensim-SC_OLD-f70e580f861e4dc0c3f9224491478d22320cf5f2.tar.bz2 opensim-SC_OLD-f70e580f861e4dc0c3f9224491478d22320cf5f2.tar.xz |
From: Christopher Yeoh <yeohc@au1.ibm.com>
This changeset add the RegionReady module code. The module sends a
message on a configurable channel when an oar file has finished
loading or if the script engine has emptied its queue for the first
time (eg server startup). Config is something like this:
[RegionReady]
enabled = true
channel_notify = -800
The module also knows if there was an error with startup.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/RegionReady/RegionReady.cs | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReady/RegionReady.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReady/RegionReady.cs new file mode 100644 index 0000000..c68d1cb --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/RegionReady/RegionReady.cs | |||
@@ -0,0 +1,146 @@ | |||
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 OpenSim 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 | |||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | |||
40 | namespace OpenSim.Region.CoreModules.Scripting.RegionReady | ||
41 | { | ||
42 | public class RegionReady : IRegionModule | ||
43 | { | ||
44 | private readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | private IConfig m_config = null; | ||
46 | private bool m_firstEmptyCompileQueue; | ||
47 | private bool m_oarFileLoading; | ||
48 | private bool m_lastOarLoadedOk; | ||
49 | private int m_channelNotify = -1000; | ||
50 | private bool m_enabled = false; | ||
51 | |||
52 | Scene m_scene = null; | ||
53 | |||
54 | #region IRegionModule interface | ||
55 | |||
56 | public void Initialise(Scene scene, IConfigSource config) | ||
57 | { | ||
58 | m_log.Info("[RegionReady] Initialising"); | ||
59 | m_scene = scene; | ||
60 | m_firstEmptyCompileQueue = true; | ||
61 | m_oarFileLoading = false; | ||
62 | m_lastOarLoadedOk = true; | ||
63 | m_config = config.Configs["RegionReady"]; | ||
64 | |||
65 | if (m_config != null) | ||
66 | { | ||
67 | m_enabled = m_config.GetBoolean("enabled", false); | ||
68 | if (m_enabled) | ||
69 | { | ||
70 | m_channelNotify = m_config.GetInt("channel_notify", m_channelNotify); | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | public void PostInitialise() | ||
76 | { | ||
77 | if (m_enabled) | ||
78 | { | ||
79 | m_log.Info("[RegionReady] Enabled"); | ||
80 | m_scene.EventManager.OnEmptyScriptCompileQueue += new EventManager.EmptyScriptCompileQueue(OnEmptyScriptCompileQueue); | ||
81 | m_scene.EventManager.OnOarFileLoaded += new EventManager.OarFileLoaded(OnOarFileLoaded); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | m_log.Info("[RegionReady] Disabled"); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | public void Close() | ||
90 | { | ||
91 | } | ||
92 | |||
93 | public string Name | ||
94 | { | ||
95 | get { return "Region Ready Module"; } | ||
96 | } | ||
97 | |||
98 | public bool IsSharedModule | ||
99 | { | ||
100 | get { return false; } | ||
101 | } | ||
102 | |||
103 | #endregion | ||
104 | |||
105 | |||
106 | void OnEmptyScriptCompileQueue(int numScriptsFailed, string message) | ||
107 | { | ||
108 | if (m_firstEmptyCompileQueue || m_oarFileLoading) | ||
109 | { | ||
110 | m_firstEmptyCompileQueue = false; | ||
111 | m_oarFileLoading = false; | ||
112 | |||
113 | m_scene.Backup(); | ||
114 | |||
115 | OSChatMessage c = new OSChatMessage(); | ||
116 | c.From = "RegionReady"; | ||
117 | if (m_lastOarLoadedOk) | ||
118 | c.Message = "1,"; | ||
119 | else | ||
120 | c.Message = "0,"; | ||
121 | c.Channel = m_channelNotify; | ||
122 | c.Message += numScriptsFailed.ToString() + "," + message; | ||
123 | c.Type = ChatTypeEnum.Region; | ||
124 | c.Position = new Vector3(128, 128, 30); | ||
125 | c.Sender = null; | ||
126 | c.SenderUUID = UUID.Zero; | ||
127 | |||
128 | m_log.InfoFormat("[RegionReady] Region is ready: \"{0}\" on channel {1}", | ||
129 | c.Message, m_channelNotify); | ||
130 | m_scene.EventManager.TriggerOnChatBroadcast(this, c); | ||
131 | } | ||
132 | } | ||
133 | |||
134 | void OnOarFileLoaded(string message) | ||
135 | { | ||
136 | m_oarFileLoading = true; | ||
137 | if (message==String.Empty) | ||
138 | { | ||
139 | m_lastOarLoadedOk = true; | ||
140 | } else { | ||
141 | m_log.InfoFormat("[RegionReady] Oar file load errors: {0}", message); | ||
142 | m_lastOarLoadedOk = false; | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | } | ||