diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs | 18 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/World/Region/RestartModule.cs | 263 |
2 files changed, 280 insertions, 1 deletions
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index 622fc08..ddae20f 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs | |||
@@ -231,7 +231,23 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
231 | 231 | ||
232 | private void handleEstateRestartSimRequest(IClientAPI remoteClient, int timeInSeconds) | 232 | private void handleEstateRestartSimRequest(IClientAPI remoteClient, int timeInSeconds) |
233 | { | 233 | { |
234 | m_scene.Restart(timeInSeconds); | 234 | IRestartModule restartModule = m_scene.RequestModuleInterface<IRestartModule>(); |
235 | if (restartModule != null) | ||
236 | { | ||
237 | List<int> times = new List<int>(); | ||
238 | while (timeInSeconds > 0) | ||
239 | { | ||
240 | times.Add(timeInSeconds); | ||
241 | if (timeInSeconds > 300) | ||
242 | timeInSeconds -= 120; | ||
243 | else if (timeInSeconds > 30) | ||
244 | timeInSeconds -= 30; | ||
245 | else | ||
246 | timeInSeconds -= 15; | ||
247 | } | ||
248 | |||
249 | restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true); | ||
250 | } | ||
235 | } | 251 | } |
236 | 252 | ||
237 | private void handleChangeEstateCovenantRequest(IClientAPI remoteClient, UUID estateCovenantID) | 253 | private void handleChangeEstateCovenantRequest(IClientAPI remoteClient, UUID estateCovenantID) |
diff --git a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs new file mode 100644 index 0000000..c65aa6a --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs | |||
@@ -0,0 +1,263 @@ | |||
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.Framework.Console; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using Timer=System.Timers.Timer; | ||
41 | using Mono.Addins; | ||
42 | |||
43 | namespace OpenSim.Region.CoreModules.World.Region | ||
44 | { | ||
45 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RestartModule")] | ||
46 | public class RestartModule : INonSharedRegionModule, IRestartModule | ||
47 | { | ||
48 | private static readonly ILog m_log = | ||
49 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | protected Scene m_Scene; | ||
52 | protected Timer m_CountdownTimer = null; | ||
53 | protected DateTime m_RestartBegin; | ||
54 | protected List<int> m_Alerts; | ||
55 | protected string m_Message; | ||
56 | protected UUID m_Initiator; | ||
57 | protected bool m_Notice = false; | ||
58 | protected IDialogModule m_DialogModule = null; | ||
59 | |||
60 | public void Initialise(IConfigSource config) | ||
61 | { | ||
62 | } | ||
63 | |||
64 | public void AddRegion(Scene scene) | ||
65 | { | ||
66 | m_Scene = scene; | ||
67 | scene.RegisterModuleInterface<IRestartModule>(this); | ||
68 | MainConsole.Instance.Commands.AddCommand("RestartModule", | ||
69 | false, "region restart bluebox", | ||
70 | "region restart bluebox <message> <time> ...", | ||
71 | "Restart the region", HandleRegionRestart); | ||
72 | MainConsole.Instance.Commands.AddCommand("RestartModule", | ||
73 | false, "region restart notice", | ||
74 | "region restart notice <message> <time> ...", | ||
75 | "Restart the region", HandleRegionRestart); | ||
76 | MainConsole.Instance.Commands.AddCommand("RestartModule", | ||
77 | false, "region restart abort", | ||
78 | "region restart abort [<message>]", | ||
79 | "Restart the region", HandleRegionRestart); | ||
80 | } | ||
81 | |||
82 | public void RegionLoaded(Scene scene) | ||
83 | { | ||
84 | m_DialogModule = m_Scene.RequestModuleInterface<IDialogModule>(); | ||
85 | } | ||
86 | |||
87 | public void RemoveRegion(Scene scene) | ||
88 | { | ||
89 | } | ||
90 | |||
91 | public void Close() | ||
92 | { | ||
93 | } | ||
94 | |||
95 | public string Name | ||
96 | { | ||
97 | get { return "RestartModule"; } | ||
98 | } | ||
99 | |||
100 | public Type ReplaceableInterface | ||
101 | { | ||
102 | get { return typeof(IRestartModule); } | ||
103 | } | ||
104 | |||
105 | public TimeSpan TimeUntilRestart | ||
106 | { | ||
107 | get { return DateTime.Now - m_RestartBegin; } | ||
108 | } | ||
109 | |||
110 | public void ScheduleRestart(UUID initiator, string message, int[] alerts, bool notice) | ||
111 | { | ||
112 | if (m_CountdownTimer != null) | ||
113 | return; | ||
114 | |||
115 | if (alerts == null) | ||
116 | { | ||
117 | m_Scene.RestartNow(); | ||
118 | return; | ||
119 | } | ||
120 | |||
121 | m_Message = message; | ||
122 | m_Initiator = initiator; | ||
123 | m_Notice = notice; | ||
124 | m_Alerts = new List<int>(alerts); | ||
125 | m_Alerts.Sort(); | ||
126 | m_Alerts.Reverse(); | ||
127 | |||
128 | if (m_Alerts[0] == 0) | ||
129 | { | ||
130 | m_Scene.RestartNow(); | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | int nextInterval = DoOneNotice(); | ||
135 | |||
136 | SetTimer(nextInterval); | ||
137 | } | ||
138 | |||
139 | public int DoOneNotice() | ||
140 | { | ||
141 | if (m_Alerts.Count == 0 || m_Alerts[0] == 0) | ||
142 | { | ||
143 | m_Scene.RestartNow(); | ||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | int nextAlert = 0; | ||
148 | while (m_Alerts.Count > 1) | ||
149 | { | ||
150 | if (m_Alerts[1] == m_Alerts[0]) | ||
151 | { | ||
152 | m_Alerts.RemoveAt(0); | ||
153 | continue; | ||
154 | } | ||
155 | nextAlert = m_Alerts[1]; | ||
156 | break; | ||
157 | } | ||
158 | |||
159 | int currentAlert = m_Alerts[0]; | ||
160 | |||
161 | m_Alerts.RemoveAt(0); | ||
162 | |||
163 | int minutes = currentAlert / 60; | ||
164 | string currentAlertString = String.Empty; | ||
165 | if (minutes > 0) | ||
166 | { | ||
167 | if (minutes == 1) | ||
168 | currentAlertString += "1 minute"; | ||
169 | else | ||
170 | currentAlertString += String.Format("{0} minutes", minutes); | ||
171 | if ((currentAlert % 60) != 0) | ||
172 | currentAlertString += " and "; | ||
173 | } | ||
174 | if ((currentAlert % 60) != 0) | ||
175 | { | ||
176 | int seconds = currentAlert % 60; | ||
177 | if (seconds == 1) | ||
178 | currentAlertString += "1 second"; | ||
179 | else | ||
180 | currentAlertString += String.Format("{0} seconds", seconds); | ||
181 | } | ||
182 | |||
183 | string msg = String.Format(m_Message, currentAlertString); | ||
184 | |||
185 | if (m_DialogModule != null && msg != String.Empty) | ||
186 | { | ||
187 | if (m_Notice) | ||
188 | m_DialogModule.SendGeneralAlert(msg); | ||
189 | else | ||
190 | m_DialogModule.SendNotificationToUsersInRegion(m_Initiator, "System", msg); | ||
191 | } | ||
192 | |||
193 | return currentAlert - nextAlert; | ||
194 | } | ||
195 | |||
196 | public void SetTimer(int intervalSeconds) | ||
197 | { | ||
198 | m_CountdownTimer = new Timer(); | ||
199 | m_CountdownTimer.AutoReset = false; | ||
200 | m_CountdownTimer.Interval = intervalSeconds * 1000; | ||
201 | m_CountdownTimer.Elapsed += OnTimer; | ||
202 | m_CountdownTimer.Start(); | ||
203 | } | ||
204 | |||
205 | private void OnTimer(object source, ElapsedEventArgs e) | ||
206 | { | ||
207 | int nextInterval = DoOneNotice(); | ||
208 | |||
209 | SetTimer(nextInterval); | ||
210 | } | ||
211 | |||
212 | public void AbortRestart(string message) | ||
213 | { | ||
214 | if (m_CountdownTimer != null) | ||
215 | { | ||
216 | m_CountdownTimer.Stop(); | ||
217 | m_CountdownTimer = null; | ||
218 | if (m_DialogModule != null && message != String.Empty) | ||
219 | m_DialogModule.SendGeneralAlert(message); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | private void HandleRegionRestart(string module, string[] args) | ||
224 | { | ||
225 | if (!(MainConsole.Instance.ConsoleScene is Scene)) | ||
226 | return; | ||
227 | |||
228 | if (MainConsole.Instance.ConsoleScene != m_Scene) | ||
229 | return; | ||
230 | |||
231 | if (args.Length < 5) | ||
232 | { | ||
233 | if (args.Length > 2) | ||
234 | { | ||
235 | if (args[2] == "abort") | ||
236 | { | ||
237 | string msg = String.Empty; | ||
238 | if (args.Length > 3) | ||
239 | msg = args[3]; | ||
240 | |||
241 | AbortRestart(msg); | ||
242 | |||
243 | MainConsole.Instance.Output("Region restart aborted"); | ||
244 | return; | ||
245 | } | ||
246 | } | ||
247 | |||
248 | MainConsole.Instance.Output("Error: restart region <mode> <name> <time> ..."); | ||
249 | return; | ||
250 | } | ||
251 | |||
252 | bool notice = false; | ||
253 | if (args[2] == "notice") | ||
254 | notice = true; | ||
255 | |||
256 | List<int> times = new List<int>(); | ||
257 | for (int i = 4 ; i < args.Length ; i++) | ||
258 | times.Add(Convert.ToInt32(args[i])); | ||
259 | |||
260 | ScheduleRestart(UUID.Zero, args[3], times.ToArray(), notice); | ||
261 | } | ||
262 | } | ||
263 | } | ||