diff options
author | Melanie | 2010-11-25 01:24:32 +0000 |
---|---|---|
committer | Melanie | 2010-11-25 01:24:32 +0000 |
commit | 2c1c04119d11a98cd847c6a86afc8a6e3d6bbe33 (patch) | |
tree | 03e8cf7dbc1b11b424b238b6362a360ac176dbe8 /OpenSim/Region/CoreModules/World | |
parent | Merge branch 'master' into careminster-presence-refactor (diff) | |
parent | Implement the restart module (diff) | |
download | opensim-SC_OLD-2c1c04119d11a98cd847c6a86afc8a6e3d6bbe33.zip opensim-SC_OLD-2c1c04119d11a98cd847c6a86afc8a6e3d6bbe33.tar.gz opensim-SC_OLD-2c1c04119d11a98cd847c6a86afc8a6e3d6bbe33.tar.bz2 opensim-SC_OLD-2c1c04119d11a98cd847c6a86afc8a6e3d6bbe33.tar.xz |
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/CoreModules/World')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Region/RestartModule.cs | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs new file mode 100644 index 0000000..1c26c38 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs | |||
@@ -0,0 +1,204 @@ | |||
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.Reflection; | ||
30 | using System.Timers; | ||
31 | using System.Threading; | ||
32 | using System.Collections.Generic; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using Timer=System.Timers.Timer; | ||
40 | |||
41 | namespace OpenSim.Region.CoreModules.World.Region | ||
42 | { | ||
43 | public class RestartModule : INonSharedRegionModule, IRestartModule | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | protected Scene m_Scene; | ||
49 | protected Timer m_CountdownTimer = null; | ||
50 | protected DateTime m_RestartBegin; | ||
51 | protected List<int> m_Alerts; | ||
52 | protected string m_Message; | ||
53 | protected UUID m_Initiator; | ||
54 | protected bool m_Notice = false; | ||
55 | protected IDialogModule m_DialogModule = null; | ||
56 | |||
57 | public void Initialise(IConfigSource config) | ||
58 | { | ||
59 | } | ||
60 | |||
61 | public void AddRegion(Scene scene) | ||
62 | { | ||
63 | m_Scene = scene; | ||
64 | m_DialogModule = m_Scene.RequestModuleInterface<IDialogModule>(); | ||
65 | } | ||
66 | |||
67 | public void RegionLoaded(Scene scene) | ||
68 | { | ||
69 | } | ||
70 | |||
71 | public void RemoveRegion(Scene scene) | ||
72 | { | ||
73 | } | ||
74 | |||
75 | public void Close() | ||
76 | { | ||
77 | } | ||
78 | |||
79 | public string Name | ||
80 | { | ||
81 | get { return "RestartModule"; } | ||
82 | } | ||
83 | |||
84 | public Type ReplaceableInterface | ||
85 | { | ||
86 | get { return typeof(IRestartModule); } | ||
87 | } | ||
88 | |||
89 | public TimeSpan TimeUntilRestart | ||
90 | { | ||
91 | get { return DateTime.Now - m_RestartBegin; } | ||
92 | } | ||
93 | |||
94 | public void ScheduleRestart(UUID initiator, string message, int[] alerts, bool notice) | ||
95 | { | ||
96 | if (m_CountdownTimer != null) | ||
97 | return; | ||
98 | |||
99 | if (alerts == null) | ||
100 | { | ||
101 | m_Scene.RestartNow(); | ||
102 | return; | ||
103 | } | ||
104 | |||
105 | m_Message = message; | ||
106 | m_Initiator = initiator; | ||
107 | m_Notice = notice; | ||
108 | m_Alerts = new List<int>(alerts); | ||
109 | m_Alerts.Sort(); | ||
110 | m_Alerts.Reverse(); | ||
111 | |||
112 | if (m_Alerts[0] == 0) | ||
113 | { | ||
114 | m_Scene.RestartNow(); | ||
115 | return; | ||
116 | } | ||
117 | |||
118 | int nextInterval = DoOneNotice(); | ||
119 | |||
120 | SetTimer(nextInterval); | ||
121 | } | ||
122 | |||
123 | public int DoOneNotice() | ||
124 | { | ||
125 | if (m_Alerts.Count == 0 || m_Alerts[0] == 0) | ||
126 | { | ||
127 | m_Scene.RestartNow(); | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | int nextAlert = 0; | ||
132 | while (m_Alerts.Count > 1) | ||
133 | { | ||
134 | if (m_Alerts[1] == m_Alerts[0]) | ||
135 | { | ||
136 | m_Alerts.RemoveAt(0); | ||
137 | continue; | ||
138 | } | ||
139 | nextAlert = m_Alerts[1]; | ||
140 | } | ||
141 | |||
142 | int currentAlert = m_Alerts[0]; | ||
143 | |||
144 | m_Alerts.RemoveAt(0); | ||
145 | |||
146 | int minutes = currentAlert / 60; | ||
147 | string currentAlertString = ""; | ||
148 | if (minutes > 0) | ||
149 | { | ||
150 | if (minutes == 1) | ||
151 | currentAlertString += "1 minute"; | ||
152 | else | ||
153 | currentAlertString += String.Format("{0} minutes", minutes); | ||
154 | if ((currentAlert % 60) != 0) | ||
155 | currentAlertString += " and "; | ||
156 | } | ||
157 | if ((currentAlert % 60) != 0) | ||
158 | { | ||
159 | int seconds = currentAlert % 60; | ||
160 | if (seconds == 1) | ||
161 | currentAlertString += "1 second"; | ||
162 | else | ||
163 | currentAlertString += String.Format("{0} seconds", seconds); | ||
164 | } | ||
165 | |||
166 | string msg = String.Format(m_Message, currentAlertString); | ||
167 | |||
168 | if (m_DialogModule != null) | ||
169 | { | ||
170 | if (m_Notice) | ||
171 | m_DialogModule.SendGeneralAlert(msg); | ||
172 | else | ||
173 | m_DialogModule.SendNotificationToUsersInRegion(m_Initiator, "System", msg); | ||
174 | } | ||
175 | |||
176 | return currentAlert - nextAlert; | ||
177 | } | ||
178 | |||
179 | public void SetTimer(int intervalSeconds) | ||
180 | { | ||
181 | m_CountdownTimer = new Timer(); | ||
182 | m_CountdownTimer.AutoReset = false; | ||
183 | m_CountdownTimer.Interval = intervalSeconds * 1000; | ||
184 | m_CountdownTimer.Elapsed += OnTimer; | ||
185 | m_CountdownTimer.Start(); | ||
186 | } | ||
187 | |||
188 | private void OnTimer(object source, ElapsedEventArgs e) | ||
189 | { | ||
190 | int nextInterval = DoOneNotice(); | ||
191 | |||
192 | SetTimer(nextInterval); | ||
193 | } | ||
194 | |||
195 | public void AbortRestart(string message) | ||
196 | { | ||
197 | if (m_CountdownTimer != null) | ||
198 | { | ||
199 | m_CountdownTimer.Stop(); | ||
200 | m_CountdownTimer = null; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | } | ||