diff options
author | Melanie | 2010-11-25 01:22:05 +0000 |
---|---|---|
committer | Melanie | 2010-11-25 01:22:05 +0000 |
commit | 6734c9f83ae00b762873c3d99293435552b9a0c2 (patch) | |
tree | 2ec1179910897c50d204882357251696f56fb85d /OpenSim/Region/CoreModules | |
parent | Adding the skeleton for the restart module (diff) | |
download | opensim-SC_OLD-6734c9f83ae00b762873c3d99293435552b9a0c2.zip opensim-SC_OLD-6734c9f83ae00b762873c3d99293435552b9a0c2.tar.gz opensim-SC_OLD-6734c9f83ae00b762873c3d99293435552b9a0c2.tar.bz2 opensim-SC_OLD-6734c9f83ae00b762873c3d99293435552b9a0c2.tar.xz |
Implement the restart module
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Region/RestartModule.cs | 115 |
1 files changed, 113 insertions, 2 deletions
diff --git a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs index a92a28d..1c26c38 100644 --- a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs +++ b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs | |||
@@ -29,6 +29,7 @@ using System; | |||
29 | using System.Reflection; | 29 | using System.Reflection; |
30 | using System.Timers; | 30 | using System.Timers; |
31 | using System.Threading; | 31 | using System.Threading; |
32 | using System.Collections.Generic; | ||
32 | using log4net; | 33 | using log4net; |
33 | using Nini.Config; | 34 | using Nini.Config; |
34 | using OpenMetaverse; | 35 | using OpenMetaverse; |
@@ -46,6 +47,12 @@ namespace OpenSim.Region.CoreModules.World.Region | |||
46 | 47 | ||
47 | protected Scene m_Scene; | 48 | protected Scene m_Scene; |
48 | protected Timer m_CountdownTimer = null; | 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; | ||
49 | 56 | ||
50 | public void Initialise(IConfigSource config) | 57 | public void Initialise(IConfigSource config) |
51 | { | 58 | { |
@@ -54,6 +61,7 @@ namespace OpenSim.Region.CoreModules.World.Region | |||
54 | public void AddRegion(Scene scene) | 61 | public void AddRegion(Scene scene) |
55 | { | 62 | { |
56 | m_Scene = scene; | 63 | m_Scene = scene; |
64 | m_DialogModule = m_Scene.RequestModuleInterface<IDialogModule>(); | ||
57 | } | 65 | } |
58 | 66 | ||
59 | public void RegionLoaded(Scene scene) | 67 | public void RegionLoaded(Scene scene) |
@@ -80,14 +88,117 @@ namespace OpenSim.Region.CoreModules.World.Region | |||
80 | 88 | ||
81 | public TimeSpan TimeUntilRestart | 89 | public TimeSpan TimeUntilRestart |
82 | { | 90 | { |
83 | get { return TimeSpan.FromSeconds(0); } | 91 | get { return DateTime.Now - m_RestartBegin; } |
84 | } | 92 | } |
85 | public void ScheduleRestart(UUID initiator, string message, int seconds, int[] alerts, bool notice) | 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) | ||
86 | { | 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); | ||
87 | } | 193 | } |
88 | 194 | ||
89 | public void AbortRestart(string message) | 195 | public void AbortRestart(string message) |
90 | { | 196 | { |
197 | if (m_CountdownTimer != null) | ||
198 | { | ||
199 | m_CountdownTimer.Stop(); | ||
200 | m_CountdownTimer = null; | ||
201 | } | ||
91 | } | 202 | } |
92 | } | 203 | } |
93 | } | 204 | } |